isolate logic for square ui buttons and fix layer selector

main
Jared Beller 2021-01-12 20:03:38 -05:00
parent 8cf5957b26
commit dc63304827
No known key found for this signature in database
GPG Key ID: 044B207F4820E3AE
4 changed files with 26 additions and 11 deletions

View File

@ -3,7 +3,7 @@
KEY_SIZE_RATIO = 2.667
KEY_SPACING_RATIO = 0.267
KEYCODE_BTN_RATIO = 3
KEYCODE_BTN_RATIO = 3.333
WINDOW_WIDTH, WINDOW_HEIGHT = 1024, 768

View File

@ -9,6 +9,7 @@ from keyboard_widget import KeyboardWidget, EncoderWidget
from keycodes import keycode_label, keycode_tooltip, keycode_is_mask, find_keycode
from constants import LAYER_BTN_STYLE, ACTIVE_LAYER_BTN_STYLE
from keymaps import KEYMAPS
from square_button import SquareButton
from util import tr
@ -54,8 +55,8 @@ class KeyboardContainer(QWidget):
# create new layer labels
for x in range(self.keyboard.layers):
btn = QPushButton(str(x))
btn.setFixedSize(25, 25)
btn = SquareButton(str(x))
btn.setRelSize(1.667)
btn.setCheckable(True)
btn.clicked.connect(lambda state, idx=x: self.switch_layer(idx))
self.layout_layers.addWidget(btn)

View File

@ -0,0 +1,19 @@
# SPDX-License-Identifier: GPL-2.0-or-later
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QPushButton
class SquareButton(QPushButton):
def __init__(self, parent=None):
super().__init__(parent)
self.scale = 1.2
def setRelSize(self, ratio):
self.scale = ratio
self.updateGeometry()
def sizeHint(self):
size = int(round(self.fontMetrics().height() * self.scale))
return QSize(size, size)

View File

@ -9,6 +9,7 @@ from flowlayout import FlowLayout
from keycodes import keycode_tooltip, KEYCODES_BASIC, KEYCODES_ISO, KEYCODES_MACRO, KEYCODES_LAYERS, KEYCODES_QUANTUM, \
KEYCODES_BACKLIGHT, KEYCODES_MEDIA, KEYCODES_SPECIAL
from keymaps import KEYMAPS
from square_button import SquareButton
from util import tr
@ -65,7 +66,8 @@ class TabbedKeycodes(QTabWidget):
buttons = []
for keycode in keycodes:
btn = KeycodeButton()
btn = SquareButton()
btn.setRelSize(KEYCODE_BTN_RATIO)
btn.setToolTip(keycode_tooltip(keycode.code))
btn.clicked.connect(lambda st, k=keycode: self.keycode_changed.emit(k.code))
btn.keycode = keycode
@ -99,10 +101,3 @@ class TabbedKeycodes(QTabWidget):
label = widget.keycode.label
widget.setStyleSheet("QPushButton {}")
widget.setText(label.replace("&", "&&"))
class KeycodeButton(QPushButton):
def sizeHint(self):
size = KEYCODE_BTN_RATIO * self.fontMetrics().height()
return QSize(size, size)