diff --git a/qt/aqt/mpv.py b/qt/aqt/mpv.py index 7a13c5b7d..e0de10e44 100644 --- a/qt/aqt/mpv.py +++ b/qt/aqt/mpv.py @@ -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: