summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/gui/frames/__init__.py86
-rw-r--r--jfr_playoff/gui/frames/team.py (renamed from jfr_playoff/gui/frames.py)87
-rw-r--r--jfr_playoff/gui/tabs.py4
3 files changed, 94 insertions, 83 deletions
diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py
new file mode 100644
index 0000000..c046e53
--- /dev/null
+++ b/jfr_playoff/gui/frames/__init__.py
@@ -0,0 +1,86 @@
+#coding=utf-8
+
+import tkinter as tk
+from tkinter import ttk
+
+class WidgetRepeater(tk.Frame):
+ def __init__(self, master, widgetClass, headers=None, *args, **kwargs):
+ if not issubclass(widgetClass, RepeatableFrame):
+ raise AttributeError(
+ 'WidgetRepeater widget must be a RepeatableFrame')
+ tk.Frame.__init__(self, master, **kwargs)
+ self.widgetClass = widgetClass
+ self.widgets = []
+ self.headers = headers
+ self.addButton = ttk.Button(
+ self, text='[+]', width=5, command=self._addWidget)
+ self.renderContent()
+
+ def _findWidget(self, row, column):
+ for children in self.children.values():
+ info = children.grid_info()
+ if info['row'] == str(row) and info['column'] == str(column):
+ return children
+ return None
+
+ def _addWidget(self):
+ removeButton = ttk.Button(
+ self, text='[-]', width=5,
+ command=lambda i=len(self.widgets): self._removeWidget(i))
+ removeButton.grid(row=len(self.widgets), column=0, sticky=tk.N)
+ widget = self.widgetClass(self)
+ self.widgets.append(widget)
+ self._updateGrid()
+
+ def _removeWidget(self, idx):
+ self.widgets.pop(idx).destroy()
+ self._findWidget(row=len(self.widgets), column=0).destroy()
+ self._updateGrid()
+
+ def _updateGrid(self):
+ for idx, widget in enumerate(self.widgets):
+ widget.grid(row=idx, column=1, sticky=tk.W+tk.E+tk.N+tk.S)
+ self.addButton.grid(
+ row=len(self.widgets), column=0, columnspan=1, sticky=tk.W+tk.N)
+
+ def _renderHeader(self):
+ if self.headers:
+ headerFrame = tk.Frame(self)
+ for idx, header in enumerate(self.headers):
+ headerFrame.columnconfigure(idx, weight=1)
+ widget = header[0](headerFrame, **header[1])
+ widget.grid(row=0, column=idx, sticky=tk.W+tk.E+tk.N)
+ self.widgets.append(headerFrame)
+ (tk.Label(self, text=' ')).grid(
+ row=0, column=0, sticky=tk.W+tk.E+tk.N)
+
+ def renderContent(self):
+ self.columnconfigure(1, weight=1)
+ self._renderHeader()
+ self._updateGrid()
+
+class RepeatableFrame(tk.Frame):
+ def __init__(self, *args, **kwargs):
+ tk.Frame.__init__(self, *args, **kwargs)
+ self.renderContent()
+
+ def renderContent(self):
+ pass
+
+ def getValue(self):
+ pass
+
+ def setValue(self, value):
+ pass
+
+class RepeatableEntry(RepeatableFrame):
+ def renderContent(self):
+ self.value = tk.StringVar()
+ self.field = ttk.Entry(self, textvariable=self.value)
+ self.field.pack(expand=True, fill=tk.BOTH)
+
+ def getValue(self):
+ return self.value.get()
+
+ def setValue(self, value):
+ return self.value.set(value)
diff --git a/jfr_playoff/gui/frames.py b/jfr_playoff/gui/frames/team.py
index 8993558..eb77a41 100644
--- a/jfr_playoff/gui/frames.py
+++ b/jfr_playoff/gui/frames/team.py
@@ -4,87 +4,7 @@ import tkinter as tk
from tkinter import ttk
import tkMessageBox
-class WidgetRepeater(tk.Frame):
- def __init__(self, master, widgetClass, headers=None, *args, **kwargs):
- if not issubclass(widgetClass, RepeatableFrame):
- raise AttributeError(
- 'WidgetRepeater widget must be a RepeatableFrame')
- tk.Frame.__init__(self, master, **kwargs)
- self.widgetClass = widgetClass
- self.widgets = []
- self.headers = headers
- self.addButton = ttk.Button(
- self, text='[+]', width=5, command=self._addWidget)
- self.renderContent()
-
- def _findWidget(self, row, column):
- for children in self.children.values():
- info = children.grid_info()
- if info['row'] == str(row) and info['column'] == str(column):
- return children
- return None
-
- def _addWidget(self):
- removeButton = ttk.Button(
- self, text='[-]', width=5,
- command=lambda i=len(self.widgets): self._removeWidget(i))
- removeButton.grid(row=len(self.widgets), column=0, sticky=tk.N)
- widget = self.widgetClass(self)
- self.widgets.append(widget)
- self._updateGrid()
-
- def _removeWidget(self, idx):
- self.widgets.pop(idx).destroy()
- self._findWidget(row=len(self.widgets), column=0).destroy()
- self._updateGrid()
-
- def _updateGrid(self):
- for idx, widget in enumerate(self.widgets):
- widget.grid(row=idx, column=1, sticky=tk.W+tk.E+tk.N+tk.S)
- self.addButton.grid(
- row=len(self.widgets), column=0, columnspan=1, sticky=tk.W+tk.N)
-
- def _renderHeader(self):
- if self.headers:
- headerFrame = tk.Frame(self)
- for idx, header in enumerate(self.headers):
- headerFrame.columnconfigure(idx, weight=1)
- widget = header[0](headerFrame, **header[1])
- widget.grid(row=0, column=idx, sticky=tk.W+tk.E+tk.N)
- self.widgets.append(headerFrame)
- (tk.Label(self, text=' ')).grid(
- row=0, column=0, sticky=tk.W+tk.E+tk.N)
-
- def renderContent(self):
- self.columnconfigure(1, weight=1)
- self._renderHeader()
- self._updateGrid()
-
-class RepeatableFrame(tk.Frame):
- def __init__(self, *args, **kwargs):
- tk.Frame.__init__(self, *args, **kwargs)
- self.renderContent()
-
- def renderContent(self):
- pass
-
- def getValue(self):
- pass
-
- def setValue(self, value):
- pass
-
-class RepeatableEntry(RepeatableFrame):
- def renderContent(self):
- self.value = tk.StringVar()
- self.field = ttk.Entry(self, textvariable=self.value)
- self.field.pack(expand=True, fill=tk.BOTH)
-
- def getValue(self):
- return self.value.get()
-
- def setValue(self, value):
- return self.value.set(value)
+from ..frames import RepeatableFrame, WidgetRepeater, RepeatableEntry
class ManualTeamRow(RepeatableFrame):
def renderContent(self):
@@ -284,3 +204,8 @@ class TeamAliasFrame(tk.Frame):
row=0, column=0, sticky=tk.W+tk.E)
self.repeater = WidgetRepeater(self, TeamAliasRow)
self.repeater.grid(row=1, column=0, sticky=tk.W+tk.E)
+
+class TeamPreviewFrame(tk.Frame):
+ pass
+
+__all__ = ['TeamSettingsFrame', 'TeamAliasFrame', 'TeamPreviewFrame']
diff --git a/jfr_playoff/gui/tabs.py b/jfr_playoff/gui/tabs.py
index 94348b9..3d424d7 100644
--- a/jfr_playoff/gui/tabs.py
+++ b/jfr_playoff/gui/tabs.py
@@ -6,7 +6,7 @@ import tkinter as tk
from tkinter import ttk
import tkFileDialog as tkfd
-from .frames import TeamSettingsFrame, TeamAliasFrame
+from .frames.team import *
class PlayoffTab(ttk.Frame):
def __init__(self, master):
@@ -100,7 +100,7 @@ class TeamsTab(PlayoffTab):
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 = TeamPreviewFrame(container)
previewFrame.grid(row=0, column=1, rowspan=2,
sticky=tk.N+tk.E+tk.S+tk.W)
aliasFrame = TeamAliasFrame(container)