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

Comment updates

parent cd5212d6
No related branches found
No related tags found
No related merge requests found
...@@ -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):
......
...@@ -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( # >>> myPropObj.addListener(
# myPropObj, 'myListener', myPropertyChanged) # >>> 'myProperty', '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') # myPropObj.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
# instances. When an instance of the HasProperties class is created, one # as class attributes. 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>
# #
......
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