mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-12 01:10:38 +00:00
3637204bff
* 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>
565 lines
20 KiB
Python
565 lines
20 KiB
Python
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
# input-remapper - GUI for device specific keyboard mappings
|
|
# Copyright (C) 2022 sezanzeb <proxima@sezanzeb.de>
|
|
#
|
|
# This file is part of input-remapper.
|
|
#
|
|
# input-remapper is free software: you can redistribute it and/or modify
|
|
# 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.
|
|
#
|
|
# input-remapper is distributed in the hope that it will be useful,
|
|
# 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
|
|
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
|
import glob
|
|
import os
|
|
import re
|
|
import time
|
|
from typing import Optional, List, Tuple, Set
|
|
|
|
from gi.repository import GLib
|
|
|
|
from inputremapper.configs.global_config import GlobalConfig
|
|
from inputremapper.configs.mapping import UIMapping
|
|
from inputremapper.configs.paths import get_preset_path, mkdir, split_all
|
|
from inputremapper.configs.preset import Preset
|
|
from inputremapper.configs.system_mapping import SystemMapping
|
|
from inputremapper.daemon import DaemonProxy
|
|
from inputremapper.event_combination import EventCombination
|
|
from inputremapper.exceptions import DataManagementError
|
|
from inputremapper.groups import _Group
|
|
from inputremapper.gui.message_broker import (
|
|
MessageBroker,
|
|
GroupData,
|
|
PresetData,
|
|
CombinationUpdate,
|
|
UInputsData,
|
|
)
|
|
from inputremapper.gui.reader import Reader
|
|
from inputremapper.injection.global_uinputs import GlobalUInputs
|
|
from inputremapper.injection.injector import (
|
|
STOPPED,
|
|
RUNNING,
|
|
FAILED,
|
|
UPGRADE_EVDEV,
|
|
NO_GRAB,
|
|
InjectorState,
|
|
)
|
|
from inputremapper.input_event import InputEvent
|
|
from inputremapper.logger import logger
|
|
|
|
DEFAULT_PRESET_NAME = "new preset"
|
|
|
|
# useful type aliases
|
|
Name = str
|
|
GroupKey = str
|
|
|
|
|
|
class DataManager:
|
|
"""DataManager provides an interface to create and modify configurations as well
|
|
as modify the state of the Service.
|
|
|
|
Any state changes will be announced via the MessageBroker.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
message_broker: MessageBroker,
|
|
config: GlobalConfig,
|
|
reader: Reader,
|
|
daemon: DaemonProxy,
|
|
uinputs: GlobalUInputs,
|
|
system_mapping: SystemMapping,
|
|
):
|
|
self.message_broker = message_broker
|
|
self._reader = reader
|
|
self._daemon = daemon
|
|
self._uinputs = uinputs
|
|
self._system_mapping = system_mapping
|
|
uinputs.prepare_all()
|
|
|
|
self._config = config
|
|
self._config.load_config()
|
|
|
|
self._active_preset: Optional[Preset[UIMapping]] = None
|
|
self._active_mapping: Optional[UIMapping] = None
|
|
self._active_event: Optional[InputEvent] = None
|
|
|
|
def send_group(self):
|
|
"""send active group to the MessageBroker.
|
|
|
|
This is internally called whenever the group changes.
|
|
It is usually not necessary to call this explicitly from
|
|
outside DataManager"""
|
|
self.message_broker.send(
|
|
GroupData(self.active_group.key, self.get_preset_names())
|
|
)
|
|
|
|
def send_preset(self):
|
|
"""send active preset to the MessageBroker.
|
|
|
|
This is internally called whenever the preset changes.
|
|
It is usually not necessary to call this explicitly from
|
|
outside DataManager"""
|
|
self.message_broker.send(
|
|
PresetData(
|
|
self.active_preset.name, self.get_mappings(), self.get_autoload()
|
|
)
|
|
)
|
|
|
|
def send_mapping(self):
|
|
"""send active mapping to the MessageBroker
|
|
|
|
This is internally called whenever the mapping changes.
|
|
It is usually not necessary to call this explicitly from
|
|
outside DataManager"""
|
|
if self.active_mapping:
|
|
self.message_broker.send(self.active_mapping.get_bus_message())
|
|
|
|
def send_event(self):
|
|
"""send active event to the MessageBroker.
|
|
|
|
This is internally called whenever the event changes.
|
|
It is usually not necessary to call this explicitly from
|
|
outside DataManager"""
|
|
if self.active_event:
|
|
assert self.active_event in self.active_mapping.event_combination
|
|
self.message_broker.send(self.active_event)
|
|
|
|
def send_uinputs(self):
|
|
"""send the "uinputs" message on the MessageBroker"""
|
|
self.message_broker.send(
|
|
UInputsData(
|
|
{
|
|
name: uinput.capabilities()
|
|
for name, uinput in self._uinputs.devices.items()
|
|
}
|
|
)
|
|
)
|
|
|
|
def send_groups(self):
|
|
"""send the "groups" message on the MessageBroker"""
|
|
self._reader.send_groups()
|
|
|
|
def send_injector_state(self):
|
|
"""send the "injector_state" message with the state of the injector
|
|
for the active_group"""
|
|
if not self.active_group:
|
|
return
|
|
self.message_broker.send(InjectorState(self.get_state()))
|
|
|
|
@property
|
|
def active_group(self) -> Optional[_Group]:
|
|
"""the currently loaded group"""
|
|
return self._reader.group
|
|
|
|
@property
|
|
def active_preset(self) -> Optional[Preset[UIMapping]]:
|
|
"""the currently loaded preset"""
|
|
return self._active_preset
|
|
|
|
@property
|
|
def active_mapping(self) -> Optional[UIMapping]:
|
|
"""the currently loaded mapping"""
|
|
return self._active_mapping
|
|
|
|
@property
|
|
def active_event(self) -> Optional[InputEvent]:
|
|
"""the currently loaded event"""
|
|
return self._active_event
|
|
|
|
def get_group_keys(self) -> Tuple[GroupKey, ...]:
|
|
"""Get all group keys (plugged devices)"""
|
|
return tuple(group.key for group in self._reader.groups.filter())
|
|
|
|
def get_preset_names(self) -> Tuple[Name, ...]:
|
|
"""Get all preset names for active_group and current user,
|
|
starting with the newest."""
|
|
if not self.active_group:
|
|
raise DataManagementError("cannot find presets: Group is not set")
|
|
device_folder = get_preset_path(self.active_group.name)
|
|
mkdir(device_folder)
|
|
|
|
paths = glob.glob(os.path.join(device_folder, "*.json"))
|
|
presets = [
|
|
os.path.splitext(os.path.basename(path))[0]
|
|
for path in sorted(paths, key=os.path.getmtime)
|
|
]
|
|
# the highest timestamp to the front
|
|
presets.reverse()
|
|
return tuple(presets)
|
|
|
|
def get_mappings(self) -> Optional[List[Tuple[Optional[Name], EventCombination]]]:
|
|
"""all mapping names and their combination from the active_preset"""
|
|
if not self._active_preset:
|
|
return None
|
|
return [
|
|
(mapping.name, mapping.event_combination) for mapping in self._active_preset
|
|
]
|
|
|
|
def get_autoload(self) -> bool:
|
|
"""the autoload status of the active_preset"""
|
|
if not self.active_preset or not self.active_group:
|
|
return False
|
|
return self._config.is_autoloaded(
|
|
self.active_group.key, self.active_preset.name
|
|
)
|
|
|
|
def set_autoload(self, status: bool):
|
|
"""set the autoload status of the active_preset.
|
|
Will send "preset" message on the MessageBroker
|
|
"""
|
|
if not self.active_preset or not self.active_group:
|
|
raise DataManagementError("cannot set autoload status: Preset is not set")
|
|
|
|
if status:
|
|
self._config.set_autoload_preset(
|
|
self.active_group.key, self.active_preset.name
|
|
)
|
|
elif self.get_autoload:
|
|
self._config.set_autoload_preset(self.active_group.key, None)
|
|
|
|
self.send_preset()
|
|
|
|
def get_newest_group_key(self) -> GroupKey:
|
|
"""group_key of the group with the most recently modified preset"""
|
|
paths = []
|
|
for path in glob.glob(os.path.join(get_preset_path(), "*/*.json")):
|
|
if self._reader.groups.find(key=split_all(path)[-2]):
|
|
paths.append((path, os.path.getmtime(path)))
|
|
|
|
if not paths:
|
|
raise FileNotFoundError()
|
|
|
|
path, _ = max(paths, key=lambda x: x[1])
|
|
return split_all(path)[-2]
|
|
|
|
def get_newest_preset_name(self) -> Name:
|
|
"""preset name of the most recently modified preset in the active group"""
|
|
if not self.active_group:
|
|
raise DataManagementError("cannot find newest preset: Group is not set")
|
|
|
|
paths = [
|
|
(path, os.path.getmtime(path))
|
|
for path in glob.glob(
|
|
os.path.join(get_preset_path(self.active_group.name), "*.json")
|
|
)
|
|
]
|
|
if not paths:
|
|
raise FileNotFoundError()
|
|
|
|
path, _ = max(paths, key=lambda x: x[1])
|
|
return os.path.split(path)[-1].split(".")[0]
|
|
|
|
def get_available_preset_name(self, name=DEFAULT_PRESET_NAME) -> Name:
|
|
"""the first available preset in the active group"""
|
|
if not self.active_group:
|
|
raise DataManagementError("unable find preset name. Group is not set")
|
|
|
|
name = name.strip()
|
|
|
|
# find a name that is not already taken
|
|
if os.path.exists(get_preset_path(self.active_group.name, name)):
|
|
# if there already is a trailing number, increment it instead of
|
|
# adding another one
|
|
match = re.match(r"^(.+) (\d+)$", name)
|
|
if match:
|
|
name = match[1]
|
|
i = int(match[2]) + 1
|
|
else:
|
|
i = 2
|
|
|
|
while os.path.exists(
|
|
get_preset_path(self.active_group.name, f"{name} {i}")
|
|
):
|
|
i += 1
|
|
|
|
return f"{name} {i}"
|
|
|
|
return name
|
|
|
|
def load_group(self, group_key: str):
|
|
"""Load a group. will send "groups" and "injector_state"
|
|
messages on the MessageBroker.
|
|
|
|
this will render the active_mapping and active_preset invalid
|
|
"""
|
|
if group_key not in self.get_group_keys():
|
|
raise DataManagementError("Unable to load non existing group")
|
|
|
|
self._active_event = None
|
|
self._active_mapping = None
|
|
self._active_preset = None
|
|
group = self._reader.groups.find(key=group_key)
|
|
self._reader.set_group(group)
|
|
self.send_group()
|
|
self.send_injector_state()
|
|
|
|
def load_preset(self, name: str):
|
|
"""Load a preset. Will send "preset" message on the MessageBroker
|
|
|
|
this will render the active_mapping invalid
|
|
"""
|
|
if not self.active_group:
|
|
raise DataManagementError("Unable to load preset. Group is not set")
|
|
|
|
preset_path = get_preset_path(self.active_group.name, name)
|
|
preset = Preset(preset_path, mapping_factory=UIMapping)
|
|
preset.load()
|
|
self._active_event = None
|
|
self._active_mapping = None
|
|
self._active_preset = preset
|
|
self.send_preset()
|
|
|
|
def load_mapping(self, combination: EventCombination):
|
|
"""Load a mapping. Will send "mapping" message on the MessageBroker"""
|
|
if not self._active_preset:
|
|
raise DataManagementError("Unable to load mapping. Preset is not set")
|
|
|
|
mapping = self._active_preset.get_mapping(combination)
|
|
if not mapping:
|
|
raise KeyError(
|
|
f"the mapping with {combination = } does not "
|
|
f"exist in the {self._active_preset.path}"
|
|
)
|
|
self._active_event = None
|
|
self._active_mapping = mapping
|
|
self.send_mapping()
|
|
|
|
def load_event(self, event: InputEvent):
|
|
"""Load a InputEvent from the combination in the active mapping.
|
|
|
|
Will send "event" message on the MessageBroker"""
|
|
if not self.active_mapping:
|
|
raise DataManagementError("Unable to load event. mapping is not set")
|
|
if event not in self.active_mapping.event_combination:
|
|
raise ValueError(
|
|
f"{event} is not member of active_mapping.event_combination: "
|
|
f"{self.active_mapping.event_combination}"
|
|
)
|
|
self._active_event = event
|
|
self.send_event()
|
|
|
|
def rename_preset(self, new_name: str):
|
|
"""rename the current preset and move the correct file
|
|
|
|
Will send "group" and then "preset" message on the MessageBroker
|
|
"""
|
|
if not self.active_preset or not self.active_group:
|
|
raise DataManagementError("Unable rename preset: Preset is not set")
|
|
|
|
if self.active_preset.path == get_preset_path(self.active_group.name, new_name):
|
|
return
|
|
|
|
old_path = self.active_preset.path
|
|
assert old_path is not None
|
|
old_name = os.path.basename(old_path).split(".")[0]
|
|
new_path = get_preset_path(self.active_group.name, new_name)
|
|
if os.path.exists(new_path):
|
|
raise ValueError(
|
|
f"cannot rename {old_name} to " f"{new_name}, preset already exists"
|
|
)
|
|
|
|
logger.info('Moving "%s" to "%s"', old_path, new_path)
|
|
os.rename(old_path, new_path)
|
|
now = time.time()
|
|
os.utime(new_path, (now, now))
|
|
|
|
if self._config.is_autoloaded(self.active_group.key, old_name):
|
|
self._config.set_autoload_preset(self.active_group.key, new_name)
|
|
|
|
self.active_preset.path = get_preset_path(self.active_group.name, new_name)
|
|
self.send_group()
|
|
self.send_preset()
|
|
|
|
def copy_preset(self, name: str):
|
|
"""copy the current preset to the given name.
|
|
Will send "group" and "preset" message to the MessageBroker and load the copy
|
|
"""
|
|
# todo: Do we want to load the copy here? or is this up to the controller?
|
|
if not self.active_preset or not self.active_group:
|
|
raise DataManagementError("Unable to copy preset: Preset is not set")
|
|
|
|
if self.active_preset.path == get_preset_path(self.active_group.name, name):
|
|
return
|
|
|
|
if name in self.get_preset_names():
|
|
raise ValueError(f"a preset with the name {name} already exits")
|
|
|
|
new_path = get_preset_path(self.active_group.name, name)
|
|
logger.info('Copy "%s" to "%s"', self.active_preset.path, new_path)
|
|
self.active_preset.path = new_path
|
|
self.save()
|
|
self.send_group()
|
|
self.send_preset()
|
|
|
|
def create_preset(self, name: str):
|
|
"""create empty preset in the active_group.
|
|
Will send "group" message to the MessageBroker
|
|
"""
|
|
if not self.active_group:
|
|
raise DataManagementError("Unable to add preset. Group is not set")
|
|
|
|
path = get_preset_path(self.active_group.name, name)
|
|
if os.path.exists(path):
|
|
raise DataManagementError("Unable to add preset. Preset exists")
|
|
|
|
Preset(path).save()
|
|
self.send_group()
|
|
|
|
def delete_preset(self):
|
|
"""delete the active preset
|
|
Will send "group" message to the MessageBroker
|
|
this will invalidate the active mapping,
|
|
"""
|
|
preset_path = self._active_preset.path
|
|
logger.info('Removing "%s"', preset_path)
|
|
os.remove(preset_path)
|
|
self._active_mapping = None
|
|
self._active_preset = None
|
|
self.send_group()
|
|
|
|
def update_mapping(self, **kwargs):
|
|
"""update the active mapping with the given keywords and values.
|
|
|
|
Will send "mapping" message to the MessageBroker. In case of a new event_combination
|
|
this will first send a "combination_update" message
|
|
"""
|
|
if not self._active_mapping:
|
|
raise DataManagementError("Cannot modify Mapping: mapping is not set")
|
|
|
|
if symbol := kwargs.get("output_symbol"):
|
|
kwargs["output_symbol"] = self._system_mapping.correct_case(symbol)
|
|
|
|
combination = self.active_mapping.event_combination
|
|
for key, value in kwargs.items():
|
|
setattr(self._active_mapping, key, value)
|
|
|
|
if (
|
|
"event_combination" in kwargs
|
|
and combination != self.active_mapping.event_combination
|
|
):
|
|
self._active_event = None
|
|
self.message_broker.send(
|
|
CombinationUpdate(combination, self._active_mapping.event_combination)
|
|
)
|
|
self.send_mapping()
|
|
|
|
def update_event(self, new_event: InputEvent):
|
|
"""update the active event.
|
|
|
|
Will send "combination_update", "mapping" and "event" messages to the
|
|
MessageBroker (in that order)
|
|
"""
|
|
if not self.active_mapping or not self.active_event:
|
|
raise DataManagementError("Cannot modify event: event is not set")
|
|
|
|
combination = list(self.active_mapping.event_combination)
|
|
combination[combination.index(self.active_event)] = new_event
|
|
self.update_mapping(event_combination=EventCombination(combination))
|
|
self._active_event = new_event
|
|
self.send_event()
|
|
|
|
def create_mapping(self):
|
|
"""create empty mapping in the active preset.
|
|
Will send "preset" message to the MessageBroker
|
|
"""
|
|
if not self._active_preset:
|
|
raise DataManagementError("cannot create mapping: preset is not set")
|
|
self._active_preset.add(UIMapping())
|
|
self.send_preset()
|
|
|
|
def delete_mapping(self):
|
|
"""delete the active mapping
|
|
Will send "preset" message to the MessageBroker
|
|
"""
|
|
if not self._active_mapping:
|
|
raise DataManagementError(
|
|
"cannot delete active mapping: active mapping is not set"
|
|
)
|
|
|
|
self._active_preset.remove(self._active_mapping.event_combination)
|
|
self._active_mapping = None
|
|
self.send_preset()
|
|
|
|
def save(self):
|
|
"""save the active preset"""
|
|
if self._active_preset:
|
|
self._active_preset.save()
|
|
|
|
def refresh_groups(self):
|
|
"""refresh the groups (plugged devices)
|
|
Should send "groups" message to MessageBroker this will not happen immediately
|
|
because the system might take a bit until the groups are available
|
|
"""
|
|
self._reader.refresh_groups()
|
|
|
|
def start_combination_recording(self):
|
|
"""Record user input.
|
|
|
|
Will send "combination_recorded" messages as new input arrives.
|
|
Will eventually send a "recording_finished" message.
|
|
"""
|
|
self._reader.start_recorder()
|
|
|
|
def stop_combination_recording(self):
|
|
"""Stop recording user input.
|
|
|
|
Will send RecordingFinished message if a recording is running.
|
|
"""
|
|
self._reader.stop_recorder()
|
|
|
|
def stop_injecting(self) -> None:
|
|
"""stop injecting for the active group
|
|
|
|
Will send "injector_state" message once the injector has stopped"""
|
|
if not self.active_group:
|
|
raise DataManagementError("cannot stop injection: group is not set")
|
|
self._daemon.stop_injecting(self.active_group.key)
|
|
self.do_when_injector_state({STOPPED}, self.send_injector_state)
|
|
|
|
def start_injecting(self) -> bool:
|
|
"""start injecting the active preset for the active group.
|
|
|
|
returns if the startup was successfully initialized.
|
|
Will send "injector_state" message once the startup is complete.
|
|
"""
|
|
if not self.active_preset or not self.active_group:
|
|
raise DataManagementError("cannot start injection: preset is not set")
|
|
|
|
self._daemon.set_config_dir(self._config.get_dir())
|
|
assert self.active_preset.name is not None
|
|
if self._daemon.start_injecting(self.active_group.key, self.active_preset.name):
|
|
self.do_when_injector_state(
|
|
{RUNNING, FAILED, NO_GRAB, UPGRADE_EVDEV}, self.send_injector_state
|
|
)
|
|
return True
|
|
return False
|
|
|
|
def get_state(self) -> int:
|
|
"""the state of the injector"""
|
|
if not self.active_group:
|
|
raise DataManagementError("cannot read state: group is not set")
|
|
return self._daemon.get_state(self.active_group.key)
|
|
|
|
def refresh_service_config_path(self):
|
|
"""tell the service to refresh its config path"""
|
|
self._daemon.set_config_dir(self._config.get_dir())
|
|
|
|
def do_when_injector_state(self, states: Set[int], callback):
|
|
"""run callback once the injector state is one of states"""
|
|
|
|
def do():
|
|
if self.get_state() in states:
|
|
callback()
|
|
return False
|
|
return True
|
|
|
|
GLib.timeout_add(100, do)
|