summaryrefslogtreecommitdiff
path: root/jfr_playoff/gui
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-07-07 21:24:44 +0200
committeremkael <emkael@tlen.pl>2019-07-07 21:24:44 +0200
commit1059281a8962dd7529318b529aeda02ca8544722 (patch)
treeb7f729d69e3212151b8859b5e5c31ade9e5129b1 /jfr_playoff/gui
parent4f55701e1b291a9a6da9eb7aef5802e6bc20cbf0 (diff)
Tracing dirty state of edited file
Diffstat (limited to 'jfr_playoff/gui')
-rw-r--r--jfr_playoff/gui/__init__.py11
-rw-r--r--jfr_playoff/gui/frames/__init__.py2
-rw-r--r--jfr_playoff/gui/variables.py7
3 files changed, 15 insertions, 5 deletions
diff --git a/jfr_playoff/gui/__init__.py b/jfr_playoff/gui/__init__.py
index 2a890d1..6f94df2 100644
--- a/jfr_playoff/gui/__init__.py
+++ b/jfr_playoff/gui/__init__.py
@@ -15,7 +15,8 @@ class PlayoffGUI(tk.Tk):
self.newFileIndex = 0
self._title = tk.StringVar()
self._title.trace('w', self._setTitle)
- self._dirty = False
+ self._dirty = tk.BooleanVar()
+ self._dirty.trace('w', self._setTitle)
self._filepath = None
def run(self):
@@ -28,8 +29,12 @@ class PlayoffGUI(tk.Tk):
self.openFile(sys.argv[1])
else:
self.newFile()
+ self.bind('<<ValueChanged>>', self._onFileChange, add='+')
self.mainloop()
+ def _onFileChange(self, *args):
+ self._dirty.set(True)
+
def _setValues(self, config):
for tab in self.tabs.values():
tab.setValues(config)
@@ -42,18 +47,20 @@ class PlayoffGUI(tk.Tk):
self.newFileIndex += 1
self._title.set('Nowa drabinka %d' % (self.newFileIndex))
self._resetValues()
+ self.after(0, self._dirty.set, False)
def _setTitle(self, *args):
self.title('%s - %s%s' % (
'TeamyPlayOff',
self._title.get(),
- '* ' if self._dirty else ''
+ ' *' if self._dirty.get() else ''
))
def openFile(self, filepath):
self._filepath = filepath
self._title.set(os.path.basename(filepath))
self._setValues(json.load(open(filepath)))
+ self.after(0, self._dirty.set, False)
def getDbConfig(self):
return self.tabs['NetworkTab'].getDB()
diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py
index e50231d..bef832f 100644
--- a/jfr_playoff/gui/frames/__init__.py
+++ b/jfr_playoff/gui/frames/__init__.py
@@ -440,7 +440,7 @@ class TraceableText(tk.Text):
self._variableLock = True
self.delete('1.0', tk.END)
self.insert(tk.END, self._variable.get())
- self._varaibleLock = False
+ self._variableLock = False
def _proxy(self, command, *args):
cmd = (self._orig, command) + args
diff --git a/jfr_playoff/gui/variables.py b/jfr_playoff/gui/variables.py
index abb3cc1..8927179 100644
--- a/jfr_playoff/gui/variables.py
+++ b/jfr_playoff/gui/variables.py
@@ -5,10 +5,13 @@ import tkinter as tk
class NotifyVar(tk.Variable):
def __init__(self, *args, **kwargs):
tk.Variable.__init__(self, *args, **kwargs)
- self.trace('w', self._onChange)
+ self._prevValue = self.get()
+ self._root.after(0, self.trace, 'w', self._onChange)
def _onChange(self, *args):
- self._root.event_generate('<<ValueChanged>>', when='tail')
+ if self._prevValue != self.get():
+ self._root.event_generate('<<ValueChanged>>', when='tail')
+ self._prevValue = self.get()
class NotifyStringVar(NotifyVar, tk.StringVar):
pass