Skip to content

Commit

Permalink
[#18] Use events to load files.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Feb 20, 2021
1 parent b45277b commit 29fec80
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion zx/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ class IsTapePlayerPaused(DeviceEvent):
pass


class KeyStroke(object):
class KeyStroke(DeviceEvent):
def __init__(self, id, pressed):
self.id = id
self.pressed = pressed


class LoadFile(DeviceEvent):
def __init__(self, filename):
self.filename = filename


class PauseStateUpdated(DeviceEvent):
pass

Expand Down
3 changes: 2 additions & 1 deletion zx/_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ._device import GetTapePlayerTime
from ._device import IsTapePlayerPaused
from ._device import KeyStroke
from ._device import LoadFile
from ._device import PauseStateUpdated
from ._device import QuantumRun
from ._device import ScreenUpdated
Expand Down Expand Up @@ -355,7 +356,7 @@ def _choose_and_load_file(self, devices):

if filename is not None:
try:
self.xmachine._load_file(filename)
devices.notify(LoadFile(filename))
except USER_ERRORS as e:
self._error_box('File error', verbalize_error(e))

Expand Down
3 changes: 3 additions & 0 deletions zx/_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ._device import GetTapePlayerTime
from ._device import IsTapePlayerPaused
from ._device import KeyStroke
from ._device import LoadFile
from ._device import PauseStateUpdated
from ._device import ToggleEmulationPause
from ._device import ToggleTapePause
Expand Down Expand Up @@ -437,6 +438,8 @@ def on_event(self, event, devices, result):
self.paused = False
self._quit_playback_mode()
self._handle_key_stroke(key, event.pressed)
elif isinstance(event, LoadFile):
self._load_file(event.filename)
elif isinstance(event, ToggleEmulationPause):
self.paused ^= True
elif isinstance(event, ToggleTapePause):
Expand Down

0 comments on commit 29fec80

Please sign in to comment.