fsleyes_props.widgets
¶
This module provides functions to generate Generate wx
GUI widgets
which allow the user to edit the properties of a HasProperties
instance.
Most of the functions in this module are not intended to be called directly -
they are used by the build
module. However, a few functions defined
here are made available at the fsleyes_props
namespace level, and are
intended to be called by application code:
Given
hasProps
(aHasProperties
instance),propName
(the name of a property ofhasProps
), andparent
, a GUI object, creates and returns a widget, or a panel containing widgets, which may be used to edit the property value.Creeates a widget for a specific value in the specified list property.
Creates a widget for every value in the given list property.
Creates a button which controls synchronisation of the specified property on the given
hasProps
instance, with the corresponding property on its parent.Binds the given widget to the specified property.
Unbinds the given widget from the specified property, assumed to have been previously bound via the
bindWidget()
function.
The other functions defined in this module are used by the build
module, which generates a GUI from a view specification. The following
functions are available:
Creates and returns a panel containing a
wx.TextCtrl
and awx.Button
.Creates and returns a
wx.TextCtrl
object, allowing the user to edit the givenpropVal
(managed by aString
instance).Creates and returns a widget allowing the user to edit the given
Real
property value.Creates and returns a widget allowing the user to edit the given
Int
property value.Creates and returns a widget allowing the user to edit the given
Percentage
property value.Creates and returns a
ColourButton
widget, allowing the user to modify the givenColour
property value.Creates and returns a combobox, allowing the user to change the value of the given
ColourMap
property value.Creates a ‘link’ button which toggles synchronisation between the property on the given
hasProps
instance, and its parent.
Widgets for some other property types are implemented in separate modules, purely to keep module file sizes down:
Creates and returns a panel containing sliders/spinboxes which allow the user to edit the low/high values along each dimension of the given
Bounds
property value.Creates and returns a
SliderSpinPanel
allowing the user to edit the low/high values along each dimension of the givenPoint
property value.Creates and returns a widget allowing the user to modify the given
Choice
property value.Creates and returns a
wx.CheckBox
, allowing the user to set the givenBoolean
property value.Creates and returns a widget allowing the user to edit the given
Number
property value.Warning
The
widgets_list
module has not been looked at in a while, and is probably broken.
While all of these functions have a standardised signature, some of them
(e.g. the _Colour
function) accept extra arguments which provide some
level of customisation. You can provide these arguments indirectly in the
ViewItem
specification for a specific property. For example:
import fsleyes_props as props
class MyObj(props.HasProperties):
myColour = props.Colour()
myBoolean = props.Boolean()
view = props.VGroup((
# Give the colour button a size of 32 * 32
props.Widget('myColour', size=(32, 32)),
# Use a toggle button for the boolean property,
# using 'boolean.png' as the button icon
props.Widget('myBoolean', icon='boolean.png') ))
myobj = MyObj()
dlg = props.buildDialog(None, myobj, view=view)
dlg.ShowModal()
-
fsleyes_props.widgets.
_propBind
(hasProps, propObj, propVal, guiObj, evType, widgetGet=None, widgetSet=None, widgetDestroy=None)¶ Binds a
PropertyValue
instance to a widget.Sets up event callback functions such that, on a change to the given property value, the value displayed by the given GUI widget will be updated. Similarly, whenever a GUI event of the specified type (or types - you may pass in a list of event types) occurs, the property value will be set to the value controlled by the GUI widget.
- Parameters
hasProps – The owning
HasProperties
instance.propObj – The
PropertyBase
property type.propVal – The
PropertyValue
to be bound.guiObj – The
wx
GUI widgetevType – The event type (or list of event types) which should be listened for on the
guiObj
.widgetGet – Function which returns the current widget value. If
None
, theguiObj.GetValue
method is used.widgetSet – Function which sets the current widget value. If
None
, theguiObj.SetValue
method is used.widgetDestroy – Function which is called if/when the widget is destroyed. Must accept one argument - the
wx.Event
object.
-
fsleyes_props.widgets.
_propUnbind
(hasProps, propObj, propVal, guiObj, evType)¶ Removes any event binding which has been previously configured via the
_propBind()
function, between the givenPropertyValue
instance, and the givenwx
widget.
-
fsleyes_props.widgets.
_setupValidation
(widget, hasProps, propObj, propVal)¶ Configures input validation for the given widget, which is assumed to be bound to the given
propVal
(aPropertyValue
object).Any changes to the property value are validated and, if the new value is invalid, the widget background colour is changed to a light red, so that the user is aware of the invalid-ness.
- Parameters
widget – The
wx
GUI widget.hasProps – The owning
HasProperties
instance.propObj – The
PropertyBase
property type.propVal – The
PropertyValue
instance.
-
fsleyes_props.widgets.
_String
(parent, hasProps, propObj, propVal, **kwargs)¶ Creates and returns a
wx.TextCtrl
object, allowing the user to edit the givenpropVal
(managed by aString
instance).- Parameters
parent – The
wx
parent object.hasProps – The owning
HasProperties
instance.propObj – The
PropertyBase
instance (assumed to be aString
).propVal – The
PropertyValue
instance.kwargs – Type-specific options.
-
fsleyes_props.widgets.
_FilePath
(parent, hasProps, propObj, propVal, **kwargs)¶ Creates and returns a panel containing a
wx.TextCtrl
and awx.Button
.The button, when clicked, opens a file dialog allowing the user to choose a file/directory to open, or a location to save (this depends upon how the
propObj
[aFilePath
instance] object was configured).See the
_String()
documentation for details on the parameters.
-
fsleyes_props.widgets.
_Real
(parent, hasProps, propObj, propVal, **kwargs)¶ Creates and returns a widget allowing the user to edit the given
Real
property value. See thewidgets_number._Number()
function for more details.See the
_String()
documentation for details on the parameters.
-
fsleyes_props.widgets.
_Int
(parent, hasProps, propObj, propVal, **kwargs)¶ Creates and returns a widget allowing the user to edit the given
Int
property value. See thewidgets_number._Number()
function for more details.See the
_String()
documentation for details on the parameters.
-
fsleyes_props.widgets.
_Percentage
(parent, hasProps, propObj, propVal, **kwargs)¶ Creates and returns a widget allowing the user to edit the given
Percentage
property value. See thewidgets_number._Number()
function for more details.See the
_String()
documentation for details on the parameters.
-
fsleyes_props.widgets.
_Colour
(parent, hasProps, propObj, propVal, size=(16, 16), **kwargs)¶ Creates and returns a
ColourButton
widget, allowing the user to modify the givenColour
property value.- Parameters
size – Desired size, in pixels, of the
ColourButton
.
-
fsleyes_props.widgets.
_makeColourMapBitmap
(cmap)¶ Used by the
_ColourMap()
function.Makes a little bitmap image from a
Colormap
instance.
-
fsleyes_props.widgets.
_ColourMap
(parent, hasProps, propObj, propVal, labels=None, **kwargs)¶ Creates and returns a combobox, allowing the user to change the value of the given
ColourMap
property value.- Parameters
labels –
A dictionary containing
{name : label}
mappings, defining a display name/label for each colour map. If not provided, the colour mapname
attribute is used as the display name.Can alternately be a function which accepts a colour map identifier name, and returns its display name.
See also the
_makeColourMapBitmap()
function.
-
fsleyes_props.widgets.
_LinkBox
(parent, hasProps, propObj, propVal, **kwargs)¶ Creates a ‘link’ button which toggles synchronisation between the property on the given
hasProps
instance, and its parent.
-
fsleyes_props.widgets.
makeSyncWidget
(parent, hasProps, propName, **kwargs)¶ Creates a button which controls synchronisation of the specified property on the given
hasProps
instance, with the corresponding property on its parent.See the
makeWidget()
function for a description of the arguments.
-
fsleyes_props.widgets.
makeWidget
(parent, hasProps, propName, **kwargs)¶ Given
hasProps
(aHasProperties
instance),propName
(the name of a property ofhasProps
), andparent
, a GUI object, creates and returns a widget, or a panel containing widgets, which may be used to edit the property value.- Parameters
parent – A
wx
object to be used as the parent for the generated widget(s).hasProps – A
HasProperties
instance.propName (str) – Name of the
PropertyBase
property to generate a widget for.kwargs – Type specific arguments.
-
fsleyes_props.widgets.
makeListWidget
(parent, hasProps, propName, index, **kwargs)¶ Creeates a widget for a specific value in the specified list property.
-
fsleyes_props.widgets.
makeListWidgets
(parent, hasProps, propName, **kwargs)¶ Creates a widget for every value in the given list property.
-
fsleyes_props.widgets.
bindWidget
(widget, hasProps, propName, evTypes, widgetGet=None, widgetSet=None)¶ Binds the given widget to the specified property. See the
_propBind()
method for details of the arguments.
-
fsleyes_props.widgets.
bindListWidgets
(widgets, hasProps, propName, evTypes, widgetSets=None, widgetGets=None)¶ Binds the given sequence of widgets to each of the values in the specified list property.
-
fsleyes_props.widgets.
unbindWidget
(widget, hasProps, propName, evTypes)¶ Unbinds the given widget from the specified property, assumed to have been previously bound via the
bindWidget()
function.