Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
07065cb
add listbox filter component and use to for filtering mappings
Feb 17, 2023
3d47406
add missing can_emit method, used in tests
Feb 18, 2023
bce087d
use help func to create combination
Feb 18, 2023
3f3904d
add tests for listbox filter
Feb 18, 2023
b782024
cleanup and black format
Feb 19, 2023
6be2700
remove debug log
Feb 19, 2023
d8e07ae
Merge branch 'beta' into feature/mapping-filter
ubunatic Feb 19, 2023
5460f0c
add Gtk.ListBox filter
Feb 21, 2023
5abf431
split mapping filter in list control and entry control
Feb 21, 2023
b2b0c46
override all optional args, fix format
Feb 21, 2023
eee1752
remove key event test
Feb 21, 2023
d06dd8d
use GtkSearchEntry, rm clear button
Feb 21, 2023
ecc7930
moving the search to a second row
sezanzeb Feb 21, 2023
2a8075f
fixed horizontal resizing
sezanzeb Feb 22, 2023
00fec91
Update inputremapper/gui/components/gtkext/listbox_filter.py
ubunatic Feb 22, 2023
5757af2
Update tests/integration/test_gui.py
ubunatic Feb 22, 2023
f0b0bf5
use GTK_PATH to allow overriding the data dir for glade and style loa…
Feb 22, 2023
69463e6
Merge branch 'feature/mapping-filter-generic' of github.com:ubunatic/…
Feb 22, 2023
817c3d9
black fmt
Feb 22, 2023
d8461fe
Update inputremapper/gui/components/gtkext/listbox_filter.py
ubunatic Feb 22, 2023
dc6b59d
remove root flag, use pkexec only on failure
Feb 23, 2023
3026a8e
use env var to ignore pkexec errors
Feb 23, 2023
fe9dd37
remove -R flag, use env var for pkexec error ignoring
ubunatic Feb 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions bin/input-remapper-gtk
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ from inputremapper.daemon import DaemonProxy
from inputremapper.logger import logger, update_verbosity, log_info


def start_processes() -> DaemonProxy:
def start_processes(ignore_pkexec_errors=False) -> DaemonProxy:
"""Start reader-service and daemon via pkexec to run in the background."""
# this function is overwritten in tests
try:
ReaderService.pkexec_reader_service()
ReaderService.pkexec_reader_service(ingore_errors=ignore_pkexec_errors)
except Exception as e:
logger.error(e)
sys.exit(11)
Expand All @@ -57,7 +57,12 @@ if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument(
'-d', '--debug', action='store_true', dest='debug',
help=_('Displays additional debug information'),
help=_('displays additional debug information'),
default=False
)
parser.add_argument(
'-R', '--no-root', action='store_true', dest='no_root',
help=_('allow rejecting root access (by cancelling the pkexec dialog)'),
default=False
)

Expand Down Expand Up @@ -85,8 +90,8 @@ if __name__ == '__main__':

# create the reader before we start the reader-service (start_processes) otherwise
# it can come to race conditions with the creation of pipes
reader_client = ReaderClient(message_broker, _Groups())
daemon = start_processes()
reader_client = ReaderClient(message_broker, _Groups(), ignore_pkexec_errors=options.no_root)
daemon = start_processes(ignore_pkexec_errors=options.no_root)

data_manager = DataManager(
message_broker, GlobalConfig(), reader_client, daemon, GlobalUInputs(), system_mapping
Expand Down
115 changes: 87 additions & 28 deletions data/input-remapper.glade
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ Shortcut: ctrl + del</property>
<object class="GtkEntry" id="preset_name_input">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="placeholder-text" translatable="yes">enter preset name...</property>
</object>
<packing>
<property name="expand">True</property>
Expand Down Expand Up @@ -501,6 +502,7 @@ Shortcut: ctrl + del</property>
<property name="can-focus">False</property>
<property name="margin-top">18</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
Expand All @@ -521,36 +523,51 @@ Shortcut: ctrl + del</property>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="margin-bottom">18</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="spacing">6</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkLabel" id="combination-label">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">no input configured</property>
<property name="wrap">True</property>
<property name="halign">center</property>
<property name="margin-bottom">18</property>
<child>
<object class="GtkLabel" id="combination-label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">no input configured</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="recording_status">
<property name="can-focus">False</property>
<property name="opacity">0.5</property>
<property name="label" translatable="yes"> (recording ...)</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</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="GtkLabel" id="recording_status">
<property name="can-focus">False</property>
<property name="opacity">0.5</property>
<property name="label" translatable="yes"> (recording ...)</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand All @@ -564,11 +581,9 @@ Shortcut: ctrl + del</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="margin-start">18</property>
<property name="margin-end">18</property>
<property name="margin-bottom">18</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="spacing">6</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="create_mapping_button">
<property name="label" translatable="yes">Add</property>
Expand All @@ -580,8 +595,8 @@ Shortcut: ctrl + del</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
Expand All @@ -596,7 +611,7 @@ Shortcut: ctrl + del</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
Expand All @@ -610,7 +625,7 @@ Shortcut: ctrl + del</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
Expand All @@ -629,6 +644,50 @@ Shortcut: ctrl + del</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkBox" id="mapping-filter-box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">3</property>
<child>
<object class="GtkSearchEntry" id="mapping-filter-input">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="truncate-multiline">True</property>
<property name="placeholder-text" translatable="yes">filter mappings...</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkToggleButton" id="mapping-filter-case-button">
<property name="label" translatable="yes">Aa</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="focus-on-click">False</property>
<property name="receives-default">True</property>
<property name="tooltip-text" translatable="yes">Toggle case sensitive</property>
<property name="halign">end</property>
<property name="valign">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
Expand Down
70 changes: 68 additions & 2 deletions inputremapper/gui/components/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

from gi.repository import Gtk

from typing import Optional
from typing import (
Optional,
Iterator,
)

from inputremapper.configs.mapping import MappingData

Expand All @@ -36,7 +39,11 @@
MessageBroker,
MessageType,
)
from inputremapper.gui.messages.message_data import GroupData, PresetData
from inputremapper.gui.messages.message_data import (
GroupData,
PresetData,
MappingFilter,
)
from inputremapper.gui.utils import HandlerDisabled


