fsleyes_props.build

Automatically build a wx GUI for a HasProperties instance.

This module provides functionality to automatically build a wx GUI containing widgets which allow the user to change the property values (PropertyBase instances) of a specified HasProperties instance.

This module has two main entry points:

buildGUI

Builds a GUI interface which allows the properties of the given HasProperties object to be edited.

buildDialog

Convenience method which embeds the result of a call to buildGUI() in a wx.Dialog.

A number of classes are defined in the separate build_parts module. The ViewItem class allows the layout of the generated interface to be customised. Property widgets may be grouped together by embedding them within a HGroup or VGroup object; they will then respectively be laid out horizontally or verticaly. Groups may be embedded within a NotebookGroup object, which will result in a notebook-like interface containing a tab for each child Group.

The label for, and behaviour of, the widget for an individual property may be customised with a Widget object. As an example:

import wx
import fsleyes_props as props

class MyObj(props.HasProperties):
    myint  = props.Int()
    mybool = props.Boolean()

# A reasonably complex view specification
view = props.VGroup(
  label='MyObj properties',
  children=(
      props.Widget('mybool',
                   label='MyObj Boolean',
                   tooltip='If this is checked, you can '
                           'edit the MyObj Integer'),
      props.Widget('myint',
                   label='MyObj Integer',
                   enabledWhen=lambda mo: mo.mybool)))

# A simpler view specification
view = props.VGroup(('mybool', 'myint'))

# The simplest view specification - a
# default one will be generated
view = None

myobj = MyObj()

app   = wx.App()
frame = wx.Frame(None)

myObjPanel = props.buildGUI(frame, myobj, view)

See the build_parts module for details on the Widget (and other ViewItem) definitions.

You may also pass in widget labels and tooltips to the buildGUI() function:

labels = {
    'myint':  'MyObj Integer value',
    'mybool': 'MyObj Boolean value'
}

tooltips = {
    'myint' : 'MyObj Integer tooltip'
}

props.buildGUI(frame, myobj, view=view, labels=labels, tooltips=tooltips)

As an alternative to passing in a view, labels, and tooltips to the buildGUI() function, they may be specified as class attributes of the HasProperties instance or class, with respective names _view, _labels, and _tooltips:

class MyObj(props.HasProperties):
    myint  = props.Int()
    mybool = props.Boolean()

    _view = props.HGroup(('myint', 'mybool'))
    _labels = {
        'myint':  'MyObj integer',
        'mybool': 'MyObj boolean'
    }
    _tooltips = {
        'myint':  'MyObj integer tooltip',
        'mybool': 'MyObj boolean tooltip'
    }

props.buildGUI(frame, myobj)
class fsleyes_props.build.PropGUI[source]

Bases: object

An internal container class used for convenience. Stores references to all wx objects that are created, and to all conditional callbacks (which control visibility/state).

fsleyes_props.build.buildGUI(parent, hasProps, view=None, labels=None, tooltips=None, showUnlink=False)[source]

Builds a GUI interface which allows the properties of the given HasProperties object to be edited.

Returns a reference to the top level GUI object (typically a wx.Frame, wx.Panel or Notebook).

Parameters:

Parameters:
  • parent – The parent GUI object. If None, the interface is embedded within a wx.Frame.

  • hasProps – The HasProperties instance.

  • view – A ViewItem object, specifying the interface layout.

  • labels – A dictionary specifying labels.

  • tooltips – A dictionary specifying tooltips.

  • showUnlink – If the given hasProps instance is a SyncableHasProperties instance, and it has a parent, a ‘link/unlink’ checkbox will be shown next to any properties that can be bound/unbound from the parent object.

fsleyes_props.build.buildDialog(parent, hasProps, view=None, labels=None, tooltips=None, showUnlink=False, dlgButtons=True)[source]

Convenience method which embeds the result of a call to buildGUI() in a wx.Dialog.

See the buildGUI() documentation for details on the paramters.

Parameters:

dlgButtons – If True, the dialog will have ‘Ok’ and ‘Cancel’ buttons.