summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-05-25 13:33:37 +0200
committeremkael <emkael@tlen.pl>2019-05-25 13:33:37 +0200
commitdea76ab5f260d3a009237dcc59ca998edfd522be (patch)
tree8ce0388e83a77461ef4be45b2b9dbc0540b2edd6
parent9aef8ec85fa1b4b8db4274c33b99e5773f4f4242 (diff)
Team source settings GUI
-rw-r--r--jfr_playoff/gui/frames.py153
-rw-r--r--jfr_playoff/gui/tabs.py24
2 files changed, 173 insertions, 4 deletions
diff --git a/jfr_playoff/gui/frames.py b/jfr_playoff/gui/frames.py
new file mode 100644
index 0000000..80e296c
--- /dev/null
+++ b/jfr_playoff/gui/frames.py
@@ -0,0 +1,153 @@
+#coding=utf-8
+
+import tkinter as tk
+from tkinter import ttk
+import tkMessageBox
+
+class TeamSelectionFrame(tk.Frame):
+ def __init__(self, master, title='', teams=[],
+ selected=None, callback=None):
+ tk.Frame.__init__(self, master=master)
+ self.values = []
+ self.renderContent(title, teams, selected)
+ self.callback = callback
+
+ def _save(self):
+ if self.callback:
+ self.callback(
+ [idx+1 for idx, value
+ in enumerate(self.values) if value.get()])
+ self.master.destroy()
+
+ def renderContent(self, title, teams, selected):
+ self.columnconfigure(1, weight=1)
+ (ttk.Label(self, text=title)).grid(row=0, column=0, columnspan=2)
+ row = 1
+ for team in teams:
+ (ttk.Label(self, text='[%d]' % (row))).grid(row=row, column=0)
+ self.values.append(tk.IntVar())
+ (ttk.Checkbutton(
+ self, text=team[0],
+ variable=self.values[row-1]
+ )).grid(row=row, column=1, sticky=tk.W)
+ if selected and selected(row-1, team):
+ self.values[row-1].set(True)
+ row += 1
+ (ttk.Button(self, text='Zapisz', command=self._save)).grid(
+ row=row, column=0, columnspan=2)
+
+class TeamFetchSettingsFrame(tk.Frame):
+ SOURCE_LINK = 0
+ SOURCE_DB = 1
+
+ def __init__(self, *args, **kwargs):
+ tk.Frame.__init__(self, *args, **kwargs)
+ self.renderContent()
+
+ def _setFinishingPositions(self, positions):
+ self.finishingPositions = positions
+ self.finishingPositionsBtn.configure(
+ text='[wybrano: %d]' % (len(self.finishingPositions)))
+
+ def _chooseFinishingPositions(self):
+ if not self.master.teams:
+ tkMessageBox.showerror(
+ 'Wybór teamów', 'W turnieju nie ma teamów do wyboru')
+ self._setFinishingPositions([])
+ else:
+ dialog = tk.Toplevel(self)
+ selectionFrame = TeamSelectionFrame(
+ dialog, title='Wybierz teamy, które zakończyły rozgrywki ' + \
+ 'na swojej pozycji:',
+ teams=self.master.teams,
+ selected=lambda idx, team: idx+1 in self.finishingPositions,
+ callback=self._setFinishingPositions)
+ selectionFrame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
+
+
+ def renderContent(self):
+ (ttk.Label(self, text=' ')).grid(row=0, column=0, rowspan=2)
+
+ self.fetchSource = tk.IntVar()
+ self.fetchSource.set(self.SOURCE_LINK)
+ (ttk.Radiobutton(
+ self, text='Baza danych',
+ variable=self.fetchSource, value=self.SOURCE_DB)).grid(
+ row=0, column=1, columnspan=2, sticky=tk.W)
+ self.fetchDB = tk.StringVar()
+ (ttk.OptionMenu(self, self.fetchDB, '')).grid(
+ row=0, column=3, sticky=tk.W+tk.E)
+
+ (ttk.Radiobutton(
+ self, text='Strona wyników',
+ variable=self.fetchSource, value=self.SOURCE_LINK)).grid(
+ row=1, column=1, columnspan=2, sticky=tk.W)
+ self.fetchLink = ttk.Entry(self, width=20)
+ self.fetchLink.grid(row=1, column=3)
+
+ (ttk.Label(self, text='Pobierz do ')).grid(
+ row=2, column=0, columnspan=2, sticky=tk.W)
+ self.fetchLimit = tk.Spinbox(self, from_=0, value=0,
+ width=5, justify=tk.RIGHT)
+ self.fetchLimit.grid(row=2, column=2, sticky=tk.W)
+ (ttk.Label(self, text=' miejsca (0 = wszystkie)')).grid(
+ row=2, column=3, sticky=tk.W+tk.E)
+
+ (ttk.Label(self, text='Pozycje końcowe: ')).grid(
+ row=3, column=0, columnspan=3, sticky=tk.W+tk.E)
+ self.finishingPositionsBtn = ttk.Button(
+ self, command=self._chooseFinishingPositions)
+ self.finishingPositionsBtn.grid(row=3, column=3, sticky=tk.W)
+ self._setFinishingPositions([])
+
+class TeamSettingsFrame(tk.Frame):
+ FORMAT_FETCH = 0
+ FORMAT_MANUAL = 1
+
+ def __init__(self, *args, **kwargs):
+ tk.Frame.__init__(self, *args, **kwargs)
+ self.renderContent()
+
+ def _setPanelState(self, frame, state):
+ for child in frame.winfo_children():
+ child.configure(state=state)
+
+ def _enablePanels(self, *args):
+ panels = {self.FORMAT_FETCH: self.fetchSettingsFrame}
+ for value, panel in panels.iteritems():
+ self._setPanelState(
+ frame=panel,
+ state=tk.NORMAL \
+ if self.teamFormat.get()==value else tk.DISABLED)
+
+ def setTeams(self, teams):
+ self.teams = teams
+ # emit event or sth
+
+ def renderContent(self):
+ self.teamFormat = tk.IntVar()
+ self.teamFormat.trace('w', self._enablePanels)
+
+ (ttk.Radiobutton(
+ self, text='Pobierz z JFR Teamy:',
+ variable=self.teamFormat, value=self.FORMAT_FETCH)).grid(
+ row=0, column=0, sticky=tk.W)
+
+ self.fetchSettingsFrame = TeamFetchSettingsFrame(self)
+ self.fetchSettingsFrame.grid(row=1, column=0, sticky=tk.W+tk.E)
+
+ (ttk.Separator(
+ self, orient=tk.HORIZONTAL)).grid(
+ row=2, column=0, sticky=tk.W+tk.E)
+
+ (ttk.Radiobutton(
+ self, text='Ustaw ręcznie:',
+ variable=self.teamFormat, value=self.FORMAT_MANUAL)).grid(
+ row=3, column=0, sticky=tk.W+tk.E)
+
+ self.teamFormat.set(self.FORMAT_FETCH)
+ self.setTeams([
+ ['Drużyna nr 1', 'TEAM1', None, None],
+ ['Drużyna nr 2', 'TEAM2', None, None],
+ ['Drużyna nr 3', 'TEAM3', None, None]
+ ])
diff --git a/jfr_playoff/gui/tabs.py b/jfr_playoff/gui/tabs.py
index ab70968..691bb6c 100644
--- a/jfr_playoff/gui/tabs.py
+++ b/jfr_playoff/gui/tabs.py
@@ -6,6 +6,8 @@ import tkinter as tk
from tkinter import ttk
import tkFileDialog as tkfd
+from .frames import TeamSettingsFrame
+
class PlayoffTab(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master)
@@ -46,9 +48,9 @@ class MainSettingsTab(PlayoffTab):
outputPath = tk.Frame(container)
outputPath.grid(row=0, column=1, sticky=tk.E+tk.W, pady=2)
self.outputPath = tk.StringVar()
- (tk.Entry(outputPath, width=60, textvariable=self.outputPath)).grid(
+ (ttk.Entry(outputPath, width=60, textvariable=self.outputPath)).grid(
row=0, column=0, sticky=tk.W+tk.E)
- (tk.Button(
+ (ttk.Button(
outputPath,
text='[]', command=self._chooseOutputPath)).grid(row=0, column=1)
outputPath.columnconfigure(0, weight=1)
@@ -75,13 +77,13 @@ class MainSettingsTab(PlayoffTab):
refreshPanel = tk.Frame(container)
refreshPanel.grid(row=5, column=1, sticky=tk.W+tk.E, pady=2)
self.refresh = tk.IntVar()
- (tk.Checkbutton(
+ (ttk.Checkbutton(
refreshPanel,
command=self._updateRefreshFields, variable=self.refresh)).grid(
row=0, column=0)
(ttk.Label(refreshPanel, text='co:')).grid(row=0, column=1)
self.refreshInterval = tk.Spinbox(
- refreshPanel, from_=30, to=3600, width=5)
+ refreshPanel, from_=30, to=3600, width=5, justify=tk.RIGHT)
self.refreshInterval.grid(row=0, column=2)
(ttk.Label(refreshPanel, text='sekund')).grid(row=0, column=3)
self._updateRefreshFields()
@@ -94,6 +96,20 @@ class TeamsTab(PlayoffTab):
def title(self):
return 'Uczestnicy'
+ def renderContent(self, container):
+ settingsFrame = TeamSettingsFrame(container, padx=5, pady=5)
+ settingsFrame.grid(row=0, column=0, sticky=tk.N+tk.E+tk.S+tk.W)
+ settingsFrame.columnconfigure(2, weight=1)
+ previewFrame = tk.Frame(container, bg='red')
+ previewFrame.grid(row=0, column=1, sticky=tk.N+tk.E+tk.S+tk.W)
+ aliasFrame = tk.Frame(container, bg='green')
+ aliasFrame.grid(row=1, column=0, columnspan=2,
+ sticky=tk.N+tk.E+tk.S+tk.W)
+ container.columnconfigure(0, weight=2)
+ container.columnconfigure(1, weight=3)
+ container.rowconfigure(0, weight=2)
+ container.rowconfigure(1, weight=1)
+
class MatchesTab(PlayoffTab):
@property
def title(self):