summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-01-10 00:40:13 +0100
committeremkael <emkael@tlen.pl>2017-01-10 00:40:13 +0100
commitc5d4e6e943ecc5c2b47942ab9dbd091601b4328b (patch)
tree75226c5eaa1b07b2627659253f6a98a001228a9c
Initial GUI experiments
-rw-r--r--playoff_gui.py133
1 files changed, 133 insertions, 0 deletions
diff --git a/playoff_gui.py b/playoff_gui.py
new file mode 100644
index 0000000..9bdef67
--- /dev/null
+++ b/playoff_gui.py
@@ -0,0 +1,133 @@
+# encoding=utf-8
+
+import random
+
+import tkinter as tk
+
+class PlayoffGUI(tk.Frame):
+
+ def __on_scroll(self, event):
+ if event.state == 0:
+ self.canvas.yview_scroll(-event.delta/100, tk.UNITS)
+ if event.state == 1:
+ self.canvas.xview_scroll(-event.delta/100, tk.UNITS)
+
+ def __on_frame_configure(self, event):
+ self.master.configure(scrollregion=self.master.bbox(tk.ALL))
+
+ def __init__(self, *args, **kwargs):
+ master = kwargs['master']
+ self.canvas = tk.Canvas(master=master)
+
+ self.h_scrollbar = tk.Scrollbar(master=master, orient=tk.HORIZONTAL, command=self.canvas.xview)
+ self.h_scrollbar.pack(side=tk.BOTTOM, fill=tk.X)
+
+ self.v_scrollbar = tk.Scrollbar(master=master, orient=tk.VERTICAL, command=self.canvas.yview)
+ self.v_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
+
+ self.canvas.configure(xscrollcommand=self.h_scrollbar.set, yscrollcommand=self.v_scrollbar.set)
+ self.canvas.bind_all('<MouseWheel>', self.__on_scroll)
+
+ self.canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
+
+ kwargs['master'] = self.canvas
+ tk.Frame.__init__(self, *args, **kwargs)
+
+ self.bind('<Configure>', self.__on_frame_configure)
+ self.master.create_window((0,0), window=self, anchor=tk.N+tk.W)
+
+ self.phase_count = 0
+
+ def add_phase(self, phase):
+ phase.grid(row=0, column=self.phase_count)
+ self.phase_count += 1
+
+class PlayoffPhaseGUI(tk.Frame):
+ def __init__(self, *args, **kwargs):
+ tk.Frame.__init__(self, *args, **kwargs)
+ self.match_count = 0
+
+ def add_match(self, match):
+ match.grid(column=0, row=self.match_count)
+ self.match_count += 1
+
+class PlayoffMatchGUI(tk.Frame):
+
+ def __init__(self, *args, **kwargs):
+ tk.Frame.__init__(self, *args, **kwargs)
+ self.table = tk.StringVar(master=self)
+ self.team_names = [
+ tk.StringVar(master=self),
+ tk.StringVar(master=self)
+ ]
+ self.team_results = [
+ tk.DoubleVar(master=self),
+ tk.DoubleVar(master=self)
+ ]
+ self.winners = tk.StringVar
+ self.losers = tk.StringVar
+
+ self.phase = kwargs['phase'] if 'phase' in kwargs else None
+
+ self.__create_widgets()
+
+ def __create_widgets(self):
+ for row in range(0, 2):
+ team_label = tk.Label(
+ self, textvariable=self.team_names[row],
+ font=('Arial', 16))
+ team_label.grid(row=row, column=1)
+ if self.phase is not None and self.phase.number == 1:
+ team_edit_btn = tk.Button(
+ self, text='#')
+ team_edit_btn.grid(row=row, column=2)
+ score_label = tk.Label(
+ self, textvariable=self.team_results[row],
+ font=('Arial', 16))
+ score_label.grid(row=row, column=3)
+ table_label = tk.Label(
+ self, textvariable=self.table)
+ table_label.grid(row=2, column=1, columnspan=3)
+
+ def set_data(self, match):
+ self.table.set('%s, R%d, T%d' % (match.database_name,
+ match.round_no,
+ match.table_no))
+ for team in range(0, 2):
+ self.team_names[team].set('Team A/Team B')
+ self.team_results[team].set('%.2f' % random.uniform(10.0, 30.0))
+
+ def get_match(self, match):
+ pass
+
+class PlayoffMatch(object):
+ id_number = None
+ database_name = ''
+ round_no = 0
+ table_no = 0
+ input_teams = [
+ [], []
+ ]
+ winner = []
+ loser = []
+
+root = tk.Tk()
+root.state('zoomed')
+
+frame = PlayoffGUI(master=root)
+
+for j in range(0, 9):
+ phase_gui = PlayoffPhaseGUI(master=frame)
+ for i in range(0, 10):
+ match = PlayoffMatch()
+ match.database_name = 'ivld_r3'
+ match.round_no = 1
+ match.table_no = 1
+
+ match_gui = PlayoffMatchGUI(master=phase_gui)
+ match_gui.set_data(match)
+ phase_gui.add_match(match_gui)
+
+ frame.add_phase(phase_gui)
+
+root.mainloop()