Skip to content

Commit

Permalink
[#18] Use events to get tape player time.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Feb 20, 2021
1 parent d0c06e3 commit 2aa291f
Show file tree
Hide file tree
Showing 3 changed files with 16 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 @@ -15,6 +15,10 @@ class DeviceEvent(object):
pass


class GetTapePlayerTime(DeviceEvent):
pass


class PauseStateUpdated(DeviceEvent):
pass

Expand Down
6 changes: 4 additions & 2 deletions zx/_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions zx/_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 2aa291f

Please sign in to comment.