Skip to content

Commit

Permalink
[#18] Use events to pause/unpause emulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Feb 19, 2021
1 parent ab6323e commit d0c06e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions zx/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class TapeStateUpdated(DeviceEvent):
pass


class ToggleEmulationPause(DeviceEvent):
pass


class ToggleTapePause(DeviceEvent):
pass

Expand Down
7 changes: 4 additions & 3 deletions zx/_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ._device import QuantumRun
from ._device import ScreenUpdated
from ._device import TapeStateUpdated
from ._device import ToggleEmulationPause
from ._device import ToggleTapePause
from ._error import USER_ERRORS
from ._error import verbalize_error
Expand Down Expand Up @@ -393,7 +394,7 @@ def __on_gdk_click(self, widget, event):

def __on_click(self, event, devices):
if event.type == _ClickType.Single:
self.xmachine.paused ^= True
self.__toggle_pause(devices)
elif event.type == _ClickType.Double:
self._toggle_fullscreen(devices)

Expand Down Expand Up @@ -438,8 +439,8 @@ def _on_quantum_run(self, event, devices):
while self.__events:
devices.notify(self.__events.pop(0))

def __toggle_pause(self):
self.xmachine.paused ^= True
def __toggle_pause(self, devices):
devices.notify(ToggleEmulationPause())

def __toggle_tape_pause(self, devices):
devices.notify(ToggleTapePause())
Expand Down
5 changes: 4 additions & 1 deletion zx/_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ._data import MachineSnapshot
from ._data import ProcessorSnapshot
from ._device import PauseStateUpdated
from ._device import ToggleEmulationPause
from ._device import ToggleTapePause
from ._emulatorbase import _Spectrum48Base
from ._except import EmulationExit
Expand Down Expand Up @@ -412,5 +413,7 @@ def on_breakpoint(self):
raise EmulatorException('Breakpoint triggered.')

def on_event(self, event, devices):
if isinstance(event, ToggleTapePause):
if isinstance(event, ToggleEmulationPause):
self.paused ^= True
elif isinstance(event, ToggleTapePause):
self._toggle_tape_pause()

0 comments on commit d0c06e3

Please sign in to comment.