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:

makeWidget

Given hasProps (a HasProperties instance), propName (the name of a property of hasProps), and parent, a GUI object, creates and returns a widget, or a panel containing widgets, which may be used to edit the property value.

makeListWidget

Creeates a widget for a specific value in the specified list property.

makeListWidgets

Creates a widget for every value in the given list property.

makeSyncWidget

Creates a button which controls synchronisation of the specified property on the given hasProps instance, with the corresponding property on its parent.

bindWidget

Binds the given widget to the specified property.

unbindWidget

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:

_FilePath

Creates and returns a panel containing a wx.TextCtrl and a wx.Button.

_String

Creates and returns a wx.TextCtrl object, allowing the user to edit the given propVal (managed by a String instance).

_Real

Creates and returns a widget allowing the user to edit the given Real property value.

_Int

Creates and returns a widget allowing the user to edit the given Int property value.

_Percentage

Creates and returns a widget allowing the user to edit the given Percentage property value.

_Colour

Creates and returns a ColourButton widget, allowing the user to modify the given Colour property value.

_ColourMap

Creates and returns a combobox, allowing the user to change the value of the given ColourMap property value.

_LinkBox

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:

_List

_Bounds

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.

_Point

Creates and returns a SliderSpinPanel allowing the user to edit the low/high values along each dimension of the given Point property value.

_Choice

Creates and returns a widget allowing the user to modify the given Choice property value.

_Boolean

Creates and returns a wx.CheckBox, allowing the user to set the given Boolean property value.

_Number

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 widget

  • evType – 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, the guiObj.GetValue method is used.

  • widgetSet – Function which sets the current widget value. If None, the guiObj.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 given PropertyValue instance, and the given wx 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 (a PropertyValue 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.

This function is only used for a few different property types, namely
Parameters
fsleyes_props.widgets._String(parent, hasProps, propObj, propVal, **kwargs)

Creates and returns a wx.TextCtrl object, allowing the user to edit the given propVal (managed by a String instance).

Parameters
  • parent – The wx parent object.

  • hasProps – The owning HasProperties instance.

  • propObj – The PropertyBase instance (assumed to be a String).

  • 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 a wx.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 [a FilePath 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 the widgets_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 the widgets_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 the widgets_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 given Colour 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 map name 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.

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 (a HasProperties instance), propName (the name of a property of hasProps), and parent, 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.