-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,284 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
from PyQt5 import QtCore | ||
from PyQt5.QtCore import pyqtSignal, QObject | ||
from PyQt5.QtWidgets import QTabWidget, QWidget, QSizePolicy, QGridLayout, QVBoxLayout, QLabel | ||
|
||
from key_widget import KeyWidget | ||
from tabbed_keycodes import TabbedKeycodes | ||
from vial_device import VialKeyboard | ||
from basic_editor import BasicEditor | ||
|
||
|
||
class ComboEntryUI(QObject): | ||
|
||
key_changed = pyqtSignal() | ||
|
||
def __init__(self, idx): | ||
super().__init__() | ||
|
||
self.idx = idx | ||
self.container = QGridLayout() | ||
self.kc_inputs = [] | ||
self.populate_container() | ||
|
||
w = QWidget() | ||
w.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) | ||
w.setLayout(self.container) | ||
l = QVBoxLayout() | ||
l.addWidget(w) | ||
l.setAlignment(w, QtCore.Qt.AlignHCenter) | ||
self.w2 = QWidget() | ||
self.w2.setLayout(l) | ||
|
||
def populate_container(self): | ||
for x in range(4): | ||
kc_widget = KeyWidget() | ||
kc_widget.changed.connect(self.on_key_changed) | ||
self.container.addWidget(QLabel("Key {}".format(x + 1)), x, 0) | ||
self.container.addWidget(kc_widget, x, 1) | ||
self.kc_inputs.append(kc_widget) | ||
|
||
self.kc_output = KeyWidget() | ||
self.kc_output.changed.connect(self.on_key_changed) | ||
self.container.addWidget(QLabel("Output key"), 4, 0) | ||
self.container.addWidget(self.kc_output, 4, 1) | ||
|
||
def widget(self): | ||
return self.w2 | ||
|
||
def load(self, data): | ||
objs = self.kc_inputs + [self.kc_output] | ||
for o in objs: | ||
o.blockSignals(True) | ||
|
||
for x in range(4): | ||
self.kc_inputs[x].set_keycode(data[x]) | ||
self.kc_output.set_keycode(data[4]) | ||
|
||
for o in objs: | ||
o.blockSignals(False) | ||
|
||
def save(self): | ||
return ( | ||
self.kc_inputs[0].keycode, | ||
self.kc_inputs[1].keycode, | ||
self.kc_inputs[2].keycode, | ||
self.kc_inputs[3].keycode, | ||
self.kc_output.keycode | ||
) | ||
|
||
def on_key_changed(self): | ||
self.key_changed.emit() | ||
|
||
|
||
class CustomTabWidget(QTabWidget): | ||
|
||
def mouseReleaseEvent(self, ev): | ||
TabbedKeycodes.close_tray() | ||
|
||
|
||
class Combos(BasicEditor): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.keyboard = None | ||
|
||
self.combo_entries = [] | ||
self.combo_entries_available = [] | ||
self.tabs = CustomTabWidget() | ||
for x in range(128): | ||
entry = ComboEntryUI(x) | ||
entry.key_changed.connect(self.on_key_changed) | ||
self.combo_entries_available.append(entry) | ||
|
||
self.addWidget(self.tabs) | ||
|
||
def rebuild_ui(self): | ||
while self.tabs.count() > 0: | ||
self.tabs.removeTab(0) | ||
self.combo_entries = self.combo_entries_available[:self.keyboard.combo_count] | ||
for x, e in enumerate(self.combo_entries): | ||
self.tabs.addTab(e.widget(), str(x + 1)) | ||
for x, e in enumerate(self.combo_entries): | ||
e.load(self.keyboard.combo_get(x)) | ||
|
||
def rebuild(self, device): | ||
super().rebuild(device) | ||
if self.valid(): | ||
self.keyboard = device.keyboard | ||
self.rebuild_ui() | ||
|
||
def valid(self): | ||
return isinstance(self.device, VialKeyboard) and \ | ||
(self.device.keyboard and self.device.keyboard.vial_protocol >= 4 | ||
and self.device.keyboard.combo_count > 0) | ||
|
||
def on_key_changed(self): | ||
for x, e in enumerate(self.combo_entries): | ||
self.keyboard.combo_set(x, self.combo_entries[x].save()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from PyQt5.QtCore import pyqtSignal | ||
|
||
from any_keycode_dialog import AnyKeycodeDialog | ||
from keyboard_widget import KeyboardWidget | ||
from kle_serial import Key | ||
from tabbed_keycodes import TabbedKeycodes | ||
from util import KeycodeDisplay | ||
|
||
|
||
class KeyWidget(KeyboardWidget): | ||
|
||
changed = pyqtSignal() | ||
|
||
def __init__(self): | ||
super().__init__(None) | ||
|
||
self.padding = 1 | ||
|
||
self.keycode = 0 | ||
|
||
key = Key() | ||
key.row = key.col = 0 | ||
key.layout_index = key.layout_option = -1 | ||
self.set_keys([key], []) | ||
|
||
self.anykey.connect(self.on_anykey) | ||
|
||
def mousePressEvent(self, ev): | ||
super().mousePressEvent(ev) | ||
if self.active_key is not None: | ||
TabbedKeycodes.open_tray(self) | ||
else: | ||
TabbedKeycodes.close_tray() | ||
|
||
def mouseReleaseEvent(self, ev): | ||
ev.accept() | ||
|
||
def on_keycode_changed(self, keycode): | ||
""" Unlike set_keycode, this handles setting masked keycode inside the mask """ | ||
|
||
if self.active_mask: | ||
if keycode > 0xFF: | ||
return | ||
keycode = (self.keycode & 0xFF00) | keycode | ||
self.set_keycode(keycode) | ||
|
||
def on_anykey(self): | ||
if self.active_key is None: | ||
return | ||
dlg = AnyKeycodeDialog(self.keycode) | ||
if dlg.exec_() and dlg.value >= 0: | ||
self.set_keycode(dlg.value) | ||
|
||
def set_keycode(self, kc): | ||
if kc == self.keycode: | ||
return | ||
self.keycode = kc | ||
KeycodeDisplay.display_keycode(self.widgets[0], self.keycode) | ||
self.update() | ||
|
||
self.changed.emit() |
Oops, something went wrong.