From 854376fe220cb005bb3992339330d1fdf04097ed Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sun, 11 Feb 2024 07:46:15 -0500 Subject: [PATCH] ui: tidy up scrolling appearance in configuration panel --- lib/solaar/ui/config_panel.py | 4 +- lib/solaar/ui/window.py | 2 +- tests/test_hidpp20_simple.py | 75 +++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 tests/test_hidpp20_simple.py diff --git a/lib/solaar/ui/config_panel.py b/lib/solaar/ui/config_panel.py index 41bcff7bae..99d2ea30ff 100644 --- a/lib/solaar/ui/config_panel.py +++ b/lib/solaar/ui/config_panel.py @@ -740,13 +740,13 @@ def _disable_listbox_highlight_bg(lb): def create(): global _box assert _box is None - _box = Gtk.VBox(homogeneous=False, spacing=8) + _box = Gtk.VBox(homogeneous=False, spacing=4) _box._last_device = None config_scroll = Gtk.ScrolledWindow() config_scroll.add(_box) config_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) - config_scroll.set_shadow_type(Gtk.ShadowType.IN) + config_scroll.set_shadow_type(Gtk.ShadowType.NONE) # was IN config_scroll.set_size_request(0, 350) # ask for enough vertical space for about eight settings return config_scroll diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index cc456b7756..39c02d0856 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -134,7 +134,7 @@ def _status_line(label_text): p._lux = _status_line(_('Lighting')) p.pack_start(p._lux, False, False, 0) - # p.pack_start(Gtk.Separator.new(Gtk.Orientation.HORIZONTAL), False, False, 0) # spacer + p.pack_start(Gtk.Separator.new(Gtk.Orientation.HORIZONTAL), False, False, 0) # spacer p._config = _config_panel.create() p.pack_end(p._config, True, True, 4) diff --git a/tests/test_hidpp20_simple.py b/tests/test_hidpp20_simple.py new file mode 100644 index 0000000000..43770fb2a0 --- /dev/null +++ b/tests/test_hidpp20_simple.py @@ -0,0 +1,75 @@ +from collections import namedtuple + +import logitech_receiver.hidpp20 as hidpp20 + +response = namedtuple('response', 'response device feature function params') + + +def feature_request(device, feature, function=0x00, *params, no_reply=False): + global responses + assert len(responses) > 0, f"extra call of feature_request {device}, {feature}, {function}, {params}, {no_reply}" + r = responses[0] + if r.device == device and r.feature == feature and r.function == function and r.params == params: + responses = responses[1:] + return bytes.fromhex(r.response) if r.response is not None else None + raise AssertionError(f"incorrect call of feature_request {device}, {feature}, {function}, {params}, {no_reply}") + + +def test_set_host_name(mocker): # FIXME + return None + global responses + mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request) + responses = [response('03FFFFFFFF', None, hidpp20.FEATURE.HOSTS_INFO, 0x00, ())] # FIXME + hidpp20.set_host_name(None, 'THIS IS A LONG HOST NAME') + assert responses == [] + + +def test_get_onboard_mode(mocker): + global responses + mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request) + responses = [response('03FFFFFFFF', None, hidpp20.FEATURE.ONBOARD_PROFILES, 0x20, ())] + result = hidpp20.get_onboard_mode(None) + assert result == 0x3 + assert responses == [] + + +def test_set_onboard_mode(mocker): + global responses + mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request) + responses = [response('03FFFFFFFF', None, hidpp20.FEATURE.ONBOARD_PROFILES, 0x10, (0x3, ))] + hidpp20.set_onboard_mode(None, 0x3) + assert responses == [] + + +def test_get_polling_rate(mocker): + global responses + mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request) + responses = [response('03FFFF', None, hidpp20.FEATURE.REPORT_RATE, 0x10, ())] + result = hidpp20.get_polling_rate(None) + assert result == '3ms' + assert responses == [] + responses = [ + response(None, None, hidpp20.FEATURE.REPORT_RATE, 0x10, ()), + response('04FFFF', None, hidpp20.FEATURE.EXTENDED_ADJUSTABLE_REPORT_RATE, 0x20, ()) + ] + result = hidpp20.get_polling_rate(None) + assert result == '500us' + assert responses == [] + + +def test_get_remaining_pairing(mocker): + global responses + mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request) + responses = [response('03FFFF', None, hidpp20.FEATURE.REMAINING_PAIRING, 0x0, ())] + result = hidpp20.get_remaining_pairing(None) + assert result == 0x03 + assert responses == [] + + +def test_config_change(mocker): + global responses + mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request) + responses = [response('03FFFF', None, hidpp20.FEATURE.CONFIG_CHANGE, 0x0, (0x2, ))] + result = hidpp20.config_change(None, 0x2) + assert result == bytes.fromhex('03FFFF') + assert responses == []