AppleRemote Class

Inheritance diagram of AppleRemote

class AppleRemote(device)

High-level interface for Apple remote control.

This interface provides access to the 6 button controls on the remote. Pressing and holding certain buttons on the remote is interpreted as a separate control.

Variables:
  • device – The underlying device used by this interface.
  • left_control – Button control for the left (prev) button.
  • left_hold_control – Button control for holding the left button (rewind).
  • right_control – Button control for the right (next) button.
  • right_hold_control – Button control for holding the right button (fast forward).
  • up_control – Button control for the up (volume increase) button.
  • down_control – Button control for the down (volume decrease) button.
  • select_control – Button control for the select (play/pause) button.
  • select_hold_control – Button control for holding the select button.
  • menu_control – Button control for the menu button.
  • menu_hold_control – Button control for holding the menu button.

Constructor:

__init__(device)

Methods:

close() Close the device.
dispatch_event(event_type, *args) Dispatch a single event to the attached handlers.
event(*args) Function decorator for an event handler.
open([window, exclusive]) Open the device.
pop_handlers() Pop the top level of event handlers off the stack.
push_handlers(*args, **kwargs) Push a level onto the top of the handler stack, then attach zero or more event handlers.
register_event_type(name) Register an event type with the dispatcher.
remove_handler(name, handler) Remove a single event handler.
remove_handlers(*args, **kwargs) Remove event handlers from the event stack.
set_handler(name, handler) Attach a single event handler.
set_handlers(*args, **kwargs) Attach one or more event handlers to the top level of the handler stack.

Events:

on_button_press(button) A button on the remote was pressed.
on_button_release(button) A button on the remote was released.

Attributes:

event_types Type: list

Methods

AppleRemote.close()

Close the device. See Device.close.

AppleRemote.open(window=None, exclusive=False)

Open the device. See Device.open.

Events

AppleRemote.on_button_press(button)

A button on the remote was pressed.

Only the ‘up’ and ‘down’ buttons will generate an event when the button is first pressed. All other buttons on the remote will wait until the button is released and then send both the press and release events at the same time.

Parameters:button (unicode) – The name of the button that was pressed. The valid names are ‘up’, ‘down’, ‘left’, ‘right’, ‘left_hold’, ‘right_hold’, ‘menu’, ‘menu_hold’, ‘select’, and ‘select_hold’
AppleRemote.on_button_release(button)

A button on the remote was released.

The ‘select_hold’ and ‘menu_hold’ button release events are sent immediately after the corresponding press events regardless of whether or not the user has released the button.

Parameters:button (unicode) – The name of the button that was released. The valid names are ‘up’, ‘down’, ‘left’, ‘right’, ‘left_hold’, ‘right_hold’, ‘menu’, ‘menu_hold’, ‘select’, and ‘select_hold’

Attributes

AppleRemote.event_types = ['on_button_press', 'on_button_release']

Inherited members

Methods

AppleRemote.dispatch_event(event_type, *args)

Dispatch a single event to the attached handlers.

The event is propagated to all handlers from from the top of the stack until one returns EVENT_HANDLED. This method should be used only by EventDispatcher implementors; applications should call the dispatch_events method.

Since pyglet 1.2, the method returns EVENT_HANDLED if an event handler returned EVENT_HANDLED or EVENT_UNHANDLED if all events returned EVENT_UNHANDLED. If no matching event handlers are in the stack, False is returned.

Parameters:
  • event_type (str) – Name of the event.
  • args (sequence) – Arguments to pass to the event handler.
Return type:

bool or None

Returns:

(Since pyglet 1.2) EVENT_HANDLED if an event handler returned EVENT_HANDLED; EVENT_UNHANDLED if one or more event handlers were invoked but returned only EVENT_UNHANDLED; otherwise False. In pyglet 1.1 and earler, the return value is always None.

AppleRemote.event(*args)

Function decorator for an event handler.

Usage:

win = window.Window()

@win.event
def on_resize(self, width, height):
    # ...

or:

@win.event('on_resize')
def foo(self, width, height):
    # ...
AppleRemote.pop_handlers()

Pop the top level of event handlers off the stack.

AppleRemote.push_handlers(*args, **kwargs)

Push a level onto the top of the handler stack, then attach zero or more event handlers.

If keyword arguments are given, they name the event type to attach. Otherwise, a callable’s __name__ attribute will be used. Any other object may also be specified, in which case it will be searched for callables with event names.

classmethod AppleRemote.register_event_type(name)

Register an event type with the dispatcher.

Registering event types allows the dispatcher to validate event handler names as they are attached, and to search attached objects for suitable handlers.

Parameters:name (str) – Name of the event to register.
AppleRemote.remove_handler(name, handler)

Remove a single event handler.

The given event handler is removed from the first handler stack frame it appears in. The handler must be the exact same callable as passed to set_handler, set_handlers or push_handlers; and the name must match the event type it is bound to.

No error is raised if the event handler is not set.

Parameters:
  • name (str) – Name of the event type to remove.
  • handler (callable) – Event handler to remove.
AppleRemote.remove_handlers(*args, **kwargs)

Remove event handlers from the event stack.

See push_handlers for the accepted argument types. All handlers are removed from the first stack frame that contains any of the given handlers. No error is raised if any handler does not appear in that frame, or if no stack frame contains any of the given handlers.

If the stack frame is empty after removing the handlers, it is removed from the stack. Note that this interferes with the expected symmetry of push_handlers and pop_handlers.

AppleRemote.set_handler(name, handler)

Attach a single event handler.

Parameters:
  • name (str) – Name of the event type to attach to.
  • handler (callable) – Event handler to attach.
AppleRemote.set_handlers(*args, **kwargs)

Attach one or more event handlers to the top level of the handler stack.

See push_handlers for the accepted argument types.

Table Of Contents

Previous topic

AbsoluteAxis Class

Next topic

Button Class