mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
parent
97618564f4
commit
c37390ae14
1 changed files with 15 additions and 0 deletions
|
@ -433,6 +433,9 @@ class MPV(MPVBase):
|
|||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._callbacks_queue = Queue()
|
||||
self._callbacks_initialized = False
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._callbacks = {}
|
||||
|
@ -455,6 +458,14 @@ class MPV(MPVBase):
|
|||
name = name.replace("_", "-")
|
||||
self.register_callback(name, method)
|
||||
|
||||
self._callbacks_initialized = True
|
||||
while True:
|
||||
try:
|
||||
message = self._callbacks_queue.get_nowait()
|
||||
except Empty:
|
||||
break
|
||||
self._handle_event(message)
|
||||
|
||||
# Simulate an init event when the process and all callbacks have been
|
||||
# completely set up.
|
||||
if hasattr(self, "on_init"):
|
||||
|
@ -495,6 +506,10 @@ class MPV(MPVBase):
|
|||
def _handle_event(self, message):
|
||||
"""Lookup and call the callbacks for a particular event message.
|
||||
"""
|
||||
if not self._callbacks_initialized:
|
||||
self._callbacks_queue.put(message)
|
||||
return
|
||||
|
||||
if message["event"] == "property-change":
|
||||
name = "property-" + message["name"]
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue