bunch of stuff

first
sezanzeb 4 years ago
parent e0f45f1b23
commit 5932d0f36c

@ -32,7 +32,8 @@ gi.require_version('GLib', '2.0')
from gi.repository import Gtk
from keymapper.data import get_data_path
from keymapper.profiles import find_devices, get_presets, get_mappings
from keymapper.presets import find_devices, get_presets, get_mappings, \
find_newest_preset, create_preset
from keymapper.logger import logger, update_verbosity, log_info
@ -91,7 +92,10 @@ class Window:
self.window = window
self.populate_devices()
self.on_select_profile('asdf')
# find an select the newest preset based on file modification dates
self.on_select_preset(find_newest_preset())
def get(self, name):
"""Get a widget from the window"""
@ -108,11 +112,29 @@ class Window:
for (id, device) in devices:
device_selection.append(device, device)
def populate_profiles(self):
"""Show the available profiles for the selected device."""
def populate_presets(self, device):
"""Show the available presets for the selected device."""
presets = get_presets(device)
preset_selection = self.get('preset_selection')
for preset in presets:
preset_selection.append(preset)
def on_select_device(self, dropdown):
"""List all presets, create one if none exist yet.
"""
device = dropdown.get_active_text()
presets = get_presets(device)
if len(presets) == 0:
create_preset(device)
self.populate_presets(device)
def on_select_preset(self, preset):
"""Show the mappings of the preset
def on_select_profile(self, profile):
"""Show the mappings of the profile"""
Parameters
----------
preset : string
"""
# prepare one empty input to add stuff, and to get the grid to
# the correct column width, otherwise it may jump if the user adds
# the first row.
@ -149,6 +171,7 @@ class Window:
# add back an empty row
self.on_add_key_clicked()
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument(

@ -36,6 +36,7 @@
<property name="width_request">400</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_select_device" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
@ -62,7 +63,7 @@
</packing>
</child>
<child>
<object class="GtkBox" id="profile_settings">
<object class="GtkBox" id="preset_settings">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">10</property>
@ -78,7 +79,7 @@
<property name="width_request">50</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Profile</property>
<property name="label" translatable="yes">preset</property>
<property name="width_chars">10</property>
<property name="xalign">0</property>
</object>
@ -89,10 +90,11 @@
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="profile_selection">
<object class="GtkComboBoxText" id="preset_selection">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_select_preset" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
@ -122,7 +124,7 @@
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkBox" id="rename_container">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">10</property>

@ -34,6 +34,9 @@ _configs = {}
_defaults = {}
# TODO this works on xmodmaps instead of config files
def _modify_config(config_contents, key, value):
"""Return a string representing the modified contents of the config file.
@ -173,8 +176,22 @@ class Config:
return True
def get_config(device, preset, path):
"""Ask for the config. Initialize it if not yet done so.
def get_config(device, preset, path=None):
"""Ask for a config object.
There should not be multiple Config objects for the same preset, so make
sure to use this function insted of the Config constructor.
Creates a config file if it doesn't exist yet.
Parameters
----------
device : string
preset : string
path : string or None
If none, will default to '~/.config/key-mapper/'.
In that directory, a folder for the device and a file for
the preset will be created.
"""
# don't initialize it right away in the global scope, to avoid having
# the wrong logging verbosity.

@ -24,7 +24,9 @@
import os
import subprocess
from keymapper.logger import logger
from keymapper.config import get_config
def get_xinput_list(type):
@ -62,7 +64,24 @@ def get_presets(device):
----------
device : string
"""
pass
print('get_presets not yet implemented')
return []
def create_preset(device, name=None):
"""Create an empty preset."""
existing_names = get_presets(device)
if name is None:
name = 'new preset'
# find a name that is not already taken
i = 1
while name in existing_names:
i += 1
name = f'new preset {i}'
# trigger the creation of a new config file:
get_config(device, name)
def get_mappings(device, preset):
@ -74,3 +93,9 @@ def get_mappings(device, preset):
preset : string
"""
pass
def find_newest_preset():
"""Get the device and present that was most recently modified."""
print('find_newest_preset not yet implemented')
return None, None

@ -90,6 +90,11 @@ class Integration(unittest.TestCase):
self.assertIsNotNone(self.window)
self.assertTrue(self.window.window.get_visible())
def test_select_device_and_preset(self):
self.window.on_select_device('fakeDevice1')
self.window.on_select_preset('fakePreset1')
# TODO test meaningful stuff here
if __name__ == "__main__":
unittest.main()

Loading…
Cancel
Save