tabbed_keycodes: show tap dance in the UI

main
Ilya Zhuravlev 2021-07-03 22:25:45 -04:00
parent 8381824948
commit 5bb6446155
2 changed files with 22 additions and 8 deletions

View File

@ -524,6 +524,8 @@ KEYCODES_MEDIA = [
K(132, "KC_LSCR", "Locking\nScroll", "Locking Scroll Lock", alias=["KC_LOCKING_SCROLL"]), K(132, "KC_LSCR", "Locking\nScroll", "Locking Scroll Lock", alias=["KC_LOCKING_SCROLL"]),
] ]
KEYCODES_TAP_DANCE = []
KEYCODES_USER = [] KEYCODES_USER = []
KEYCODES_MACRO = [] KEYCODES_MACRO = []
@ -544,8 +546,8 @@ def recreate_keycodes():
KEYCODES.clear() KEYCODES.clear()
KEYCODES.extend(KEYCODES_SPECIAL + KEYCODES_BASIC + KEYCODES_SHIFTED + KEYCODES_ISO + KEYCODES_LAYERS + KEYCODES.extend(KEYCODES_SPECIAL + KEYCODES_BASIC + KEYCODES_SHIFTED + KEYCODES_ISO + KEYCODES_LAYERS +
KEYCODES_QUANTUM + KEYCODES_BACKLIGHT + KEYCODES_MEDIA + KEYCODES_MACRO + KEYCODES_USER + KEYCODES_QUANTUM + KEYCODES_BACKLIGHT + KEYCODES_MEDIA + KEYCODES_TAP_DANCE + KEYCODES_MACRO +
KEYCODES_HIDDEN) KEYCODES_USER + KEYCODES_HIDDEN)
def create_user_keycodes(): def create_user_keycodes():
@ -608,6 +610,10 @@ def recreate_keyboard_keycodes(keyboard):
lbl = "M{}".format(x) lbl = "M{}".format(x)
KEYCODES_MACRO.append(Keycode(0x5F12 + x, lbl, lbl)) KEYCODES_MACRO.append(Keycode(0x5F12 + x, lbl, lbl))
for x in range(keyboard.tap_dance_count):
lbl = "TD({})".format(x)
KEYCODES_TAP_DANCE.append(Keycode(QK_TAP_DANCE | x, lbl, lbl))
# Check if custom keycodes are defined in keyboard, and if so add them to user keycodes # Check if custom keycodes are defined in keyboard, and if so add them to user keycodes
if keyboard.custom_keycodes is not None and len(keyboard.custom_keycodes) > 0: if keyboard.custom_keycodes is not None and len(keyboard.custom_keycodes) > 0:
create_custom_user_keycodes(keyboard.custom_keycodes) create_custom_user_keycodes(keyboard.custom_keycodes)

View File

