mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-04 12:00:16 +00:00
switch to autoloat presets
This commit is contained in:
parent
ce32423c7c
commit
fa563d45b9
@ -487,6 +487,42 @@
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Automatically load this preset</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="preset_autoload_switch">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<signal name="state-set" handler="on_preset_autoload_switch_activate" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
|
@ -44,12 +44,16 @@ class _Config:
|
||||
self._config = {}
|
||||
self.load_config()
|
||||
|
||||
def set_autoload_preset(self, device, preset):
|
||||
def set_autoload_preset(self, device, preset, load=True):
|
||||
"""Set a preset to be automatically applied on start."""
|
||||
if self._config.get('autoload') is None:
|
||||
self._config['autoload'] = {}
|
||||
|
||||
self._config['autoload'][device] = preset
|
||||
if load:
|
||||
self._config['autoload'][device] = preset
|
||||
elif self._config['autoload'].get(device) is not None:
|
||||
# TODO test
|
||||
del self._config['autoload'][device]
|
||||
|
||||
def iterate_autoload_presets(self):
|
||||
"""get tuples of (device, preset)."""
|
||||
|
@ -80,9 +80,11 @@ class Daemon(service.Object):
|
||||
"""
|
||||
def __init__(self, *args, autoload=True, **kwargs):
|
||||
"""Constructs the daemon. You still need to run the GLib mainloop."""
|
||||
print(autoload)
|
||||
self.injectors = {}
|
||||
if autoload:
|
||||
for device, preset in config.iterate_autoload_presets():
|
||||
print(device, preset)
|
||||
mapping = Mapping()
|
||||
mapping.load(device, preset)
|
||||
self.injectors[device] = KeycodeInjector(device, mapping)
|
||||
|
@ -37,7 +37,7 @@ from keymapper.gtk.row import Row
|
||||
from keymapper.gtk.unsaved import unsaved_changes_dialog, GO_BACK
|
||||
from keymapper.dev.reader import keycode_reader
|
||||
from keymapper.daemon import get_dbus_interface
|
||||
from keymapper.paths import get_config_path
|
||||
from keymapper.config import config
|
||||
|
||||
|
||||
def gtk_iteration():
|
||||
@ -288,6 +288,14 @@ class Window:
|
||||
# changes a bit
|
||||
keycode_reader.start_reading(self.selected_device)
|
||||
|
||||
def on_preset_autoload_switch_activate(self, _, active):
|
||||
"""Load the preset automatically next time the user logs in."""
|
||||
device = self.selected_device
|
||||
preset = self.selected_preset
|
||||
# TODO test call this and then check config
|
||||
config.set_autoload_preset(device, preset, active)
|
||||
config.save_config()
|
||||
|
||||
def on_select_device(self, dropdown):
|
||||
"""List all presets, create one if none exist yet."""
|
||||
if dropdown.get_active_id() == self.selected_device:
|
||||
|
Loading…
Reference in New Issue
Block a user