The gui_helpers module

Classes and functions to facilitate general wx actions.

Classes

KeyValListCtrl

class src.gui.gui_helpers.KeyValListCtrl(parent)[source]

A list control for managing typed key-value pairs.

Parameters :

parent : wxWindow

The panel or frame which contains this control.

Methods

BaseDialog

class src.gui.gui_helpers.BaseDialog(parent, wxId=-1, title='Dialog', info=None, minWidth=None)[source]

A base class to be extended by dialogs.

Note: it is important to call this class’s finish method after all components have been added.

Parameters :

parent : wxWindow

The panel or frame which spawns this dialog.

wxId : int

The wxPython identification number for this dialog.

title : str

The title to display in the dialog’s title bar.

info : tuple of str

A tuple of strings. The first is the title of the info bar, and the second is the text of the info bar. The info bar will not be displayed if infoBar is None.

Methods

setPanel(panel, proportion=1, flags=8432, border=5)[source]

Finish laying out the panel.

update()[source]

Update whatever objects this dialog is supposed to modify.

Returns :

bool :

Whether the attempt to update the appropriate objects was successful.

InfoBar

StaticWrapText

Panel

class src.gui.gui_helpers.Panel(parent, sizerType='vertical', label=None, *args, **kwargs)[source]

A panel subclass which builds in sizer support.

Methods

add(item, *args, **kwargs)[source]

Add an item to the panel’s sizer.

All extra arguments are passed to the sizer.Add method.

Parameters :

item : wxWindow

The control to add to the panel.

addButton(label, wxId=-1, border=3, handler=None)[source]

Create a new button and add it to the panel.

Parameters :

label : str

The text which should go on the button.

wxId : int

The ID for the button.

border : int

The size in pixels of the border to go around the button.

handler : method

The method to execute when the button is clicked.

Returns :

wxButton :

The button created by this method.

addGrowableColumn(index, proportion=1)[source]

Make a column growable in a flexible sizer.

Parameters :

index : int

The index of the column to allow to expand.

proportion : int

The weighting factor for expansion.

addLabel(text, border=3, flag=None)[source]

Add a text label to the control using default options.

Parameters :

text : str

The text of the label to add.

border : int

The width in pixels of the border which will surround the new text label.

Returns :

wxStaticText :

The added text label.

addLabeledComboBox(label, initialValue='', choices=None, border=0, style=0, defocusHandler=None, valueHandler=None, proportion=1)[source]

Add a label and a text control.

Parameters :

label : str

The text to label the combo box.

initialValue : str

The initial value of the combo box.

choices : list of str

The accepted values for the combo box.

border : int

The width in pixels of the border which will surround both the new label and the new combo box.

style : int

The style (in terms of wx constants) of the combo box.

defocusHandler : method

The method to execute when the combo box loses focus.

valueHandler : method

The method to execute when the selection of the combo box changes.

proportion : int

The weighting factor for sizing the combo box.

addLabeledMultiCtrl(label, initialValue=None, allowed=None, border=0, style=0, defocusHandler=None)[source]

Add a label and text controls to the panel.

The number of controls to be added will be determined by initialValue. There will be one item for each value of initialValue, If the value of allowed at the same position as a value of initialValue is a list, the created control will be a wxComboBox with the listed choices available.

Parameters :

label : str

The text to label the text control.

initialValue : list of str

The initial values of the text controls.

allowed : list of list of str

A list of lists of strings. Each element in the outer list corresponds to a single control. The strings in the inner list correspond to the allowed values for the control. If any element of the outer list is None, that list item will create a wxTextCtrl instead of a wxComboBox.

border : int

The width in pixels of the border which will surround both the new label and the new text control.

style : int

The style (in terms of wx constants) of the text control.

defocusHandler : method or list of method

The method to execute when the text control loses focus. If it is a list, the handlers will be applied sequentially to the controls created for each element in initialValue. If it is a single method, the same method will be bound to all controls.

Returns :

list of (wxTextCtrl or wxComboBox) :

The list of text controls and combo box controls which have been created and added to the panel.

addLabeledText(label, initialValue=None, border=0, style=0, defocusHandler=None)[source]

Add a label and a text control.

Parameters :

label : str

The text to label the text control.

initialValue : str

The initial value of the text control.

border : int

The width in pixels of the border which will surround both the new label and the new text control.

style : int

The style (in terms of wx constants) of the text control.

defocusHandler : method

The method to execute when the text control loses focus.

Returns :

wxTextCtrl :

The text control which has been created and added to the panel.

addStretchSpacer(proportion)[source]

Add a stretchable spacer to the panel.

Parameters :

proportion : int

The weighting factor for expansion.

setLabel(newLabel)[source]

Set the label for the border.

Parameters :

newLabel : str

The new label for the panel’s border.

ScanPanel

class src.gui.gui_helpers.ScanPanel(parent, wxId=-1, initialData=None, formatString='%.3f', buttonIcons=True, label=None)[source]

A scan panel with extra options.

Parameters :

parent : wxWindow

The panel or frame which contains this panel.

wxId : int

The ID of this panel.

initialData : list of tuple of float

The data the table should contain initially. Each tuple is one row and should be of the form (initial point, final point, step size), where all are in the same units.

formatString : str

The string used to format the floats into appropriate strings.

buttonIcons : bool

Whether to use icons for the editing buttons. If False, text will be used instead.

label : str

The label to surround the panel. If None, the panel will not have either a label or a border.

Methods

formatData()[source]

Format the data in the control using the format string.

getData(formatData=False)[source]

Get the data values from the table control.

Parameters :

formatData : bool

Whether to format the data before returning it from the table.

