Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD 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
FSL
fslpy
Commits
7fb25241
Commit
7fb25241
authored
10 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Comment updates
parent
cd5212d6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/props/build.py
+4
-1
4 additions, 1 deletion
fsl/props/build.py
fsl/props/properties.py
+49
-75
49 additions, 75 deletions
fsl/props/properties.py
with
53 additions
and
76 deletions
fsl/props/build.py
+
4
−
1
View file @
7fb25241
...
@@ -23,6 +23,10 @@
...
@@ -23,6 +23,10 @@
# tab for each child Group. The label for, and behaviour of, the widget
# tab for each child Group. The label for, and behaviour of, the widget
# for an individual property may be customised with a Widget object.
# for an individual property may be customised with a Widget object.
#
#
# As an alternative to passing in a view, labels, and tooltips, they
# may be specified as class attributes of the HasProperties object,
# with respective names '_view', '_labels', and '_tooltips'.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
#
...
@@ -337,7 +341,6 @@ def _makeGroupBorder(parent, group, ctr, *args, **kwargs):
...
@@ -337,7 +341,6 @@ def _makeGroupBorder(parent, group, ctr, *args, **kwargs):
borderSizer
.
Fit
(
borderPanel
)
borderSizer
.
Fit
(
borderPanel
)
return
borderPanel
,
groupObject
return
borderPanel
,
groupObject
def
_createNotebookGroup
(
parent
,
group
,
hasProps
,
propGui
):
def
_createNotebookGroup
(
parent
,
group
,
hasProps
,
propGui
):
...
...
This diff is collapsed.
Click to expand it.
fsl/props/properties.py
+
49
−
75
View file @
7fb25241
...
@@ -7,54 +7,44 @@
...
@@ -7,54 +7,44 @@
#
#
# Usage:
# Usage:
#
#
# import Tkinter as tk
# >>> import fsl.props as props
# import tkprops as tkp
#
#
# >>> class PropObj(props.HasProperties):
# >>> myProperty = props.Boolean()
#
#
# class PropObj(tkp.HasProperties):
# >>> myPropObj = PropObj()
# myProperty = tkp.Boolean()
#
#
# # The Tk root object must be created
# # before any HasProperties objects.
# app = tk.Tk()
# myPropObj = PropObj()
#
#
#
#
# # Access the property value as a normal attribute:
# # Access the property value as a normal attribute:
# myPropObj.myProperty = True
# >>> myPropObj.myProperty = True
# myPropObj.myProperty
# >>> myPropObj.myProperty
#
# >>> True
# # >>> True
#
#
#
#
# # access the tkp.Boolean instance:
# # access the props.Boolean instance:
# myPropObj.getTkProp('myProperty')
# >>> myPropObj.getProp('myProperty')
# >>> <props.prop.Boolean at 0x1045e2710>
#
#
# # >>> <tkprops.tkprop.Boolean at 0x1045e2710>
#
#
#
# # access the underlying props.PropertyValue object
# # access the underlying Tkinter control variable
# # (there are caveats for List properties):
# # (there are caveats for List properties):
# myPropObj.getTkVar('myProperty').tkVar
# >>> myPropObj.getPropVal('myProperty')
#
# >>> <props.prop.PropertyValue instance at 0x1047ef518>
# # >>> <tkinter.BooleanVar instance at 0x1047ef518>
#
#
#
#
# # Receive notification of property value changes
# # Receive notification of property value changes
# def myPropertyChanged(
instance, name, value
):
#
>>>
def myPropertyChanged(
value, *args
):
# print('New
value for {}
: {}'.format(
name,
value))
#
>>>
print('New
property value
: {}'.format(value))
#
#
# PropObj.
myProperty.
addListener(
#
>>> my
PropObj.addListener(
# myProp
Obj
, 'myListener', myPropertyChanged)
#
>>>
'
myProp
erty'
, 'myListener', myPropertyChanged)
#
#
# myPropObj.myProperty = False
# >>> myPropObj.myProperty = False
#
# >>> New property value: False
# # >>> New value for myProperty: False
#
#
#
#
# # Remove a previously added listener
# # Remove a previously added listener
# PropObj.
myProperty.
removeListener(
myPropObj,
'myListener')
#
my
PropObj.removeListener('myListener')
#
#
#
#
# Lots of the code in this file is probably very confusing. First of
# Lots of the code in this file is probably very confusing. First of
...
@@ -74,53 +64,37 @@
...
@@ -74,53 +64,37 @@
#
#
# - http://pyvideo.org/video/1760/encapsulation-with-descriptors
# - http://pyvideo.org/video/1760/encapsulation-with-descriptors
#
#
# Once you know how Python descriptors work, you then need to know how
# Tk control variables work. These are simple objects which may be
# passed to a Tkinter widget object when it is created. When a user
# modifies the widget value, the Tk control variable is
# modified. Conversely, if the value of a Tk control variable object is
# modified, any widgets which are bound to the variable are updated to
# reflect the new value.
#
# This module, and the associated tkpropwidget module, uses magic to
# encapsulate Tkinter control variables within python descriptors, thus
# allowing custom validation rules to be enforced on such control
# variables.
#
# The runtime structure of Tk properties is organised as follows:
#
#
# A HasProperties (sub)class contains a collection of PropertyBase
# A HasProperties (sub)class contains a collection of PropertyBase
instances
#
instanc
es. When an instance of the HasProperties class is created,
one
#
as class attribut
es. When an instance of the HasProperties class is created,
# or more
TkVarProxy
objects are created for each of the PropertyBase
#
one
or more
PropertyValue
objects are created for each of the PropertyBase
# instances. For most properties, there is a one-to-one mapping between
# instances. For most properties, there is a one-to-one mapping between
# TkVarProxy instances and PropertyBase instances (for each
# ProperyyValue instances and PropertyBase instances (for each HasProperties
# HasProperties instance), however this is not mandatory. For example,
# instance), however this is not mandatory. For example, the List property
# the List property manages multiple TkVarProxy objects for each
# manages multiple PropertyValue objects for each HasProperties instance.
# HasProperties instance.
# Each of these PropertyValue instances encapsulates a single value, of any
# Each of these TkVarProxy instances encapsulates a single Tkinter
# type. Whenever a variable value changes, the PropertyValue instance passes
# control variable. Whenever a variable value changes, the TkVarProxy
# the new value to the validate method of its parent PropertyBase instance to
# instance passes the new value to the validate method of its parent
# determine whether the new value is valid, and notifies any registered
# PropertyBase instance to determine whether the new value is valid, and
# listeners of the change. The PropertyValue object will allow its underlying
# notifies any registered listeners of the change. The TkVarProxy object
# value to be set to something invalid, but it will tell registered listeners
# will allow its underlying Tkinter variable to be given invalid values,
# whether the new value is valid or invalid.
# but it will tell registered listeners whether the new value is valid
#
# or invalid.
# Application code may be notified of property changes in two ways. First, a
#
# listener may be registered with a PropertyBase object, either via the
# Application code may be notified of property changes in two ways.
# HasProperties.addListener instance method, or the PropertyBase.addListener
# First, a listener may be registered with a PropertyBase object, by
# class method (these are equivalent). Such a listener will be notified of
# passing a reference to the HasProperties instance, a name, and a
# changes to any of the PropertyValue objects managed by the PropertyBase
# callback function to the PropertyBase.addListener method. Such a
# object, and associated with the HasProperties instance. This is important
# listener will be notified of changes to any of the TkVarProxy objects
# for List properties, as it means that a change to a single PropertyValue
# managed by the PropertyBase object, and associated with the
# object in a list will result in notification of all registered listeners.
# HasProperties instance. This is important for List properties, as it
#
# means that a change to a single TkVarProxy object in a list will
# If one is interested in changes to a single PropertyValue object (e.g. one
# result in notification of all registered listeners.
# element of a List property), then a listener may be registered directly with
#
# the PropertyValue object, via the PropertyValue.addListener instance
# If one is interested in changes to a single TkVarProxy object
# method. This listener will then only be notified of changes to that
# (e.g. one element of a List property), then a listener may be
# PropertyValue object.
# registered directly with the TkVarProxy object. This listener will
# then only be notified of changes to that TkVarProxy object.
#
#
# author: Paul McCarthy <pauldmccarthy@gmail.com>
# author: Paul McCarthy <pauldmccarthy@gmail.com>
#
#
...
...
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