summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2017-05-10 12:12:36 +0200
committerjaseg <git@jaseg.net>2017-05-10 12:14:43 +0200
commit7a378544d5aff55ce9cf1adae3180b6951efa33e (patch)
tree19e51f823948b929f53e7939f1b1a4960b570c21
parentd2ffe25700bb41f899a71b7e7b4fe560acdd9a25 (diff)
downloadpython-mpv-7a378544d5aff55ce9cf1adae3180b6951efa33e.tar.gz
python-mpv-7a378544d5aff55ce9cf1adae3180b6951efa33e.tar.bz2
python-mpv-7a378544d5aff55ce9cf1adae3180b6951efa33e.zip
MPV.event_callback: Allow str event type names
-rw-r--r--mpv.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/mpv.py b/mpv.py
index df34563..a7a8565 100644
--- a/mpv.py
+++ b/mpv.py
@@ -163,6 +163,10 @@ class MpvEventID(c_int):
'TICK', 'SCRIPT_INPUT_DISPATCH', 'CLIENT_MESSAGE', 'VIDEO_RECONFIG', 'AUDIO_RECONFIG',
'METADATA_UPDATE', 'SEEK', 'PLAYBACK_RESTART', 'PROPERTY_CHANGE', 'CHAPTER_CHANGE'][self.value]
+ @classmethod
+ def from_str(kls, s):
+ return getattr(kls, s.upper().replace('-', '_'))
+
class MpvNodeList(Structure):
def array_value(self, decode_str=False):
@@ -637,9 +641,10 @@ class MPV(object):
def event_callback(self, *event_types):
def register(callback):
+ types = [MpvEventID.from_str(t) if isinstance(t, str) else t for t in event_types] or MpvEventID.ANY
@wraps(callback)
def wrapper(event, *args, **kwargs):
- if event['event_id'] in (event_types or MpvEventID.ANY):
+ if event['event_id'] in types:
callback(event, *args, **kwargs)
self._event_callbacks.append(wrapper)
wrapper.unregister_event_callback = partial(self.unregister_event_callback, wrapper)