Add OSD property access
This commit is contained in:
parent
ab773a5934
commit
f55b62667f
1 changed files with 9 additions and 2 deletions
11
mpv.py
11
mpv.py
|
|
@ -419,6 +419,10 @@ def _event_loop(event_handle, playback_cond, event_callbacks, message_handlers,
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
class OSDPropertyProxy:
|
||||||
|
def __init__(self, mpv):
|
||||||
|
self.mpv = mpv
|
||||||
|
|
||||||
class MPV(object):
|
class MPV(object):
|
||||||
""" See man mpv(1) for the details of the implemented commands. """
|
""" See man mpv(1) for the details of the implemented commands. """
|
||||||
def __init__(self, *extra_mpv_flags, log_handler=None, start_event_thread=True, **extra_mpv_opts):
|
def __init__(self, *extra_mpv_flags, log_handler=None, start_event_thread=True, **extra_mpv_opts):
|
||||||
|
|
@ -439,6 +443,7 @@ class MPV(object):
|
||||||
finally:
|
finally:
|
||||||
_mpv_initialize(self.handle)
|
_mpv_initialize(self.handle)
|
||||||
|
|
||||||
|
self.osd = OSDPropertyProxy(self)
|
||||||
self._event_callbacks = []
|
self._event_callbacks = []
|
||||||
self._property_handlers = collections.defaultdict(lambda: [])
|
self._property_handlers = collections.defaultdict(lambda: [])
|
||||||
self._message_handlers = {}
|
self._message_handlers = {}
|
||||||
|
|
@ -691,8 +696,8 @@ class MPV(object):
|
||||||
self.loadfile(filename, 'append', **options)
|
self.loadfile(filename, 'append', **options)
|
||||||
|
|
||||||
# Property accessors
|
# Property accessors
|
||||||
def _get_property(self, name, proptype=str, decode_str=False):
|
def _get_property(self, name, proptype=str, decode_str=False, force_format=None):
|
||||||
fmt = {int: MpvFormat.INT64,
|
fmt = force_format or {int: MpvFormat.INT64,
|
||||||
float: MpvFormat.DOUBLE,
|
float: MpvFormat.DOUBLE,
|
||||||
bool: MpvFormat.FLAG,
|
bool: MpvFormat.FLAG,
|
||||||
str: MpvFormat.STRING,
|
str: MpvFormat.STRING,
|
||||||
|
|
@ -951,12 +956,14 @@ ALL_PROPERTIES = {
|
||||||
|
|
||||||
def bindproperty(MPV, name, proptype, access, decode_str=False):
|
def bindproperty(MPV, name, proptype, access, decode_str=False):
|
||||||
getter = lambda self: self._get_property(name, proptype, decode_str)
|
getter = lambda self: self._get_property(name, proptype, decode_str)
|
||||||
|
osdgetter = lambda osdself: osdself.mpv._get_property(name, force_format=MpvFormat.OSD_STRING)
|
||||||
setter = lambda self, value: self._set_property(name, value, proptype)
|
setter = lambda self, value: self._set_property(name, value, proptype)
|
||||||
|
|
||||||
def barf(*args):
|
def barf(*args):
|
||||||
raise NotImplementedError('Access denied')
|
raise NotImplementedError('Access denied')
|
||||||
|
|
||||||
setattr(MPV, name.replace('-', '_'), property(getter if 'r' in access else barf, setter if 'w' in access else barf))
|
setattr(MPV, name.replace('-', '_'), property(getter if 'r' in access else barf, setter if 'w' in access else barf))
|
||||||
|
setattr(OSDPropertyProxy, name.replace('-', '_'), property(osdgetter if 'r' in access else barf, barf))
|
||||||
|
|
||||||
for name, (proptype, access, *args) in ALL_PROPERTIES.items():
|
for name, (proptype, access, *args) in ALL_PROPERTIES.items():
|
||||||
bindproperty(MPV, name, proptype, access, *args)
|
bindproperty(MPV, name, proptype, access, *args)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue