input-remapper/tests/unit/test_daemon.py

483 lines
17 KiB
Python
Raw Normal View History

2020-11-20 20:38:59 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
2022-01-01 12:00:49 +00:00
# input-remapper - GUI for device specific keyboard mappings
2022-01-01 12:52:33 +00:00
# Copyright (C) 2022 sezanzeb <proxima@sezanzeb.de>
2020-11-20 20:38:59 +00:00
#
2022-01-01 12:00:49 +00:00
# This file is part of input-remapper.
2020-11-20 20:38:59 +00:00
#
2022-01-01 12:00:49 +00:00
# input-remapper is free software: you can redistribute it and/or modify
2020-11-20 20:38:59 +00:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
2022-01-01 12:00:49 +00:00
# input-remapper is distributed in the hope that it will be useful,
2020-11-20 20:38:59 +00:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2022-01-01 12:00:49 +00:00
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
2020-11-20 20:38:59 +00:00
from tests.test import (
cleanup,
uinput_write_history_pipe,
new_event,
push_events,
is_service_running,
fixtures,
tmp,
2022-04-17 10:19:23 +00:00
get_key_mapping,
)
2020-11-29 00:44:14 +00:00
import os
2020-11-20 20:38:59 +00:00
import unittest
2020-11-29 00:44:14 +00:00
import time
2020-12-26 18:36:47 +00:00
import subprocess
2021-02-07 14:00:36 +00:00
import json
2020-11-20 20:38:59 +00:00
import evdev
2022-08-28 10:38:40 +00:00
from evdev.ecodes import EV_KEY, EV_ABS, KEY_B, KEY_A, ABS_X, BTN_A, BTN_B
2020-12-26 18:36:47 +00:00
from pydbus import SystemBus
2020-11-20 20:38:59 +00:00
2022-01-31 19:58:37 +00:00
from inputremapper.configs.system_mapping import system_mapping
from inputremapper.configs.global_config import global_config
2022-01-01 12:00:49 +00:00
from inputremapper.groups import groups
2022-01-31 19:58:37 +00:00
from inputremapper.configs.paths import get_config_path, mkdir, get_preset_path
from inputremapper.event_combination import EventCombination
from inputremapper.configs.preset import Preset
2022-01-01 12:00:49 +00:00
from inputremapper.injection.injector import STARTING, RUNNING, STOPPED, UNKNOWN
2022-01-17 23:55:01 +00:00
from inputremapper.daemon import Daemon
2022-03-17 09:32:22 +00:00
from inputremapper.injection.global_uinputs import global_uinputs
2020-11-20 20:38:59 +00:00
2020-12-26 18:36:47 +00:00
check_output = subprocess.check_output
2021-03-21 18:15:20 +00:00
os_system = os.system
2020-12-26 18:36:47 +00:00
dbus_get = type(SystemBus()).get
2020-11-20 20:38:59 +00:00
class TestDaemon(unittest.TestCase):
2021-09-26 10:44:56 +00:00
new_fixture_path = "/dev/input/event9876"
def setUp(self):
self.grab = evdev.InputDevice.grab
self.daemon = None
2021-03-21 18:15:20 +00:00
mkdir(get_config_path())
2022-01-31 19:58:37 +00:00
global_config._save_config()
2020-11-20 20:38:59 +00:00
2022-03-17 09:32:22 +00:00
# the daemon should be able to create them on demand:
global_uinputs.devices = {}
global_uinputs.is_service = True
2020-11-20 20:38:59 +00:00
def tearDown(self):
# avoid race conditions with other tests, daemon may run processes
if self.daemon is not None:
2021-02-07 14:00:36 +00:00
self.daemon.stop_all()
2020-11-20 20:38:59 +00:00
self.daemon = None
evdev.InputDevice.grab = self.grab
2020-12-26 18:36:47 +00:00
subprocess.check_output = check_output
2021-03-21 18:15:20 +00:00
os.system = os_system
2020-12-26 18:36:47 +00:00
type(SystemBus()).get = dbus_get
cleanup()
2020-11-20 20:38:59 +00:00
2021-03-21 18:15:20 +00:00
def test_connect(self):
os_system_history = []
os.system = os_system_history.append
2020-12-26 18:36:47 +00:00
2021-03-21 18:15:20 +00:00
self.assertFalse(is_service_running())
2021-03-21 18:15:20 +00:00
# no daemon runs, should try to run it via pkexec instead.
# It fails due to the patch on os.system and therefore exits the process
2021-03-21 18:15:20 +00:00
self.assertRaises(SystemExit, Daemon.connect)
self.assertEqual(len(os_system_history), 1)
self.assertIsNone(Daemon.connect(False))
2020-12-26 18:36:47 +00:00
# make the connect command work this time by acting like a connection is
# available:
set_config_dir_callcount = 0
2020-12-26 18:36:47 +00:00
class FakeConnection:
def set_config_dir(self, *args, **kwargs):
nonlocal set_config_dir_callcount
set_config_dir_callcount += 1
2020-12-26 18:36:47 +00:00
type(SystemBus()).get = lambda *args, **kwargs: FakeConnection()
2021-03-21 18:15:20 +00:00
self.assertIsInstance(Daemon.connect(), FakeConnection)
self.assertEqual(set_config_dir_callcount, 1)
2021-03-21 18:15:20 +00:00
self.assertIsInstance(Daemon.connect(False), FakeConnection)
self.assertEqual(set_config_dir_callcount, 2)
2020-12-26 18:36:47 +00:00
2020-11-20 20:38:59 +00:00
def test_daemon(self):
2021-02-07 14:00:36 +00:00
# remove the existing system mapping to force our own into it
2021-09-26 10:44:56 +00:00
if os.path.exists(get_config_path("xmodmap.json")):
os.remove(get_config_path("xmodmap.json"))
2021-02-07 14:00:36 +00:00
2022-04-17 10:19:23 +00:00
preset_name = "foo"
2022-04-17 10:19:23 +00:00
ev_1 = (EV_KEY, BTN_A)
ev_2 = (EV_ABS, ABS_X)
2022-04-17 10:19:23 +00:00
group = groups.find(name="gamepad")
2020-11-20 20:38:59 +00:00
2022-04-17 10:19:23 +00:00
# unrelated group that shouldn't be affected at all
group2 = groups.find(name="Bar Device")
2020-12-02 17:07:46 +00:00
2022-04-17 10:19:23 +00:00
preset = Preset(group.get_preset_path(preset_name))
preset.add(get_key_mapping(EventCombination([*ev_1, 1]), "keyboard", "a"))
preset.add(get_key_mapping(EventCombination([*ev_2, -1]), "keyboard", "b"))
preset.save()
global_config.set_autoload_preset(group.key, preset_name)
2020-11-20 20:38:59 +00:00
"""Injection 1"""
# should forward the event unchanged
2022-08-28 10:38:40 +00:00
push_events(fixtures.gamepad, [new_event(EV_KEY, BTN_B, 1)])
2020-11-20 20:38:59 +00:00
self.daemon = Daemon()
2020-12-02 17:07:46 +00:00
2021-01-01 21:20:33 +00:00
self.assertFalse(uinput_write_history_pipe[0].poll())
2022-03-17 09:32:22 +00:00
# has been cleanedUp in setUp
self.assertNotIn("keyboard", global_uinputs.devices)
2022-04-17 10:19:23 +00:00
self.daemon.start_injecting(group.key, preset_name)
2022-03-17 09:32:22 +00:00
# created on demand
self.assertIn("keyboard", global_uinputs.devices)
self.assertNotIn("gamepad", global_uinputs.devices)
self.assertEqual(self.daemon.get_state(group.key), STARTING)
self.assertEqual(self.daemon.get_state(group2.key), UNKNOWN)
2020-12-02 17:07:46 +00:00
event = uinput_write_history_pipe[0].recv()
self.assertEqual(self.daemon.get_state(group.key), RUNNING)
self.assertEqual(event.type, EV_KEY)
2022-08-28 10:38:40 +00:00
self.assertEqual(event.code, BTN_B)
self.assertEqual(event.value, 1)
2020-12-02 17:07:46 +00:00
self.daemon.stop_injecting(group.key)
Frontend Refactor (#375) * Tests for the GuiEventHandler * Implement GuiEventHandler * tests for data manager * Implemented data_manager * Remove Ellipsis from type hint * workaround for old pydantic version * workaround for old pydantic version * some more tests for data_manager * Updated Data Manager * move DeviceSelection to its own class * Data Manager no longer listens for events * Moved PresetSelection to its own class * MappingListBox and SelectionLable Listen to the EventHandler * DataManager no longer creates its own data objects in the init * removed global reader object * Changed UI startup * created backend Interface * event_handler debug logs show function which emit a event * some cleanup * added target selector to components * created code editor component * adapted autocompletion & some cleanup * black * connected some buttons to the event_handler * tests for data_manager newest_preset and group * cleanup presets and test_presets * migrated confirm delete dialog * backend tests * controller tests * add python3-gi to ci * more dependencies * and more ... * Github-Actions workaround remove this commit * not so many permission denyed errors in test.yml * Fix #404 (hopefully) * revert Github-Actions workaround * More tests * event_handler allows for event supression * more tests * WIP Implement Key recording * Start and Stop Injection * context no longer stores preset * restructured the RelToBtnHandler * Simplified read_loop * Implement async iterator for ipc.pipe * multiple event actions * helper now implements mapping handlers to read inputs all with async * updated and simplified reader the helper uses the mapping handlers, so the reader now can be much simpler * Fixed race condition in tests * implemented DataBus * Fixed a UIMapping bug where the last_error would not be deleted * added a immutable variant of the UIMapping * updated data_manager to use data_bus * Uptdated tests to use the DataBus * Gui uses DataBus * removed EventHandler * Renamed controller methods * Implemented recording toggle * implemented StatusBar * Sending validation errors to status bar * sending injection status to status bar * proper preset renaming * implemented copy preset in the data manager * implemented copy_preset in controller * fixed a bug where a wron selection lable would update * no longer send invalid data over the bus, if the preset or group changes * Implement create and delete mapping * Allow for frontend specific mapping defaults * implemented autoload toggle * cleanup user_interface * removed editor * Docstings renaming and ordering of methods * more simplifications to user_interface * integrated backend into data_manager * removed active preset * transformation tests * controller tests * fix missing uinputs in gui * moved some tests and implemented basic tests for mapping handlers * docstring reformatting Co-authored-by: Tobi <proxima@sezanzeb.de> * allow for empty groups * docstring * fixed TestGroupFromHelper * some work on integration tests * test for annoying import error in tests * testing if test_user_interface works * I feel lucky * not so lucky * some more tests * fixed but where the group_key was used as folder name * Fixed a bug where state=NO_GRAB would never be read from the injector * allow to stop the recorder * working on integration tests * integration tests * fixed more integration tests * updated coveragerc * no longer attempt to record keys when injecting * event_reader cleans up not finished tasks * More integration tests * All tests pass * renamed data_bus * WIP fixing typing issues * more typing fixes * added keyboard+mouse device to tests * cleanup imports * new read loop because the evdev async read loop can not be cancelled * Added field to modify mapping name * created tests for components * even more component tests * do component tests need a screen? * apparently they do :_( * created release_input switch * Don't record relative axis when movement is slow * show delete dialog above main window * wip basic dialog to edit combination * some gui changes to the combination-editor * Simple implementation of CombinationListbox * renamed attach_to_events method and mark as private * shorter str() for UInputsData * moved logic to generate readable event string from combination to event * new mapping parameter force release timeout this helps with the helper when recording multiple relative axis at once * make it possible to rearange the event_combination * more work on the combination editor * tests for DataManager.load_event * simplyfied test_controller * more controller tests * Implement input threshold in gui * greater range for time dependent unit test * implemented a output-axis selector * data_manager now provides injector state * black * mypy * Updated confirm cancel dialog * created release timeout input * implemented transformation graph * Added sliders for gain, expo and deadzone * fix bug where the system_mapping was overridden in each injector thread * updated slider settings * removed debug statement * explicitly checking output code against None (0 is a valid code) * usage * Allow for multiple axis to be activated by same button * readme * only warn about not implemented mapping-handler don't fail to create event-pipelines * More accurate event names * Allow removal of single events from the input-combination * rename callback to notify_callback * rename event message to selected_event * made read_continuisly private * typing for autocompletion * docstrings for message_broker messages * make components methods and propreties private * gui spacings * removed eval * make some controller functions private * move status message generation from data_manager to controller * parse mapping errors in controller for more helpful messages * remove system_mapping from code editor * More component tests * more tests * mypy * make grab_devices less greedy (partial mitigation for #435) only grab one device if there are multiple which can satisfy the same mapping * accumulate more values in test * docstrings * Updated status messages * comments, docstrings, imports Co-authored-by: Tobi <proxima@sezanzeb.de>
2022-07-23 08:53:41 +00:00
time.sleep(0.2)
self.assertEqual(self.daemon.get_state(group.key), STOPPED)
2020-12-02 17:07:46 +00:00
2021-01-01 21:20:33 +00:00
try:
self.assertFalse(uinput_write_history_pipe[0].poll())
except AssertionError:
2021-09-26 10:44:56 +00:00
print("Unexpected", uinput_write_history_pipe[0].recv())
2021-01-05 18:33:47 +00:00
# possibly a duplicate write!
2021-01-01 21:20:33 +00:00
raise
"""Injection 2"""
Frontend Refactor (#375) * Tests for the GuiEventHandler * Implement GuiEventHandler * tests for data manager * Implemented data_manager * Remove Ellipsis from type hint * workaround for old pydantic version * workaround for old pydantic version * some more tests for data_manager * Updated Data Manager * move DeviceSelection to its own class * Data Manager no longer listens for events * Moved PresetSelection to its own class * MappingListBox and SelectionLable Listen to the EventHandler * DataManager no longer creates its own data objects in the init * removed global reader object * Changed UI startup * created backend Interface * event_handler debug logs show function which emit a event * some cleanup * added target selector to components * created code editor component * adapted autocompletion & some cleanup * black * connected some buttons to the event_handler * tests for data_manager newest_preset and group * cleanup presets and test_presets * migrated confirm delete dialog * backend tests * controller tests * add python3-gi to ci * more dependencies * and more ... * Github-Actions workaround remove this commit * not so many permission denyed errors in test.yml * Fix #404 (hopefully) * revert Github-Actions workaround * More tests * event_handler allows for event supression * more tests * WIP Implement Key recording * Start and Stop Injection * context no longer stores preset * restructured the RelToBtnHandler * Simplified read_loop * Implement async iterator for ipc.pipe * multiple event actions * helper now implements mapping handlers to read inputs all with async * updated and simplified reader the helper uses the mapping handlers, so the reader now can be much simpler * Fixed race condition in tests * implemented DataBus * Fixed a UIMapping bug where the last_error would not be deleted * added a immutable variant of the UIMapping * updated data_manager to use data_bus * Uptdated tests to use the DataBus * Gui uses DataBus * removed EventHandler * Renamed controller methods * Implemented recording toggle * implemented StatusBar * Sending validation errors to status bar * sending injection status to status bar * proper preset renaming * implemented copy preset in the data manager * implemented copy_preset in controller * fixed a bug where a wron selection lable would update * no longer send invalid data over the bus, if the preset or group changes * Implement create and delete mapping * Allow for frontend specific mapping defaults * implemented autoload toggle * cleanup user_interface * removed editor * Docstings renaming and ordering of methods * more simplifications to user_interface * integrated backend into data_manager * removed active preset * transformation tests * controller tests * fix missing uinputs in gui * moved some tests and implemented basic tests for mapping handlers * docstring reformatting Co-authored-by: Tobi <proxima@sezanzeb.de> * allow for empty groups * docstring * fixed TestGroupFromHelper * some work on integration tests * test for annoying import error in tests * testing if test_user_interface works * I feel lucky * not so lucky * some more tests * fixed but where the group_key was used as folder name * Fixed a bug where state=NO_GRAB would never be read from the injector * allow to stop the recorder * working on integration tests * integration tests * fixed more integration tests * updated coveragerc * no longer attempt to record keys when injecting * event_reader cleans up not finished tasks * More integration tests * All tests pass * renamed data_bus * WIP fixing typing issues * more typing fixes * added keyboard+mouse device to tests * cleanup imports * new read loop because the evdev async read loop can not be cancelled * Added field to modify mapping name * created tests for components * even more component tests * do component tests need a screen? * apparently they do :_( * created release_input switch * Don't record relative axis when movement is slow * show delete dialog above main window * wip basic dialog to edit combination * some gui changes to the combination-editor * Simple implementation of CombinationListbox * renamed attach_to_events method and mark as private * shorter str() for UInputsData * moved logic to generate readable event string from combination to event * new mapping parameter force release timeout this helps with the helper when recording multiple relative axis at once * make it possible to rearange the event_combination * more work on the combination editor * tests for DataManager.load_event * simplyfied test_controller * more controller tests * Implement input threshold in gui * greater range for time dependent unit test * implemented a output-axis selector * data_manager now provides injector state * black * mypy * Updated confirm cancel dialog * created release timeout input * implemented transformation graph * Added sliders for gain, expo and deadzone * fix bug where the system_mapping was overridden in each injector thread * updated slider settings * removed debug statement * explicitly checking output code against None (0 is a valid code) * usage * Allow for multiple axis to be activated by same button * readme * only warn about not implemented mapping-handler don't fail to create event-pipelines * More accurate event names * Allow removal of single events from the input-combination * rename callback to notify_callback * rename event message to selected_event * made read_continuisly private * typing for autocompletion * docstrings for message_broker messages * make components methods and propreties private * gui spacings * removed eval * make some controller functions private * move status message generation from data_manager to controller * parse mapping errors in controller for more helpful messages * remove system_mapping from code editor * More component tests * more tests * mypy * make grab_devices less greedy (partial mitigation for #435) only grab one device if there are multiple which can satisfy the same mapping * accumulate more values in test * docstrings * Updated status messages * comments, docstrings, imports Co-authored-by: Tobi <proxima@sezanzeb.de>
2022-07-23 08:53:41 +00:00
self.daemon.start_injecting(group.key, preset_name)
Frontend Refactor (#375) * Tests for the GuiEventHandler * Implement GuiEventHandler * tests for data manager * Implemented data_manager * Remove Ellipsis from type hint * workaround for old pydantic version * workaround for old pydantic version * some more tests for data_manager * Updated Data Manager * move DeviceSelection to its own class * Data Manager no longer listens for events * Moved PresetSelection to its own class * MappingListBox and SelectionLable Listen to the EventHandler * DataManager no longer creates its own data objects in the init * removed global reader object * Changed UI startup * created backend Interface * event_handler debug logs show function which emit a event * some cleanup * added target selector to components * created code editor component * adapted autocompletion & some cleanup * black * connected some buttons to the event_handler * tests for data_manager newest_preset and group * cleanup presets and test_presets * migrated confirm delete dialog * backend tests * controller tests * add python3-gi to ci * more dependencies * and more ... * Github-Actions workaround remove this commit * not so many permission denyed errors in test.yml * Fix #404 (hopefully) * revert Github-Actions workaround * More tests * event_handler allows for event supression * more tests * WIP Implement Key recording * Start and Stop Injection * context no longer stores preset * restructured the RelToBtnHandler * Simplified read_loop * Implement async iterator for ipc.pipe * multiple event actions * helper now implements mapping handlers to read inputs all with async * updated and simplified reader the helper uses the mapping handlers, so the reader now can be much simpler * Fixed race condition in tests * implemented DataBus * Fixed a UIMapping bug where the last_error would not be deleted * added a immutable variant of the UIMapping * updated data_manager to use data_bus * Uptdated tests to use the DataBus * Gui uses DataBus * removed EventHandler * Renamed controller methods * Implemented recording toggle * implemented StatusBar * Sending validation errors to status bar * sending injection status to status bar * proper preset renaming * implemented copy preset in the data manager * implemented copy_preset in controller * fixed a bug where a wron selection lable would update * no longer send invalid data over the bus, if the preset or group changes * Implement create and delete mapping * Allow for frontend specific mapping defaults * implemented autoload toggle * cleanup user_interface * removed editor * Docstings renaming and ordering of methods * more simplifications to user_interface * integrated backend into data_manager * removed active preset * transformation tests * controller tests * fix missing uinputs in gui * moved some tests and implemented basic tests for mapping handlers * docstring reformatting Co-authored-by: Tobi <proxima@sezanzeb.de> * allow for empty groups * docstring * fixed TestGroupFromHelper * some work on integration tests * test for annoying import error in tests * testing if test_user_interface works * I feel lucky * not so lucky * some more tests * fixed but where the group_key was used as folder name * Fixed a bug where state=NO_GRAB would never be read from the injector * allow to stop the recorder * working on integration tests * integration tests * fixed more integration tests * updated coveragerc * no longer attempt to record keys when injecting * event_reader cleans up not finished tasks * More integration tests * All tests pass * renamed data_bus * WIP fixing typing issues * more typing fixes * added keyboard+mouse device to tests * cleanup imports * new read loop because the evdev async read loop can not be cancelled * Added field to modify mapping name * created tests for components * even more component tests * do component tests need a screen? * apparently they do :_( * created release_input switch * Don't record relative axis when movement is slow * show delete dialog above main window * wip basic dialog to edit combination * some gui changes to the combination-editor * Simple implementation of CombinationListbox * renamed attach_to_events method and mark as private * shorter str() for UInputsData * moved logic to generate readable event string from combination to event * new mapping parameter force release timeout this helps with the helper when recording multiple relative axis at once * make it possible to rearange the event_combination * more work on the combination editor * tests for DataManager.load_event * simplyfied test_controller * more controller tests * Implement input threshold in gui * greater range for time dependent unit test * implemented a output-axis selector * data_manager now provides injector state * black * mypy * Updated confirm cancel dialog * created release timeout input * implemented transformation graph * Added sliders for gain, expo and deadzone * fix bug where the system_mapping was overridden in each injector thread * updated slider settings * removed debug statement * explicitly checking output code against None (0 is a valid code) * usage * Allow for multiple axis to be activated by same button * readme * only warn about not implemented mapping-handler don't fail to create event-pipelines * More accurate event names * Allow removal of single events from the input-combination * rename callback to notify_callback * rename event message to selected_event * made read_continuisly private * typing for autocompletion * docstrings for message_broker messages * make components methods and propreties private * gui spacings * removed eval * make some controller functions private * move status message generation from data_manager to controller * parse mapping errors in controller for more helpful messages * remove system_mapping from code editor * More component tests * more tests * mypy * make grab_devices less greedy (partial mitigation for #435) only grab one device if there are multiple which can satisfy the same mapping * accumulate more values in test * docstrings * Updated status messages * comments, docstrings, imports Co-authored-by: Tobi <proxima@sezanzeb.de>
2022-07-23 08:53:41 +00:00
time.sleep(0.1)
2021-09-29 18:17:45 +00:00
# -1234 will be classified as -1 by the injector
2022-08-28 10:38:40 +00:00
push_events(fixtures.gamepad, [new_event(*ev_2, -1234)])
2021-02-07 14:00:36 +00:00
time.sleep(0.1)
Frontend Refactor (#375) * Tests for the GuiEventHandler * Implement GuiEventHandler * tests for data manager * Implemented data_manager * Remove Ellipsis from type hint * workaround for old pydantic version * workaround for old pydantic version * some more tests for data_manager * Updated Data Manager * move DeviceSelection to its own class * Data Manager no longer listens for events * Moved PresetSelection to its own class * MappingListBox and SelectionLable Listen to the EventHandler * DataManager no longer creates its own data objects in the init * removed global reader object * Changed UI startup * created backend Interface * event_handler debug logs show function which emit a event * some cleanup * added target selector to components * created code editor component * adapted autocompletion & some cleanup * black * connected some buttons to the event_handler * tests for data_manager newest_preset and group * cleanup presets and test_presets * migrated confirm delete dialog * backend tests * controller tests * add python3-gi to ci * more dependencies * and more ... * Github-Actions workaround remove this commit * not so many permission denyed errors in test.yml * Fix #404 (hopefully) * revert Github-Actions workaround * More tests * event_handler allows for event supression * more tests * WIP Implement Key recording * Start and Stop Injection * context no longer stores preset * restructured the RelToBtnHandler * Simplified read_loop * Implement async iterator for ipc.pipe * multiple event actions * helper now implements mapping handlers to read inputs all with async * updated and simplified reader the helper uses the mapping handlers, so the reader now can be much simpler * Fixed race condition in tests * implemented DataBus * Fixed a UIMapping bug where the last_error would not be deleted * added a immutable variant of the UIMapping * updated data_manager to use data_bus * Uptdated tests to use the DataBus * Gui uses DataBus * removed EventHandler * Renamed controller methods * Implemented recording toggle * implemented StatusBar * Sending validation errors to status bar * sending injection status to status bar * proper preset renaming * implemented copy preset in the data manager * implemented copy_preset in controller * fixed a bug where a wron selection lable would update * no longer send invalid data over the bus, if the preset or group changes * Implement create and delete mapping * Allow for frontend specific mapping defaults * implemented autoload toggle * cleanup user_interface * removed editor * Docstings renaming and ordering of methods * more simplifications to user_interface * integrated backend into data_manager * removed active preset * transformation tests * controller tests * fix missing uinputs in gui * moved some tests and implemented basic tests for mapping handlers * docstring reformatting Co-authored-by: Tobi <proxima@sezanzeb.de> * allow for empty groups * docstring * fixed TestGroupFromHelper * some work on integration tests * test for annoying import error in tests * testing if test_user_interface works * I feel lucky * not so lucky * some more tests * fixed but where the group_key was used as folder name * Fixed a bug where state=NO_GRAB would never be read from the injector * allow to stop the recorder * working on integration tests * integration tests * fixed more integration tests * updated coveragerc * no longer attempt to record keys when injecting * event_reader cleans up not finished tasks * More integration tests * All tests pass * renamed data_bus * WIP fixing typing issues * more typing fixes * added keyboard+mouse device to tests * cleanup imports * new read loop because the evdev async read loop can not be cancelled * Added field to modify mapping name * created tests for components * even more component tests * do component tests need a screen? * apparently they do :_( * created release_input switch * Don't record relative axis when movement is slow * show delete dialog above main window * wip basic dialog to edit combination * some gui changes to the combination-editor * Simple implementation of CombinationListbox * renamed attach_to_events method and mark as private * shorter str() for UInputsData * moved logic to generate readable event string from combination to event * new mapping parameter force release timeout this helps with the helper when recording multiple relative axis at once * make it possible to rearange the event_combination * more work on the combination editor * tests for DataManager.load_event * simplyfied test_controller * more controller tests * Implement input threshold in gui * greater range for time dependent unit test * implemented a output-axis selector * data_manager now provides injector state * black * mypy * Updated confirm cancel dialog * created release timeout input * implemented transformation graph * Added sliders for gain, expo and deadzone * fix bug where the system_mapping was overridden in each injector thread * updated slider settings * removed debug statement * explicitly checking output code against None (0 is a valid code) * usage * Allow for multiple axis to be activated by same button * readme * only warn about not implemented mapping-handler don't fail to create event-pipelines * More accurate event names * Allow removal of single events from the input-combination * rename callback to notify_callback * rename event message to selected_event * made read_continuisly private * typing for autocompletion * docstrings for message_broker messages * make components methods and propreties private * gui spacings * removed eval * make some controller functions private * move status message generation from data_manager to controller * parse mapping errors in controller for more helpful messages * remove system_mapping from code editor * More component tests * more tests * mypy * make grab_devices less greedy (partial mitigation for #435) only grab one device if there are multiple which can satisfy the same mapping * accumulate more values in test * docstrings * Updated status messages * comments, docstrings, imports Co-authored-by: Tobi <proxima@sezanzeb.de>
2022-07-23 08:53:41 +00:00
2021-02-07 14:00:36 +00:00
self.assertTrue(uinput_write_history_pipe[0].poll())
2020-12-02 17:07:46 +00:00
# the written key is a key-down event, not the original
2021-01-05 18:33:47 +00:00
# event value of -1234
2020-12-02 17:07:46 +00:00
event = uinput_write_history_pipe[0].recv()
2021-02-07 14:00:36 +00:00
self.assertEqual(event.type, EV_KEY)
self.assertEqual(event.code, KEY_B)
2020-12-02 17:07:46 +00:00
self.assertEqual(event.value, 1)
2020-11-20 20:38:59 +00:00
def test_config_dir(self):
2022-01-31 19:58:37 +00:00
global_config.set("foo", "bar")
self.assertEqual(global_config.get("foo"), "bar")
# freshly loads the config and therefore removes the previosly added key.
# This is important so that if the service is started via sudo or pkexec
# it knows where to look for configuration files.
self.daemon = Daemon()
self.assertEqual(self.daemon.config_dir, get_config_path())
2022-01-31 19:58:37 +00:00
self.assertIsNone(global_config.get("foo"))
def test_refresh_on_start(self):
2021-09-26 10:44:56 +00:00
if os.path.exists(get_config_path("xmodmap.json")):
os.remove(get_config_path("xmodmap.json"))
2021-02-07 14:00:36 +00:00
2022-04-17 10:19:23 +00:00
preset_name = "foo"
ev = (EV_KEY, 9)
2021-09-26 10:44:56 +00:00
group_name = "9876 name"
# expected key of the group
group_key = group_name
group = groups.find(name=group_name)
# this test only makes sense if this device is unknown yet
self.assertIsNone(group)
2022-04-17 10:19:23 +00:00
system_mapping.clear()
system_mapping._set("a", KEY_A)
2021-02-07 14:00:36 +00:00
2022-04-17 10:19:23 +00:00
preset = Preset(get_preset_path(group_name, preset_name))
preset.add(get_key_mapping(EventCombination([*ev, 1]), "keyboard", "a"))
2021-02-07 14:00:36 +00:00
# make the daemon load the file instead
2021-09-26 10:44:56 +00:00
with open(get_config_path("xmodmap.json"), "w") as file:
2021-02-07 14:00:36 +00:00
json.dump(system_mapping._mapping, file, indent=4)
system_mapping.clear()
2022-04-17 10:19:23 +00:00
preset.save()
global_config.set_autoload_preset(group_key, preset_name)
self.daemon = Daemon()
# make sure the devices are populated
groups.refresh()
# the daemon is supposed to find this device by calling refresh
fixtures[self.new_fixture_path] = {
2021-09-26 10:44:56 +00:00
"capabilities": {evdev.ecodes.EV_KEY: [ev[1]]},
"phys": "9876 phys",
"info": evdev.device.DeviceInfo(4, 5, 6, 7),
"name": group_name,
}
2022-08-28 10:38:40 +00:00
push_events(fixtures[self.new_fixture_path], [new_event(*ev, 1)])
2022-04-17 10:19:23 +00:00
self.daemon.start_injecting(group_key, preset_name)
# test if the injector called groups.refresh successfully
group = groups.find(key=group_key)
self.assertEqual(group.name, group_name)
self.assertEqual(group.key, group_key)
2021-02-07 14:00:36 +00:00
time.sleep(0.1)
self.assertTrue(uinput_write_history_pipe[0].poll())
event = uinput_write_history_pipe[0].recv()
self.assertEqual(event.t, (EV_KEY, KEY_A, 1))
self.daemon.stop_injecting(group_key)
Frontend Refactor (#375) * Tests for the GuiEventHandler * Implement GuiEventHandler * tests for data manager * Implemented data_manager * Remove Ellipsis from type hint * workaround for old pydantic version * workaround for old pydantic version * some more tests for data_manager * Updated Data Manager * move DeviceSelection to its own class * Data Manager no longer listens for events * Moved PresetSelection to its own class * MappingListBox and SelectionLable Listen to the EventHandler * DataManager no longer creates its own data objects in the init * removed global reader object * Changed UI startup * created backend Interface * event_handler debug logs show function which emit a event * some cleanup * added target selector to components * created code editor component * adapted autocompletion & some cleanup * black * connected some buttons to the event_handler * tests for data_manager newest_preset and group * cleanup presets and test_presets * migrated confirm delete dialog * backend tests * controller tests * add python3-gi to ci * more dependencies * and more ... * Github-Actions workaround remove this commit * not so many permission denyed errors in test.yml * Fix #404 (hopefully) * revert Github-Actions workaround * More tests * event_handler allows for event supression * more tests * WIP Implement Key recording * Start and Stop Injection * context no longer stores preset * restructured the RelToBtnHandler * Simplified read_loop * Implement async iterator for ipc.pipe * multiple event actions * helper now implements mapping handlers to read inputs all with async * updated and simplified reader the helper uses the mapping handlers, so the reader now can be much simpler * Fixed race condition in tests * implemented DataBus * Fixed a UIMapping bug where the last_error would not be deleted * added a immutable variant of the UIMapping * updated data_manager to use data_bus * Uptdated tests to use the DataBus * Gui uses DataBus * removed EventHandler * Renamed controller methods * Implemented recording toggle * implemented StatusBar * Sending validation errors to status bar * sending injection status to status bar * proper preset renaming * implemented copy preset in the data manager * implemented copy_preset in controller * fixed a bug where a wron selection lable would update * no longer send invalid data over the bus, if the preset or group changes * Implement create and delete mapping * Allow for frontend specific mapping defaults * implemented autoload toggle * cleanup user_interface * removed editor * Docstings renaming and ordering of methods * more simplifications to user_interface * integrated backend into data_manager * removed active preset * transformation tests * controller tests * fix missing uinputs in gui * moved some tests and implemented basic tests for mapping handlers * docstring reformatting Co-authored-by: Tobi <proxima@sezanzeb.de> * allow for empty groups * docstring * fixed TestGroupFromHelper * some work on integration tests * test for annoying import error in tests * testing if test_user_interface works * I feel lucky * not so lucky * some more tests * fixed but where the group_key was used as folder name * Fixed a bug where state=NO_GRAB would never be read from the injector * allow to stop the recorder * working on integration tests * integration tests * fixed more integration tests * updated coveragerc * no longer attempt to record keys when injecting * event_reader cleans up not finished tasks * More integration tests * All tests pass * renamed data_bus * WIP fixing typing issues * more typing fixes * added keyboard+mouse device to tests * cleanup imports * new read loop because the evdev async read loop can not be cancelled * Added field to modify mapping name * created tests for components * even more component tests * do component tests need a screen? * apparently they do :_( * created release_input switch * Don't record relative axis when movement is slow * show delete dialog above main window * wip basic dialog to edit combination * some gui changes to the combination-editor * Simple implementation of CombinationListbox * renamed attach_to_events method and mark as private * shorter str() for UInputsData * moved logic to generate readable event string from combination to event * new mapping parameter force release timeout this helps with the helper when recording multiple relative axis at once * make it possible to rearange the event_combination * more work on the combination editor * tests for DataManager.load_event * simplyfied test_controller * more controller tests * Implement input threshold in gui * greater range for time dependent unit test * implemented a output-axis selector * data_manager now provides injector state * black * mypy * Updated confirm cancel dialog * created release timeout input * implemented transformation graph * Added sliders for gain, expo and deadzone * fix bug where the system_mapping was overridden in each injector thread * updated slider settings * removed debug statement * explicitly checking output code against None (0 is a valid code) * usage * Allow for multiple axis to be activated by same button * readme * only warn about not implemented mapping-handler don't fail to create event-pipelines * More accurate event names * Allow removal of single events from the input-combination * rename callback to notify_callback * rename event message to selected_event * made read_continuisly private * typing for autocompletion * docstrings for message_broker messages * make components methods and propreties private * gui spacings * removed eval * make some controller functions private * move status message generation from data_manager to controller * parse mapping errors in controller for more helpful messages * remove system_mapping from code editor * More component tests * more tests * mypy * make grab_devices less greedy (partial mitigation for #435) only grab one device if there are multiple which can satisfy the same mapping * accumulate more values in test * docstrings * Updated status messages * comments, docstrings, imports Co-authored-by: Tobi <proxima@sezanzeb.de>
2022-07-23 08:53:41 +00:00
time.sleep(0.2)
self.assertEqual(self.daemon.get_state(group_key), STOPPED)
def test_refresh_for_unknown_key(self):
2021-09-26 10:44:56 +00:00
device = "9876 name"
2021-02-12 19:29:26 +00:00
# this test only makes sense if this device is unknown yet
self.assertIsNone(groups.find(name=device))
2021-02-12 19:29:26 +00:00
self.daemon = Daemon()
# make sure the devices are populated
groups.refresh()
2021-02-12 19:29:26 +00:00
self.daemon.refresh()
2021-02-12 19:29:26 +00:00
fixtures[self.new_fixture_path] = {
2021-09-26 10:44:56 +00:00
"capabilities": {evdev.ecodes.EV_KEY: [evdev.ecodes.KEY_A]},
"phys": "9876 phys",
"info": evdev.device.DeviceInfo(4, 5, 6, 7),
"name": device,
2021-02-12 19:29:26 +00:00
}
2021-09-26 10:44:56 +00:00
self.daemon._autoload("25v7j9q4vtj")
# this is unknown, so the daemon will scan the devices again
2021-02-12 19:29:26 +00:00
# test if the injector called groups.refresh successfully
self.assertIsNotNone(groups.find(name=device))
2021-02-12 19:29:26 +00:00
def test_xmodmap_file(self):
from_keycode = evdev.ecodes.KEY_A
2022-01-14 17:50:57 +00:00
target = "keyboard"
2022-04-17 10:19:23 +00:00
to_name = "q"
to_keycode = 100
event = (EV_KEY, from_keycode, 1)
2021-09-26 10:44:56 +00:00
name = "Bar Device"
2022-04-17 10:19:23 +00:00
preset_name = "foo"
group = groups.find(name=name)
2021-09-26 10:44:56 +00:00
config_dir = os.path.join(tmp, "foo")
2021-02-07 14:00:36 +00:00
2022-04-17 10:19:23 +00:00
path = os.path.join(config_dir, "presets", name, f"{preset_name}.json")
2022-04-17 10:19:23 +00:00
preset = Preset(path)
preset.add(get_key_mapping(EventCombination(event), target, to_name))
preset.save()
system_mapping.clear()
2022-08-28 10:38:40 +00:00
push_events(fixtures.bar_device, [new_event(*event)])
2021-02-07 14:00:36 +00:00
# an existing config file is needed otherwise set_config_dir refuses
# to use the directory
2021-09-26 10:44:56 +00:00
config_path = os.path.join(config_dir, "config.json")
2022-01-31 19:58:37 +00:00
global_config.path = config_path
global_config._save_config()
2021-09-26 10:44:56 +00:00
xmodmap_path = os.path.join(config_dir, "xmodmap.json")
with open(xmodmap_path, "w") as file:
file.write(f'{{"{to_name}":{to_keycode}}}')
self.daemon = Daemon()
2021-02-07 14:00:36 +00:00
self.daemon.set_config_dir(config_dir)
2022-04-17 10:19:23 +00:00
self.daemon.start_injecting(group.key, preset_name)
2021-02-07 14:00:36 +00:00
time.sleep(0.1)
self.assertTrue(uinput_write_history_pipe[0].poll())
event = uinput_write_history_pipe[0].recv()
self.assertEqual(event.type, EV_KEY)
self.assertEqual(event.code, to_keycode)
self.assertEqual(event.value, 1)
2021-02-07 14:00:36 +00:00
def test_start_stop(self):
2021-09-26 10:44:56 +00:00
group = groups.find(key="Foo Device 2")
2022-04-17 10:19:23 +00:00
preset_name = "preset8"
2021-02-07 14:00:36 +00:00
daemon = Daemon()
self.daemon = daemon
2022-04-17 10:19:23 +00:00
pereset = Preset(group.get_preset_path(preset_name))
pereset.add(get_key_mapping(EventCombination([3, 2, 1]), "keyboard", "a"))
pereset.save()
2021-02-07 14:00:36 +00:00
# start
2022-04-17 10:19:23 +00:00
daemon.start_injecting(group.key, preset_name)
2021-02-07 14:00:36 +00:00
# explicit start, not autoload, so the history stays empty
self.assertNotIn(group.key, daemon.autoload_history._autoload_history)
2022-04-17 10:19:23 +00:00
self.assertTrue(daemon.autoload_history.may_autoload(group.key, preset_name))
2021-02-07 14:00:36 +00:00
# path got translated to the device name
self.assertIn(group.key, daemon.injectors)
2021-02-07 14:00:36 +00:00
# start again
previous_injector = daemon.injectors[group.key]
2021-02-07 14:00:36 +00:00
self.assertNotEqual(previous_injector.get_state(), STOPPED)
2022-04-17 10:19:23 +00:00
daemon.start_injecting(group.key, preset_name)
self.assertNotIn(group.key, daemon.autoload_history._autoload_history)
2022-04-17 10:19:23 +00:00
self.assertTrue(daemon.autoload_history.may_autoload(group.key, preset_name))
self.assertIn(group.key, daemon.injectors)
Frontend Refactor (#375) * Tests for the GuiEventHandler * Implement GuiEventHandler * tests for data manager * Implemented data_manager * Remove Ellipsis from type hint * workaround for old pydantic version * workaround for old pydantic version * some more tests for data_manager * Updated Data Manager * move DeviceSelection to its own class * Data Manager no longer listens for events * Moved PresetSelection to its own class * MappingListBox and SelectionLable Listen to the EventHandler * DataManager no longer creates its own data objects in the init * removed global reader object * Changed UI startup * created backend Interface * event_handler debug logs show function which emit a event * some cleanup * added target selector to components * created code editor component * adapted autocompletion & some cleanup * black * connected some buttons to the event_handler * tests for data_manager newest_preset and group * cleanup presets and test_presets * migrated confirm delete dialog * backend tests * controller tests * add python3-gi to ci * more dependencies * and more ... * Github-Actions workaround remove this commit * not so many permission denyed errors in test.yml * Fix #404 (hopefully) * revert Github-Actions workaround * More tests * event_handler allows for event supression * more tests * WIP Implement Key recording * Start and Stop Injection * context no longer stores preset * restructured the RelToBtnHandler * Simplified read_loop * Implement async iterator for ipc.pipe * multiple event actions * helper now implements mapping handlers to read inputs all with async * updated and simplified reader the helper uses the mapping handlers, so the reader now can be much simpler * Fixed race condition in tests * implemented DataBus * Fixed a UIMapping bug where the last_error would not be deleted * added a immutable variant of the UIMapping * updated data_manager to use data_bus * Uptdated tests to use the DataBus * Gui uses DataBus * removed EventHandler * Renamed controller methods * Implemented recording toggle * implemented StatusBar * Sending validation errors to status bar * sending injection status to status bar * proper preset renaming * implemented copy preset in the data manager * implemented copy_preset in controller * fixed a bug where a wron selection lable would update * no longer send invalid data over the bus, if the preset or group changes * Implement create and delete mapping * Allow for frontend specific mapping defaults * implemented autoload toggle * cleanup user_interface * removed editor * Docstings renaming and ordering of methods * more simplifications to user_interface * integrated backend into data_manager * removed active preset * transformation tests * controller tests * fix missing uinputs in gui * moved some tests and implemented basic tests for mapping handlers * docstring reformatting Co-authored-by: Tobi <proxima@sezanzeb.de> * allow for empty groups * docstring * fixed TestGroupFromHelper * some work on integration tests * test for annoying import error in tests * testing if test_user_interface works * I feel lucky * not so lucky * some more tests * fixed but where the group_key was used as folder name * Fixed a bug where state=NO_GRAB would never be read from the injector * allow to stop the recorder * working on integration tests * integration tests * fixed more integration tests * updated coveragerc * no longer attempt to record keys when injecting * event_reader cleans up not finished tasks * More integration tests * All tests pass * renamed data_bus * WIP fixing typing issues * more typing fixes * added keyboard+mouse device to tests * cleanup imports * new read loop because the evdev async read loop can not be cancelled * Added field to modify mapping name * created tests for components * even more component tests * do component tests need a screen? * apparently they do :_( * created release_input switch * Don't record relative axis when movement is slow * show delete dialog above main window * wip basic dialog to edit combination * some gui changes to the combination-editor * Simple implementation of CombinationListbox * renamed attach_to_events method and mark as private * shorter str() for UInputsData * moved logic to generate readable event string from combination to event * new mapping parameter force release timeout this helps with the helper when recording multiple relative axis at once * make it possible to rearange the event_combination * more work on the combination editor * tests for DataManager.load_event * simplyfied test_controller * more controller tests * Implement input threshold in gui * greater range for time dependent unit test * implemented a output-axis selector * data_manager now provides injector state * black * mypy * Updated confirm cancel dialog * created release timeout input * implemented transformation graph * Added sliders for gain, expo and deadzone * fix bug where the system_mapping was overridden in each injector thread * updated slider settings * removed debug statement * explicitly checking output code against None (0 is a valid code) * usage * Allow for multiple axis to be activated by same button * readme * only warn about not implemented mapping-handler don't fail to create event-pipelines * More accurate event names * Allow removal of single events from the input-combination * rename callback to notify_callback * rename event message to selected_event * made read_continuisly private * typing for autocompletion * docstrings for message_broker messages * make components methods and propreties private * gui spacings * removed eval * make some controller functions private * move status message generation from data_manager to controller * parse mapping errors in controller for more helpful messages * remove system_mapping from code editor * More component tests * more tests * mypy * make grab_devices less greedy (partial mitigation for #435) only grab one device if there are multiple which can satisfy the same mapping * accumulate more values in test * docstrings * Updated status messages * comments, docstrings, imports Co-authored-by: Tobi <proxima@sezanzeb.de>
2022-07-23 08:53:41 +00:00
time.sleep(0.2)
2021-02-07 14:00:36 +00:00
self.assertEqual(previous_injector.get_state(), STOPPED)
# a different injetor is now running
self.assertNotEqual(previous_injector, daemon.injectors[group.key])
self.assertNotEqual(daemon.injectors[group.key].get_state(), STOPPED)
2021-02-07 14:00:36 +00:00
# trying to inject a non existing preset keeps the previous inejction
# alive
injector = daemon.injectors[group.key]
2021-09-26 10:44:56 +00:00
daemon.start_injecting(group.key, "qux")
self.assertEqual(injector, daemon.injectors[group.key])
self.assertNotEqual(daemon.injectors[group.key].get_state(), STOPPED)
2021-02-07 14:00:36 +00:00
# trying to start injecting for an unknown device also just does
# nothing
2021-09-26 10:44:56 +00:00
daemon.start_injecting("quux", "qux")
self.assertNotEqual(daemon.injectors[group.key].get_state(), STOPPED)
2021-02-07 14:00:36 +00:00
# after all that stuff autoload_history is still unharmed
self.assertNotIn(group.key, daemon.autoload_history._autoload_history)
2022-04-17 10:19:23 +00:00
self.assertTrue(daemon.autoload_history.may_autoload(group.key, preset_name))
2021-02-07 14:00:36 +00:00
# stop
daemon.stop_injecting(group.key)
Frontend Refactor (#375) * Tests for the GuiEventHandler * Implement GuiEventHandler * tests for data manager * Implemented data_manager * Remove Ellipsis from type hint * workaround for old pydantic version * workaround for old pydantic version * some more tests for data_manager * Updated Data Manager * move DeviceSelection to its own class * Data Manager no longer listens for events * Moved PresetSelection to its own class * MappingListBox and SelectionLable Listen to the EventHandler * DataManager no longer creates its own data objects in the init * removed global reader object * Changed UI startup * created backend Interface * event_handler debug logs show function which emit a event * some cleanup * added target selector to components * created code editor component * adapted autocompletion & some cleanup * black * connected some buttons to the event_handler * tests for data_manager newest_preset and group * cleanup presets and test_presets * migrated confirm delete dialog * backend tests * controller tests * add python3-gi to ci * more dependencies * and more ... * Github-Actions workaround remove this commit * not so many permission denyed errors in test.yml * Fix #404 (hopefully) * revert Github-Actions workaround * More tests * event_handler allows for event supression * more tests * WIP Implement Key recording * Start and Stop Injection * context no longer stores preset * restructured the RelToBtnHandler * Simplified read_loop * Implement async iterator for ipc.pipe * multiple event actions * helper now implements mapping handlers to read inputs all with async * updated and simplified reader the helper uses the mapping handlers, so the reader now can be much simpler * Fixed race condition in tests * implemented DataBus * Fixed a UIMapping bug where the last_error would not be deleted * added a immutable variant of the UIMapping * updated data_manager to use data_bus * Uptdated tests to use the DataBus * Gui uses DataBus * removed EventHandler * Renamed controller methods * Implemented recording toggle * implemented StatusBar * Sending validation errors to status bar * sending injection status to status bar * proper preset renaming * implemented copy preset in the data manager * implemented copy_preset in controller * fixed a bug where a wron selection lable would update * no longer send invalid data over the bus, if the preset or group changes * Implement create and delete mapping * Allow for frontend specific mapping defaults * implemented autoload toggle * cleanup user_interface * removed editor * Docstings renaming and ordering of methods * more simplifications to user_interface * integrated backend into data_manager * removed active preset * transformation tests * controller tests * fix missing uinputs in gui * moved some tests and implemented basic tests for mapping handlers * docstring reformatting Co-authored-by: Tobi <proxima@sezanzeb.de> * allow for empty groups * docstring * fixed TestGroupFromHelper * some work on integration tests * test for annoying import error in tests * testing if test_user_interface works * I feel lucky * not so lucky * some more tests * fixed but where the group_key was used as folder name * Fixed a bug where state=NO_GRAB would never be read from the injector * allow to stop the recorder * working on integration tests * integration tests * fixed more integration tests * updated coveragerc * no longer attempt to record keys when injecting * event_reader cleans up not finished tasks * More integration tests * All tests pass * renamed data_bus * WIP fixing typing issues * more typing fixes * added keyboard+mouse device to tests * cleanup imports * new read loop because the evdev async read loop can not be cancelled * Added field to modify mapping name * created tests for components * even more component tests * do component tests need a screen? * apparently they do :_( * created release_input switch * Don't record relative axis when movement is slow * show delete dialog above main window * wip basic dialog to edit combination * some gui changes to the combination-editor * Simple implementation of CombinationListbox * renamed attach_to_events method and mark as private * shorter str() for UInputsData * moved logic to generate readable event string from combination to event * new mapping parameter force release timeout this helps with the helper when recording multiple relative axis at once * make it possible to rearange the event_combination * more work on the combination editor * tests for DataManager.load_event * simplyfied test_controller * more controller tests * Implement input threshold in gui * greater range for time dependent unit test * implemented a output-axis selector * data_manager now provides injector state * black * mypy * Updated confirm cancel dialog * created release timeout input * implemented transformation graph * Added sliders for gain, expo and deadzone * fix bug where the system_mapping was overridden in each injector thread * updated slider settings * removed debug statement * explicitly checking output code against None (0 is a valid code) * usage * Allow for multiple axis to be activated by same button * readme * only warn about not implemented mapping-handler don't fail to create event-pipelines * More accurate event names * Allow removal of single events from the input-combination * rename callback to notify_callback * rename event message to selected_event * made read_continuisly private * typing for autocompletion * docstrings for message_broker messages * make components methods and propreties private * gui spacings * removed eval * make some controller functions private * move status message generation from data_manager to controller * parse mapping errors in controller for more helpful messages * remove system_mapping from code editor * More component tests * more tests * mypy * make grab_devices less greedy (partial mitigation for #435) only grab one device if there are multiple which can satisfy the same mapping * accumulate more values in test * docstrings * Updated status messages * comments, docstrings, imports Co-authored-by: Tobi <proxima@sezanzeb.de>
2022-07-23 08:53:41 +00:00
time.sleep(0.2)
self.assertNotIn(group.key, daemon.autoload_history._autoload_history)
self.assertEqual(daemon.injectors[group.key].get_state(), STOPPED)
2022-04-17 10:19:23 +00:00
self.assertTrue(daemon.autoload_history.may_autoload(group.key, preset_name))
2021-02-07 14:00:36 +00:00
def test_autoload(self):
2022-04-17 10:19:23 +00:00
preset_name = "preset7"
2021-09-26 10:44:56 +00:00
group = groups.find(key="Foo Device 2")
2021-02-07 14:00:36 +00:00
daemon = Daemon()
self.daemon = daemon
2022-04-17 10:19:23 +00:00
preset = Preset(group.get_preset_path(preset_name))
preset.add(get_key_mapping(EventCombination([3, 2, 1]), "keyboard", "a"))
preset.save()
2021-02-07 14:00:36 +00:00
# no autoloading is configured yet
self.daemon._autoload(group.key)
self.assertNotIn(group.key, daemon.autoload_history._autoload_history)
2022-04-17 10:19:23 +00:00
self.assertTrue(daemon.autoload_history.may_autoload(group.key, preset_name))
2021-02-07 14:00:36 +00:00
2022-04-17 10:19:23 +00:00
global_config.set_autoload_preset(group.key, preset_name)
2021-02-12 19:29:26 +00:00
len_before = len(self.daemon.autoload_history._autoload_history)
# now autoloading is configured, so it will autoload
self.daemon._autoload(group.key)
2021-02-12 19:29:26 +00:00
len_after = len(self.daemon.autoload_history._autoload_history)
2021-09-26 10:44:56 +00:00
self.assertEqual(
2022-04-17 10:19:23 +00:00
daemon.autoload_history._autoload_history[group.key][1], preset_name
2021-09-26 10:44:56 +00:00
)
2022-04-17 10:19:23 +00:00
self.assertFalse(daemon.autoload_history.may_autoload(group.key, preset_name))
injector = daemon.injectors[group.key]
2021-02-12 19:29:26 +00:00
self.assertEqual(len_before + 1, len_after)
2021-02-07 14:00:36 +00:00
Frontend Refactor (#375) * Tests for the GuiEventHandler * Implement GuiEventHandler * tests for data manager * Implemented data_manager * Remove Ellipsis from type hint * workaround for old pydantic version * workaround for old pydantic version * some more tests for data_manager * Updated Data Manager * move DeviceSelection to its own class * Data Manager no longer listens for events * Moved PresetSelection to its own class * MappingListBox and SelectionLable Listen to the EventHandler * DataManager no longer creates its own data objects in the init * removed global reader object * Changed UI startup * created backend Interface * event_handler debug logs show function which emit a event * some cleanup * added target selector to components * created code editor component * adapted autocompletion & some cleanup * black * connected some buttons to the event_handler * tests for data_manager newest_preset and group * cleanup presets and test_presets * migrated confirm delete dialog * backend tests * controller tests * add python3-gi to ci * more dependencies * and more ... * Github-Actions workaround remove this commit * not so many permission denyed errors in test.yml * Fix #404 (hopefully) * revert Github-Actions workaround * More tests * event_handler allows for event supression * more tests * WIP Implement Key recording * Start and Stop Injection * context no longer stores preset * restructured the RelToBtnHandler * Simplified read_loop * Implement async iterator for ipc.pipe * multiple event actions * helper now implements mapping handlers to read inputs all with async * updated and simplified reader the helper uses the mapping handlers, so the reader now can be much simpler * Fixed race condition in tests * implemented DataBus * Fixed a UIMapping bug where the last_error would not be deleted * added a immutable variant of the UIMapping * updated data_manager to use data_bus * Uptdated tests to use the DataBus * Gui uses DataBus * removed EventHandler * Renamed controller methods * Implemented recording toggle * implemented StatusBar * Sending validation errors to status bar * sending injection status to status bar * proper preset renaming * implemented copy preset in the data manager * implemented copy_preset in controller * fixed a bug where a wron selection lable would update * no longer send invalid data over the bus, if the preset or group changes * Implement create and delete mapping * Allow for frontend specific mapping defaults * implemented autoload toggle * cleanup user_interface * removed editor * Docstings renaming and ordering of methods * more simplifications to user_interface * integrated backend into data_manager * removed active preset * transformation tests * controller tests * fix missing uinputs in gui * moved some tests and implemented basic tests for mapping handlers * docstring reformatting Co-authored-by: Tobi <proxima@sezanzeb.de> * allow for empty groups * docstring * fixed TestGroupFromHelper * some work on integration tests * test for annoying import error in tests * testing if test_user_interface works * I feel lucky * not so lucky * some more tests * fixed but where the group_key was used as folder name * Fixed a bug where state=NO_GRAB would never be read from the injector * allow to stop the recorder * working on integration tests * integration tests * fixed more integration tests * updated coveragerc * no longer attempt to record keys when injecting * event_reader cleans up not finished tasks * More integration tests * All tests pass * renamed data_bus * WIP fixing typing issues * more typing fixes * added keyboard+mouse device to tests * cleanup imports * new read loop because the evdev async read loop can not be cancelled * Added field to modify mapping name * created tests for components * even more component tests * do component tests need a screen? * apparently they do :_( * created release_input switch * Don't record relative axis when movement is slow * show delete dialog above main window * wip basic dialog to edit combination * some gui changes to the combination-editor * Simple implementation of CombinationListbox * renamed attach_to_events method and mark as private * shorter str() for UInputsData * moved logic to generate readable event string from combination to event * new mapping parameter force release timeout this helps with the helper when recording multiple relative axis at once * make it possible to rearange the event_combination * more work on the combination editor * tests for DataManager.load_event * simplyfied test_controller * more controller tests * Implement input threshold in gui * greater range for time dependent unit test * implemented a output-axis selector * data_manager now provides injector state * black * mypy * Updated confirm cancel dialog * created release timeout input * implemented transformation graph * Added sliders for gain, expo and deadzone * fix bug where the system_mapping was overridden in each injector thread * updated slider settings * removed debug statement * explicitly checking output code against None (0 is a valid code) * usage * Allow for multiple axis to be activated by same button * readme * only warn about not implemented mapping-handler don't fail to create event-pipelines * More accurate event names * Allow removal of single events from the input-combination * rename callback to notify_callback * rename event message to selected_event * made read_continuisly private * typing for autocompletion * docstrings for message_broker messages * make components methods and propreties private * gui spacings * removed eval * make some controller functions private * move status message generation from data_manager to controller * parse mapping errors in controller for more helpful messages * remove system_mapping from code editor * More component tests * more tests * mypy * make grab_devices less greedy (partial mitigation for #435) only grab one device if there are multiple which can satisfy the same mapping * accumulate more values in test * docstrings * Updated status messages * comments, docstrings, imports Co-authored-by: Tobi <proxima@sezanzeb.de>
2022-07-23 08:53:41 +00:00
# calling duplicate get_autoload does nothing
self.daemon._autoload(group.key)
2021-09-26 10:44:56 +00:00
self.assertEqual(
2022-04-17 10:19:23 +00:00
daemon.autoload_history._autoload_history[group.key][1], preset_name
2021-09-26 10:44:56 +00:00
)
self.assertEqual(injector, daemon.injectors[group.key])
2022-04-17 10:19:23 +00:00
self.assertFalse(daemon.autoload_history.may_autoload(group.key, preset_name))
2021-02-07 14:00:36 +00:00
# explicit start_injecting clears the autoload history
2022-04-17 10:19:23 +00:00
self.daemon.start_injecting(group.key, preset_name)
self.assertTrue(daemon.autoload_history.may_autoload(group.key, preset_name))
2021-02-12 19:29:26 +00:00
# calling autoload for (yet) unknown devices does nothing
len_before = len(self.daemon.autoload_history._autoload_history)
2021-09-26 10:44:56 +00:00
self.daemon._autoload("unknown-key-1234")
2021-02-12 19:29:26 +00:00
len_after = len(self.daemon.autoload_history._autoload_history)
self.assertEqual(len_before, len_after)
2022-01-01 12:00:49 +00:00
# autoloading input-remapper devices does nothing
2021-02-12 19:29:26 +00:00
len_before = len(self.daemon.autoload_history._autoload_history)
2021-09-26 10:44:56 +00:00
self.daemon.autoload_single("Bar Device")
2021-02-12 19:29:26 +00:00
len_after = len(self.daemon.autoload_history._autoload_history)
self.assertEqual(len_before, len_after)
def test_autoload_2(self):
self.daemon = Daemon()
history = self.daemon.autoload_history._autoload_history
# existing device
2022-04-17 10:19:23 +00:00
preset_name = "preset7"
2021-09-26 10:44:56 +00:00
group = groups.find(key="Foo Device 2")
2022-04-17 10:19:23 +00:00
preset = Preset(group.get_preset_path(preset_name))
preset.add(get_key_mapping(EventCombination([3, 2, 1]), "keyboard", "a"))
preset.save()
global_config.set_autoload_preset(group.key, preset_name)
# ignored, won't cause problems:
2022-01-31 19:58:37 +00:00
global_config.set_autoload_preset("non-existant-key", "foo")
self.daemon.autoload()
self.assertEqual(len(history), 1)
2022-04-17 10:19:23 +00:00
self.assertEqual(history[group.key][1], preset_name)
2021-04-29 20:22:05 +00:00
def test_autoload_3(self):
# based on a bug
2022-04-17 10:19:23 +00:00
preset_name = "preset7"
2021-09-26 10:44:56 +00:00
group = groups.find(key="Foo Device 2")
2021-04-29 20:22:05 +00:00
2022-04-17 10:19:23 +00:00
preset = Preset(group.get_preset_path(preset_name))
preset.add(get_key_mapping(EventCombination([3, 2, 1]), "keyboard", "a"))
preset.save()
2021-04-29 20:22:05 +00:00
2022-04-17 10:19:23 +00:00
global_config.set_autoload_preset(group.key, preset_name)
2021-04-29 20:22:05 +00:00
self.daemon = Daemon()
2021-04-29 20:24:38 +00:00
groups.set_groups([]) # caused the bug
2021-09-26 10:44:56 +00:00
self.assertIsNone(groups.find(key="Foo Device 2"))
2021-04-29 20:22:05 +00:00
self.daemon.autoload()
2021-04-29 20:24:38 +00:00
# it should try to refresh the groups because all the
# group_keys are unknown at the moment
2021-04-29 20:22:05 +00:00
history = self.daemon.autoload_history._autoload_history
2022-04-17 10:19:23 +00:00
self.assertEqual(history[group.key][1], preset_name)
2021-04-29 20:22:05 +00:00
self.assertEqual(self.daemon.get_state(group.key), STARTING)
2021-09-26 10:44:56 +00:00
self.assertIsNotNone(groups.find(key="Foo Device 2"))
2021-04-29 20:22:05 +00:00
2020-11-20 20:38:59 +00:00
if __name__ == "__main__":
unittest.main()