Returns :

list of tuple of str :

The data from the list control. Each tuple represents one row.

getRowData(index)[source]

Get the data from one row of the table.

Parameters :

index : int

The index of the row whose data should be returned.

Returns :

list of str :

A list of strings containing the data from the specified row.

onAdd(event)[source]

Add a new item.

onInsert(event)[source]

Insert an item at the current position

onMoveDown(event)[source]

Move the selected item down.

onMoveUp(event)[source]

Move the currently selected item up.

onRemove(event)[source]

Remove the selected item.

setData(data, formatData=True)[source]

Set the data values in the table control.

Parameters :

data : list of tuple

A list of tuples, where each tuple contains the data for one row. The data type of the elements in the tuples can be str, int, or float, as long as it can be cast to float.

formatData : bool

Whether to format the data before passing it to the table control.

ErrorDialog

class src.gui.gui_helpers.ErrorDialog(parent, error)[source]

A dialog for displaying general sequence errors.

Parameters :

parent : wxWindow

The panel or frame which spawns this dialog.

error : GeneralExperimentError

The exception whose contents should be displayed in the dialog.

Methods

ComboBoxPrompter

class src.gui.gui_helpers.ComboBoxPrompter(parent=None, width=60)[source]

An object for prompting for user input from a combo box dialog.

Methods

Functions

src.gui.gui_helpers.createButton(parent, sizer, wxId=-1, icon=None, label='', tooltip=None, border=2, handler=None)[source]

Create a new button.

Parameters :

parent : wxWindow

The button’s parent frame or panel.

sizer : wxSizer

The sizer to which the button should be added.

wxId : int

The ID number of the control (default: wx.ID_ANY).

icon : wxBitmap

A bitmap object to use as the icon for the button (default: None). If None, the label will be used instead of an icon.

label : str

The label for the button. If icon is provided, then label will be ignored.

tooltip : str

The tooltip to display when the user hovers over the button.

border : int

The amount of space in pixels to display around all sides of the button.

handler : method

The method which will be invoked when the user clicks on the button.

Returns :

wxButton :

The newly created button.

src.gui.gui_helpers.createMenuItem(parent, menu, wxId, label, tooltip=None, handler=None, pos=None)[source]

Create a new menu item and add it to the appropriate menu.

Parameters :

parent : wxWindow

The frame or control which contains the appropriate menu bar.

menu : wxMenu

The menu to which the item should be added.

wxId : int

The ID of the menu item.

label : str

The text which should label the item.

tooltip : str

The text which should go in the tooltip and/or the status bar when the item is highlighted.

handler : method

The method which should respond to clicks on the item.

pos : int

The position before which the item should be inserted. If None (the default), the item will be appended to the end.

Returns :

wxMenuItem :

The newly created menu item.

src.gui.gui_helpers.createMenu(parent, menuBar, menuTitle, menuItems)[source]

Create a new menu and populate it.

Parameters :

parent : wxWindow

The frame or control which contains the appropriate menu bar.

menuBar : wxMenuBar

The menu bar which should contain the new menu.

menuTitle : str

The title of the menu.

menuItems : list of tuple

A list of tuples, where each tuple describes one item for the menu. The tuples should contain, in order, wxId, label, tooltip, and handler. For the meanings, see createMenuItem. If an element in the list is None, a separator will be appended at that point.

Returns :

list of wxMenuItem :

The menu item objects which constitute the menu.

src.gui.gui_helpers.createLabeledTextControl(parent, sizer, wxId=-1, label='Input:', initialValue='', border=0, style=0, defocusHandler=None)[source]

Create a label and a text control and add them to the sizer.

Parameters :

parent : wxWindow

The panel or frame which should serve as the parent for the label and control.

sizer : wxSizer

The sizer to which the label and text control should be added. Usually, it should be a wxFlexGridSizer or wxGridSizer.

wxId : int

The ID for the text control (default: wx.ID_ANY).

label : str

The text that goes in the label (default: “Input:”).

initialValue : str

The initial value for the control (default: “”).

border : int

The border thickness in pixels (default: 0). The same border is applied around both the label and the control.

style : int

The style (normally, use wx constants) to use for the text control (default: 0).

defocusHandler : method

A method to be called when the text control loses focus (default: None).

Returns :

wxTextCtrl :

The text control created by this function.

src.gui.gui_helpers.createLabeledComboBox(parent, sizer, wxId=-1, label='Input:', initialValue='', choices=None, border=0, style=32, defocusHandler=None, valueHandler=None)[source]

Create a label and a combo box and add them to the sizer.

Parameters :

parent : wxWindow

The panel or frame which should serve as the parent for the label and control.

sizer : wxSizer

The sizer to which the label and combo box should be added. Usually, it should be a wxFlexGridSizer or wxGridSizer.

wxId : int

The ID for the combo box (default: wx.ID_ANY).

label : str

The text that goes in the label (default: “Input:”).

initialValue : str

The initial value for the control (default: “”).

choices : list of str

A list of strings representing the values the combo box offers. If None (the default), no options will be available initially. (If None, make sure that style is not wx.CB_READONLY, or the combo box will be entirely useless.)

border : int

The border thickness in pixels (default: 0). The same border is applied around both the label and the control.

style : int

The style (normally, use wx constants) to use for the combo box (default: wx.CB_DROPDOWN; the other typical value is wx.CB_READONLY).

defocusHandler : method

A method to be called when the text control loses focus (default: None).

valueHandler : method

A method to be called when the value selection in the combo box changes (default: None)

Returns :

wxComboBox :

The combo box created by this function.

Table Of Contents

Previous topic

The images module

Next topic

The core package

This Page