Skip to content
Snippets Groups Projects
Commit 3dbcdd0b authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Added 'Button' type to build ViewItem objects, for embedding buttons with custom callbacks.

parent 9bfed362
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,17 @@ class ViewItem(object):
self.visibleWhen = visibleWhen
self.enabledWhen = enabledWhen
class Button(ViewItem):
"""
Represents a button which, when clicked, willl call a specified
callback function.
"""
def __init__(self, callback=None, **kwargs):
self.callback = callback
ViewItem.__init__(self, **kwargs)
class Widget(ViewItem):
......@@ -222,6 +232,15 @@ def _createLabel(parent, viewItem, propObj):
return label
def _createButton(parent, widget):
"""
Creates a ttk.Button object for the given Button widget.
"""
button = ttk.Button(parent, text=widget.label, command=widget.callback)
return button
def _createWidget(parent, widget, propObj):
"""
Creates a widget for the given Widget object, using the
......@@ -353,6 +372,9 @@ def _create(parent, viewItem, propObj):
if isinstance(viewItem, Widget):
return _createWidget(parent, viewItem, propObj)
elif isinstance(viewItem, Button):
return _createButton(parent, viewItem)
elif isinstance(viewItem, NotebookGroup):
return _createNotebookGroup(parent, viewItem, propObj)
......
......@@ -77,6 +77,7 @@ import os.path as op
import Tkinter as tk
#
# The classes below are used in place of the Tkinter.*Var classes.
# They are identical to the Tkinter versions, with the following
# exceptions:
......@@ -88,7 +89,13 @@ import Tkinter as tk
# PropertyBase.validate method is called, to test that
# the new value is valid. If the new value is not valid,
# a ValueError is raised.
#
# NOTE TO SELF: Another way that I could provide this callback
# functionality is to simply use the trace feature of Tkinter
# variables. I'd need to come up with some sort of mechanism
# for reverting to a previous value for invalid writes, though.
# Better? Worse? I don't know.
#
class _StringVar(tk.StringVar):
def __init__(self, tkProp, **kwargs):
self.tkProp = tkProp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment