Skip to content

brian.buttons.UiEventsListener

brian.buttons

UiEventsListener class objects

class UiEventsListener()

Collects button and knob events, so a program polling in a loop does not miss presses that happen between polls.

KnobEvent class objects

class KnobEvent()

Knob events since the last knob_event_since_last() call.

turn_delta

Turn indents since the last call; positive is clockwise

turned_to

Absolute turn indent count since this listener was created

is_pressed

True if the knob is pressed

just_pressed

True if the knob was pressed since the last call

just_released

True if the knob was released since the last call

ButtonEvent class objects

class ButtonEvent()

Events of one button since the last buttons_event_since_last() call.

is_pressed

True if the button is pressed

just_pressed

True if the button was pressed since the last call

just_released

True if the button was released since the last call

ButtonsEvent class objects

class ButtonsEvent()

Events of all buttons since the last buttons_event_since_last() call.

top_left

Top left button

top_right

Top right button

bottom_left

Bottom left button

bottom_right

Bottom right button

any_button

Any of the four corner buttons (knob excluded)

any_button_incl_knob

Any of the four corner buttons or the knob press

Button class objects

class Button()

A button seen through this listener.

is_pressed

def is_pressed() -> bool

Returns:

True if the button is currently pressed (live state, does not consume events).

last_button_event

def last_button_event() -> 'UiEventsListener.ButtonEvent'

Returns:

Snapshot of the last event of this button, without resetting the just_pressed / just_released flags.

set_led

def set_led(effect: LedEffect,
            color: LedColor = 'DEFAULT_COLOR_FROM_SETTINGS') -> None

Sets desired effect and color for the LED of this button. These settings override the effect

requested by the OS, unless LedEffect.inherit is used. For any_button and any_button_incl_knob all respective buttons change color/effect.

Arguments:

  • effect: Target LED effect.
  • color: Target color. When unfilled default color from settings is used.

wait_for_press

def wait_for_press(timeout_ms: Optional[int] = None) -> bool

Waits for next button press event.

This function is blocking.

Arguments:

  • timeout_ms: Maximum number of milliseconds to wait.
  • If the timeout is not provided or is None, the function will wait indefinitely.

Returns:

success: - True: If the desired button event was caught. - False: If the timeout ran out.

wait_for_release

def wait_for_release(timeout_ms: Optional[int] = None) -> bool

Waits for next button release event.

This function is blocking.

Arguments:

  • timeout_ms: Maximum number of milliseconds to wait.
  • If the timeout is not provided or is None, the function will wait indefinitely.

Returns:

success: - True: If the desired button event was caught. - False: If the timeout ran out.

wait_for_press_and_release

def wait_for_press_and_release(timeout_ms: Optional[int] = None) -> bool

Waits for next button press and release event.

This function is blocking.

Arguments:

  • timeout_ms: Maximum number of milliseconds to wait.
  • If the timeout is not provided or is None, the function will wait indefinitely.

Returns:

success: - True: If the desired button event was caught. - False: If the timeout ran out.

Knob class objects

class Knob(Button)

The knob seen through this listener.

turned_to

def turned_to() -> int

Returns:

Absolute turn indent count since this listener was created (live state, does not consume events).

last_button_event

def last_button_event() -> 'UiEventsListener.KnobEvent'

Returns:

Snapshot of the last event of the knob, without resetting the just_pressed / just_released and turn_delta fields.

wait_for_directional_turn

def wait_for_directional_turn(clockwise: bool = True,
                              timeout_ms: Optional[int] = None) -> bool

Waits for next directional turn of the knob.

This function is blocking.

Arguments:

  • clockwise: Whether to wait for clockwise or counterclockwise turn.
  • timeout_ms: Maximum number of milliseconds to wait.
  • If the timeout is not provided or is None, the function will wait indefinitely.

Returns:

success: - True: If the desired button event was caught. - False: If the timeout ran out.

wait_for_any_turn

def wait_for_any_turn(timeout_ms: Optional[int] = None) -> bool

Waits for next any turn of the knob.

This function is blocking.

Arguments:

  • timeout_ms: Maximum number of milliseconds to wait.
  • If the timeout is not provided or is None, the function will wait indefinitely.

Returns:

success: - True: If the desired button event was caught. - False: If the timeout ran out.

top_left

Top left button

top_right

Top right button

bottom_left

Bottom left button

bottom_right

Bottom right button

any_button

Any of the four corner buttons (knob excluded)

any_button_incl_knob

Any of the four corner buttons or the knob press

knob

The knob

__init__

def __init__()

Initializes a new UiEventsListener class.

knob_event_since_last

def knob_event_since_last() -> KnobEvent

This function will reset just_pressed, just_released fields and turn_delta fields.

Returns:

KnobEvent class of events that happened since last call.

buttons_event_since_last

def buttons_event_since_last() -> ButtonsEvent

This function will reset just_pressed and just_released fields.

Returns:

ButtonsEvent class of events that happened since last call.