summaryrefslogtreecommitdiff
path: root/jfr_playoff/gui/variables.py
diff options
context:
space:
mode:
Diffstat (limited to 'jfr_playoff/gui/variables.py')
-rw-r--r--jfr_playoff/gui/variables.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/jfr_playoff/gui/variables.py b/jfr_playoff/gui/variables.py
new file mode 100644
index 0000000..9dcbff2
--- /dev/null
+++ b/jfr_playoff/gui/variables.py
@@ -0,0 +1,32 @@
+#coding=utf-8
+
+import tkinter as tk
+
+class NotifyVar(tk.Variable):
+ def __init__(self, *args, **kwargs):
+ tk.Variable.__init__(self, *args, **kwargs)
+ self._prevValue = self.get()
+ self._root.after(0, self.trace, 'w', self._onChange)
+
+ def _onChange(self, *args):
+ if self._prevValue != self.get():
+ self._root.event_generate('<<ValueChanged>>', when='tail')
+ self._prevValue = self.get()
+
+class NumericVar(tk.StringVar):
+ def get(self, default=None):
+ try:
+ return int(str(tk.StringVar.get(self)).strip())
+ except ValueError:
+ return default
+
+class NotifyStringVar(NotifyVar, tk.StringVar):
+ pass
+
+class NotifyIntVar(NotifyVar, tk.IntVar):
+ pass
+
+class NotifyNumericVar(NumericVar, NotifyVar):
+ def __init__(self, *args, **kwargs):
+ NotifyVar.__init__(self, *args, **kwargs)
+ NumericVar.__init__(self, *args, **kwargs)