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:
Builds a GUI interface which allows the properties of the given
HasPropertiesobject to be edited.Convenience method which embeds the result of a call to
buildGUI()in awx.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¶ Bases:
objectAn internal container class used for convenience. Stores references to all
wxobjects that are created, and to all conditional callbacks (which control visibility/state).-
__init__()¶ Initialize self. See help(type(self)) for accurate signature.
-
__dict__= mappingproxy({'__module__': 'fsleyes_props.build', '__doc__': 'An internal container class used for convenience. Stores references to\n all :mod:`wx` objects that are created, and to all conditional callbacks\n (which control visibility/state).\n ', '__init__': <function PropGUI.__init__>, '__dict__': <attribute '__dict__' of 'PropGUI' objects>, '__weakref__': <attribute '__weakref__' of 'PropGUI' objects>})¶
-
__module__= 'fsleyes_props.build'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
-
fsleyes_props.build._configureEnabledWhen(viewItem, guiObj, hasProps, propGui)¶ Configures a callback function for this view item, if its
enabledWhenattribute was set.- Parameters
viewItem – The
ViewItemobjectguiObj – The GUI object created from the
ViewItemhasProps – The
HasPropertiesinstancepropGui – The
PropGuiinstance, in which references to all event callbacks are stored
-
fsleyes_props.build._configureVisibleWhen(viewItem, guiObj, hasProps, propGui)¶ Configures a callback function for this view item, if its visibleWhen attribute was set. See
_configureEnabledWhen().- Parameters
viewItem – The
ViewItemobjectguiObj – The GUI object created from the
ViewItemhasProps – The
HasPropertiesinstancepropGui – The
PropGuiinstance, in which references to all event callbacks are stored
-
fsleyes_props.build._configureEventCallback(viewItem, callback, evType, hasProps, guiObj, propGui)¶ Called by both the
_configureVisibleWhen()and_configureEnabledWhen()functions.Wraps the given
callbackfunction (which is essentially aViewItem.visibleWhenorViewItem.enabledWhenfunction) inside another function, which handles the marshalling of arguments to be passed to thecallback.The arguments that are passed to the function depend on the value of the
ViewItem.dependenciesattribute - see thebuild_partsmodule for an explanation.The resulting callback function is added to the
PropGui.onChangeCallbackslist.- Parameters
viewItem – The
ViewIteminstancecallback – The callback function to be encapsulated.
evType – Purely for logging. Either ‘visible’ or ‘enable’.
hasProps – The
HasPropertiesinstance.guiObj – The
wxGUI object which has been created from theviewItemspecification.propGui – The
PropGuiinstance which stores references to all event callbacks.
-
fsleyes_props.build._createLinkBox(parent, viewItem, hasProps, propGui)¶ Creates a checkbox which can be used to link/unlink a property from its parent property.
-
fsleyes_props.build._createLabel(parent, viewItem, hasProps, propGui)¶ Creates a
wx.StaticTextobject containing a label for the givenViewItem.
-
fsleyes_props.build._createButton(parent, viewItem, hasProps, propGui)¶ Creates a
wx.Buttonobject for the givenButtonobject.
-
fsleyes_props.build._createToggle(parent, viewItem, hasProps, propGui)¶ Creates a widget for the given
Toggleobject. If no icons have been set, awx.CheckBoxis used. Otherwise aBitmapToggleButtonis used.
-
fsleyes_props.build._createWidget(parent, viewItem, hasProps, propGui)¶ Creates a widget for the given
Widgetobject, using themakeWidget()function (see theprops.widgetsmodule for more details).
-
fsleyes_props.build._makeGroupBorder(parent, group, ctr, *args, **kwargs)¶ Makes a border for a
Group.If a the
borderattribute of aGroupobject has been set toTrue, this function is called. It creates a parentwx.Panelwith a border and title, then creates and embeds the GUI object representing the group (via the ctr argument). Returns the parent border panel, and the group GUI object. Parameters:- Parameters
parent – Parent GUI object
group –
VGroup,HGrouporNotebookGroupctr – Constructor for a
wx.Windowobject.args – Passed to ctr. You don’t need to pass in the parent.
kwargs – Passed to ctr.
-
fsleyes_props.build._createNotebookGroup(parent, group, hasProps, propGui)¶ Creates a
fsleyes_widgets.notebook.Notebookobject from the givenNotebookGroupobject.The children of the group object are also created via recursive calls to the
_create()function.
-
fsleyes_props.build._layoutHGroup(group, parent, children, labels)¶ Lays out the children (and labels, if not
None) of the givenHGroupobject. Parameters:- Parameters
group –
HGroupobjectparent – GUI object which represents the group
children – List of GUI objects, the children of the group.
labels –
Noneif no labels, otherwise a list of GUI Label objects, one for each child.
-
fsleyes_props.build._layoutVGroup(group, parent, children, labels)¶ Lays out the children (and labels, if not
None) of the givenVGroupobject. Parameters the same as_layoutHGroup().
-
fsleyes_props.build._createGroup(parent, group, hasProps, propGui)¶ Creates a GUI panel object for the given
HGrouporVGroup.Children of the group are recursively created via calls to
_create(), and laid out via the_layoutHGroupor_layoutVGroupfunctions.
-
fsleyes_props.build._createHGroup(parent, group, hasProps, propGui)¶ Alias for the
_createGroup()function.
-
fsleyes_props.build._createVGroup(parent, group, hasProps, propGui)¶ Alias for the
_createGroup()function.
-
fsleyes_props.build._getCreateFunction(viewItemClass)¶ Searches within this module for a function which can parse instances of the specified
ViewItemclass.A match will be found if the given class is one of those defined in the
build_partsmodule, or has one of those classes in its base class hierarchy. In other words, application-defined subclasses of any of thebuild_partsclasses will still be built.
-
fsleyes_props.build._create(parent, viewItem, hasProps, propGui)¶ Creates a GUI object for the given
ViewItemobject and, if it is a group, all of its children.
-
fsleyes_props.build._defaultView(hasProps)¶ Creates a default view specification for the given
HasPropertiesobject, with all properties laid out vertically. This function is only called if a view specification was not provided in the call to thebuildGUI()function
-
fsleyes_props.build._prepareView(hasProps, viewItem, labels, tooltips, showUnlink)¶ Recursively steps through the given
viewItemand its children (if any).If the
viewItemis a string, it is assumed to be a property name, and it is turned into aWidgetobject. If theviewItemdoes not have a label/tooltip, and there is a label/tooltip for it in the given labels/tooltips dict, then its label/tooltip is set. Returns a reference to the updated/newly createdViewItem.
-
fsleyes_props.build._finaliseCallbacks(hasProps, propGui)¶ Calls all defined
ViewItemvisibleWhenandenabledWhencallback functions, in order to set the initial GUI state.Also registers a listener on the top level GUI panel to remove all property listeners from the
hasPropsinstance when the panel is destroyed.
-
fsleyes_props.build.buildGUI(parent, hasProps, view=None, labels=None, tooltips=None, showUnlink=False)¶ Builds a GUI interface which allows the properties of the given
HasPropertiesobject to be edited.Returns a reference to the top level GUI object (typically a
wx.Frame,wx.PanelorNotebook).Parameters:
- Parameters
parent – The parent GUI object. If
None, the interface is embedded within awx.Frame.hasProps – The
HasPropertiesinstance.view – A
ViewItemobject, specifying the interface layout.labels – A dictionary specifying labels.
tooltips – A dictionary specifying tooltips.
showUnlink – If the given
hasPropsinstance is aSyncableHasPropertiesinstance, 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)¶ Convenience method which embeds the result of a call to
buildGUI()in awx.Dialog.See the
buildGUI()documentation for details on the paramters.- Parameters
dlgButtons – If
True, the dialog will have ‘Ok’ and ‘Cancel’ buttons.