diff options
author | emkael <emkael@tlen.pl> | 2019-07-22 11:39:02 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-07-22 11:39:02 +0200 |
commit | 8bf96412b75689c578f5690dd0974304265d7fea (patch) | |
tree | 00927af4c406028b437a1890840ea7168267f1f9 /jfr_playoff/gui/__init__.py | |
parent | 37a2b34d2dd68092196e391b8ccc08c092f9912a (diff) |
Collecting and saving config file
Diffstat (limited to 'jfr_playoff/gui/__init__.py')
-rw-r--r-- | jfr_playoff/gui/__init__.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/jfr_playoff/gui/__init__.py b/jfr_playoff/gui/__init__.py index 59821cb..551aec2 100644 --- a/jfr_playoff/gui/__init__.py +++ b/jfr_playoff/gui/__init__.py @@ -1,6 +1,6 @@ #coding=utf-8 -import json, os, sys +import codecs, copy, json, os, sys import tkinter as tk from tkinter import ttk @@ -122,7 +122,33 @@ class PlayoffGUI(tk.Tk): self.after(0, self._dirty.set, False) def saveFile(self, filepath): - pass + json.dump( + self.getConfig(), codecs.open(filepath, 'w', encoding='utf8'), + indent=4, ensure_ascii=False) + self._filepath = filepath + self._title.set(os.path.basename(filepath)) + self.after(0, self._dirty.set, False) + + def getConfig(self): + config = {} # TODO: OrderderDict, everywhere + for tab in self.tabs.values(): + tabConfig = tab.getConfig() + if tabConfig is not None: + config = self._mergeConfig(config, tab.getConfig()) + return config + + def _mergeConfig(self, base, update): + result = copy.copy(base) + for key, value in update.iteritems(): + if key in result: + if isinstance(result[key], dict): + result[key] = self._mergeConfig( + result[key], update[key]) + else: + result[key] = update[key] + else: + result[key] = value + return result def getDbConfig(self): return self.tabs['NetworkTab'].getDB() |