Expand Down Expand Up @@ -173,3 +180,62 @@ def _render(self):
label.append(self._mapping_name or "?")

self._gui.set_label(" / ".join(label))


class FilterControl:
"""Watches a text input to produce filter events.

The following example creates a new ``FilterControl`` for a given ``Gtk.Entry``
for text input. It also sets all optional arguments to override some default behavior.

>>> ListFilterControl(
>>> message_broker,
>>> message_type,
>>> my_gtk_entry,
>>> case_toggle=my_gtk_toggle, # use optional case sensitivity switch
>>> )

"""

def __init__(
self,
message_broker: MessageBroker,
message_type: MessageType,
filter_entry: Gtk.GtkEntry,
case_toggle: Gtk.ToggleButton = None,
):
self._message_broker: MessageBroker = message_broker
self._message_type: MessageType = message_type
self._filter_entry: Gtk.Entry = filter_entry
self._case_toggle: Gtk.ToggleButton = case_toggle

self._filter_value: str = ""
self._case_sensitive = case_toggle is None or case_toggle.get_active()

self._connect_gtk_signals()

self._update()

def _update(self, force=False) -> bool:
old_value = self._filter_value
self._filter_value = (self._filter_entry.get_text() or "").strip()
if force or self._filter_value != old_value:
self._message_broker.publish(
MappingFilter(
filter_value=self._filter_value,
case_sensitive=self._case_sensitive,
)
)

def _connect_gtk_signals(self):
self._filter_entry.connect("changed", self._on_gtk_input_changed)
if self._case_toggle:
self._case_toggle.connect("toggled", self._on_gtk_case_button_toggled)

def _on_gtk_case_button_toggled(self, btn: Gtk.ToggleButton):
self._case_sensitive = btn.get_active()
if self._filter_value != "":
self._update(force=True)

def _on_gtk_input_changed(self, *_):
self._update()
11 changes: 11 additions & 0 deletions inputremapper/gui/components/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@
UInputsData,
PresetData,
CombinationUpdate,
MappingFilter,
)
from inputremapper.gui.utils import HandlerDisabled, Colors
from inputremapper.injection.mapping_handlers.axis_transform import Transformation
from inputremapper.input_event import InputEvent
from inputremapper.configs.system_mapping import system_mapping, XKB_KEYCODE_OFFSET
from inputremapper.utils import get_evdev_constant_name
from inputremapper.gui.components.gtkext.listbox_filter import ListBoxFilter

Capabilities = Dict[int, List]

Expand Down Expand Up @@ -148,9 +150,13 @@ def __init__(
self._controller = controller
self._gui = listbox
self._gui.set_sort_func(self._sort_func)
self._mapping_filter = ListBoxFilter(listbox)

self._message_broker.subscribe(MessageType.preset, self._on_preset_changed)
self._message_broker.subscribe(MessageType.mapping, self._on_mapping_changed)
self._message_broker.subscribe(
MessageType.mapping_filter, self._on_mapping_filter_changed
)
self._gui.connect("row-selected", self._on_gtk_mapping_selected)

@staticmethod
Expand Down Expand Up @@ -190,6 +196,11 @@ def _on_mapping_changed(self, mapping: MappingData):
if row.combination == combination:
self._gui.select_row(row)

def _on_mapping_filter_changed(self, filter: MappingFilter):
self._mapping_filter.set_filter(
filter.filter_value, case_sensitive=filter.case_sensitive
)

def _on_gtk_mapping_selected(self, _, row: Optional[MappingSelectionLabel]):
if not row:
return
Expand Down
5 changes: 5 additions & 0 deletions inputremapper/gui/components/gtkext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Module with general Gtk enhancements

All code in this module is indendent from any inputremapper code.
"""
Loading