2020-12-02 02:58:52 -05:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
2020-12-20 19:29:48 -05:00
|
|
|
from basic_editor import BasicEditor
|
2020-12-02 02:58:52 -05:00
|
|
|
from keyboard_container import KeyboardContainer
|
2020-12-25 14:27:28 -05:00
|
|
|
from keycodes import recreate_keyboard_keycodes
|
2020-12-02 02:58:52 -05:00
|
|
|
from tabbed_keycodes import TabbedKeycodes
|
2020-12-02 10:10:59 -05:00
|
|
|
from vial_device import VialKeyboard
|
2020-12-02 02:58:52 -05:00
|
|
|
|
|
|
|
|
|
2020-12-20 19:29:48 -05:00
|
|
|
class KeymapEditor(BasicEditor):
|
2020-12-02 02:58:52 -05:00
|
|
|
|
2020-12-20 22:13:16 -05:00
|
|
|
def __init__(self, layout_editor):
|
|
|
|
|
super().__init__()
|
2020-12-02 02:58:52 -05:00
|
|
|
|
2020-12-20 22:13:16 -05:00
|
|
|
self.keyboard_container = KeyboardContainer(layout_editor)
|
2020-12-02 02:58:52 -05:00
|
|
|
|
|
|
|
|
self.tabbed_keycodes = TabbedKeycodes()
|
|
|
|
|
self.tabbed_keycodes.keycode_changed.connect(self.on_keycode_changed)
|
|
|
|
|
|
|
|
|
|
self.addWidget(self.keyboard_container)
|
|
|
|
|
self.addWidget(self.tabbed_keycodes)
|
|
|
|
|
|
2020-12-02 10:10:59 -05:00
|
|
|
self.device = None
|
|
|
|
|
|
2020-12-02 02:58:52 -05:00
|
|
|
def on_keycode_changed(self, code):
|
|
|
|
|
self.keyboard_container.set_key(code)
|
|
|
|
|
|
2020-12-02 10:10:59 -05:00
|
|
|
def rebuild(self, device):
|
2020-12-20 19:29:48 -05:00
|
|
|
super().rebuild(device)
|
2020-12-25 14:27:28 -05:00
|
|
|
if self.valid():
|
2020-12-02 10:10:59 -05:00
|
|
|
self.keyboard_container.rebuild(device.keyboard)
|
2020-12-25 14:27:28 -05:00
|
|
|
recreate_keyboard_keycodes(self.keyboard_container.keyboard)
|
|
|
|
|
self.tabbed_keycodes.recreate_keycode_buttons()
|
|
|
|
|
self.keyboard_container.refresh_layer_display()
|
2020-12-02 10:10:59 -05:00
|
|
|
|
|
|
|
|
def valid(self):
|
|
|
|
|
return isinstance(self.device, VialKeyboard)
|
2020-12-02 02:58:52 -05:00
|
|
|
|
|
|
|
|
def save_layout(self):
|
|
|
|
|
return self.keyboard_container.save_layout()
|
|
|
|
|
|
|
|
|
|
def restore_layout(self, data):
|
|
|
|
|
self.keyboard_container.restore_layout(data)
|