summaryrefslogtreecommitdiff
path: root/jfr_playoff/gui/frames
diff options
context:
space:
mode:
Diffstat (limited to 'jfr_playoff/gui/frames')
-rw-r--r--jfr_playoff/gui/frames/match.py98
-rw-r--r--jfr_playoff/gui/frames/network.py12
-rw-r--r--jfr_playoff/gui/frames/translations.py8
-rw-r--r--jfr_playoff/gui/frames/visual.py55
4 files changed, 172 insertions, 1 deletions
diff --git a/jfr_playoff/gui/frames/match.py b/jfr_playoff/gui/frames/match.py
index 685d399..ad22a3b 100644
--- a/jfr_playoff/gui/frames/match.py
+++ b/jfr_playoff/gui/frames/match.py
@@ -170,6 +170,22 @@ class SwissSettingsFrame(RepeatableFrame):
self.linkRelPath.set(
value['relative_path'] if 'relative_path' in value else '')
+ def getValue(self):
+ config = {}
+ if self.source.get() == self.SOURCE_DB:
+ config['database'] = self.fetchDB.get()
+ if self.linkRelPath.get():
+ config['relative_path'] = self.linkRelPath.get()
+ if self.source.get() == self.SOURCE_LINK:
+ config['link'] = self.fetchLink.get()
+ if self.linkLabel.get():
+ config['label'] = self.linkLabel.get()
+ config['position'] = self.setFrom.get()
+ if self.setToEnabled.get():
+ config['position_to'] = self.setTo.get()
+ if self.fetchFromEnabled.get():
+ config['swiss_position'] = self.fetchFrom.get()
+ return config
class SwissesFrame(ScrollableFrame):
def renderContent(self, container):
@@ -179,6 +195,9 @@ class SwissesFrame(ScrollableFrame):
def setValues(self, values):
self.swisses.setValue(values)
+ def getValues(self):
+ return self.swisses.getValue()
+
class MatchSelectionButton(SelectionButton):
@property
def defaultPrompt(self):
@@ -390,6 +409,16 @@ class BracketMatchSettingsFrame(GuiFrame):
self.selectedIndex.set(('none', ''))
self.selected.set(0)
+ def getSelectedTeam(self):
+ if self.selected.get():
+ try:
+ return self.bracketWidgets[7].getValues().index(
+ self.selectedIndex.get())
+ except ValueError:
+ return -1
+ else:
+ return -1
+
def getConfig(self):
if self.source.get() == self.SOURCE_TEAM:
return self.teams
@@ -406,6 +435,9 @@ class BracketMatchSettingsFrame(GuiFrame):
config[key] = values
return config
+ def getValue(self):
+ return self.getConfig()
+
class MatchSettingsFrame(RepeatableFrame):
SCORE_SOURCE_DB = 0
SCORE_SOURCE_LINK = 1
@@ -665,6 +697,53 @@ class MatchSettingsFrame(RepeatableFrame):
for idx in range(0, 2):
self.bracketSettings[idx].setSelectedTeam(-1)
+ def getValue(self):
+ config = {}
+ config['id'] = self.matchID.get()
+ if self.link.get():
+ config['link'] = self.link.get()
+
+ config['teams'] = [bracket.getValue()
+ for bracket in self.bracketSettings]
+
+ if len(self.winnerPositions):
+ config['winner'] = self.winnerPositions
+ if len(self.loserPositions):
+ config['loser'] = self.loserPositions
+
+ selected = [bracket.getSelectedTeam()
+ for bracket in self.bracketSettings]
+ if len([s for s in selected if s > -1]):
+ config['selected_teams'] = selected
+
+ if self.source.get() == self.SCORE_SOURCE_DB:
+ config['database'] = self.scoreDB.get()
+ config['round'] = self.scoreRound.get()
+ if self.source.get() != self.SCORE_SOURCE_CUSTOM:
+ config['table'] = self.scoreTable.get()
+
+ if self.source.get() == self.SCORE_SOURCE_CUSTOM:
+ config['score'] = []
+ for score in self.scoreCustom:
+ try:
+ config['score'].append(float(score.get()))
+ except ValueError:
+ config['score'].append(0.0)
+ if self.scoreNotFinished.get():
+ config['running'] = self.scoreBoards.get()
+
+ return config
+
+ if 'selected_teams' in value \
+ and isinstance(value['selected_teams'], list):
+ for idx, val in enumerate(value['selected_teams']):
+ if idx < 2:
+ self.bracketSettings[idx].setSelectedTeam(val)
+ else:
+ for idx in range(0, 2):
+ self.bracketSettings[idx].setSelectedTeam(-1)
+
+
class MatchSeparator(RepeatableFrame):
def renderContent(self):
@@ -725,5 +804,24 @@ class MatchPhaseFrame(ScrollableFrame):
self.winfo_toplevel().event_generate(
'<<MatchListChanged>>', when='tail')
+ def getConfig(self):
+ config = {}
+ if self.name.get():
+ config['title'] = self.name.get()
+ if self.link.get():
+ config['link'] = self.link.get()
+ values = self.matches.getValue()
+ dummies = []
+ matches = []
+ for idx, value in enumerate(values):
+ if value is None:
+ dummies.append(idx)
+ else:
+ matches.append(value)
+ if len(dummies):
+ config['dummies'] = dummies
+ config['matches'] = matches
+ return config
+
__all__ = ['SwissesFrame', 'MatchPhaseFrame', 'MatchSettingsFrame']
diff --git a/jfr_playoff/gui/frames/network.py b/jfr_playoff/gui/frames/network.py
index d44ff49..fc00575 100644
--- a/jfr_playoff/gui/frames/network.py
+++ b/jfr_playoff/gui/frames/network.py
@@ -166,6 +166,15 @@ class GoniecConfigurationFrame(GuiFrame):
values['port'] if 'port' in values else self.DEFAULT_PORT)
self.enable.set(values['enabled'] if 'enabled' in values else 0)
+ def getValues(self):
+ config = {
+ 'enabled': self.enable.get()
+ }
+ if self.enable.get():
+ config['host'] = self.host.get()
+ config['port'] = self.port.get()
+ return config
+
class RemoteConfigurationFrame(ScrollableFrame):
def renderContent(self, container):
frame = ttk.LabelFrame(container, text='Zdalne pliki konfiguracyjne:')
@@ -178,4 +187,7 @@ class RemoteConfigurationFrame(ScrollableFrame):
def setValues(self, values):
self.repeater.setValue(values)
+ def getValues(self):
+ return self.repeater.getValue()
+
__all__ = ['MySQLConfigurationFrame', 'GoniecConfigurationFrame', 'RemoteConfigurationFrame']
diff --git a/jfr_playoff/gui/frames/translations.py b/jfr_playoff/gui/frames/translations.py
index 3ba660f..e5b8940 100644
--- a/jfr_playoff/gui/frames/translations.py
+++ b/jfr_playoff/gui/frames/translations.py
@@ -23,6 +23,9 @@ class TranslationRow(RepeatableFrame):
self.key.set(value[0])
self.value.set(value[1])
+ def getValue(self):
+ return (self.key.get(), self.value.get())
+
class TranslationConfigurationFrame(ScrollableFrame):
def setTranslations(self, translations):
@@ -33,6 +36,11 @@ class TranslationConfigurationFrame(ScrollableFrame):
values.append(value)
self.repeater.setValue(values)
+ def getTranslations(self):
+ return {
+ key: value for key, value in self.repeater.getValue()
+ }
+
def renderContent(self, container):
self.repeater = WidgetRepeater(container, TranslationRow)
self.repeater.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
diff --git a/jfr_playoff/gui/frames/visual.py b/jfr_playoff/gui/frames/visual.py
index 6780e99..9bbe5f6 100644
--- a/jfr_playoff/gui/frames/visual.py
+++ b/jfr_playoff/gui/frames/visual.py
@@ -178,6 +178,25 @@ class VisualSettingsFrame(GuiFrame):
self.teamNameSeparator.set(values['team_boxes']['name_separator'])
self.teamNamePrefix.set(values['team_boxes']['name_prefix'])
+ def getValues(self):
+ return {
+ 'width': self.boxWidth.get(default=250),
+ 'height': self.boxHeight.get(default=80),
+ 'margin': self.boxMargin.get(default=60),
+ 'starting_position_indicators': self.startingPositionIndicators.get(),
+ 'finishing_position_indicators': self.finishingPositionIndicators.get(),
+ 'team_boxes': {
+ 'label_length_limit': self.teamNameLength.get(default=25) if self.shortenTeamNames else 0,
+ 'predict_teams': self.teamNamePredict.get(),
+ 'label_separator': self.teamLabelSeparator.get(),
+ 'label_placeholder': self.teamNamePlaceholder.get(),
+ 'label_ellipsis': self.teamNameEllipsis.get(),
+ 'name_separator': self.teamNameSeparator.get(),
+ 'name_prefix': self.teamNamePrefix.get(),
+ 'sort_eligible_first': self.teamNameSortPredictions.get()
+ }
+ }
+
class MatchList(RefreshableOptionMenu):
def __init__(self, *args, **kwargs):
@@ -235,6 +254,13 @@ class BoxPositionFrame(RepeatableFrame):
self.vertical.set(0)
self.horizontal.set(-1)
+ def getValue(self):
+ horizontal = self.horizontal.get(default=-1)
+ vertical = self.vertical.get(default=0)
+ return (
+ self.match.get(),
+ [vertical, horizontal] if horizontal >= 0 else vertical)
+
class BoxPositionsFrame(ScrollableFrame):
def renderContent(self, container):
(ttk.Label(container, text='Pozycje tabelek meczów:')).pack(
@@ -255,6 +281,9 @@ class BoxPositionsFrame(ScrollableFrame):
values_to_set.append(value)
self.positions.setValue(values_to_set)
+ def getValues(self):
+ return { match: config for match, config in self.positions.getValue() }
+
class LineStyle(GuiFrame):
def _selectColour(self):
colour = tkcc.askcolor(self._getColour())
@@ -288,6 +317,9 @@ class LineStyle(GuiFrame):
self.hOffset.set(value[1])
self.vOffset.set(value[2])
+ def getValue(self):
+ return [self._getColour(), self.hOffset.get(), self.vOffset.get()]
+
class LineStylesFrame(GuiFrame):
DEFAULT_VALUES = [
('winner', ('#00ff00', 5, -10),
@@ -303,6 +335,7 @@ class LineStylesFrame(GuiFrame):
('finish_loser', ('#ff0000', 20, 10),
'Przegrani meczów kończący rozgrywki: ')
]
+ CONFIG_KEYS = ['colour', 'h_offset', 'v_offset']
def renderContent(self):
self.lines = {}
@@ -317,12 +350,20 @@ class LineStylesFrame(GuiFrame):
def setValues(self, values):
for line in self.DEFAULT_VALUES:
value = list(line[1])
- for idx, key in enumerate(['colour', 'h_offset', 'v_offset']):
+ for idx, key in enumerate(self.CONFIG_KEYS):
key = '%s_%s' % (line[0], key)
if key in values:
value[idx] = values[key]
self.lines[line[0]].setValue(value)
+ def getValues(self):
+ config = {}
+ for line, widget in self.lines.iteritems():
+ value = widget.getValue()
+ for idx, key in enumerate(self.CONFIG_KEYS):
+ config['%s_%s' % (line, key)] = value[idx]
+ return config
+
class PositionsSelectionFrame(SelectionFrame):
COLUMN_COUNT=10
@@ -381,6 +422,15 @@ class PositionStyleFrame(RepeatableFrame):
value['positions'] if 'positions' in value else [])
self.description.set(value['caption'] if 'caption' in value else '')
+ def getValue(self):
+ config = {
+ 'class': self.name.get(),
+ 'positions': self.positions
+ }
+ caption = self.description.get()
+ if caption:
+ config['caption'] = caption
+ return config
class PositionStylesFrame(ScrollableFrame):
def renderContent(self, container):
@@ -392,4 +442,7 @@ class PositionStylesFrame(ScrollableFrame):
def setValues(self, values):
self.styles.setValue(values)
+ def getValues(self):
+ return self.styles.getValue()
+
__all__ = ['VisualSettingsFrame', 'BoxPositionsFrame', 'LineStylesFrame', 'PositionStylesFrame']