some rearrangement

This commit is contained in:
sezanzeb 2020-11-02 20:55:17 +01:00
parent 5e80afc7ce
commit b8c602822c
5 changed files with 256 additions and 194 deletions

View File

@ -12,7 +12,7 @@ work.
# Running
```
```bash
sudo python3 setup.py install && sudo key-mapper-gtk -d
```
@ -26,7 +26,7 @@ No idea which one are relevant at the moment
sudo is required because some tests actually read /dev stuff.
```
```bash
sudo python3 setup.py install && sudo python3 tests/test.py
```

View File

@ -129,7 +129,12 @@ class Window:
else:
logger.debug('Presets for "%s": %s', device, ', '.join(presets))
preset_selection = self.get('preset_selection')
preset_selection.handler_block_by_func(self.on_select_preset)
# otherwise the handler is called with None for each removed preset
preset_selection.remove_all()
preset_selection.handler_unblock_by_func(self.on_select_preset)
for preset in presets:
preset_selection.append(preset, preset)
# and select the newest one (on the top)

View File

@ -6,7 +6,12 @@
<property name="width_request">450</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Key Mapper</property>
<property name="resizable">False</property>
<signal name="delete-event" handler="on_close" swapped="no"/>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -23,7 +28,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Device</property>
<property name="width_chars">10</property>
<property name="width_chars">13</property>
<property name="xalign">0</property>
</object>
<packing>
@ -59,7 +64,6 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">10</property>
<property name="position">1</property>
</packing>
</child>
@ -76,17 +80,16 @@
<property name="can_focus">False</property>
<property name="spacing">10</property>
<child>
<object class="GtkButton" id="create_preset">
<property name="label">gtk-new</property>
<object class="GtkButton" id="create_preset1">
<property name="label">gtk-apply</property>
<property name="width_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_create_preset_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@ -101,11 +104,39 @@
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="create_preset">
<property name="label">gtk-new</property>
<property name="width_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_create_preset_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="create_preset3">
<property name="label">gtk-delete</property>
@ -116,9 +147,9 @@
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">4</property>
</packing>
</child>
</object>
@ -139,7 +170,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">preset</property>
<property name="width_chars">10</property>
<property name="width_chars">13</property>
<property name="xalign">0</property>
</object>
<packing>
@ -178,7 +209,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Rename</property>
<property name="width_chars">10</property>
<property name="width_chars">13</property>
<property name="xalign">0</property>
</object>
<packing>
@ -212,6 +243,13 @@
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
@ -220,10 +258,15 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">10</property>
<property name="position">3</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox" id="add_mapping">
<property name="visible">True</property>
@ -263,7 +306,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">0</property>
</packing>
</child>
<child>
@ -273,8 +316,8 @@
<property name="margin_start">10</property>
<property name="margin_end">10</property>
<property name="margin_bottom">10</property>
<property name="row_spacing">10</property>
<property name="column_spacing">10</property>
<property name="row_spacing">2</property>
<property name="column_spacing">2</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
@ -306,7 +349,14 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -42,14 +42,21 @@ def get_devices():
return _devices
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
# group them together by usb device because there could be stuff like
# "Logitech USB Keyboard" and "Logitech USB Keyboard Consumer Control"
grouped = {}
for device in devices:
# only keyboard devices
# https://www.kernel.org/doc/html/latest/input/event-codes.html
if not evdev.ecodes.EV_KEY in device.capabilities().keys():
continue
usb = device.phys.split('/')[0]
if grouped.get(usb) is None:
grouped[usb] = []
grouped[usb].append((device.name, device.path))
# now write down all the paths of that group
result = {}
for group in grouped.values():