campy.gui.ginteractors module

Graphical interactors.

This module provides five types of interactors:

class campy.gui.ginteractors.GButton(label)[source]

Bases: campy.gui.ginteractors.GInteractor

An onscreen, clickable button.

The following program displays a button that, when pressed, generates the message: “Please do not press this button again!” (credit Douglas Adams):

window = GWindow()
button = GButton('RED BUTTON')
window.add_to_region(button, Region.NORTH)

@button.onclick
def chastise(event):
    event.button.label = 'Please do not press this button again!'
    event.button.disable()
add_click_handler(function)[source]
click()[source]
disable()[source]

Disable this GButton, meaning it cannot receive clicks.

disabled

Get or set whether this GButton: is disabled.

enable()[source]

Enable this GButton, meaning it can receive clicks.

label

Get or set this GButton:’s label.

onclick(function)[source]
remove_click_handler(function)[source]
class campy.gui.ginteractors.GCheckBox(label)[source]

Bases: campy.gui.ginteractors.GInteractor

An onscreen check box.

Clicking once on the check box selects it; clicking again removes the selection.

Clicking on the box generates a GActionEvent.

selected

Get or set whether the checkbox is selected.

Parameters:state (bool) – Whether the checkbox is selected.
class campy.gui.ginteractors.GChooser(*items)[source]

Bases: campy.gui.ginteractors.GInteractor

A list of selectable items.

You can construct a GChooser with an ordered collection of items, or add() and remove() items after construction:

size_chooser = GChooser('Small', 'Medium', 'Large')
size_chooser.add_item('X-Large')
size_chooser.remove_item('Medium')

To get the selected item:

size_chooser = GChooser('Small', 'Medium', 'Large')
selected = size_chooser.selected_item
add_item(item)[source]

Add a new option to this GChooser.

Parameters:item – The new item to add to this GChooser.
remove_item(item)[source]

Remove an option from this GChooser.

Parameters:item – The item to remove from this GChooser.
Returns:Whether the item was removed.
selected_item

Get or set the currently selected item of this GChooser.

Setting the selected item to something not in this GChooser’s list of items results in no change.

class campy.gui.ginteractors.GInteractor(command='')[source]

Bases: campy.graphics.gobjects.GObject

Superclass of all graphical interactors.

In most applications, interactors will be added to one region in a GWindow, but interactors can also be placed in specific positions in a GCompound (or the GWindow’s default top GCompound) just like any other GObject.

command

Get or set the action command for this interactor.

class campy.gui.ginteractors.GSlider(min_value=0, max_value=100, starting_value=50)[source]

Bases: campy.gui.ginteractors.GInteractor

An onscreen slider.

Dragging

value

Get or set the current value of the GSlider.

Parameters:value (int) – The value of the GSlider.
class campy.gui.ginteractors.GTextField(width=10)[source]

Bases: campy.gui.ginteractors.GInteractor

An onscreen text field for entering short text strings.

Hitting RETURN in a text field generates a GActionEvent.

text

Get or set the contents of this GTextField.