Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
3dbcdd0b
Commit
3dbcdd0b
authored
11 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Added 'Button' type to build ViewItem objects, for embedding buttons with custom callbacks.
parent
9bfed362
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tkprop/build.py
+23
-1
23 additions, 1 deletion
tkprop/build.py
tkprop/properties.py
+8
-1
8 additions, 1 deletion
tkprop/properties.py
with
31 additions
and
2 deletions
tkprop/build.py
+
23
−
1
View file @
3dbcdd0b
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
tkprop/properties.py
+
8
−
1
View file @
3dbcdd0b
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment