|
|
|
@ -138,7 +138,8 @@ class Controller:
|
|
|
|
|
self.message_broker.publish(MappingData(**MAPPING_DEFAULTS))
|
|
|
|
|
|
|
|
|
|
def _on_combination_recorded(self, data: CombinationRecorded):
|
|
|
|
|
self.update_combination(data.combination)
|
|
|
|
|
combination = self._auto_use_as_analog(data.combination)
|
|
|
|
|
self.update_combination(combination)
|
|
|
|
|
|
|
|
|
|
def _publish_mapping_errors_as_status_msg(self, *__):
|
|
|
|
|
"""Send mapping ValidationErrors to the MessageBroker."""
|
|
|
|
@ -244,8 +245,36 @@ class Controller:
|
|
|
|
|
)
|
|
|
|
|
self.message_broker.publish(DoStackSwitch(1))
|
|
|
|
|
|
|
|
|
|
def _auto_use_as_analog(self, combination: InputCombination) -> InputCombination:
|
|
|
|
|
"""If output is analog, set the first fitting input to analog."""
|
|
|
|
|
if self.data_manager.active_mapping is None:
|
|
|
|
|
return combination
|
|
|
|
|
|
|
|
|
|
if not self.data_manager.active_mapping.is_analog_output():
|
|
|
|
|
return combination
|
|
|
|
|
|
|
|
|
|
if combination.find_analog_input_config():
|
|
|
|
|
# something is already set to do that
|
|
|
|
|
return combination
|
|
|
|
|
|
|
|
|
|
for i, input_config in enumerate(combination):
|
|
|
|
|
# find the first analog input and set it to "use as analog"
|
|
|
|
|
if input_config.type in (EV_ABS, EV_REL):
|
|
|
|
|
logger.info("Using %s as analog input", input_config)
|
|
|
|
|
|
|
|
|
|
# combinations and input_configs are immutable, a new combination
|
|
|
|
|
# is created to fit the needs instead
|
|
|
|
|
combination_list = list(combination)
|
|
|
|
|
combination_list[i] = input_config.modify(analog_threshold=0)
|
|
|
|
|
new_combination = InputCombination(combination_list)
|
|
|
|
|
return new_combination
|
|
|
|
|
|
|
|
|
|
return combination
|
|
|
|
|
|
|
|
|
|
def update_combination(self, combination: InputCombination):
|
|
|
|
|
"""Update the input_combination of the active mapping."""
|
|
|
|
|
combination = self._auto_use_as_analog(combination)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
self.data_manager.update_mapping(input_combination=combination)
|
|
|
|
|
self.save()
|
|
|
|
@ -435,16 +464,16 @@ class Controller:
|
|
|
|
|
self.data_manager.load_mapping(input_combination)
|
|
|
|
|
self.load_input_config(input_combination[0])
|
|
|
|
|
|
|
|
|
|
def update_mapping(self, **kwargs):
|
|
|
|
|
def update_mapping(self, **changes):
|
|
|
|
|
"""Update the active_mapping with the given keywords and values."""
|
|
|
|
|
if "mapping_type" in kwargs.keys():
|
|
|
|
|
if not (kwargs := self._change_mapping_type(kwargs)):
|
|
|
|
|
if "mapping_type" in changes.keys():
|
|
|
|
|
if not (changes := self._change_mapping_type(changes)):
|
|
|
|
|
# we need to synchronize the gui
|
|
|
|
|
self.data_manager.publish_mapping()
|
|
|
|
|
self.data_manager.publish_event()
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self.data_manager.update_mapping(**kwargs)
|
|
|
|
|
self.data_manager.update_mapping(**changes)
|
|
|
|
|
self.save()
|
|
|
|
|
|
|
|
|
|
def create_mapping(self):
|
|
|
|
@ -653,17 +682,17 @@ class Controller:
|
|
|
|
|
"""Focus the given component."""
|
|
|
|
|
self.gui.window.set_focus(component)
|
|
|
|
|
|
|
|
|
|
def _change_mapping_type(self, kwargs: Dict[str, Any]):
|
|
|
|
|
def _change_mapping_type(self, changes: Dict[str, Any]):
|
|
|
|
|
"""Query the user to update the mapping in order to change the mapping type."""
|
|
|
|
|
mapping = self.data_manager.active_mapping
|
|
|
|
|
|
|
|
|
|
if mapping is None:
|
|
|
|
|
return kwargs
|
|
|
|
|
return changes
|
|
|
|
|
|
|
|
|
|
if kwargs["mapping_type"] == mapping.mapping_type:
|
|
|
|
|
return kwargs
|
|
|
|
|
if changes["mapping_type"] == mapping.mapping_type:
|
|
|
|
|
return changes
|
|
|
|
|
|
|
|
|
|
if kwargs["mapping_type"] == "analog":
|
|
|
|
|
if changes["mapping_type"] == "analog":
|
|
|
|
|
msg = _("You are about to change the mapping to analog.")
|
|
|
|
|
if mapping.output_symbol:
|
|
|
|
|
msg += _('\nThis will remove "{}" ' "from the text input!").format(
|
|
|
|
@ -677,20 +706,20 @@ class Controller:
|
|
|
|
|
]:
|
|
|
|
|
# there is no analog input configured, let's try to autoconfigure it
|
|
|
|
|
inputs: List[InputConfig] = list(mapping.input_combination)
|
|
|
|
|
for i, e in enumerate(inputs):
|
|
|
|
|
if e.type in [EV_ABS, EV_REL]:
|
|
|
|
|
inputs[i] = e.modify(analog_threshold=0)
|
|
|
|
|
kwargs["input_combination"] = InputCombination(inputs)
|
|
|
|
|
for i, input_config in enumerate(inputs):
|
|
|
|
|
if input_config.type in [EV_ABS, EV_REL]:
|
|
|
|
|
inputs[i] = input_config.modify(analog_threshold=0)
|
|
|
|
|
changes["input_combination"] = InputCombination(inputs)
|
|
|
|
|
msg += _(
|
|
|
|
|
'\nThe input "{}" will be used as analog input.'
|
|
|
|
|
).format(e.description())
|
|
|
|
|
).format(input_config.description())
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
# not possible to autoconfigure inform the user
|
|
|
|
|
msg += _("\nYou need to record an analog input.")
|
|
|
|
|
|
|
|
|
|
elif not mapping.output_symbol:
|
|
|
|
|
return kwargs
|
|
|
|
|
return changes
|
|
|
|
|
|
|
|
|
|
answer = None
|
|
|
|
|
|
|
|
|
@ -700,21 +729,21 @@ class Controller:
|
|
|
|
|
|
|
|
|
|
self.message_broker.publish(UserConfirmRequest(msg, get_answer))
|
|
|
|
|
if answer:
|
|
|
|
|
kwargs["output_symbol"] = None
|
|
|
|
|
return kwargs
|
|
|
|
|
changes["output_symbol"] = None
|
|
|
|
|
return changes
|
|
|
|
|
else:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
if kwargs["mapping_type"] == "key_macro":
|
|
|
|
|
if changes["mapping_type"] == "key_macro":
|
|
|
|
|
try:
|
|
|
|
|
analog_input = tuple(
|
|
|
|
|
filter(lambda i: i.defines_analog_input, mapping.input_combination)
|
|
|
|
|
)
|
|
|
|
|
analog_input = analog_input[0]
|
|
|
|
|
except IndexError:
|
|
|
|
|
kwargs["output_type"] = None
|
|
|
|
|
kwargs["output_code"] = None
|
|
|
|
|
return kwargs
|
|
|
|
|
changes["output_type"] = None
|
|
|
|
|
changes["output_code"] = None
|
|
|
|
|
return changes
|
|
|
|
|
|
|
|
|
|
answer = None
|
|
|
|
|
|
|
|
|
@ -731,10 +760,10 @@ class Controller:
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
if answer:
|
|
|
|
|
kwargs["output_type"] = None
|
|
|
|
|
kwargs["output_code"] = None
|
|
|
|
|
return kwargs
|
|
|
|
|
changes["output_type"] = None
|
|
|
|
|
changes["output_code"] = None
|
|
|
|
|
return changes
|
|
|
|
|
else:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
return kwargs
|
|
|
|
|
return changes
|
|
|
|
|