Skip to content

Commit

Permalink
Updated smartwidgets to make inheritance more straightforward.
Browse files Browse the repository at this point in the history
  • Loading branch information
slightlynybbled committed Jul 18, 2018
1 parent 815e5d8 commit dc9914f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tk_tools/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.10.2'
__version__ = '0.10.3'
14 changes: 10 additions & 4 deletions tk_tools/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def internal_callback(*args):
self._var.trace('w', internal_callback)


class SmartSpinBox(tk.Spinbox, SmartWidget):
class SmartSpinBox(SmartWidget):
"""
Easy-to-use spinbox. Takes most options that work with a normal SpinBox.
Attempts to call your callback function - if assigned - whenever there
Expand All @@ -114,6 +114,8 @@ def __init__(self, parent, entry_type: str='float',
Constructor for SmartSpinBox
"""
self._parent = parent
super().__init__(self._parent)

sb_options = options.copy()

if entry_type == 'str':
Expand All @@ -126,7 +128,8 @@ def __init__(self, parent, entry_type: str='float',
raise ValueError('Entry type must be "str", "int", or "float"')

sb_options['textvariable'] = self._var
super().__init__(self._parent, **sb_options)
self._spin_box = tk.Spinbox(self, **sb_options)
self._spin_box.grid()

if callback is not None:
def internal_callback(*args):
Expand All @@ -137,7 +140,7 @@ def internal_callback(*args):
self._var.trace('w', internal_callback)


class SmartCheckbutton(tk.Checkbutton, SmartWidget):
class SmartCheckbutton(SmartWidget):
"""
Easy-to-use check button. Takes most options that work with
a normal CheckButton. Attempts to call your callback
Expand All @@ -162,8 +165,11 @@ def callback():
"""
def __init__(self, parent, callback: callable=None, **options):
self._parent = parent
super().__init__(self._parent)

self._var = tk.BooleanVar()
super().__init__(self._parent, variable=self._var, **options)
self._cb = tk.Checkbutton(self, variable=self._var, **options)
self._cb.grid()

if callback is not None:
def internal_callback(*args):
Expand Down

0 comments on commit dc9914f

Please sign in to comment.