From e932dc7e2e45cdd56f7ef5148335f758dbb26a7b Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 23 Jun 2019 12:40:00 +0200 Subject: Refreshing match list dropdowns on match list change --- jfr_playoff/gui/frames/__init__.py | 18 ++++++++++++++++++ jfr_playoff/gui/frames/match.py | 8 +++++++- jfr_playoff/gui/frames/visual.py | 16 ++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'jfr_playoff/gui') diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py index 4c4950e..50860b1 100644 --- a/jfr_playoff/gui/frames/__init__.py +++ b/jfr_playoff/gui/frames/__init__.py @@ -308,3 +308,21 @@ class SelectionFrame(ScrollableFrame): self.renderOption(container, option, idx) if self.selected and self.selected(idx, option): self.values[idx].set(True) + +class RefreshableOptionMenu(ttk.OptionMenu): + def __init__(self, *args, **kwargs): + ttk.OptionMenu.__init__(self, *args, **kwargs) + self.refreshOptions() + + def refreshOptions(self, *args): + oldValue = self._variable.get() + options = self.getOptions() + self['menu'].delete(0, tk.END) + for option in options: + self['menu'].add_command( + label=option, command=tk._setit(self._variable, option)) + if oldValue not in options: + self._variable.set('') + + def getOptions(self): + pass diff --git a/jfr_playoff/gui/frames/match.py b/jfr_playoff/gui/frames/match.py index 6772e6b..ceaeec2 100644 --- a/jfr_playoff/gui/frames/match.py +++ b/jfr_playoff/gui/frames/match.py @@ -163,7 +163,7 @@ class MatchSelectionFrame(SelectionFrame): (ttk.Label(container, text='[%d]' % (idx+1))).grid( row=idx+1, column=0) (ttk.Checkbutton( - container, text='Mecz nr %d' % (option.getMatchID()), + container, text=option.label, variable=self.values[idx] )).grid(row=idx+1, column=1, sticky=tk.W) @@ -360,6 +360,8 @@ class MatchSettingsFrame(RepeatableFrame): self.source.set(self.SCORE_SOURCE_CUSTOM) + self.winfo_toplevel().event_generate( + '<>', when='tail') @classmethod def info(cls): @@ -368,6 +370,10 @@ class MatchSettingsFrame(RepeatableFrame): def getMatchID(self): return self.matchID + @property + def label(self): + return 'Mecz nr %d' % (self.getMatchID()) + class MatchSeparator(RepeatableFrame): def renderContent(self): (ttk.Separator(self, orient=tk.HORIZONTAL)).pack( diff --git a/jfr_playoff/gui/frames/visual.py b/jfr_playoff/gui/frames/visual.py index b36a5ec..372f02f 100644 --- a/jfr_playoff/gui/frames/visual.py +++ b/jfr_playoff/gui/frames/visual.py @@ -6,7 +6,7 @@ import tkColorChooser as tkcc from ..frames import GuiFrame, RepeatableFrame, ScrollableFrame from ..frames import WidgetRepeater -from ..frames import SelectionFrame +from ..frames import SelectionFrame, RefreshableOptionMenu from ..frames.team import TeamSelectionButton class VisualSettingsFrame(GuiFrame): @@ -141,13 +141,25 @@ class VisualSettingsFrame(GuiFrame): field.configure(state=tk.NORMAL if var.get() else tk.DISABLED) +class MatchList(RefreshableOptionMenu): + def __init__(self, *args, **kwargs): + RefreshableOptionMenu.__init__(self, *args, **kwargs) + self.winfo_toplevel().bind( + '<>', self.refreshOptions, add='+') + self.configure(width=10) + + def getOptions(self): + return [match.label for match in self.winfo_toplevel().getMatches()] + + class BoxPositionFrame(RepeatableFrame): def renderContent(self): self.match = tk.StringVar() self.vertical = tk.IntVar() self.horizontal = tk.IntVar() self.horizontal.set(-1) - (ttk.OptionMenu(self, self.match)).grid(row=0, column=0) + self.matchBox = MatchList(self, self.match) + self.matchBox.grid(row=0, column=0) (ttk.Label(self, text=' w pionie:')).grid(row=0, column=1) (tk.Spinbox( self, textvariable=self.vertical, from_=0, to=9999, -- cgit v1.2.3