From afc3218988ec1fd6d42ee543e43be15811490e97 Mon Sep 17 00:00:00 2001 From: Ivan Kosarev Date: Sat, 20 Feb 2021 12:27:05 +0200 Subject: [PATCH] [#18] Use events to query tape player pause state. --- zx/_device.py | 4 ++++ zx/_gui.py | 3 ++- zx/_machine.py | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/zx/_device.py b/zx/_device.py index 0a6ebe4..6d4b47e 100644 --- a/zx/_device.py +++ b/zx/_device.py @@ -19,6 +19,10 @@ class GetTapePlayerTime(DeviceEvent): pass +class IsTapePlayerPaused(DeviceEvent): + pass + + class PauseStateUpdated(DeviceEvent): pass diff --git a/zx/_gui.py b/zx/_gui.py index 0ad51b2..bbe31ba 100644 --- a/zx/_gui.py +++ b/zx/_gui.py @@ -13,6 +13,7 @@ import gi from ._device import Device from ._device import GetTapePlayerTime +from ._device import IsTapePlayerPaused from ._device import PauseStateUpdated from ._device import QuantumRun from ._device import ScreenUpdated @@ -426,7 +427,7 @@ def _on_updated_pause_state(self, event, devices): self._notification.clear() def _on_updated_tape_state(self, event, devices): - tape_paused = self.xmachine._is_tape_paused() + tape_paused = devices.notify(IsTapePlayerPaused()) draw = (draw_tape_pause_notification if tape_paused else draw_tape_resume_notification) tape_time = devices.notify(GetTapePlayerTime()) diff --git a/zx/_machine.py b/zx/_machine.py index 63a9046..c1a5608 100644 --- a/zx/_machine.py +++ b/zx/_machine.py @@ -13,6 +13,7 @@ from ._data import MachineSnapshot from ._data import ProcessorSnapshot from ._device import GetTapePlayerTime +from ._device import IsTapePlayerPaused from ._device import PauseStateUpdated from ._device import ToggleEmulationPause from ._device import ToggleTapePause @@ -416,10 +417,12 @@ def on_breakpoint(self): raise EmulatorException('Breakpoint triggered.') def on_event(self, event, devices, result): - if isinstance(event, ToggleEmulationPause): + if isinstance(event, GetTapePlayerTime): + return self._tape_player.get_time() + elif isinstance(event, IsTapePlayerPaused): + return self._is_tape_paused() + elif 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