showing button names instead of numbers

pull/14/head
sezanzeb 4 years ago
parent c092145a62
commit 813ecf2b02

@ -271,7 +271,7 @@
<property name="icon_name">document-save</property>
</object>
<object class="GtkWindow" id="window">
<property name="width_request">-1</property>
<property name="width_request">700</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Key Mapper</property>
<property name="default_height">350</property>
@ -666,7 +666,7 @@
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="width_request">50</property>
<property name="width_request">130</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Click on a cell below and hit a key on your device. If you have your preset active, the reported keycodes may be wrong.</property>

@ -22,6 +22,8 @@
"""A single, configurable key mapping."""
import evdev
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GLib', '2.0')
@ -39,6 +41,18 @@ CTX_KEYCODE = 2
# and the whole offset thing probably drops away
def to_string(ev_type, code):
"""A nice to show description of the pressed key."""
# TODO test
try:
name = evdev.ecodes.bytype[ev_type][code]
if isinstance(name, list):
name = name[0]
return name.replace('KEY_', '')
except KeyError:
return 'unknown'
class Row(Gtk.ListBoxRow):
"""A single, configurable key mapping."""
__gtype_name__ = 'ListBoxRow'
@ -56,7 +70,10 @@ class Row(Gtk.ListBoxRow):
self.character_input = None
self.keycode_input = None
self.put_together(ev_type, keycode, character)
self.ev_type = ev_type
self.keycode = keycode
self.put_together(character)
def get_keycode(self):
"""Get a tuple of event_type and keycode from the left column.
@ -67,8 +84,7 @@ class Row(Gtk.ListBoxRow):
if not keycode:
return None
ev_type, keycode = keycode.split(',')
return int(ev_type), int(keycode)
return self.ev_type, self.keycode
def get_character(self):
"""Get the assigned character from the middle column."""
@ -101,7 +117,9 @@ class Row(Gtk.ListBoxRow):
# it's legal to display the keycode
self.window.get('status_bar').remove_all(CTX_KEYCODE)
self.keycode_input.set_label(f'{ev_type},{new_keycode}')
self.keycode_input.set_label(to_string(ev_type, new_keycode))
self.ev_type = ev_type
self.keycode = new_keycode
# switch to the character, don't require mouse input because
# that would overwrite the key with the mouse-button key if
# the current device is a mouse. idle_add this so that the
@ -146,7 +164,7 @@ class Row(Gtk.ListBoxRow):
previous_keycode=None
)
def put_together(self, ev_type, keycode, character):
def put_together(self, character):
"""Create all child GTK widgets and connect their signals."""
delete_button = Gtk.EventBox()
delete_button.add(Gtk.Image.new_from_icon_name(
@ -160,10 +178,10 @@ class Row(Gtk.ListBoxRow):
delete_button.set_size_request(50, -1)
keycode_input = Gtk.ToggleButton()
keycode_input.set_size_request(50, -1)
keycode_input.set_size_request(130, -1)
if keycode is not None:
keycode_input.set_label(f'{ev_type},{keycode}')
if self.keycode is not None:
keycode_input.set_label(to_string(self.ev_type, self.keycode))
# make the togglebutton go back to its normal state when doing
# something else in the UI

@ -36,7 +36,7 @@ from keymapper.presets import get_presets, find_newest_preset, \
delete_preset, rename_preset, get_available_preset_name
from keymapper.logger import logger
from keymapper.getdevices import get_devices
from keymapper.gtk.row import Row
from keymapper.gtk.row import Row, to_string
from keymapper.gtk.unsaved import unsaved_changes_dialog, GO_BACK
from keymapper.dev.reader import keycode_reader
from keymapper.daemon import get_dbus_interface
@ -72,10 +72,6 @@ def get_selected_row_bg():
return color.to_string()
# TODO show if the preset is being injected
# apply button -> stop button. makes "Apply Defaults" obsolete
class Window:
"""User Interface."""
def __init__(self):
@ -232,11 +228,18 @@ class Window:
# which breaks the current workflow.
return True
self.get('keycode').set_text(f'{ev_type},{keycode}')
self.get('keycode').set_text(to_string(ev_type, keycode))
# inform the currently selected row about the new keycode
focused = self.window.get_focus()
row = focused.get_parent().get_parent()
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.set_new_keycode(ev_type, keycode)
@ -325,6 +328,10 @@ class Window:
dropdown.set_active_id(self.selected_device)
return
# selecting a device will also automatically select a different
# preset. Prevent another unsaved-changes dialog to pop up
custom_mapping.changed = False
device = dropdown.get_active_text()
logger.debug('Selecting device "%s"', device)

Loading…
Cancel
Save