|
|
|
@ -80,6 +80,7 @@ class Window:
|
|
|
|
|
"""User Interface."""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.rows = 0
|
|
|
|
|
self.selected_device = None
|
|
|
|
|
|
|
|
|
|
gladefile = os.path.join(get_data_path(), 'key-mapper.glade')
|
|
|
|
|
builder = Gtk.Builder()
|
|
|
|
@ -94,8 +95,11 @@ class Window:
|
|
|
|
|
self.populate_devices()
|
|
|
|
|
|
|
|
|
|
# find an select the newest preset based on file modification dates
|
|
|
|
|
self.on_select_preset(find_newest_preset())
|
|
|
|
|
|
|
|
|
|
device, preset = find_newest_preset()
|
|
|
|
|
if device:
|
|
|
|
|
self.on_select_device(device)
|
|
|
|
|
if preset:
|
|
|
|
|
self.on_select_preset(preset)
|
|
|
|
|
|
|
|
|
|
def get(self, name):
|
|
|
|
|
"""Get a widget from the window"""
|
|
|
|
@ -112,32 +116,49 @@ class Window:
|
|
|
|
|
for (id, device) in devices:
|
|
|
|
|
device_selection.append(device, device)
|
|
|
|
|
|
|
|
|
|
def populate_presets(self, device):
|
|
|
|
|
def populate_presets(self):
|
|
|
|
|
"""Show the available presets for the selected device."""
|
|
|
|
|
presets = get_presets(device)
|
|
|
|
|
presets = get_presets(self.selected_device)
|
|
|
|
|
preset_selection = self.get('preset_selection')
|
|
|
|
|
for preset in presets:
|
|
|
|
|
preset_selection.append(preset)
|
|
|
|
|
preset_selection.append(preset, preset)
|
|
|
|
|
|
|
|
|
|
def on_select_device(self, dropdown):
|
|
|
|
|
"""List all presets, create one if none exist yet.
|
|
|
|
|
"""
|
|
|
|
|
device = dropdown.get_active_text()
|
|
|
|
|
def on_select_device(self, device):
|
|
|
|
|
"""List all presets, create one if none exist yet."""
|
|
|
|
|
if isinstance(device, Gtk.ComboBoxText):
|
|
|
|
|
preset = device.get_active_text()
|
|
|
|
|
|
|
|
|
|
device = device.get_active_text()
|
|
|
|
|
presets = get_presets(device)
|
|
|
|
|
if len(presets) == 0:
|
|
|
|
|
create_preset(device)
|
|
|
|
|
self.populate_presets(device)
|
|
|
|
|
self.selected_device = device
|
|
|
|
|
self.populate_presets()
|
|
|
|
|
|
|
|
|
|
def on_create_preset_clicked(self, button):
|
|
|
|
|
"""Create a new preset and select it."""
|
|
|
|
|
new_preset = create_preset(self.selected_device)
|
|
|
|
|
self.get('preset_selection').append(new_preset, new_preset)
|
|
|
|
|
self.on_select_preset(new_preset)
|
|
|
|
|
|
|
|
|
|
def on_select_preset(self, preset):
|
|
|
|
|
"""Show the mappings of the preset
|
|
|
|
|
"""Show the mappings of the preset"""
|
|
|
|
|
if isinstance(preset, Gtk.ComboBoxText):
|
|
|
|
|
preset = preset.get_active_text()
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
key_list = self.get('key_list')
|
|
|
|
|
for i in range(self.rows):
|
|
|
|
|
# don't remove the header
|
|
|
|
|
key_list.remove_row(i + 1)
|
|
|
|
|
self.rows = 0
|
|
|
|
|
|
|
|
|
|
self.get('preset_selection').set_active_id(preset)
|
|
|
|
|
|
|
|
|
|
# TODO show all mapped keys from config
|
|
|
|
|
|
|
|
|
|
self.on_add_key_clicked()
|
|
|
|
|
|
|
|
|
|
def on_add_key_clicked(self, button=None):
|
|
|
|
|