tap_dance: initial implementation of key selection tray
parent
cc031a5c01
commit
ec3df5bdd0
|
|
@ -0,0 +1,25 @@
|
|||
from keyboard_widget import KeyboardWidget
|
||||
from kle_serial import Key
|
||||
from tabbed_keycodes import TabbedKeycodes
|
||||
|
||||
|
||||
class KeyWidget(KeyboardWidget):
|
||||
|
||||
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], [])
|
||||
|
||||
def mousePressEvent(self, ev):
|
||||
super().mousePressEvent(ev)
|
||||
if self.active_key is not None:
|
||||
TabbedKeycodes.open_tray(self)
|
||||
else:
|
||||
TabbedKeycodes.close_tray()
|
||||
|
|
@ -4,7 +4,8 @@ from PyQt5.QtGui import QPainter, QColor, QPainterPath, QTransform, QBrush, QPol
|
|||
from PyQt5.QtWidgets import QWidget, QToolTip, QApplication
|
||||
from PyQt5.QtCore import Qt, QSize, QRect, QPointF, pyqtSignal, QEvent, QRectF
|
||||
|
||||
from constants import KEY_SIZE_RATIO, KEY_SPACING_RATIO, KEYBOARD_WIDGET_PADDING, KEYBOARD_WIDGET_MASK_PADDING, KEYBOARD_WIDGET_MASK_HEIGHT, KEY_ROUNDNESS
|
||||
from constants import KEY_SIZE_RATIO, KEY_SPACING_RATIO, KEYBOARD_WIDGET_PADDING, KEYBOARD_WIDGET_MASK_PADDING,\
|
||||
KEYBOARD_WIDGET_MASK_HEIGHT, KEY_ROUNDNESS
|
||||
|
||||
|
||||
class KeyWidget:
|
||||
|
|
@ -166,6 +167,7 @@ class KeyboardWidget(QWidget):
|
|||
|
||||
self.enabled = True
|
||||
self.scale = 1
|
||||
self.padding = KEYBOARD_WIDGET_PADDING
|
||||
|
||||
self.setMouseTracking(True)
|
||||
|
||||
|
|
@ -215,7 +217,7 @@ class KeyboardWidget(QWidget):
|
|||
|
||||
# place common widgets, that is, ones which are always displayed and require no extra transforms
|
||||
for widget in self.common_widgets:
|
||||
widget.update_position(scale_factor, -top_x + KEYBOARD_WIDGET_PADDING, -top_y + KEYBOARD_WIDGET_PADDING)
|
||||
widget.update_position(scale_factor, -top_x + self.padding, -top_y + self.padding)
|
||||
self.widgets.append(widget)
|
||||
|
||||
# top-left position for specific layout
|
||||
|
|
@ -236,7 +238,7 @@ class KeyboardWidget(QWidget):
|
|||
if opt == self.layout_editor.get_choice(idx):
|
||||
shift_x = layout_x[idx][opt] - layout_x[idx][0]
|
||||
shift_y = layout_y[idx][opt] - layout_y[idx][0]
|
||||
widget.update_position(scale_factor, -shift_x - top_x + KEYBOARD_WIDGET_PADDING, -shift_y - top_y + KEYBOARD_WIDGET_PADDING)
|
||||
widget.update_position(scale_factor, -shift_x - top_x + self.padding, -shift_y - top_y + self.padding)
|
||||
self.widgets.append(widget)
|
||||
|
||||
def update_layout(self):
|
||||
|
|
@ -255,8 +257,8 @@ class KeyboardWidget(QWidget):
|
|||
max_w = max(max_w, p.x() * self.scale)
|
||||
max_h = max(max_h, p.y() * self.scale)
|
||||
|
||||
self.width = max_w + 2 * KEYBOARD_WIDGET_PADDING
|
||||
self.height = max_h + 2 * KEYBOARD_WIDGET_PADDING
|
||||
self.width = max_w + 2 * self.padding
|
||||
self.height = max_h + 2 * self.padding
|
||||
|
||||
self.update()
|
||||
self.updateGeometry()
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from layout_editor import LayoutEditor
|
|||
from macro_recorder import MacroRecorder
|
||||
from qmk_settings import QmkSettings
|
||||
from rgb_configurator import RGBConfigurator
|
||||
from tabbed_keycodes import TabbedKeycodes
|
||||
from tap_dance import TapDance
|
||||
from unlocker import Unlocker
|
||||
from util import tr, find_vial_devices, EXAMPLE_KEYBOARDS
|
||||
|
|
@ -91,6 +92,10 @@ class MainWindow(QMainWindow):
|
|||
layout.addWidget(self.tabs)
|
||||
layout.addWidget(self.lbl_no_devices)
|
||||
layout.setAlignment(self.lbl_no_devices, Qt.AlignHCenter)
|
||||
self.popup_keycodes = TabbedKeycodes()
|
||||
TabbedKeycodes.set_tray(self.popup_keycodes)
|
||||
layout.addWidget(self.popup_keycodes)
|
||||
self.popup_keycodes.hide()
|
||||
w = QWidget()
|
||||
w.setLayout(layout)
|
||||
self.setCentralWidget(w)
|
||||
|
|
@ -343,6 +348,7 @@ class MainWindow(QMainWindow):
|
|||
msg.exec_()
|
||||
|
||||
def on_tab_changed(self, index):
|
||||
TabbedKeycodes.close_tray()
|
||||
old_tab = self.current_tab
|
||||
new_tab = None
|
||||
if index >= 0:
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class TabbedKeycodes(QTabWidget):
|
|||
super().__init__(parent)
|
||||
|
||||
self.keymap_override = None
|
||||
self.target = None
|
||||
|
||||
self.tab_basic = QScrollArea()
|
||||
self.tab_iso = QScrollArea()
|
||||
|
|
@ -116,3 +117,20 @@ class TabbedKeycodes(QTabWidget):
|
|||
label = widget.keycode.label
|
||||
widget.setStyleSheet("QPushButton {}")
|
||||
widget.setText(label.replace("&", "&&"))
|
||||
|
||||
@classmethod
|
||||
def set_tray(cls, tray):
|
||||
cls.tray = tray
|
||||
|
||||
@classmethod
|
||||
def open_tray(cls, target):
|
||||
cls.tray.show()
|
||||
if cls.tray.target is not None and cls.tray.target != target:
|
||||
cls.tray.target.deselect()
|
||||
cls.tray.target = target
|
||||
|
||||
@classmethod
|
||||
def close_tray(cls):
|
||||
if cls.tray.target is not None:
|
||||
cls.tray.target.deselect()
|
||||
cls.tray.hide()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from PyQt5 import QtCore
|
|||
from PyQt5.QtWidgets import QTabWidget, QWidget, QSizePolicy, QGridLayout, QVBoxLayout, QLabel, QLineEdit, QHBoxLayout, \
|
||||
QPushButton, QSpinBox
|
||||
|
||||
from key_widget import KeyWidget
|
||||
from util import tr
|
||||
from vial_device import VialKeyboard
|
||||
from basic_editor import BasicEditor
|
||||
|
|
@ -20,10 +21,10 @@ class TapDanceEntryUI:
|
|||
w.setLayout(self.container)
|
||||
l = QVBoxLayout()
|
||||
l.addStretch()
|
||||
l.addSpacing(100)
|
||||
l.addSpacing(10)
|
||||
l.addWidget(w)
|
||||
l.setAlignment(w, QtCore.Qt.AlignHCenter)
|
||||
l.addSpacing(100)
|
||||
l.addSpacing(10)
|
||||
lbl = QLabel("Use <code>TD({})</code> to set up this action in the keymap.".format(self.idx))
|
||||
l.addWidget(lbl)
|
||||
l.setAlignment(lbl, QtCore.Qt.AlignHCenter)
|
||||
|
|
@ -34,16 +35,17 @@ class TapDanceEntryUI:
|
|||
def populate_container(self):
|
||||
self.container.addWidget(QLabel("On tap"), 0, 0)
|
||||
self.txt_on_tap = QLineEdit()
|
||||
self.container.addWidget(self.txt_on_tap, 0, 1)
|
||||
# self.container.addWidget(self.txt_on_tap, 0, 1)
|
||||
self.container.addWidget(KeyWidget(), 0, 1)
|
||||
self.container.addWidget(QLabel("On hold"), 1, 0)
|
||||
self.txt_on_hold = QLineEdit()
|
||||
self.container.addWidget(self.txt_on_hold, 1, 1)
|
||||
self.container.addWidget(KeyWidget(), 1, 1)
|
||||
self.container.addWidget(QLabel("On double tap"), 2, 0)
|
||||
self.txt_on_double_tap = QLineEdit()
|
||||
self.container.addWidget(self.txt_on_double_tap, 2, 1)
|
||||
self.container.addWidget(KeyWidget(), 2, 1)
|
||||
self.container.addWidget(QLabel("On tap + hold"), 3, 0)
|
||||
self.txt_on_tap_hold = QLineEdit()
|
||||
self.container.addWidget(self.txt_on_tap_hold, 3, 1)
|
||||
self.container.addWidget(KeyWidget(), 3, 1)
|
||||
self.container.addWidget(QLabel("Tapping term (ms)"), 4, 0)
|
||||
self.txt_tapping_term = QSpinBox()
|
||||
self.txt_tapping_term.setMinimum(0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue