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

Class TkParameterizedBase

source code


A Parameterized subclass that maintains Tkinter.Variable shadows (proxies) of its Parameters. The Tkinter Variable shadows are kept in sync with the Parameter values, and vice versa.

Optionally performs the same for an additional shadowed Parameterized (extraPO). The Parameters of the extra shadowed PO are available via this object (via both the usual 'dot' attribute access and dedicated parameter accessors declared in this class).

The Tkinter.Variable shadows for this Parameterized and any extra shadowed one are available under their corresponding parameter names in the _tkvars dictionary.

(See note 1 for complications arising from name clashes.)

Parameters being represented by TkParameterizedBase also have a 'translators' dictionary, allowing mapping between string representations of the objects and the objects themselves (for use with e.g. a Tkinter.OptionMenu). More information about the translators is available from specific translator-related methods in this class.

Notes

  1. (a) There is an order of precedance for parameter lookup: this PO > shadowed PO.

    Therefore, if you create a Parameter for this PO with the same name as one of the shadowed PO's Parameters, only the Parameter on this PO will be shadowed.

    Example: 'name' is a common attribute. As a Parameterized, this object has a 'name' Parameter. Any shadowed PO will also have a 'name' Parameter. By default, this object's name will be shadowed at the expense of the name of the extra shadowed PO.

    The precedence order can be reversed by setting the attribute 'self_first' on this object to False.

    (b) Along the same lines, an additional complication can arise relating specifically to 'dot' attribute lookup. For instance, a sublass of TkParameterized might also inherit from Tkinter.Frame. Frame has many of its own attributes, including - for example - 'size'. If we shadow a Parameterized that has a 'size' Parameter, the Parameterized's size Parameter will not be available as .size because ('dot') attribute lookup begins on the local object and is not overridden by 'self_first'. Using the parameter accessors .get_parameter_object('size') or .get_parameter_value('size') (and the equivalent set versions) avoids this problem.

  2. If a shadowed PO's Parameter value is modified elsewhere, the Tkinter Variable shadow is NOT updated until that Parameter value or shadow value is requested from this object. Thus requesting the value will always return an up-to-date result, but any GUI display of the Variable might display a stale value (until a GUI refresh takes place).

Nested Classes [hide private]

Inherited from parameterized.Parameterized: __metaclass__

Instance Methods [hide private]
 
__repr__(self)
x.__repr__() <==> repr(x)
source code
 
_setup_params(self, **params)
Parameters that are not in this object itself but are in the extraPO get set on extraPO.
source code
 
__init__(self, extraPO=None, self_first=True, live_update=True, **params)
A Parameter has a value, but that might need some processing to become a value suitable for display.
source code
 
change_PO(self, extraPO)
Shadow the Parameters of extraPO.
source code
 
_init_tkvars(self, PO)
Create Tkinter Variable shadows of all Parameters of PO.
source code
 
_create_tkvar(self, PO, name, param_obj)
Add _tkvars[name] to represent the parameter object with the specified name.
source code
 
_handle_gui_set(self, p_name)
The callback to use for all GUI variable traces/binds *
source code
 
_tkvar_set(self, param_name, val)
Set the tk variable to (the possibly transformed-to-string) val.
source code
 
_tkvar_get(self, param_name)
Return the value of the tk variable representing param_name.
source code
 
_tkvar_changed(self, name)
Return True if the displayed value does not equal the object's value (and False otherwise).
source code
 
_update_param_from_tkvar(self, param_name)
Attempt to set the parameter represented by param_name to the value of its corresponding Tkinter Variable.
source code
 
_source_POs(self)
Return a list of Parameterizeds in which to find Parameters.
source code
 
get_source_po(self, name)
Return the Parameterized which contains the parameter 'name'.
source code
 
get_parameter_object(self, name, parameterized_object=None, with_source=False)
Return the Parameter object (not value) specified by name, from the source_POs in this object (or the specified parameterized_object).
source code
 
get_parameter_value(self, name, parameterized_object=None)
Return the value of the parameter specified by name.
source code
 
set_parameter_value(self, name, val, parameterized_object=None)
Set the value of the parameter specified by name to val.
source code
 
