summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-07-22 11:52:38 +0200
committeremkael <emkael@tlen.pl>2019-07-22 11:52:38 +0200
commit8c0b4f0f0ea0fddcdad348fb0c5a9f546375ec29 (patch)
treeb06936a260935479b88da715c04a716f5cca98f3
parent8bf96412b75689c578f5690dd0974304265d7fea (diff)
Ordered dictionaries for config export
-rw-r--r--jfr_playoff/gui/__init__.py3
-rw-r--r--jfr_playoff/gui/frames/match.py10
-rw-r--r--jfr_playoff/gui/frames/network.py9
-rw-r--r--jfr_playoff/gui/frames/team.py7
-rw-r--r--jfr_playoff/gui/frames/translations.py5
-rw-r--r--jfr_playoff/gui/frames/visual.py48
-rw-r--r--jfr_playoff/gui/tabs.py37
7 files changed, 66 insertions, 53 deletions
diff --git a/jfr_playoff/gui/__init__.py b/jfr_playoff/gui/__init__.py
index 551aec2..b563493 100644
--- a/jfr_playoff/gui/__init__.py
+++ b/jfr_playoff/gui/__init__.py
@@ -1,6 +1,7 @@
#coding=utf-8
import codecs, copy, json, os, sys
+from collections import OrderedDict
import tkinter as tk
from tkinter import ttk
@@ -130,7 +131,7 @@ class PlayoffGUI(tk.Tk):
self.after(0, self._dirty.set, False)
def getConfig(self):
- config = {} # TODO: OrderderDict, everywhere
+ config = OrderedDict()
for tab in self.tabs.values():
tabConfig = tab.getConfig()
if tabConfig is not None:
diff --git a/jfr_playoff/gui/frames/match.py b/jfr_playoff/gui/frames/match.py
index ad22a3b..caf14ea 100644
--- a/jfr_playoff/gui/frames/match.py
+++ b/jfr_playoff/gui/frames/match.py
@@ -1,5 +1,7 @@
#coding=utf-8
+from collections import OrderedDict
+
import tkinter as tk
from tkinter.font import Font
from tkinter import ttk
@@ -171,7 +173,7 @@ class SwissSettingsFrame(RepeatableFrame):
value['relative_path'] if 'relative_path' in value else '')
def getValue(self):
- config = {}
+ config = OrderedDict()
if self.source.get() == self.SOURCE_DB:
config['database'] = self.fetchDB.get()
if self.linkRelPath.get():
@@ -423,7 +425,7 @@ class BracketMatchSettingsFrame(GuiFrame):
if self.source.get() == self.SOURCE_TEAM:
return self.teams
else:
- config = {}
+ config = OrderedDict()
lists = {
5: self.positions,
1: self.winners,
@@ -698,7 +700,7 @@ class MatchSettingsFrame(RepeatableFrame):
self.bracketSettings[idx].setSelectedTeam(-1)
def getValue(self):
- config = {}
+ config = OrderedDict()
config['id'] = self.matchID.get()
if self.link.get():
config['link'] = self.link.get()
@@ -805,7 +807,7 @@ class MatchPhaseFrame(ScrollableFrame):
'<<MatchListChanged>>', when='tail')
def getConfig(self):
- config = {}
+ config = OrderedDict
if self.name.get():
config['title'] = self.name.get()
if self.link.get():
diff --git a/jfr_playoff/gui/frames/network.py b/jfr_playoff/gui/frames/network.py
index fc00575..90c21d1 100644
--- a/jfr_playoff/gui/frames/network.py
+++ b/jfr_playoff/gui/frames/network.py
@@ -1,6 +1,7 @@
#coding=utf-8
import socket
+from collections import OrderedDict
import tkinter as tk
from tkinter import ttk
@@ -27,12 +28,12 @@ class MySQLConfigurationFrame(GuiFrame):
def getConfig(self):
if len(self.host.get().strip()):
- return {
+ return OrderedDict({
'host': self.host.get().strip(),
'port': self.port.get(default=3306),
'user': self.user.get().strip(),
'pass': self.pass_.get().strip()
- }
+ })
return None
def _testDB(self):
@@ -167,9 +168,9 @@ class GoniecConfigurationFrame(GuiFrame):
self.enable.set(values['enabled'] if 'enabled' in values else 0)
def getValues(self):
- config = {
+ config = OrderedDict({
'enabled': self.enable.get()
- }
+ })
if self.enable.get():
config['host'] = self.host.get()
config['port'] = self.port.get()
diff --git a/jfr_playoff/gui/frames/team.py b/jfr_playoff/gui/frames/team.py
index cc474b4..dbef680 100644
--- a/jfr_playoff/gui/frames/team.py
+++ b/jfr_playoff/gui/frames/team.py
@@ -1,5 +1,7 @@
#coding=utf-8
+from collections import OrderedDict
+
import tkinter as tk
from tkinter.font import Font
from tkinter import ttk
@@ -168,7 +170,7 @@ class TeamFetchSettingsFrame(GuiFrame):
'<<TeamSettingsChanged>>', when='tail')
def getTeams(self):
- teams = {}
+ teams = OrderedDict()
if self.fetchSource.get() == self.SOURCE_LINK:
teams['link'] = self.fetchLink.get()
elif self.fetchSource.get() == self.SOURCE_DB:
@@ -364,7 +366,8 @@ class TeamAliasFrame(ScrollableFrame):
self.repeater.grid(row=1, column=0, sticky=tk.W+tk.E)
def getConfig(self):
- return {val[0]: val[1] for val in self.repeater.getValue() if val[0]}
+ return OrderedDict(
+ {val[0]: val[1] for val in self.repeater.getValue() if val[0]})
def setValues(self, values):
self.repeater.setValue(list(values.iteritems()))
diff --git a/jfr_playoff/gui/frames/translations.py b/jfr_playoff/gui/frames/translations.py
index e5b8940..a369159 100644
--- a/jfr_playoff/gui/frames/translations.py
+++ b/jfr_playoff/gui/frames/translations.py
@@ -1,6 +1,7 @@
#coding=utf-8
import copy
+from collections import OrderedDict
import tkinter as tk
from tkinter import ttk
@@ -37,9 +38,9 @@ class TranslationConfigurationFrame(ScrollableFrame):
self.repeater.setValue(values)
def getTranslations(self):
- return {
+ return OrderedDict({
key: value for key, value in self.repeater.getValue()
- }
+ })
def renderContent(self, container):
self.repeater = WidgetRepeater(container, TranslationRow)
diff --git a/jfr_playoff/gui/frames/visual.py b/jfr_playoff/gui/frames/visual.py
index 9bbe5f6..147d6fe 100644
--- a/jfr_playoff/gui/frames/visual.py
+++ b/jfr_playoff/gui/frames/visual.py
@@ -1,5 +1,7 @@
#coding=utf-8
+from collections import OrderedDict
+
import tkinter as tk
from tkinter import ttk
import tkColorChooser as tkcc
@@ -179,23 +181,24 @@ class VisualSettingsFrame(GuiFrame):
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()
- }
- }
+ return OrderedDict(
+ {
+ '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):
@@ -282,7 +285,8 @@ class BoxPositionsFrame(ScrollableFrame):
self.positions.setValue(values_to_set)
def getValues(self):
- return { match: config for match, config in self.positions.getValue() }
+ return OrderedDict(
+ { match: config for match, config in self.positions.getValue() })
class LineStyle(GuiFrame):
def _selectColour(self):
@@ -338,7 +342,7 @@ class LineStylesFrame(GuiFrame):
CONFIG_KEYS = ['colour', 'h_offset', 'v_offset']
def renderContent(self):
- self.lines = {}
+ self.lines = OrderedDict()
for idx, line in enumerate(self.DEFAULT_VALUES):
self.lines[line[0]] = LineStyle(self)
self.lines[line[0]].grid(row=idx+1, column=1, sticky=tk.W)
@@ -357,7 +361,7 @@ class LineStylesFrame(GuiFrame):
self.lines[line[0]].setValue(value)
def getValues(self):
- config = {}
+ config = OrderedDict()
for line, widget in self.lines.iteritems():
value = widget.getValue()
for idx, key in enumerate(self.CONFIG_KEYS):
@@ -423,10 +427,10 @@ class PositionStyleFrame(RepeatableFrame):
self.description.set(value['caption'] if 'caption' in value else '')
def getValue(self):
- config = {
+ config = OrderedDict({
'class': self.name.get(),
'positions': self.positions
- }
+ })
caption = self.description.get()
if caption:
config['caption'] = caption
diff --git a/jfr_playoff/gui/tabs.py b/jfr_playoff/gui/tabs.py
index 2b316f4..cc777fa 100644
--- a/jfr_playoff/gui/tabs.py
+++ b/jfr_playoff/gui/tabs.py
@@ -1,6 +1,7 @@
#coding=utf-8
import os
+from collections import OrderedDict
import tkinter as tk
from tkinter import ttk
@@ -149,15 +150,15 @@ class MainSettingsTab(PlayoffTab):
container.rowconfigure(4, weight=1)
def getConfig(self):
- return {
+ return OrderedDict({
'output': self.outputPath.get(),
- 'page': {
+ 'page': OrderedDict({
'title': self.pageTitle.get(),
'logoh': self.pageLogoh.get(),
'refresh': self.refreshInterval.get() \
if self.refresh.get() > 0 else 0
- }
- }
+ })
+ })
class TeamsTab(PlayoffTab):
@property
@@ -214,10 +215,10 @@ class TeamsTab(PlayoffTab):
return self._teamList
def collectConfig(self):
- config = {
+ config = OrderedDict({
'teams': self.settingsFrame.getConfig(),
'team_aliases': self.aliasFrame.getConfig()
- }
+ })
tieConfig = self.previewFrame.getTieConfig()
if tieConfig is not None and isinstance(config['teams'], dict):
config['teams']['ties'] = tieConfig
@@ -312,9 +313,9 @@ class MatchesTab(PlayoffTab):
self.winfo_toplevel().getNewMatchID(match))
def getConfig(self):
- return {
+ return OrderedDict({
'phases': [phase.getConfig() for phase in self.phases.values()]
- }
+ })
class SwissesTab(PlayoffTab):
@property
@@ -331,9 +332,9 @@ class SwissesTab(PlayoffTab):
def getConfig(self):
swisses = self.swisses.getValues()
if len(swisses):
- return {
+ return OrderedDict({
'swiss': swisses
- }
+ })
else:
return None
@@ -394,7 +395,7 @@ class NetworkTab(PlayoffTab):
config['remotes'] if 'remotes' in config else [])
def getConfig(self):
- config = {}
+ config = OrderedDict()
mysql = self.getDB()
if mysql is not None:
config['database'] = mysql
@@ -430,12 +431,12 @@ class VisualTab(PlayoffTab):
self.positionFrame.setValues({})
def getConfig(self):
- config = {
+ config = OrderedDict({
'page': self.settingsFrame.getValues()
- }
+ })
boxConfig = self.positionFrame.getValues()
if boxConfig:
- config['canvas'] = {}
+ config['canvas'] = OrderedDict()
config['canvas']['box_positioning'] = boxConfig
return config
@@ -466,10 +467,10 @@ class StyleTab(PlayoffTab):
self.positionStylesFrame.setValues([])
def getConfig(self):
- return {
+ return OrderedDict({
'canvas': self.linesFrame.getValues(),
'position_styles': self.positionStylesFrame.getValues()
- }
+ })
class TranslationsTab(PlayoffTab):
@property
@@ -488,9 +489,9 @@ class TranslationsTab(PlayoffTab):
self.translationsFrame.setTranslations({})
def getConfig(self):
- return {
+ return OrderedDict({
'i18n': self.translationsFrame.getTranslations()
- }
+ })
__all__ = ['MainSettingsTab', 'TeamsTab', 'MatchesTab', 'SwissesTab',
'NetworkTab', 'VisualTab', 'StyleTab', 'TranslationsTab']