diff --git a/keymapper/gtk/row.py b/keymapper/gtk/row.py
index 94bc227d..2d41967c 100644
--- a/keymapper/gtk/row.py
+++ b/keymapper/gtk/row.py
@@ -24,7 +24,6 @@
import evdev
-import gi
from gi.repository import Gtk, GLib
from keymapper.state import custom_mapping
@@ -178,6 +177,10 @@ class Row(Gtk.ListBoxRow):
# make the togglebutton go back to its normal state when doing
# something else in the UI
+ keycode_input.connect(
+ 'focus-in-event',
+ self.window.can_modify_mapping
+ )
keycode_input.connect(
'focus-out-event',
lambda *args: keycode_input.set_active(False)
diff --git a/keymapper/gtk/unsaved.py b/keymapper/gtk/unsaved.py
index 06d1263f..629b0a1d 100644
--- a/keymapper/gtk/unsaved.py
+++ b/keymapper/gtk/unsaved.py
@@ -22,7 +22,6 @@
"""Error dialog."""
-import gi
from gi.repository import Gtk
from keymapper.data import get_data_path
diff --git a/keymapper/gtk/window.py b/keymapper/gtk/window.py
index c532febd..ddf5d4ec 100755
--- a/keymapper/gtk/window.py
+++ b/keymapper/gtk/window.py
@@ -24,7 +24,6 @@
import evdev
from evdev.ecodes import EV_KEY
-import gi
from gi.repository import Gtk, Gdk, GLib
from keymapper.data import get_data_path
@@ -229,8 +228,35 @@ class Window:
key_list = self.get('key_list')
key_list.forall(lambda row: row.unhighlight())
+ def can_modify_mapping(self, *args):
+ """Show a message if changing the mapping is not possible."""
+ if self.dbus.is_injecting(self.selected_device):
+ # because the device is in grab mode by the daemon and
+ # therefore the original keycode inaccessible
+ logger.info('Cannot change keycodes while injecting')
+ self.get('status_bar').push(
+ CTX_ERROR,
+ 'Use "Apply Defaults" before editing'
+ )
+
+ def get_focused_row(self):
+ """Get the Row that is currently in focus."""
+ focused = self.window.get_focus()
+ if focused is None:
+ return True
+
+ box = focused.get_parent()
+ if box is None:
+ return True
+
+ row = box.get_parent()
+ if not isinstance(row, Row):
+ return None, None
+
+ return row, focused
+
def consume_newest_keycode(self):
- """To capture events from keyboard, mice and gamepads."""
+ """To capture events from keyboards, mice and gamepads."""
# the "event" event of Gtk.Window wouldn't trigger on gamepad
# events, so it became a GLib timeout
ev_type, keycode = keycode_reader.read()
@@ -252,16 +278,8 @@ class Window:
self.get('keycode').set_text(to_string(ev_type, keycode))
# inform the currently selected row about the new keycode
- focused = self.window.get_focus()
- if focused is None:
- return True
-
- box = focused.get_parent()
- if box is None:
- return True
-
- row = box.get_parent()
- if isinstance(focused, Gtk.ToggleButton) and isinstance(row, Row):
+ row, focused = self.get_focused_row()
+ if isinstance(focused, Gtk.ToggleButton):
row.set_new_keycode(ev_type, keycode)
return True
diff --git a/readme/pylint.svg b/readme/pylint.svg
index 6d3f49fe..bde3a939 100644
--- a/readme/pylint.svg
+++ b/readme/pylint.svg
@@ -17,7 +17,7 @@
pylint
- 9.74
- 9.74
+ 9.76
+ 9.76
\ No newline at end of file
diff --git a/tests/testcases/test_daemon.py b/tests/testcases/test_daemon.py
index 246aca03..cf8e972d 100644
--- a/tests/testcases/test_daemon.py
+++ b/tests/testcases/test_daemon.py
@@ -26,7 +26,6 @@ import time
import evdev
from evdev.ecodes import EV_KEY
-import gi
from gi.repository import Gtk
from keymapper.state import custom_mapping, system_mapping