Skip to content

Commit

Permalink
use GtkSearchEntry, rm clear button
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe committed Feb 21, 2023
1 parent eee1752 commit c878327
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 41 deletions.
26 changes: 2 additions & 24 deletions data/input-remapper.glade
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
<property name="margin-end">2</property>
<property name="icon-name">media-playback-start</property>
</object>
<object class="GtkImage" id="clear-icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">edit-clear-symbolic</property>
</object>
<object class="GtkImage" id="copy-icon1">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand Down Expand Up @@ -659,11 +654,12 @@ Shortcut: ctrl + del</property>
<property name="can-focus">False</property>
<property name="spacing">3</property>
<child>
<object class="GtkEntry" id="mapping-filter-input">
<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>
Expand All @@ -689,24 +685,6 @@ Shortcut: ctrl + del</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="mapping-filter-clear-button">
<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">Clear mapping filter</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="image">clear-icon</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
Expand Down
8 changes: 0 additions & 8 deletions inputremapper/gui/components/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class FilterControl:
>>> message_broker,
>>> message_type,
>>> my_gtk_entry,
>>> clear_button=my_gtk_button, # use an optional clear button
>>> case_toggle=my_gtk_toggle, # use optional case sensitivity switch
>>> )
Expand All @@ -203,13 +202,11 @@ def __init__(
message_broker: MessageBroker,
message_type: MessageType,
filter_entry: Gtk.GtkEntry,
clear_button: Gtk.Button = None,
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._clear_button: Gtk.Button = clear_button
self._case_toggle: Gtk.ToggleButton = case_toggle

self._filter_value: str = ""
Expand All @@ -232,8 +229,6 @@ def _update(self, force=False) -> bool:

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

Expand All @@ -242,8 +237,5 @@ def _on_gtk_case_button_toggled(self, btn: Gtk.ToggleButton):
if self._filter_value != "":
self._update(force=True)

def _on_gtk_clear_button_clicked(self, *_):
self._filter_entry.set_text("")

def _on_gtk_input_changed(self, *_):
self._update()
2 changes: 0 additions & 2 deletions inputremapper/gui/user_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
from inputremapper.gui.components.presets import PresetSelection
from inputremapper.gui.components.main import Stack, StatusBar
from inputremapper.gui.components.common import Breadcrumbs, FilterControl
from inputremapper.gui.components.gtkext.listbox_filter import ListBoxFilter
from inputremapper.gui.components.device_groups import DeviceGroupSelection
from inputremapper.gui.controller import Controller
from inputremapper.gui.messages.message_broker import (
Expand Down Expand Up @@ -154,7 +153,6 @@ def _create_components(self):
message_broker,
MessageType.mapping_filter,
self.get("mapping-filter-input"),
clear_button=self.get("mapping-filter-clear-button"),
case_toggle=self.get("mapping-filter-case-button"),
)

Expand Down
4 changes: 1 addition & 3 deletions tests/integration/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,12 @@ class TestMappingFilterListbox(TestMappingListboxBase):
def setUp(self) -> None:
super().setUp()
self.entry = Gtk.Entry()
self.button = Gtk.Button()
self.toggle = Gtk.ToggleButton()
self.filter = ListBoxFilter(self.gui)
self.control = FilterControl(
self.message_broker,
MessageType.mapping_filter,
self.entry,
clear_button=self.button,
case_toggle=self.toggle,
)

Expand All @@ -547,7 +545,7 @@ def test_filter_entry(self):
self.assertEqual(self.entry.get_text(), "not in preset")
self.assertEqual(self.get_num_visible(), 0, "mappings must not be visible")

self.button.clicked()
self.entry.set_text('')
gtk_iteration()
self.assertEqual(self.entry.get_text(), "", "filter must be cleared")
self.assertEqual(
Expand Down
15 changes: 11 additions & 4 deletions tests/integration/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
from inputremapper.gui.messages.message_data import StatusData, CombinationRecorded
from inputremapper.gui.components.editor import MappingSelectionLabel, SET_KEY_FIRST
from inputremapper.gui.components.device_groups import DeviceGroupEntry
from inputremapper.gui.components.gtkext.listbox_filter import ListBoxFilter
from inputremapper.gui.controller import Controller
from inputremapper.gui.reader_service import ReaderService
from inputremapper.gui.utils import gtk_iteration, Colors, debounce, debounce_manager
Expand Down Expand Up @@ -296,7 +297,7 @@ def setUp(self):
self.stop_injector_btn: Gtk.Button = get("stop_injection_preset_page")
self.rename_btn: Gtk.Button = get("rename-button")
self.rename_input: Gtk.Entry = get("preset_name_input")
self.mapping_filter_btn: Gtk.Button = get("mapping-filter-clear-button")
self.mapping_filter_case_btn: Gtk.Button = get("mapping-filter-case-button")
self.mapping_filter_input: Gtk.Entry = get("mapping-filter-input")
self.create_mapping_btn: Gtk.Button = get("create_mapping_button")
self.delete_mapping_btn: Gtk.Button = get("delete-mapping")
Expand Down Expand Up @@ -1441,6 +1442,15 @@ def save():
gtk_iteration()
self.assertFalse(os.path.exists(preset_path))

def test_filter_case_button(self):
self.mapping_filter_case_btn.clicked()
gtk_iteration()
self.assertEqual(self.mapping_filter_case_btn.get_active(), True)

self.mapping_filter_case_btn.clicked()
gtk_iteration()
self.assertEqual(self.mapping_filter_case_btn.get_active(), False)

def test_filtering_mappings(self):
self.controller.load_preset("preset2")
self.throttle(20)
Expand All @@ -1462,9 +1472,6 @@ def test_filtering_mappings(self):
gtk_iteration()
self.assertEqual(self.data_manager.active_mapping.format_name(), text1)

self.mapping_filter_btn.clicked()
self.assertEqual(self.mapping_filter_input.get_text(), "")

def test_check_for_unknown_symbols(self):
status = self.user_interface.get("status_bar")
error_icon = self.user_interface.get("error_status_icon")
Expand Down

0 comments on commit c878327

Please sign in to comment.