e0df8b84e5
Add a (half-finished) input library, that for now simply allows registration and triggering of events. As next steps, the trigger will happen as part of a separate thread that reads input events. Additionally, invoking commands via a execute() will be supported. Thirdly, there is need of a way to selectively update the affected modules (widgets), which should be possible given that the event contains both the instance (widget ID) and name (module name).
35 lines
751 B
Python
35 lines
751 B
Python
import uuid
|
|
|
|
LEFT_MOUSE = 1
|
|
MIDDLE_MOUSE = 2
|
|
RIGHT_MOUSE = 3
|
|
WHEEL_UP = 4
|
|
WHEEL_DOWN = 5
|
|
|
|
callbacks = {}
|
|
|
|
class Object(object):
|
|
def __init__(self):
|
|
self._id = uuid.uuid4()
|
|
|
|
def id(self):
|
|
return self._id
|
|
|
|
def register(obj, button=None, cmd=None):
|
|
callbacks.setdefault(obj.id(), {}).setdefault(button, []).append(cmd)
|
|
|
|
def trigger(event):
|
|
for field in ['instance', 'name']:
|
|
if field in event:
|
|
cb = callbacks.get(event[field])
|
|
_invoke(event, cb)
|
|
|
|
def _invoke(event, callback):
|
|
if not callback: return
|
|
if not 'button' in event: return
|
|
|
|
for cb in callback.get(event['button']):
|
|
if callable(cb):
|
|
cb(event)
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|