Package topo :: Package param :: Module tk :: Class TkParameterized
[hide private]
[frames] | no frames]

Class TkParameterized

source code

                 object --+        
                          |        
parameterized.Parameterized --+    
                              |    
            TkParameterizedBase --+
                                  |
                                 TkParameterized
Known Subclasses:

Provide widgets for Parameters of itself and up to one additional Parameterized instance or class.

A subclass that defines a Parameter p can display it appropriately for manipulation by the user simply by calling pack_param('p'). The GUI display and the actual Parameter value are automatically synchronized (though see technical notes in TkParameterizedBase's documentation for more details).

In general, pack_param() adds a Tkinter.Frame containing a label and a widget:

--------------------- The Parameter's | | 'representation' | [label] [widget] |<----frame | | ---------------------

In the same way, an instance of this class can be used to display the Parameters of an existing object. By passing in extraPO=x, where x is an existing Parameterized instance or class, a Parameter q of x can also be displayed in the GUI by calling pack_param('q').

For representation in the GUI, Parameter values might need to be converted between their real values and strings used for display (e.g. for a ClassSelector, the options are really class objects, but the user is presented with a list of strings to choose from). Such translation is handled and documented in the TkParameterizedBase; the default behaviors can be overridden if required.

(Note that this class simply adds widget drawing to TkParameterizedBase. More detail about the shadowing of Parameters is available in the documentation for TkParameterizedBase.)

Nested Classes [hide private]

Inherited from parameterized.Parameterized: __metaclass__

Instance Methods [hide private]
 
_X(self, name, widget_options) source code
 
__init__(self, master, extraPO=None, self_first=True, msg_handler=None, **params)
Initialize this object with the arguments and attributes described below:
source code
 
__pretty_print(self, s)
Convert a Parameter name s to a string suitable for display, if pretty_parameters is True.
source code
 
__update_dynamic_menu_entry(self, param_name)
Keep track of status of dynamic entry.
source code
 
_create_boolean_widget(self, frame, name, widget_options)
Return a Tkinter.Checkbutton to represent parameter 'name'.
source code
 
_create_button_widget(self, frame, name, widget_options)
Return a FocusTakingButton to represent Parameter 'name'.
source code
 
_create_number_widget(self, frame, name, widget_options)
Return a TaggedSlider to represent parameter 'name'.
source code
 
_create_selector_widget(self, frame, name, widget_options)
Return a Tkinter.OptionMenu to represent Parameter 'name'.
source code
 
_create_string_widget(self, frame, name, widget_options)
Return a Tkinter.Entry to represent parameter 'name'.
source code
 
_create_widget(self, name, master, widget_options={}, on_change=None, on_modify=None)
Return widget,label for parameter 'name', each having the master supplied
source code
 
_handle_gui_set(self, p_name, force=False)
Override the superclass's method to X and allow status indications.
source code
 
_indicate_tkvar_status(self, param_name, status=None)
blue if the GUI value differs from that set on the object
source code
 
_param_right_click(self, event, param_name)
Display a popup menu when user right clicks on a parameter.
source code
 
_post_add_param(self, param_name) source code
 
_set_widget_status(self, param_name, status) source code
 
_switch_dynamic(self, name=None, dynamic=False) source code
 
_tkvar_set(self, param_name, val)
Calls superclass's version, but adds help text for the currently selected item of SelectorParameters.
source code
 
_update_param_from_tkvar(self, param_name, force=False)
Prevents the superclass's _update_param_from_tkvar() method from being called unless:
source code
 
gui_get_param(self, param_name)
Simulate getting the parameter in the GUI.
source code
 
gui_set_param(self, param_name, val)
Simulate setting the parameter in the GUI.
source code
 
hide_param(self, name)
Hide the representation of Parameter 'name'.
source code
 
pack_param(self, name, parent=None, widget_options={}, on_change=None, on_modify=None, **pack_options)
Create a widget for the Parameter name, configured according to widget_options, and pack()ed according to the pack_options.
source code
 
repack_param(self, name) source code
 
unhide_param(self, name, new_pack_options={})
Un-hide the representation of Parameter 'name'.
source code
 
unpack_param(self, name)
Destroy the representation of Parameter 'name'.
source code
 
update_selector(self, name) source code

Inherited from TkParameterizedBase: __getattribute__, __repr__, __setattr__, change_PO, get_parameter_object, get_parameter_value, get_source_po, set_parameter_value

Inherited from parameterized.Parameterized: __getstate__, __setstate__, __str__, debug, defaults, force_new_dynamic_value, get_param_values, get_value_generator, inspect_value, message, print_param_values, script_repr, set_dynamic_time_fn, state_pop, state_push, verbose, warning

Inherited from object: __delattr__, __hash__, __new__, __reduce__, __reduce_ex__

Class Methods [hide private]

Inherited from parameterized.Parameterized: params, print_param_defaults

Class Variables [hide private]
  pretty_parameters = Boolean(default= True, precedence=-1, doc=...
Whether to format parameter names, or display the variable names instead.

Inherited from TkParameterizedBase (private): _extraPO

Inherited from parameterized.Parameterized: name, print_level

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, master, extraPO=None, self_first=True, msg_handler=None, **params)
(Constructor)

source code 

Initialize this object with the arguments and attributes described below:

extraPO: optional Parameterized object for which to shadow Parameters (in addition to Parameters of this object; see superclass)

self_first: if True, Parameters on this object take precedence over any ones with the same names in the extraPO (i.e. what to do if there are name clashes; see superclass)

Important attributes

  • param_immediately_apply_change

Some types of Parameter are represented with widgets where a complete change can be instantaneous (e.g. when selecting from an option list, the selection should be applied straightaway). Others are represented with widgets that do not finish their changes instantaneously (e.g. entry into a text box is not considered finished until Return is pressed).

  • widget_creators

A dictionary of methods to create a widget for each Parameter type. For special widget options (specific to each particular parameter), see the corresponding method's docstring.

  • representations

After pack_param() is called, a Parameter's representation consists of the tuple (frame,widget,label,pack_options) - the enclosing frame, the value-containing widget, the label holding the Parameter's name, and any options supplied for pack(). These can all be accessed through the representations dictionary, under the Parameter's name.

Overrides: object.__init__

_create_button_widget(self, frame, name, widget_options)

source code 

Return a FocusTakingButton to represent Parameter 'name'.

Buttons require a command, which should have been specified as the 'on_change' function passed to pack_param().

After creating a button for a Parameter param, self.param() also executes the button's command.

If the Button was declared with an image, the button will have that image (and no text); otherwise, the button will display the (possibly pretty_print()ed) name of the Parameter.

_create_number_widget(self, frame, name, widget_options)

source code 

Return a TaggedSlider to represent parameter 'name'.

The slider's bounds are set to those of the Parameter.

_create_selector_widget(self, frame, name, widget_options)

source code 

Return a Tkinter.OptionMenu to represent Parameter 'name'.

In addition to Tkinter.OptionMenu's usual options, the following additional ones may be included in widget_options:

  • sort_fn_args: if widget_options includes 'sort_fn_args', these are passed to the sort() method of the list of objects available for the parameter, and the names are displayed sorted in that order. If 'sort_fn_args' is not present, the default is to sort the list of names using its sort() method.
  • new_default: if widget_options includes 'new_default':True, the currently selected value for the widget will be set to the first item in the (possibly sorted as above) range. Otherwise, the currently selected value will be left as the current value.

_create_widget(self, name, master, widget_options={}, on_change=None, on_modify=None)

source code 

Return widget,label for parameter 'name', each having the master supplied

The appropriate widget creation method is found from the widget_creators dictionary; see individual widget creation methods for details to each type of widget.

_handle_gui_set(self, p_name, force=False)

source code 
Override the superclass's method to X and allow status indications.
Overrides: TkParameterizedBase._handle_gui_set

_indicate_tkvar_status(self, param_name, status=None)

source code 
Set the parameter's label to:
  • blue if the GUI value differs from that set on the object

  • red if the text doesn't translate to a correct value

  • black if the GUI and object have the same value

_tkvar_set(self, param_name, val)

source code 
Calls superclass's version, but adds help text for the currently selected item of SelectorParameters.
Overrides: TkParameterizedBase._tkvar_set

_update_param_from_tkvar(self, param_name, force=False)

source code 

Prevents the superclass's _update_param_from_tkvar() method from being called unless:

  • param_name is a Parameter type that has changes immediately applied (see doc for param_immediately_apply_change dictionary);
  • force is True.

(I.e. to update a parameter for which param_immediately_apply_change[type(parameter)]==False, call this method with force=True. E.g. when <Return> is pressed in a text box, this method is called with force=True.)

Overrides: TkParameterizedBase._update_param_from_tkvar

pack_param(self, name, parent=None, widget_options={}, on_change=None, on_modify=None, **pack_options)

source code 

Create a widget for the Parameter name, configured according to widget_options, and pack()ed according to the pack_options.

Pop-up help is automatically set from the Parameter's doc.

The widget and label (if appropriate) are enlosed in a Frame so they can be manipulated as a single unit (see the class docstring). The representation (frame,widget,label,pack_options) is returned (as well as being stored in the representations dictionary).

  • parent is an existing widget that is to be the parent

(master) of the widget created for this paramter. If no parent is specified, defaults to the originally supplied master (i.e. that set during __init__).

  • on_change is an optional function to call whenever the

Parameter's corresponding Tkinter Variable's trace_variable indicates that it has been set (this does not necessarily mean that the widget's value has changed). When the widget is created, the on_change method will be called (because the creation of the widget triggers a set in Tkinter).

  • on_modify is an optional function to call whenever the

corresponding Tkinter Variable is actually changed.

widget_options specified here override anything that might have been set elsewhere (e.g. Button's size can be overridden here if required).

Examples of use: pack_param(name) pack_param(name,side='left') pack_param(name,parent=frame3,on_change=some_func) pack_param(name,widget_options={'width':50},side='top',expand='yes',fill='y')

unhide_param(self, name, new_pack_options={})

source code 

Un-hide the representation of Parameter 'name'.

Any new pack options supplied overwrite the originally supplied ones, but the parent of the widget remains the same.

unpack_param(self, name)

source code 

Destroy the representation of Parameter 'name'.

(unpack and then pack a param if you want to put it in a different frame; otherwise simply use hide and unhide)


Class Variable Details [hide private]

pretty_parameters

Whether to format parameter names, or display the variable names instead.

Example use:
TkParameterized.pretty_parameters=False

(This causes all Parameters throughout the GUI to be displayed with variable names.)

Value:
Boolean(default= True, precedence=-1, doc= """Whether to format parameter names, o\
r display the
        variable names instead.

        Example use:
          TkParameterized.pretty_parameters=False
    
        (This causes all Parameters throughout the GUI to be displayed
...