From f697c6c660cf7287844bf3a9697aad05a7fa1d71 Mon Sep 17 00:00:00 2001 From: Ivan Kosarev Date: Sat, 13 Feb 2021 22:30:41 +0200 Subject: [PATCH] [#18] Combine handling key events. --- zx/_gui.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/zx/_gui.py b/zx/_gui.py index 5e9235d..31ae85f 100644 --- a/zx/_gui.py +++ b/zx/_gui.py @@ -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) @@ -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) @@ -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