summaryrefslogtreecommitdiff
path: root/jfr_playoff/gui/frames/__init__.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-06-27 20:44:23 +0200
committeremkael <emkael@tlen.pl>2019-06-27 20:44:23 +0200
commit69c0e0733b6c254e798bfd75569d80d220eb4a15 (patch)
treecb789c8f30d3082c2760b8bba0f5e64b4a2f77a3 /jfr_playoff/gui/frames/__init__.py
parent1b33aabd2d5949be3d94b23dfe54f4b28a8959a2 (diff)
SelectionButton/Frame with custom value mappings
Diffstat (limited to 'jfr_playoff/gui/frames/__init__.py')
-rw-r--r--jfr_playoff/gui/frames/__init__.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py
index 7f30a31..270bbbd 100644
--- a/jfr_playoff/gui/frames/__init__.py
+++ b/jfr_playoff/gui/frames/__init__.py
@@ -293,7 +293,7 @@ class SelectionButton(ttk.Button):
selectionFrame = self.dialogclass(
dialog, title=self.prompt,
options=options,
- selected=lambda idx, option: idx+1 in self.selected,
+ selected=self.selected,
callback=self.setPositions, vertical=True)
selectionFrame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
@@ -304,7 +304,7 @@ class SelectionFrame(ScrollableFrame):
def __init__(self, master, title='', options=[],
selected=None, callback=None, *args, **kwargs):
- self.values = []
+ self.values = {}
self.title = title
self.options = options
self.selected = selected
@@ -313,11 +313,14 @@ class SelectionFrame(ScrollableFrame):
(ttk.Button(master, text='Zapisz', command=self._save)).pack(
side=tk.BOTTOM, fill=tk.Y)
+ def _mapValue(self, idx, value):
+ return idx + 1
+
def _save(self):
if self.callback:
self.callback(
- [idx+1 for idx, value
- in enumerate(self.values) if value.get()])
+ [idx for idx, value
+ in self.values.iteritems() if value.get()])
self.master.destroy()
def renderHeader(self, container):
@@ -328,10 +331,11 @@ class SelectionFrame(ScrollableFrame):
def renderContent(self, container):
self.renderHeader(container)
for idx, option in enumerate(self.options):
- self.values.append(tk.IntVar())
+ key = self._mapValue(idx, option)
+ self.values[key] = tk.IntVar()
self.renderOption(container, option, idx)
- if self.selected and self.selected(idx, option):
- self.values[idx].set(True)
+ if self.selected and key in self.selected:
+ self.values[key].set(True)
class RefreshableOptionMenu(ttk.OptionMenu):
def __init__(self, *args, **kwargs):