summaryrefslogtreecommitdiff
path: root/jfr_playoff/gui
diff options
context:
space:
mode:
Diffstat (limited to 'jfr_playoff/gui')
-rw-r--r--jfr_playoff/gui/frames/__init__.py22
-rw-r--r--jfr_playoff/gui/frames/team.py8
-rw-r--r--jfr_playoff/gui/frames/visual.py26
3 files changed, 37 insertions, 19 deletions
diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py
index dba30a5..9939626 100644
--- a/jfr_playoff/gui/frames/__init__.py
+++ b/jfr_playoff/gui/frames/__init__.py
@@ -315,6 +315,8 @@ class RefreshableOptionMenu(ttk.OptionMenu):
def __init__(self, *args, **kwargs):
ttk.OptionMenu.__init__(self, *args, **kwargs)
self.refreshOptions()
+ self._variable.trace('w', self._valueSet)
+ self._valueLock = False
def refreshOptions(self, *args):
oldValue = self._variable.get()
@@ -327,8 +329,28 @@ class RefreshableOptionMenu(ttk.OptionMenu):
self._variable.set('')
def getOptions(self):
+ return [self.getLabel(value) for value in self.getValues()]
+
+ def getLabel(self, value):
+ pass
+
+ def getValues(self):
pass
+ def cmpValue(self, value):
+ return self._variable.get().strip() == self.getLabel(value)
+
+ def _valueSet(self, *args):
+ if not self._valueLock:
+ self._valueLock = True
+ for idx, value in self.getValues():
+ if self.cmpValue(value):
+ self._variable.set(self.getLabel(value))
+ self._valueLock = False
+ return
+ self._variable.set('')
+ self._valueLock = False
+
class TraceableText(tk.Text):
def __init__(self, *args, **kwargs):
self._variable = None
diff --git a/jfr_playoff/gui/frames/team.py b/jfr_playoff/gui/frames/team.py
index 28ffeba..d389206 100644
--- a/jfr_playoff/gui/frames/team.py
+++ b/jfr_playoff/gui/frames/team.py
@@ -283,8 +283,12 @@ class TeamList(RefreshableOptionMenu):
'<<TeamListChanged>>', self.refreshOptions, add='+')
self.configure(width=10)
- def getOptions(self):
- return [team[0] for team in self.winfo_toplevel().getTeams()]
+ def getLabel(self, team):
+ return team[0]
+
+ def getValues(self):
+ return self.winfo_toplevel().getTeams()
+
class TeamAliasRow(RepeatableFrame):
def renderContent(self):
diff --git a/jfr_playoff/gui/frames/visual.py b/jfr_playoff/gui/frames/visual.py
index ecc6e03..375025d 100644
--- a/jfr_playoff/gui/frames/visual.py
+++ b/jfr_playoff/gui/frames/visual.py
@@ -185,23 +185,15 @@ class MatchList(RefreshableOptionMenu):
self.winfo_toplevel().bind(
'<<MatchListChanged>>', self.refreshOptions, add='+')
self.configure(width=10)
- self._variable.trace('w', self._valueSet)
- self._valueLock = False
-
- def getOptions(self):
- return [match.label for match in self.winfo_toplevel().getMatches()]
-
- def _valueSet(self, *args):
- if not self._valueLock:
- self._valueLock = True
- value = getIntVal(self._variable, 0)
- for match in self.winfo_toplevel().getMatches():
- if match.id == value:
- self._variable.set(match.label)
- self._valueLock = False
- return
- self._variable.set('')
- self._valueLock = False
+
+ def getLabel(self, match):
+ return match.label
+
+ def getValues(self):
+ return self.winfo_toplevel().getMatches()
+
+ def cmpValue(self, match):
+ return match.id == getIntVal(self._variable, 0)
class BoxPositionFrame(RepeatableFrame):