powermate package

Submodules

powermate.pactl module

A small library for interacting with the pactl command line tool.

This library allows for a few simple interactions with linux pulseaudio, like viewing active sinks (sound outputs, usually loosely correlating with speakers) and their relative volumes, and setting volume absolutely or relatively.

Most functions take a sink argument which defaults to retrieving and using the first ‘RUNNING’ sink found. This uses a full subprocess, so users doing repeated calls are recommended to get a sink object (eg. through active_sink()) and pass that to successive calls.

The pactl tool will need to be installed for this library to work. It is commonly installed by default when PulseAudio is installed, and on many major distros.

class powermate.pactl.Sink(**kwargs)[source]

Bases: object

A class wrapping attributes of PulseAudio sink properties.

LIST_PATTERNS = {'name': (<class 'str'>, 'Name: (.+)'), 'state': (<class 'str'>, 'State: (\\w+)'), 'volume': (<class 'int'>, 'Volume: 0: +(\\d+)%')}
inc_volume(delta=1)[source]

Set a relative volume (can be negative).

name
set_volume(value)[source]

Set an absolute volume (0-100).

state
volume
powermate.pactl.active_sink()[source]

Retrieve the first running PulseAudio sink.

powermate.pactl.list_sinks()[source]

Iterate system’s sink objects as Sinks.

powermate.pactl_powermate module

class powermate.pactl_powermate.PowerMate(path, long_threshold=1000)[source]

Bases: powermate.powermate.PowerMateBase

rotate(rotation)[source]

powermate.powermate module

class powermate.powermate.AsyncFileEventDispatcher(path, event_size=24)[source]

Bases: object

add_listener(event_handler)[source]
run()[source]
send_event(event)[source]
class powermate.powermate.Event(tv_sec, tv_usec, type, code, value)[source]

Bases: object

classmethod fromraw(data)[source]
raw()[source]
class powermate.powermate.EventHandler[source]

Bases: object

handle_event(event)[source]
handle_events(source)[source]
exception powermate.powermate.EventNotImplemented[source]

Bases: NotImplementedError

Special exception type for non-implemented events.

class powermate.powermate.EventQueue(source, max_queue_size=5)[source]

Bases: object

A thread-safe event queue which registers any number of listeners for an event source.

This will store a small number of items in order for a listener to read, and they are then available to iterate over. If more events than the specified maximum are in a listener’s queue, it will stop enqueueing new events. If for instance a listener takes a long break and max_queue_size is K, it will read the next K events after the sleep started (the oldest K events not read) and then continue to read new events. Any intermediate events will be dropped for that listener.

Listeners may be simply registered by iterating over the queue, or through the .iterate method for more configuration.

iterate(max_queue_size=None)[source]

Register a listener on the queue, and retrieve an iterator for them.

send(event)[source]

Send an event to the underlying event source.

watch()[source]

Watch the underlying event source for events and send them to each registered queue.

class powermate.powermate.ExampleBadHandler(long_threshold=1000)[source]

Bases: powermate.powermate.PowerMateEventHandler

rotate(rotation)[source]
class powermate.powermate.ExamplePowerMate(path)[source]

Bases: powermate.powermate.PowerMateBase

long_press()[source]
push_rotate(rotation)[source]
rotate(rotation)[source]
short_press()[source]
class powermate.powermate.FileEventSource(path, event_size)[source]

Bases: object

An event source which reads and writes to a file object.

send(event)[source]

Write an event to the source.

class powermate.powermate.LedEvent(brightness=255, speed=0, pulse_type=0, asleep=0, awake=0)[source]

Bases: powermate.powermate.Event

classmethod max()[source]
classmethod off()[source]
classmethod percent(percent)[source]
classmethod pulse()[source]
value
class powermate.powermate.PowerMateBase(path, long_threshold=1000)[source]

Bases: powermate.powermate.AsyncFileEventDispatcher, powermate.powermate.PowerMateEventHandler

class powermate.powermate.PowerMateEventHandler(long_threshold=1000)[source]

Bases: powermate.powermate.EventHandler

handle_event(event)[source]
long_press()[source]
push_rotate(rotation)[source]
rotate(rotation)[source]
short_press()[source]

Module contents