Skip to content

Commit

Permalink
Merge branch 'nicer-key-widget'
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzz committed May 14, 2022
2 parents 10105bd + 72d7367 commit c3e8be1
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 104 deletions.
18 changes: 10 additions & 8 deletions src/main/python/constants.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# SPDX-License-Identifier: GPL-2.0-or-later

KEY_SIZE_RATIO = 2.667
KEY_SPACING_RATIO = 0.267
KEY_ROUNDNESS = 9
KEY_SIZE_RATIO = 3.2
KEY_SPACING_RATIO = 0.2
KEY_ROUNDNESS = 0.08

KEYCODE_BTN_RATIO = 3.333
KEYCODE_BTN_RATIO = 3

WINDOW_WIDTH, WINDOW_HEIGHT = 1024, 768

LAYER_BTN_STYLE = "border: 1px solid black; padding: 5px"
ACTIVE_LAYER_BTN_STYLE = "border: 1px solid black; padding: 5px; background-color: black; color: white"

KEYBOARD_WIDGET_PADDING = 5
KEYBOARD_WIDGET_MASK_PADDING = 3

KEYBOARD_WIDGET_MASK_HEIGHT = 0.65
KEYBOARD_WIDGET_NONMASK_PADDING = 0.02

SHADOW_SIDE_PADDING = 0.1
SHADOW_TOP_PADDING = 0.05
SHADOW_BOTTOM_PADDING = 0.15
4 changes: 2 additions & 2 deletions src/main/python/editor/matrix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def reset_keyboard_widget(self):
# reset keyboard widget
for w in self.keyboardWidget.widgets:
w.setPressed(False)
w.setActive(False)
w.setOn(False)

self.keyboardWidget.update_layout()
self.keyboardWidget.update()
Expand Down Expand Up @@ -135,7 +135,7 @@ def matrix_poller(self):
if row < len(matrix) and col < len(matrix[row]):
w.setPressed(matrix[row][col])
if matrix[row][col]:
w.setActive(True)
w.setOn(True)

self.keyboardWidget.update_layout()
self.keyboardWidget.update()
Expand Down
55 changes: 42 additions & 13 deletions src/main/python/tabbed_keycodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,15 @@ def keycode_filter_masked(kc):
return kc < 256


class TabbedKeycodes(QTabWidget):
class FilteredTabbedKeycodes(QTabWidget):

keycode_changed = pyqtSignal(int)
anykey = pyqtSignal()

def __init__(self, parent=None):
def __init__(self, parent=None, keycode_filter=keycode_filter_any):
super().__init__(parent)

self.target = None
self.is_tray = False
self.keycode_filter = keycode_filter_any
self.keycode_filter = keycode_filter

self.tabs = [
Tab(self, "Basic", [
Expand Down Expand Up @@ -194,8 +192,7 @@ def __init__(self, parent=None):
self.currentChanged.connect(self.on_current_changed)

def on_current_changed(self):
for tab in self.tabs:
tab.select_alternative()
self.select_alternative()

def on_keycode_changed(self, code):
if code == -1:
Expand All @@ -219,6 +216,34 @@ def on_keymap_override(self):
for tab in self.tabs:
tab.relabel_buttons()

def select_alternative(self):
for tab in self.tabs:
tab.select_alternative()


class TabbedKeycodes(QWidget):

keycode_changed = pyqtSignal(int)
anykey = pyqtSignal()

def __init__(self):
super().__init__()

self.target = None
self.is_tray = False

self.layout = QVBoxLayout()

self.all_keycodes = FilteredTabbedKeycodes()
self.basic_keycodes = FilteredTabbedKeycodes(keycode_filter=keycode_filter_masked)
for opt in [self.all_keycodes, self.basic_keycodes]:
opt.keycode_changed.connect(self.keycode_changed)
opt.anykey.connect(self.anykey)
self.layout.addWidget(opt)

self.setLayout(self.layout)
self.set_keycode_filter(keycode_filter_any)

@classmethod
def set_tray(cls, tray):
cls.tray = tray
Expand Down Expand Up @@ -253,10 +278,14 @@ def on_tray_anykey(self):
if self.target is not None:
self.target.on_anykey()

def set_keycode_filter(self, keycode_filter):
if keycode_filter is None:
keycode_filter = keycode_filter_any
def recreate_keycode_buttons(self):
for opt in [self.all_keycodes, self.basic_keycodes]:
opt.recreate_keycode_buttons()

if keycode_filter != self.keycode_filter:
self.keycode_filter = keycode_filter
self.recreate_keycode_buttons()
def set_keycode_filter(self, keycode_filter):
if keycode_filter == keycode_filter_masked:
self.all_keycodes.hide()
self.basic_keycodes.show()
else:
self.all_keycodes.show()
self.basic_keycodes.hide()
8 changes: 6 additions & 2 deletions src/main/python/unlocker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-or-later

from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QProgressBar, QDialog
from PyQt5.QtGui import QPalette
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QProgressBar, QDialog, QApplication

from widgets.keyboard_widget import KeyboardWidget
from util import tr
Expand All @@ -12,6 +13,9 @@ class Unlocker(QDialog):
def __init__(self, layout_editor, keyboard):
super().__init__()

self.setStyleSheet("background-color: {}".format(
QApplication.palette().color(QPalette.Button).lighter(130).name()))

self.keyboard = keyboard

layout = QVBoxLayout()
Expand Down Expand Up @@ -50,7 +54,7 @@ def update_reference(self):
lock_keys = self.keyboard.get_unlock_keys()
for w in self.keyboard_reference.widgets:
if (w.desc.row, w.desc.col) in lock_keys:
w.setActive(True)
w.setOn(True)

self.keyboard_reference.update_layout()
self.keyboard_reference.update()
Expand Down
Loading

0 comments on commit c3e8be1

Please sign in to comment.