mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-20 03:25:43 +00:00
mapping list headers
This commit is contained in:
parent
d6dd961ee0
commit
9253cc7e90
@ -36,18 +36,19 @@ from keymapper.profiles import find_devices, get_presets, get_mappings
|
|||||||
from keymapper.logger import logger, update_verbosity, log_info
|
from keymapper.logger import logger, update_verbosity, log_info
|
||||||
|
|
||||||
|
|
||||||
|
window = None
|
||||||
|
|
||||||
|
|
||||||
class SingleKeyMapping:
|
class SingleKeyMapping:
|
||||||
"""A single, configurable key mapping."""
|
"""A single, configurable key mapping."""
|
||||||
box = None
|
|
||||||
|
|
||||||
def __init__(self, delete_callback):
|
def __init__(self, delete_callback):
|
||||||
"""Construct a row and add it to the list in the GUI."""
|
"""Construct a row and add it to the list in the GUI."""
|
||||||
self.delete_callback = delete_callback
|
self.delete_callback = delete_callback
|
||||||
self.put_together()
|
self.put_together()
|
||||||
|
|
||||||
def get_widget(self):
|
def get_widgets(self):
|
||||||
"""Return the widget that wraps all the widgets of the row."""
|
"""Return the widget that wraps all the widgets of the row."""
|
||||||
return self.box
|
return self.widgets
|
||||||
|
|
||||||
def put_together(self):
|
def put_together(self):
|
||||||
"""Create all GTK widgets."""
|
"""Create all GTK widgets."""
|
||||||
@ -65,24 +66,20 @@ class SingleKeyMapping:
|
|||||||
original_key = Gtk.Entry()
|
original_key = Gtk.Entry()
|
||||||
original_key.set_width_chars(4)
|
original_key.set_width_chars(4)
|
||||||
|
|
||||||
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
|
self.widgets = (delete_button, key_code, original_key)
|
||||||
box.pack_start(delete_button, expand=False, fill=False, padding=0)
|
|
||||||
box.pack_start(key_code, expand=True, fill=True, padding=0)
|
|
||||||
box.pack_start(original_key, expand=True, fill=True, padding=0)
|
|
||||||
box.set_margin_start(10)
|
|
||||||
box.set_margin_end(10)
|
|
||||||
box.show_all()
|
|
||||||
self.box = box
|
|
||||||
|
|
||||||
def on_delete_button_clicked(self, button):
|
def on_delete_button_clicked(self, button):
|
||||||
"""Destroy the row and remove it from the config."""
|
"""Destroy the row and remove it from the config."""
|
||||||
self.box.destroy()
|
for widget in self.widgets:
|
||||||
|
widget.destroy()
|
||||||
self.delete_callback(self)
|
self.delete_callback(self)
|
||||||
|
|
||||||
|
|
||||||
class Window:
|
class Window:
|
||||||
"""User Interface."""
|
"""User Interface."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.rows = 0
|
||||||
|
|
||||||
gladefile = os.path.join(get_data_path(), 'key-mapper.glade')
|
gladefile = os.path.join(get_data_path(), 'key-mapper.glade')
|
||||||
builder = Gtk.Builder()
|
builder = Gtk.Builder()
|
||||||
builder.add_from_file(gladefile)
|
builder.add_from_file(gladefile)
|
||||||
@ -94,6 +91,7 @@ class Window:
|
|||||||
self.window = window
|
self.window = window
|
||||||
|
|
||||||
self.populate_devices()
|
self.populate_devices()
|
||||||
|
self.on_select_profile('asdf')
|
||||||
|
|
||||||
def get(self, name):
|
def get(self, name):
|
||||||
"""Get a widget from the window"""
|
"""Get a widget from the window"""
|
||||||
@ -113,14 +111,24 @@ class Window:
|
|||||||
def populate_profiles(self):
|
def populate_profiles(self):
|
||||||
"""Show the available profiles for the selected device."""
|
"""Show the available profiles for the selected device."""
|
||||||
|
|
||||||
|
def on_select_profile(self, profile):
|
||||||
|
"""Show the mappings of the profile"""
|
||||||
|
# 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.
|
||||||
|
self.on_add_key_clicked()
|
||||||
|
|
||||||
def on_add_key_clicked(self, button):
|
def on_add_key_clicked(self, button=None):
|
||||||
"""Add a mapping to the list of mappings."""
|
"""Add a mapping to the list of mappings."""
|
||||||
single_key_mapping = SingleKeyMapping(self.on_row_removed)
|
single_key_mapping = SingleKeyMapping(self.on_row_removed)
|
||||||
self.get('key_list').pack_start(
|
key_list = self.get('key_list')
|
||||||
single_key_mapping.get_widget(),
|
key_list.insert_row(1)
|
||||||
expand=False, fill=False, padding=0
|
widgets = single_key_mapping.get_widgets()
|
||||||
)
|
key_list.attach(widgets[0], 0, 1, 1, 1)
|
||||||
|
key_list.attach(widgets[1], 1, 1, 1, 1)
|
||||||
|
key_list.attach(widgets[2], 2, 1, 1, 1)
|
||||||
|
key_list.show_all()
|
||||||
|
self.rows += 1
|
||||||
|
|
||||||
def on_row_removed(self, mapping):
|
def on_row_removed(self, mapping):
|
||||||
"""Stuff to do when a row was removed
|
"""Stuff to do when a row was removed
|
||||||
@ -134,7 +142,12 @@ class Window:
|
|||||||
# are removed.
|
# are removed.
|
||||||
window = self.get('window')
|
window = self.get('window')
|
||||||
window.resize(window.get_size()[0], 1)
|
window.resize(window.get_size()[0], 1)
|
||||||
|
# note, that the grid row still exist, it just shrank down to 0
|
||||||
|
# because there are no contents.
|
||||||
|
self.rows -= 1
|
||||||
|
if self.rows == 0:
|
||||||
|
# add back an empty row
|
||||||
|
self.on_add_key_clicked()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
@ -148,5 +161,5 @@ if __name__ == '__main__':
|
|||||||
update_verbosity(options.debug)
|
update_verbosity(options.debug)
|
||||||
log_info()
|
log_info()
|
||||||
|
|
||||||
Window()
|
window = Window()
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<requires lib="gtk+" version="3.22"/>
|
<requires lib="gtk+" version="3.22"/>
|
||||||
<object class="GtkWindow" id="window">
|
<object class="GtkWindow" id="window">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title" translatable="yes">Key Mapper</property>
|
||||||
<signal name="delete-event" handler="on_close" swapped="no"/>
|
<signal name="delete-event" handler="on_close" swapped="no"/>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
@ -231,12 +232,38 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="key_list">
|
<object class="GtkGrid" id="key_list">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_start">10</property>
|
||||||
|
<property name="margin_end">10</property>
|
||||||
<property name="margin_bottom">10</property>
|
<property name="margin_bottom">10</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="row_spacing">10</property>
|
||||||
<property name="spacing">10</property>
|
<property name="column_spacing">10</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="label" translatable="yes">Mapping</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">2</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="label" translatable="yes">Key</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
</child>
|
</child>
|
||||||
|
@ -83,11 +83,8 @@ class Integration(unittest.TestCase):
|
|||||||
self.window.window.destroy()
|
self.window.window.destroy()
|
||||||
gtk_iteration()
|
gtk_iteration()
|
||||||
self.fakes.restore()
|
self.fakes.restore()
|
||||||
if os.path.exists(fake_config_path):
|
# TODO iterate over all config files in the fake_path and
|
||||||
os.remove(fake_config_path)
|
# empty them
|
||||||
config = get_config()
|
|
||||||
config.create_config_file()
|
|
||||||
config.load_config()
|
|
||||||
|
|
||||||
def test_can_start(self):
|
def test_can_start(self):
|
||||||
self.assertIsNotNone(self.window)
|
self.assertIsNotNone(self.window)
|
||||||
|
Loading…
Reference in New Issue
Block a user