def handle_event(self, event: Event): def handle_key(source_id, values): if values == ("SPACE", ): self._player.play_pause() def reset_player(source_id, values): self._player.stop() def restart_player(source_id, values): self._view.reset() self._player.stop() handle = { "KEY": handle_key, "MODEL_UPDATE": reset_player, "DATA_UPDATE": restart_player, }.get(event.type(), lambda *_: None) handle(event.id(), event.values())
def handle_event(self, event: Event): def recreate_view(*_): self._view.recreate() def select_data(source_id, values): if self._selected_panel: self._selected_panel.model().unselect() panel = self._view.panel_from_id(source_id) if not panel: return self._selected_panel = panel text = panel.model() if not text: return text.select(*values) self._view.refresh() def edit_data(source_id, values): if values == ("SPACE", ) or values == ("TAB", ): return panel = self._view.panel_from_id(source_id) if not panel or panel != self._selected_panel: return text = panel.model() text.input_ch(*values) data = text.as_data() Song().edit(data) self._view.refresh() handle = { "DATA_UPDATE": recreate_view, "CLICK": select_data, "KEY": edit_data, }.get(event.type(), lambda *_: None) handle(event.id(), event.values())