Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzz committed Jul 18, 2021
2 parents 69cf96f + 6bb4fa0 commit 642aaf0
Show file tree
Hide file tree
Showing 18 changed files with 1,284 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/build/settings/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"app_name": "Vial",
"author": "xyz",
"main_module": "src/main/python/main.py",
"version": "0.0.0"
"version": "0.4"
}
118 changes: 118 additions & 0 deletions src/main/python/combos.py
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())
2 changes: 2 additions & 0 deletions src/main/python/firmware_flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ def rebuild(self, device):

if isinstance(self.device, VialBootloader):
self.log("Valid Vial Bootloader device at {}".format(self.device.desc["path"].decode("utf-8")))
self.chk_restore_keymap.hide()
elif isinstance(self.device, VialKeyboard):
self.log("Vial keyboard detected")
self.chk_restore_keymap.show()

def valid(self):
return isinstance(self.device, VialBootloader) or\
Expand Down
61 changes: 61 additions & 0 deletions src/main/python/key_widget.py
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()
Loading

0 comments on commit 642aaf0

Please sign in to comment.