summaryrefslogtreecommitdiff
path: root/jfr_playoff/gui/frames/__init__.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-12-28 00:14:42 +0100
committeremkael <emkael@tlen.pl>2019-12-28 00:14:42 +0100
commit3cb673b11e53e6383cc1af8c350d6f1a3eed1f35 (patch)
treed841e6f74e83792988800fcd049cd54013fe5b18 /jfr_playoff/gui/frames/__init__.py
parent33ea79bcaf780567a67f0cd6e7be8f5c49823bb0 (diff)
Re-orederable elements of phase matches WidgetRepeater
Fixes #38
Diffstat (limited to 'jfr_playoff/gui/frames/__init__.py')
-rw-r--r--jfr_playoff/gui/frames/__init__.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py
index 97f55bf..367afc9 100644
--- a/jfr_playoff/gui/frames/__init__.py
+++ b/jfr_playoff/gui/frames/__init__.py
@@ -19,7 +19,7 @@ def setPanelState(frame, state):
class WidgetRepeater(tk.Frame):
def __init__(self, master, widgetClass, headers=None, classParams=None,
- onAdd=None, *args, **kwargs):
+ onAdd=None, reorderable=False, *args, **kwargs):
widgetList = widgetClass
if not isinstance(widgetClass, list):
widgetList = [widgetClass]
@@ -36,6 +36,7 @@ class WidgetRepeater(tk.Frame):
self.addButton = ttk.Button(
self, text='[+]', width=5, command=self._addWidget)
self.onAdd = onAdd
+ self.reorderable = reorderable
self.renderContent()
def _findWidget(self, row, column):
@@ -47,11 +48,23 @@ class WidgetRepeater(tk.Frame):
def _createWidget(self, widgetClass, widgetClassParams=None):
headeridx = int(self.headerFrame is not None)
+ buttonFrame = tk.Frame(self)
+ buttonFrame.grid(
+ row=len(self.widgets)+headeridx, column=0, sticky=tk.N)
removeButton = ttk.Button(
- self, text='[-]', width=5,
+ buttonFrame, text='[-]', width=6,
command=lambda i=len(self.widgets): self._removeWidget(i))
removeButton.grid(
- row=len(self.widgets)+headeridx, column=0, sticky=tk.N)
+ row=0, column=0, columnspan=2, sticky=tk.N+tk.E+tk.W)
+ if self.reorderable:
+ moveUpButton = ttk.Button(
+ buttonFrame, text='[↑]', width=3,
+ command=lambda i=len(self.widgets): self._moveWidgetUp(i))
+ moveUpButton.grid(row=1, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
+ moveDownButton = ttk.Button(
+ buttonFrame, text='[↓]', width=3,
+ command=lambda i=len(self.widgets): self._moveWidgetDown(i))
+ moveDownButton.grid(row=1, column=1, sticky=tk.N+tk.S+tk.E+tk.W)
widget = widgetClass(self)
if widgetClassParams is not None:
widget.configureContent(**widgetClassParams)
@@ -60,6 +73,20 @@ class WidgetRepeater(tk.Frame):
if self.onAdd is not None:
self.onAdd(widget)
+ def _moveWidgetUp(self, idx):
+ self._swapWidgets(idx, idx-1)
+
+ def _moveWidgetDown(self, idx):
+ self._swapWidgets(idx, idx+1)
+
+ def _swapWidgets(self, idx1, idx2):
+ if (idx1 >= 0) and (idx2 >= 0) and \
+ (idx1 < len(self.widgets)) and (idx2 < len(self.widgets)):
+ temp = self.widgets[idx1]
+ self.widgets[idx1] = self.widgets[idx2]
+ self.widgets[idx2] = temp
+ self._updateGrid()
+
def _handleWidgetSelection(self, selected):
if selected < len(self.widgetClass):
params = None