__getattribute__(self, name)
If the attribute is found on this object, return it.
source code
 
__setattr__(self, name, val)
If the attribute already exists on this object, set it.
source code
 
_create_translator(self, name, param) source code
 
_object2string(self, param_name, obj, replace=True)
If val is one of the objects in param_name's translator, translate to the string.
source code
 
_string2object(self, param_name, string)
Change the given string for the named parameter into an object.
source code
 
_attr_err_msg(self, attr_name, objects)
Helper method: return the 'attr_name is not in objects' message.
source code
 
_set_parameter(self, param_name, val)
Helper method:
source code

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_default, set_dynamic_time_fn, set_param, state_pop, state_push, verbose, warning

Inherited from object: __delattr__, __format__, __hash__, __new__, __reduce__, __reduce_ex__, __sizeof__, __subclasshook__

Class Methods [hide private]

Inherited from parameterized.Parameterized: params, print_param_defaults

Class Variables [hide private]
  _extraPO = None
  name = <param.parameterized.String object at 0xa9cb06c>
String identifier for this object.

Inherited from parameterized.Parameterized: print_level

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__repr__(self)
(Representation operator)

source code 
x.__repr__() <==> repr(x)
Overrides: object.__repr__
(inherited documentation)

_setup_params(self, **params)

source code 
Parameters that are not in this object itself but are in the extraPO get set on extraPO. Then calls Parameterized's _setup_params().
Overrides: parameterized.Parameterized._setup_params

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

source code 

Translation between displayed values and objects

A Parameter has a value, but that might need some processing to become a value suitable for display. For instance, the SheetMask() object <SheetMask SheetMask0001923> ...

Important attributes

  • _extraPO
  • self_first

Determines precedence order for Parameter lookup: if True, Parameters of this object take priority whenever there is a name clash; if False, Parameters of extraPO take priority.

  • obj2str_fn & str2obj_fn
  • translator_creators

(Note that in the various dictionaries above, the entry for Parameter serves as a default, since keys are looked up by class, so any Parameter type not specifically listed will be covered by the Parameter entry.)

  • _tkvars
Overrides: object.__init__

_create_tkvar(self, PO, name, param_obj)

source code 

Add _tkvars[name] to represent the parameter object with the specified name.

The appropriate Variable is used for each Parameter type.

Also adds tracing mechanism to keep the Variable and Parameter values in sync, and updates the translator dictionary to map string representations to the objects themselves.

_tkvar_get(self, param_name)

source code 

Return the value of the tk variable representing param_name.

(Before returning the variable's value, ensures it's up to date.)

_update_param_from_tkvar(self, param_name)

source code 

Attempt to set the parameter represented by param_name to the value of its corresponding Tkinter Variable.

If setting the parameter fails (e.g. an inappropriate value is set for that Parameter type), the Variable is reverted to its previous value.

(Called by the Tkinter Variable's trace_variable() method.)

_source_POs(self)

source code 

Return a list of Parameterizeds in which to find Parameters.

The list is ordered by precedence, as defined by self_first.

get_parameter_object(self, name, parameterized_object=None, with_source=False)

source code 

Return the Parameter object (not value) specified by name, from the source_POs in this object (or the specified parameterized_object).

If with_source=True, returns also the source parameterizedobject.

get_parameter_value(self, name, parameterized_object=None)

source code 

Return the value of the parameter specified by name.

If a parameterized_object is specified, looks for the parameter there. Otherwise, looks in the source_POs of this object.

set_parameter_value(self, name, val, parameterized_object=None)

source code 

Set the value of the parameter specified by name to val.

Updates the corresponding tkvar.

__getattribute__(self, name)

source code 
If the attribute is found on this object, return it. Otherwise, return the attribute from the extraPO, if it exists. If there is no match, raise an attribute error.
Overrides: object.__getattribute__

__setattr__(self, name, val)

source code 
If the attribute already exists on this object, set it. If the attribute is found on the extraPO, set it there. Otherwise, set the attribute on this object (i.e. add a new attribute).
Overrides: object.__setattr__

_string2object(self, param_name, string)

source code 

Change the given string for the named parameter into an object.

If there is a translator for param_name, translate the string to the object; otherwise, call convert_string2obj on the string.