Finish event infrastructure rework.
This commit is contained in:
parent
85ad2a6aa6
commit
3cb1196621
1 changed files with 6 additions and 6 deletions
12
mpv.py
12
mpv.py
|
|
@ -459,13 +459,12 @@ class MpvEventClientMessage(Structure):
|
||||||
class MpvEventCommand(Structure):
|
class MpvEventCommand(Structure):
|
||||||
_fields_ = [('_result', MpvNode)]
|
_fields_ = [('_result', MpvNode)]
|
||||||
|
|
||||||
@property
|
def unpack(self, decoder=identity_decoder):
|
||||||
def result_raw(self):
|
return self._result.node_value(decoder=decoder)
|
||||||
return self._result.node_value()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def result(self):
|
def result(self):
|
||||||
return self._result.node_value(decoder=lazy_decoder)
|
return self.unpack()
|
||||||
|
|
||||||
class MpvEventHook(Structure):
|
class MpvEventHook(Structure):
|
||||||
_fields_ = [('_name', c_char_p),
|
_fields_ = [('_name', c_char_p),
|
||||||
|
|
@ -918,7 +917,7 @@ class MPV(object):
|
||||||
key = event.reply_userdata
|
key = event.reply_userdata
|
||||||
callback = self._command_reply_callbacks.pop(key, None)
|
callback = self._command_reply_callbacks.pop(key, None)
|
||||||
if callback:
|
if callback:
|
||||||
callback(ErrorCode.exception_for_ec(event.error), event.data.result)
|
callback(ErrorCode.exception_for_ec(event.error), event.data)
|
||||||
|
|
||||||
if eid == MpvEventID.SHUTDOWN:
|
if eid == MpvEventID.SHUTDOWN:
|
||||||
_mpv_destroy(self._event_handle)
|
_mpv_destroy(self._event_handle)
|
||||||
|
|
@ -1111,7 +1110,7 @@ class MPV(object):
|
||||||
args = _create_null_term_cmd_arg_array(name, args)
|
args = _create_null_term_cmd_arg_array(name, args)
|
||||||
_mpv_command(self.handle, args)
|
_mpv_command(self.handle, args)
|
||||||
|
|
||||||
def command_async(self, name, *args, callback=None, **kwargs):
|
def command_async(self, name, *args, callback=None, decoder=lazy_decoder, **kwargs):
|
||||||
"""Same as mpv_command, but run the command asynchronously. If you provide a callback, that callback will be
|
"""Same as mpv_command, but run the command asynchronously. If you provide a callback, that callback will be
|
||||||
called after completion or on error. This method returns a future that evaluates to the result of the callback
|
called after completion or on error. This method returns a future that evaluates to the result of the callback
|
||||||
(if given), and the result of the libmpv call otherwise.
|
(if given), and the result of the libmpv call otherwise.
|
||||||
|
|
@ -1136,6 +1135,7 @@ class MPV(object):
|
||||||
|
|
||||||
def wrapper(error, result):
|
def wrapper(error, result):
|
||||||
try:
|
try:
|
||||||
|
result = result.unpack(decoder)
|
||||||
future.set_result(callback(error, result))
|
future.set_result(callback(error, result))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
future.set_exception(e)
|
future.set_exception(e)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue