diff --git a/zx/_device.py b/zx/_device.py index 77b4fcd..0a6ebe4 100644 --- a/zx/_device.py +++ b/zx/_device.py @@ -15,6 +15,10 @@ class DeviceEvent(object): pass +class GetTapePlayerTime(DeviceEvent): + pass + + class PauseStateUpdated(DeviceEvent): pass diff --git a/zx/_gui.py b/zx/_gui.py index c21b6ad..0ad51b2 100644 --- a/zx/_gui.py +++ b/zx/_gui.py @@ -12,6 +12,7 @@ import enum import gi from ._device import Device +from ._device import GetTapePlayerTime from ._device import PauseStateUpdated from ._device import QuantumRun from ._device import ScreenUpdated @@ -411,10 +412,11 @@ def __on_window_state_event(self, widget, event): state = event.new_window_state self._is_fullscreen = bool(state & Gdk.WindowState.FULLSCREEN) - def on_event(self, event, devices): + def on_event(self, event, devices, result): event_type = type(event) if event_type in self._EVENT_HANDLERS: self._EVENT_HANDLERS[event_type](event, devices) + return result def _on_updated_pause_state(self, event, devices): if self.xmachine.paused: @@ -427,7 +429,7 @@ def _on_updated_tape_state(self, event, devices): tape_paused = self.xmachine._is_tape_paused() draw = (draw_tape_pause_notification if tape_paused else draw_tape_resume_notification) - tape_time = self.xmachine._tape_player.get_time() + tape_time = devices.notify(GetTapePlayerTime()) self._notification.set(draw, tape_time) def _on_quantum_run(self, event, devices): diff --git a/zx/_machine.py b/zx/_machine.py index d1dfb3d..63a9046 100644 --- a/zx/_machine.py +++ b/zx/_machine.py @@ -12,6 +12,7 @@ import enum from ._data import MachineSnapshot from ._data import ProcessorSnapshot +from ._device import GetTapePlayerTime from ._device import PauseStateUpdated from ._device import ToggleEmulationPause from ._device import ToggleTapePause @@ -355,8 +356,10 @@ def __iter__(self): yield from self.__devices def notify(self, event): + result = None for device in self: - device.on_event(event, self) + result = device.on_event(event, self, result) + return result # TODO: Do that with events? def destroy(self): @@ -412,8 +415,11 @@ def set_breakpoint(self, addr): def on_breakpoint(self): raise EmulatorException('Breakpoint triggered.') - def on_event(self, event, devices): + def on_event(self, event, devices, result): if isinstance(event, ToggleEmulationPause): self.paused ^= True elif isinstance(event, ToggleTapePause): self._toggle_tape_pause() + elif isinstance(event, GetTapePlayerTime): + return self._tape_player.get_time() + return result