batgrl.gadgets.behaviors.toggle_button_behavior#

Toggle button behavior for a gadget.

Module Attributes

ToggleState

Toggle button behavior states.

Classes

ToggleButtonBehavior([group, ...])

Toggle button behavior for gadgets.

class batgrl.gadgets.behaviors.toggle_button_behavior.ToggleButtonBehavior(group: Hashable | None = None, allow_no_selection: bool = False, always_release: bool = False, **kwargs)#

Bases: ButtonBehavior

Toggle button behavior for gadgets.

Without a group, toggle button’s states switch between “on” and “off” when pressed. With a group, only a single button in the group can be in the “on” state at a time.

Parameters:
groupHashable | None, default: None

If a group is provided, only one button in a group can be in the on state.

allow_no_selectionbool, default: False

If a group is provided, setting this to true allows no selection, i.e., every button can be in the off state.

always_releasebool, default: False

Whether a mouse up event outside the button will trigger it.

Attributes:
groupHashable | None

If a group is provided, only one button in a group can be in the on state.

allow_no_selectionbool

If true and button is in a group, every button can be in the off state.

toggle_stateToggleState

Toggle state of button.

always_releasebool

Whether a mouse up event outside the button will trigger it.

button_stateButtonState

Current button state.

Methods

on_toggle()

Triggled on toggle state change.

update_off()

Paint the off state.

update_on()

Paint the on state.

on_release()

Triggered when a button is released.

update_normal()

Paint the normal state.

update_hover()

Paint the hover state.

update_down()

Paint the down state.

update_disallowed()

Paint the disallowed state.

property button_state: Literal['normal', 'hover', 'down', 'disallowed']#

Current button state.

on_add()#

Paint normal state on add.

on_mouse(mouse_event) bool | None#

Determine button state from mouse event.

on_release()#

Triggered when button is released.

on_toggle()#

Update gadget on toggle state change.

property toggle_state: Literal['on', 'off']#

Toggle state of button.

update_disallowed()#

Paint the disallowed state.

update_down()#

Paint the down state.

update_hover()#

Paint the hover state.

update_normal()#

Paint the normal state.

update_off()#

Paint the off state.

update_on()#

Paint the on state.

batgrl.gadgets.behaviors.toggle_button_behavior.ToggleState#

Toggle button behavior states.

alias of Literal[‘on’, ‘off’]