Skip to content

Commit

Permalink
[#18] Combine handling key events.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Feb 13, 2021
1 parent 5231b2d commit f697c6c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions zx/_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ def __init__(self, emulator):
if not SCREENCAST:
self.pattern.set_filter(cairo.FILTER_NEAREST)

self._window.connect('key-press-event', self._on_key_press)
self._window.connect('key-release-event', self._on_key_release)
self._window.connect('key-press-event', self._on_key_event)
self._window.connect('key-release-event', self._on_key_event)
self._window.connect('button-press-event', self._on_click)
self._window.connect('window-state-event', self._on_window_state_event)

Expand Down Expand Up @@ -334,7 +334,9 @@ def _toggle_fullscreen(self):
else:
self._window.fullscreen()

def _on_key(self, event, pressed):
def _on_key_event(self, widget, event):
pressed = event.type == Gdk.EventType.KEY_PRESS

key_id = Gdk.keyval_name(event.keyval).upper()
# print(key_id)

Expand All @@ -348,12 +350,6 @@ def _on_key(self, event, pressed):
self.machine._quit_playback_mode()
self.machine._handle_key_stroke(key, pressed)

def _on_key_press(self, widget, event):
self._on_key(event, pressed=True)

def _on_key_release(self, widget, event):
self._on_key(event, pressed=False)

def _on_click(self, widget, event):
if event.type == Gdk.EventType.BUTTON_PRESS:
self.machine.paused ^= True
Expand Down

0 comments on commit f697c6c

Please sign in to comment.