Package peppy :: Package lib :: Module userparams :: Class Param
[frames] | no frames]

Class Param

      object --+    
               |    
debug.debugmixin --+
                   |
                  Param
Known Subclasses:

Generic param interface.

Param objects follow the lifetime of the class, and so are not typically destroyed until the end of the program. That also means that they operate as flyweight objects with their state stored extrinsically. They are also factories for creating editing widgets (the getCtrl method) and as visitors to process the conversion between the user interface representation of the value and the user code's representation of the value (the get/setValue methods).

It's important to understand the two representations of the param. What I call "text" is the textual representation that is stored in the user configuration file, and what I call "value" is the result of the conversion into the correct python type. The value is what the python code operates on, and doesn't need to know anything about the textual representation. These conversions are handled by the textToValue and valueToText methods.

Note that depending on the wx control used to display the value, additional conversion may be necessary to show the value. This is handled by the getValue and setValue methods.

The default Param is a string param, and no restriction on the value of the string is imposed.

Instance Methods
 
__init__(self, keyword, default=None, help='', save_to_file=True, **kwargs)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__str__(self)
str(x)
 
isSettable(self)
True if the user can set this parameter
 
isVisible(self)
True if this item is to be displayed.
 
getLabel(self, parent)
 
getCtrl(self, parent, initial=None)
Create and editing control.
 
processCallback(self, evt, ctrl, ctrl_list)
Subclasses should override this to provide functionality.
 
OnCallback(self, evt)
Callback driver for the control
 
setCallback(self, ctrl, ctrl_list)
Set the callback that responds to changes inthe state of the control
 
setInitialState(self, ctrl, ctrl_list)
Set the initial state of the control.
 
textToValue(self, text)
Convert the user's config text to the type expected by the python code.
 
valueToText(self, value)
Convert the user value to a string suitable to be written to the config file.
 
setValue(self, ctrl, value)
Populate the control given the user value.
 
setValueWithoutCallback(self, ctrl, value)
Populate the control given the user value, but don't execute any callbacks.
 
getValue(self, ctrl)
Get the user value from the control.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__

Class Methods

Inherited from debug.debugmixin: dprint

Class Variables
  default = None
  callback_event = wx.EVT_TEXT

Inherited from debug.debugmixin: debuglevel

Properties

Inherited from object: __class__

Method Details

__init__(self, keyword, default=None, help='', save_to_file=True, **kwargs)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

__str__(self)
(Informal representation operator)

 

str(x)

Overrides: object.__str__
(inherited documentation)

getCtrl(self, parent, initial=None)

 

Create and editing control.

Given the parent window, create a user interface element to edit the param.

processCallback(self, evt, ctrl, ctrl_list)

 

Subclasses should override this to provide functionality.

This callback is the class-specific callback in response to the event named in the class attribute 'callback_event'.

evt: event object ctrl: control from evt.GetEventObject ctrl_list: dict mapping param objects to their corresponding controls

setCallback(self, ctrl, ctrl_list)

 

Set the callback that responds to changes inthe state of the control

This is called during control creation to set the callback in response to the class attribute 'callback_event' that is particular to the type of control being created. Subclasses should change the callback_event to an event that is fired in response to the user changing the state of the control.

Some controls have multiple events that can be fired; for now, only a single event is handled.

setInitialState(self, ctrl, ctrl_list)

 

Set the initial state of the control.

Callback to set the initial state of the widget based on the state of all the other controls in the collection of params. This must only be called after all of the controls in the param collection have been created, because the the ctrl_list dict must contain the entire mapping of params to controls.

textToValue(self, text)

 

Convert the user's config text to the type expected by the python code.

Subclasses should return the type expected by the user code.

valueToText(self, value)

 

Convert the user value to a string suitable to be written to the config file.

Subclasses should convert the value to a string that is acceptable to textToValue.

setValue(self, ctrl, value)

 

Populate the control given the user value.

If any conversion is needed to show the user value in the control, do it here.

setValueWithoutCallback(self, ctrl, value)

 

Populate the control given the user value, but don't execute any callbacks.

Callbacks are designed to be executed in response to the user changing the value, not to a programmatic change. If you don't care that the callback might be triggered when using the setValue method, then there's no problem with the program calling setValue. However, if you've extended a Param to depend on the value of another param; e.g. you've created a processCallback or setInitialState that changes in response to the values in another param, it is most safe to call setValueWithoutCallback for programmatic changes, unless you take care to guarantee the order of the setValue calls.

getValue(self, ctrl)

 

Get the user value from the control.

If the control doesn't automatically return a value of the correct type, convert it here.