2020-11-09 22:16:30 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper - GUI for device specific keyboard mappings
|
2022-01-01 12:52:33 +00:00
|
|
|
# Copyright (C) 2022 sezanzeb <proxima@sezanzeb.de>
|
2020-11-09 22:16:30 +00:00
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# This file is part of input-remapper.
|
2020-11-09 22:16:30 +00:00
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper is free software: you can redistribute it and/or modify
|
2020-11-09 22:16:30 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper is distributed in the hope that it will be useful,
|
2020-11-09 22:16:30 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2022-01-01 12:00:49 +00:00
|
|
|
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
2020-11-09 22:16:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
"""User Interface."""
|
2022-07-23 08:53:41 +00:00
|
|
|
from typing import Dict, Callable
|
2020-11-09 22:16:30 +00:00
|
|
|
|
2022-11-11 23:48:59 +00:00
|
|
|
import gi
|
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
from gi.repository import Gtk, GtkSource, Gdk, GObject
|
2020-11-09 22:16:30 +00:00
|
|
|
|
2022-01-31 19:58:37 +00:00
|
|
|
from inputremapper.configs.data import get_data_path
|
2022-07-23 08:53:41 +00:00
|
|
|
from inputremapper.configs.mapping import MappingData
|
2022-12-15 13:43:03 +00:00
|
|
|
from inputremapper.configs.input_config import InputCombination
|
2022-07-23 08:53:41 +00:00
|
|
|
from inputremapper.gui.autocompletion import Autocompletion
|
2022-10-16 12:56:21 +00:00
|
|
|
from inputremapper.gui.components.editor import (
|
2022-07-23 08:53:41 +00:00
|
|
|
MappingListBox,
|
|
|
|
TargetSelection,
|
|
|
|
CodeEditor,
|
|
|
|
RecordingToggle,
|
2022-10-16 12:56:21 +00:00
|
|
|
RecordingStatus,
|
2022-07-23 08:53:41 +00:00
|
|
|
AutoloadSwitch,
|
|
|
|
ReleaseCombinationSwitch,
|
|
|
|
CombinationListbox,
|
|
|
|
AnalogInputSwitch,
|
|
|
|
TriggerThresholdInput,
|
|
|
|
OutputAxisSelector,
|
|
|
|
ReleaseTimeoutInput,
|
|
|
|
TransformationDrawArea,
|
|
|
|
Sliders,
|
2022-10-02 15:33:52 +00:00
|
|
|
RelativeInputCutoffInput,
|
|
|
|
KeyAxisStackSwitcher,
|
2022-10-16 12:56:21 +00:00
|
|
|
RequireActiveMapping,
|
2022-11-20 19:36:33 +00:00
|
|
|
GdkEventRecorder,
|
2022-07-23 08:53:41 +00:00
|
|
|
)
|
2022-10-16 12:56:21 +00:00
|
|
|
from inputremapper.gui.components.presets import PresetSelection
|
|
|
|
from inputremapper.gui.components.main import Stack, StatusBar
|
|
|
|
from inputremapper.gui.components.common import Breadcrumbs
|
|
|
|
from inputremapper.gui.components.device_groups import DeviceGroupSelection
|
2022-07-23 08:53:41 +00:00
|
|
|
from inputremapper.gui.controller import Controller
|
2022-10-16 12:56:21 +00:00
|
|
|
from inputremapper.gui.messages.message_broker import (
|
|
|
|
MessageBroker,
|
|
|
|
MessageType,
|
|
|
|
)
|
|
|
|
from inputremapper.gui.messages.message_data import UserConfirmRequest
|
2022-01-10 19:37:22 +00:00
|
|
|
from inputremapper.gui.utils import (
|
|
|
|
gtk_iteration,
|
|
|
|
)
|
2022-11-01 11:07:12 +00:00
|
|
|
from inputremapper.injection.injector import InjectorStateMessage
|
2022-07-23 08:53:41 +00:00
|
|
|
from inputremapper.logger import logger, COMMIT_HASH, VERSION, EVDEV_VERSION
|
|
|
|
from inputremapper.gui.gettext import _
|
2020-11-09 22:16:30 +00:00
|
|
|
|
2022-01-10 19:37:22 +00:00
|
|
|
# https://cjenkins.wordpress.com/2012/05/08/use-gtksourceview-widget-in-glade/
|
|
|
|
GObject.type_register(GtkSource.View)
|
|
|
|
# GtkSource.View() also works:
|
|
|
|
# https://stackoverflow.com/questions/60126579/gtk-builder-error-quark-invalid-object-type-webkitwebview
|
2020-11-09 22:16:30 +00:00
|
|
|
|
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def on_close_about(about, _):
|
2022-01-10 19:37:22 +00:00
|
|
|
"""Hide the about dialog without destroying it."""
|
|
|
|
about.hide()
|
|
|
|
return True
|
2021-09-26 10:44:56 +00:00
|
|
|
|
2020-12-19 21:24:23 +00:00
|
|
|
|
2022-01-10 19:37:22 +00:00
|
|
|
class UserInterface:
|
2022-01-31 19:58:37 +00:00
|
|
|
"""The input-remapper gtk window."""
|
2021-09-26 10:44:56 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
message_broker: MessageBroker,
|
|
|
|
controller: Controller,
|
|
|
|
):
|
|
|
|
self.message_broker = message_broker
|
|
|
|
self.controller = controller
|
|
|
|
|
|
|
|
# all shortcuts executed when ctrl+...
|
|
|
|
self.shortcuts: Dict[int, Callable] = {
|
|
|
|
Gdk.KEY_q: self.controller.close,
|
|
|
|
Gdk.KEY_r: self.controller.refresh_groups,
|
|
|
|
Gdk.KEY_Delete: self.controller.stop_injecting,
|
2022-10-16 12:56:21 +00:00
|
|
|
Gdk.KEY_n: self.controller.add_preset,
|
2022-07-23 08:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# stores the ids for all the listeners attached to the gui
|
|
|
|
self.gtk_listeners: Dict[Callable, int] = {}
|
|
|
|
|
|
|
|
self.message_broker.subscribe(MessageType.terminate, lambda _: self.close())
|
|
|
|
|
|
|
|
self.builder = Gtk.Builder()
|
|
|
|
self._build_ui()
|
|
|
|
self.window: Gtk.Window = self.get("window")
|
|
|
|
self.about: Gtk.Window = self.get("about-dialog")
|
|
|
|
self.combination_editor: Gtk.Dialog = self.get("combination-editor")
|
|
|
|
|
|
|
|
self._create_dialogs()
|
|
|
|
self._create_components()
|
|
|
|
self._connect_gtk_signals()
|
|
|
|
self._connect_message_listener()
|
|
|
|
|
|
|
|
self.window.show()
|
|
|
|
# hide everything until stuff is populated
|
|
|
|
self.get("vertical-wrapper").set_opacity(0)
|
|
|
|
# if any of the next steps take a bit to complete, have the window
|
|
|
|
# already visible (without content) to make it look more responsive.
|
|
|
|
gtk_iteration()
|
2021-03-22 08:59:16 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
# now show the proper finished content of the window
|
|
|
|
self.get("vertical-wrapper").set_opacity(1)
|
2020-11-09 22:16:30 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def _build_ui(self):
|
2022-11-12 16:45:32 +00:00
|
|
|
"""Build the window from stylesheet and gladefile."""
|
2020-11-09 22:16:30 +00:00
|
|
|
css_provider = Gtk.CssProvider()
|
2022-07-23 08:53:41 +00:00
|
|
|
|
2021-09-26 10:44:56 +00:00
|
|
|
with open(get_data_path("style.css"), "r") as file:
|
|
|
|
css_provider.load_from_data(bytes(file.read(), encoding="UTF-8"))
|
2020-11-12 22:59:49 +00:00
|
|
|
|
2020-11-09 22:16:30 +00:00
|
|
|
Gtk.StyleContext.add_provider_for_screen(
|
|
|
|
Gdk.Screen.get_default(),
|
|
|
|
css_provider,
|
2021-09-26 10:44:56 +00:00
|
|
|
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION,
|
2020-11-09 22:16:30 +00:00
|
|
|
)
|
|
|
|
|
2022-01-01 12:00:49 +00:00
|
|
|
gladefile = get_data_path("input-remapper.glade")
|
2022-07-23 08:53:41 +00:00
|
|
|
self.builder.add_from_file(gladefile)
|
|
|
|
self.builder.connect_signals(self)
|
|
|
|
|
|
|
|
def _create_components(self):
|
2022-11-12 16:45:32 +00:00
|
|
|
"""Setup all objects which manage individual components of the ui."""
|
2022-07-23 08:53:41 +00:00
|
|
|
message_broker = self.message_broker
|
|
|
|
controller = self.controller
|
2022-10-16 12:56:21 +00:00
|
|
|
DeviceGroupSelection(message_broker, controller, self.get("device_selection"))
|
2022-07-23 08:53:41 +00:00
|
|
|
PresetSelection(message_broker, controller, self.get("preset_selection"))
|
|
|
|
MappingListBox(message_broker, controller, self.get("selection_label_listbox"))
|
|
|
|
TargetSelection(message_broker, controller, self.get("target-selector"))
|
2022-10-16 12:56:21 +00:00
|
|
|
|
|
|
|
Breadcrumbs(
|
|
|
|
message_broker,
|
|
|
|
self.get("selected_device_name"),
|
|
|
|
show_device_group=True,
|
|
|
|
)
|
|
|
|
Breadcrumbs(
|
|
|
|
message_broker,
|
|
|
|
self.get("selected_preset_name"),
|
|
|
|
show_device_group=True,
|
|
|
|
show_preset=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
Stack(message_broker, controller, self.get("main_stack"))
|
2022-07-23 08:53:41 +00:00
|
|
|
RecordingToggle(message_broker, controller, self.get("key_recording_toggle"))
|
|
|
|
StatusBar(
|
|
|
|
message_broker,
|
|
|
|
controller,
|
|
|
|
self.get("status_bar"),
|
|
|
|
self.get("error_status_icon"),
|
|
|
|
self.get("warning_status_icon"),
|
|
|
|
)
|
2022-10-16 12:56:21 +00:00
|
|
|
RecordingStatus(message_broker, self.get("recording_status"))
|
2022-07-23 08:53:41 +00:00
|
|
|
AutoloadSwitch(message_broker, controller, self.get("preset_autoload_switch"))
|
|
|
|
ReleaseCombinationSwitch(
|
|
|
|
message_broker, controller, self.get("release-combination-switch")
|
|
|
|
)
|
|
|
|
CombinationListbox(message_broker, controller, self.get("combination-listbox"))
|
|
|
|
AnalogInputSwitch(message_broker, controller, self.get("analog-input-switch"))
|
|
|
|
TriggerThresholdInput(
|
|
|
|
message_broker, controller, self.get("trigger-threshold-spin-btn")
|
|
|
|
)
|
2022-10-02 15:33:52 +00:00
|
|
|
RelativeInputCutoffInput(
|
|
|
|
message_broker, controller, self.get("input-cutoff-spin-btn")
|
|
|
|
)
|
2022-07-23 08:53:41 +00:00
|
|
|
OutputAxisSelector(message_broker, controller, self.get("output-axis-selector"))
|
2022-10-02 15:33:52 +00:00
|
|
|
KeyAxisStackSwitcher(
|
|
|
|
message_broker,
|
|
|
|
controller,
|
|
|
|
self.get("editor-stack"),
|
|
|
|
self.get("key_macro_toggle_btn"),
|
|
|
|
self.get("analog_toggle_btn"),
|
|
|
|
)
|
2022-07-23 08:53:41 +00:00
|
|
|
ReleaseTimeoutInput(
|
|
|
|
message_broker, controller, self.get("release-timeout-spin-button")
|
|
|
|
)
|
|
|
|
TransformationDrawArea(
|
|
|
|
message_broker, controller, self.get("transformation-draw-area")
|
|
|
|
)
|
|
|
|
Sliders(
|
|
|
|
message_broker,
|
|
|
|
controller,
|
|
|
|
self.get("gain-scale"),
|
|
|
|
self.get("deadzone-scale"),
|
|
|
|
self.get("expo-scale"),
|
|
|
|
)
|
|
|
|
|
2022-11-20 19:36:33 +00:00
|
|
|
GdkEventRecorder(self.window, self.get("gdk-event-recorder-label"))
|
|
|
|
|
2022-10-16 12:56:21 +00:00
|
|
|
RequireActiveMapping(
|
|
|
|
message_broker,
|
|
|
|
self.get("edit-combination-btn"),
|
|
|
|
require_recorded_input=True,
|
|
|
|
)
|
|
|
|
RequireActiveMapping(
|
|
|
|
message_broker,
|
|
|
|
self.get("output"),
|
|
|
|
require_recorded_input=True,
|
|
|
|
)
|
|
|
|
RequireActiveMapping(
|
|
|
|
message_broker,
|
|
|
|
self.get("delete-mapping"),
|
|
|
|
require_recorded_input=False,
|
|
|
|
)
|
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
# code editor and autocompletion
|
|
|
|
code_editor = CodeEditor(message_broker, controller, self.get("code_editor"))
|
2022-11-20 19:36:33 +00:00
|
|
|
autocompletion = Autocompletion(message_broker, controller, code_editor)
|
2022-07-23 08:53:41 +00:00
|
|
|
autocompletion.set_relative_to(self.get("code_editor_container"))
|
|
|
|
self.autocompletion = autocompletion # only for testing
|
|
|
|
|
|
|
|
def _create_dialogs(self):
|
2022-11-12 16:45:32 +00:00
|
|
|
"""Setup different dialogs, such as the about page."""
|
2021-09-26 10:44:56 +00:00
|
|
|
self.about.connect("delete-event", on_close_about)
|
2021-03-22 21:50:08 +00:00
|
|
|
# set_position needs to be done once initially, otherwise the
|
|
|
|
# dialog is not centered when it is opened for the first time
|
|
|
|
self.about.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
|
2021-09-26 10:44:56 +00:00
|
|
|
self.get("version-label").set_text(
|
2022-01-10 19:37:22 +00:00
|
|
|
f"input-remapper {VERSION} {COMMIT_HASH[:7]}"
|
|
|
|
f"\npython-evdev {EVDEV_VERSION}"
|
2021-09-26 10:44:56 +00:00
|
|
|
if EVDEV_VERSION
|
|
|
|
else ""
|
2021-03-21 13:17:34 +00:00
|
|
|
)
|
2021-01-09 16:44:24 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def _connect_gtk_signals(self):
|
|
|
|
self.get("delete_preset").connect(
|
|
|
|
"clicked", lambda *_: self.controller.delete_preset()
|
|
|
|
)
|
|
|
|
self.get("copy_preset").connect(
|
|
|
|
"clicked", lambda *_: self.controller.copy_preset()
|
|
|
|
)
|
|
|
|
self.get("create_preset").connect(
|
|
|
|
"clicked", lambda *_: self.controller.add_preset()
|
|
|
|
)
|
|
|
|
self.get("apply_preset").connect(
|
|
|
|
"clicked", lambda *_: self.controller.start_injecting()
|
|
|
|
)
|
2022-10-16 12:56:21 +00:00
|
|
|
self.get("stop_injection_preset_page").connect(
|
|
|
|
"clicked", lambda *_: self.controller.stop_injecting()
|
|
|
|
)
|
|
|
|
self.get("stop_injection_editor_page").connect(
|
2022-07-23 08:53:41 +00:00
|
|
|
"clicked", lambda *_: self.controller.stop_injecting()
|
|
|
|
)
|
|
|
|
self.get("rename-button").connect("clicked", self.on_gtk_rename_clicked)
|
|
|
|
self.get("preset_name_input").connect(
|
|
|
|
"key-release-event", self.on_gtk_preset_name_input_return
|
|
|
|
)
|
|
|
|
self.get("create_mapping_button").connect(
|
|
|
|
"clicked", lambda *_: self.controller.create_mapping()
|
|
|
|
)
|
|
|
|
self.get("delete-mapping").connect(
|
|
|
|
"clicked", lambda *_: self.controller.delete_mapping()
|
|
|
|
)
|
|
|
|
self.combination_editor.connect(
|
|
|
|
# it only takes self as argument, but delete-events provides more
|
|
|
|
# probably a gtk bug
|
|
|
|
"delete-event",
|
|
|
|
lambda dialog, *_: Gtk.Widget.hide_on_delete(dialog),
|
|
|
|
)
|
|
|
|
self.get("edit-combination-btn").connect(
|
|
|
|
"clicked", lambda *_: self.combination_editor.show()
|
|
|
|
)
|
|
|
|
self.get("remove-event-btn").connect(
|
|
|
|
"clicked", lambda *_: self.controller.remove_event()
|
|
|
|
)
|
|
|
|
self.connect_shortcuts()
|
2021-04-02 13:08:36 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def _connect_message_listener(self):
|
|
|
|
self.message_broker.subscribe(
|
|
|
|
MessageType.mapping, self.update_combination_label
|
|
|
|
)
|
|
|
|
self.message_broker.subscribe(
|
|
|
|
MessageType.injector_state, self.on_injector_state_msg
|
|
|
|
)
|
2022-10-16 12:56:21 +00:00
|
|
|
self.message_broker.subscribe(
|
|
|
|
MessageType.user_confirm_request, self._on_user_confirm_request
|
|
|
|
)
|
|
|
|
|
|
|
|
def _create_dialog(self, primary: str, secondary: str) -> Gtk.MessageDialog:
|
|
|
|
"""Create a message dialog with cancel and confirm buttons."""
|
|
|
|
message_dialog = Gtk.MessageDialog(
|
|
|
|
self.window,
|
|
|
|
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
|
|
|
|
Gtk.MessageType.QUESTION,
|
|
|
|
Gtk.ButtonsType.NONE,
|
|
|
|
primary,
|
|
|
|
)
|
|
|
|
|
|
|
|
if secondary:
|
|
|
|
message_dialog.format_secondary_text(secondary)
|
|
|
|
|
|
|
|
message_dialog.add_button("Cancel", Gtk.ResponseType.CANCEL)
|
|
|
|
|
|
|
|
confirm_button = message_dialog.add_button("Confirm", Gtk.ResponseType.ACCEPT)
|
|
|
|
confirm_button.get_style_context().add_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION)
|
|
|
|
|
|
|
|
return message_dialog
|
|
|
|
|
|
|
|
def _on_user_confirm_request(self, msg: UserConfirmRequest):
|
|
|
|
# if the message contains a line-break, use the first chunk for the primary
|
|
|
|
# message, and the rest for the secondary message.
|
|
|
|
chunks = msg.msg.split("\n")
|
|
|
|
primary = chunks[0]
|
|
|
|
secondary = " ".join(chunks[1:])
|
|
|
|
|
|
|
|
message_dialog = self._create_dialog(primary, secondary)
|
|
|
|
|
|
|
|
response = message_dialog.run()
|
|
|
|
msg.respond(response == Gtk.ResponseType.ACCEPT)
|
|
|
|
|
|
|
|
message_dialog.hide()
|
2021-04-02 13:08:36 +00:00
|
|
|
|
2022-11-01 11:07:12 +00:00
|
|
|
def on_injector_state_msg(self, msg: InjectorStateMessage):
|
2022-11-12 16:45:32 +00:00
|
|
|
"""Update the ui to reflect the status of the injector."""
|
2022-10-16 12:56:21 +00:00
|
|
|
stop_injection_preset_page: Gtk.Button = self.get("stop_injection_preset_page")
|
|
|
|
stop_injection_editor_page: Gtk.Button = self.get("stop_injection_editor_page")
|
2022-07-23 08:53:41 +00:00
|
|
|
recording_toggle: Gtk.ToggleButton = self.get("key_recording_toggle")
|
2022-10-16 12:56:21 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
if msg.active():
|
2022-10-16 12:56:21 +00:00
|
|
|
stop_injection_preset_page.set_opacity(1)
|
|
|
|
stop_injection_editor_page.set_opacity(1)
|
|
|
|
stop_injection_preset_page.set_sensitive(True)
|
|
|
|
stop_injection_editor_page.set_sensitive(True)
|
|
|
|
recording_toggle.set_opacity(0.5)
|
2022-07-23 08:53:41 +00:00
|
|
|
else:
|
2022-10-16 12:56:21 +00:00
|
|
|
stop_injection_preset_page.set_opacity(0.5)
|
|
|
|
stop_injection_editor_page.set_opacity(0.5)
|
|
|
|
stop_injection_preset_page.set_sensitive(True)
|
|
|
|
stop_injection_editor_page.set_sensitive(True)
|
2022-07-23 08:53:41 +00:00
|
|
|
recording_toggle.set_opacity(1)
|
2020-12-26 15:42:57 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def disconnect_shortcuts(self):
|
2022-10-16 12:56:21 +00:00
|
|
|
"""Stop listening for shortcuts.
|
2020-12-26 15:42:57 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
e.g. when recording key combinations
|
2020-12-26 15:42:57 +00:00
|
|
|
"""
|
2022-07-23 08:53:41 +00:00
|
|
|
try:
|
|
|
|
self.window.disconnect(self.gtk_listeners.pop(self.on_gtk_shortcut))
|
|
|
|
except KeyError:
|
|
|
|
logger.debug("key listeners seem to be not connected")
|
|
|
|
|
|
|
|
def connect_shortcuts(self):
|
2022-10-16 12:56:21 +00:00
|
|
|
"""Start listening for shortcuts."""
|
2022-07-23 08:53:41 +00:00
|
|
|
if not self.gtk_listeners.get(self.on_gtk_shortcut):
|
|
|
|
self.gtk_listeners[self.on_gtk_shortcut] = self.window.connect(
|
|
|
|
"key-press-event", self.on_gtk_shortcut
|
|
|
|
)
|
2020-12-26 15:42:57 +00:00
|
|
|
|
2022-11-12 16:45:32 +00:00
|
|
|
def get(self, name: str):
|
|
|
|
"""Get a widget from the window."""
|
2020-11-09 22:16:30 +00:00
|
|
|
return self.builder.get_object(name)
|
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def close(self):
|
2022-11-12 16:45:32 +00:00
|
|
|
"""Close the window."""
|
2021-09-26 10:44:56 +00:00
|
|
|
logger.debug("Closing window")
|
2020-12-26 15:42:57 +00:00
|
|
|
self.window.hide()
|
2021-01-07 16:15:12 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def update_combination_label(self, mapping: MappingData):
|
2022-11-12 16:45:32 +00:00
|
|
|
"""Listens for mapping and updates the combination label."""
|
2022-07-23 08:53:41 +00:00
|
|
|
label: Gtk.Label = self.get("combination-label")
|
2022-12-15 13:43:03 +00:00
|
|
|
if mapping.input_combination.beautify() == label.get_label():
|
2020-11-14 23:27:45 +00:00
|
|
|
return
|
2022-12-15 13:43:03 +00:00
|
|
|
if mapping.input_combination == InputCombination.empty_combination():
|
2022-10-16 12:56:21 +00:00
|
|
|
label.set_opacity(0.5)
|
2022-07-23 08:53:41 +00:00
|
|
|
label.set_label(_("no input configured"))
|
2021-03-21 13:17:34 +00:00
|
|
|
return
|
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
label.set_opacity(1)
|
2022-12-15 13:43:03 +00:00
|
|
|
label.set_label(mapping.input_combination.beautify())
|
2020-11-09 22:16:30 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def on_gtk_shortcut(self, _, event: Gdk.EventKey):
|
2022-11-12 16:45:32 +00:00
|
|
|
"""Execute shortcuts."""
|
2022-07-23 08:53:41 +00:00
|
|
|
if event.state & Gdk.ModifierType.CONTROL_MASK:
|
|
|
|
try:
|
|
|
|
self.shortcuts[event.keyval]()
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2021-03-21 13:17:34 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def on_gtk_close(self, *_):
|
|
|
|
self.controller.close()
|
2021-03-21 13:17:34 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def on_gtk_about_clicked(self, _):
|
2021-03-21 13:17:34 +00:00
|
|
|
"""Show the about/help dialog."""
|
|
|
|
self.about.show()
|
2021-03-21 19:47:36 +00:00
|
|
|
|
2022-07-23 08:53:41 +00:00
|
|
|
def on_gtk_about_key_press(self, _, event):
|
2021-03-21 19:47:36 +00:00
|
|
|
"""Hide the about/help dialog."""
|
|
|
|
gdk_keycode = event.get_keyval()[1]
|
|
|
|
if gdk_keycode == Gdk.KEY_Escape:
|
|
|
|
self.about.hide()
|
2022-07-23 08:53:41 +00:00
|
|
|
|
|
|
|
def on_gtk_rename_clicked(self, *_):
|
|
|
|
name = self.get("preset_name_input").get_text()
|
|
|
|
self.controller.rename_preset(name)
|
|
|
|
self.get("preset_name_input").set_text("")
|
|
|
|
|
|
|
|
def on_gtk_preset_name_input_return(self, _, event: Gdk.EventKey):
|
|
|
|
if event.keyval == Gdk.KEY_Return:
|
|
|
|
self.on_gtk_rename_clicked()
|