@ -7,7 +7,7 @@ from PyQt5.QtGui import QPalette
from constants import KEYCODE_BTN_RATIO from constants import KEYCODE_BTN_RATIO
from flowlayout import FlowLayout from flowlayout import FlowLayout
from keycodes import KEYCODES_BASIC, KEYCODES_ISO, KEYCODES_MACRO, KEYCODES_LAYERS, KEYCODES_QUANTUM, \ from keycodes import KEYCODES_BASIC, KEYCODES_ISO, KEYCODES_MACRO, KEYCODES_LAYERS, KEYCODES_QUANTUM, \
KEYCODES_BACKLIGHT, KEYCODES_MEDIA, KEYCODES_SPECIAL, KEYCODES_SHIFTED, KEYCODES_USER, Keycode KEYCODES_BACKLIGHT, KEYCODES_MEDIA, KEYCODES_SPECIAL, KEYCODES_SHIFTED, KEYCODES_USER, Keycode, KEYCODES_TAP_DANCE
from square_button import SquareButton from square_button import SquareButton
from util import tr, KeycodeDisplay from util import tr, KeycodeDisplay
@ -29,6 +29,7 @@ class TabbedKeycodes(QTabWidget):
self.tab_quantum = QScrollArea() self.tab_quantum = QScrollArea()
self.tab_backlight = QScrollArea() self.tab_backlight = QScrollArea()
self.tab_media = QScrollArea() self.tab_media = QScrollArea()
self.tab_tap_dance = QScrollArea()
self.tab_user = QScrollArea() self.tab_user = QScrollArea()
self.tab_macro = QScrollArea() self.tab_macro = QScrollArea()
@ -41,12 +42,15 @@ class TabbedKeycodes(QTabWidget):
(self.tab_quantum, "Quantum", KEYCODES_QUANTUM), (self.tab_quantum, "Quantum", KEYCODES_QUANTUM),
(self.tab_backlight, "Backlight", KEYCODES_BACKLIGHT), (self.tab_backlight, "Backlight", KEYCODES_BACKLIGHT),
(self.tab_media, "App, Media and Mouse", KEYCODES_MEDIA), (self.tab_media, "App, Media and Mouse", KEYCODES_MEDIA),
(self.tab_tap_dance, "Tap Dance", KEYCODES_TAP_DANCE),
(self.tab_user, "User", KEYCODES_USER), (self.tab_user, "User", KEYCODES_USER),
(self.tab_macro, "Macro", KEYCODES_MACRO), (self.tab_macro, "Macro", KEYCODES_MACRO),
]: ]:
layout = FlowLayout() layout = FlowLayout()
if tab == self.tab_layers: if tab == self.tab_layers:
self.layout_layers = layout self.layout_layers = layout
elif tab == self.tab_tap_dance:
self.layout_tap_dance = layout
elif tab == self.tab_macro: elif tab == self.tab_macro:
self.layout_macro = layout self.layout_macro = layout
elif tab == self.tab_user: elif tab == self.tab_user:
@ -71,16 +75,17 @@ class TabbedKeycodes(QTabWidget):
self.addTab(tab, tr("TabbedKeycodes", label)) self.addTab(tab, tr("TabbedKeycodes", label))
self.layer_keycode_buttons = [] self.layer_keycode_buttons = []
self.tap_dance_keycode_buttons = []
self.macro_keycode_buttons = [] self.macro_keycode_buttons = []
self.user_keycode_buttons = [] self.user_keycode_buttons = []
KeycodeDisplay.notify_keymap_override(self) KeycodeDisplay.notify_keymap_override(self)
def create_buttons(self, layout, keycodes, wordWrap = False): def create_buttons(self, layout, keycodes, word_wrap=False):
buttons = [] buttons = []
for keycode in keycodes: for keycode in keycodes:
btn = SquareButton() btn = SquareButton()
btn.setWordWrap(wordWrap) btn.setWordWrap(word_wrap)
btn.setRelSize(KEYCODE_BTN_RATIO) btn.setRelSize(KEYCODE_BTN_RATIO)
btn.setToolTip(Keycode.tooltip(keycode.code)) btn.setToolTip(Keycode.tooltip(keycode.code))
btn.clicked.connect(lambda st, k=keycode: self.keycode_changed.emit(k.code)) btn.clicked.connect(lambda st, k=keycode: self.keycode_changed.emit(k.code))
@ -91,14 +96,17 @@ class TabbedKeycodes(QTabWidget):
return buttons return buttons
def recreate_keycode_buttons(self): def recreate_keycode_buttons(self):
for btn in self.layer_keycode_buttons + self.macro_keycode_buttons + self.user_keycode_buttons: for btn in self.layer_keycode_buttons + self.tap_dance_keycode_buttons + self.macro_keycode_buttons \
+ self.user_keycode_buttons:
self.widgets.remove(btn) self.widgets.remove(btn)
btn.hide() btn.hide()
btn.deleteLater() btn.deleteLater()
self.layer_keycode_buttons = self.create_buttons(self.layout_layers, KEYCODES_LAYERS) self.layer_keycode_buttons = self.create_buttons(self.layout_layers, KEYCODES_LAYERS)
self.tap_dance_keycode_buttons = self.create_buttons(self.layout_tap_dance, KEYCODES_TAP_DANCE)
self.macro_keycode_buttons = self.create_buttons(self.layout_macro, KEYCODES_MACRO) self.macro_keycode_buttons = self.create_buttons(self.layout_macro, KEYCODES_MACRO)
self.user_keycode_buttons = self.create_buttons(self.layout_user, KEYCODES_USER, wordWrap=True) self.user_keycode_buttons = self.create_buttons(self.layout_user, KEYCODES_USER, word_wrap=True)
self.widgets += self.layer_keycode_buttons + self.macro_keycode_buttons + self.user_keycode_buttons self.widgets += self.layer_keycode_buttons + self.tap_dance_keycode_buttons + \
self.macro_keycode_buttons + self.user_keycode_buttons
self.relabel_buttons() self.relabel_buttons()
def on_keymap_override(self): def on_keymap_override(self):