2020-10-14 02:39:59 -04:00
|
|
|
from fbs_runtime.application_context.PyQt5 import ApplicationContext
|
|
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
|
from PyQt5.QtWidgets import QWidget, QTabWidget, QVBoxLayout, QPushButton, QLabel
|
|
|
|
|
|
|
|
|
|
import sys
|
2020-10-14 12:56:25 -04:00
|
|
|
import json
|
2020-10-14 02:39:59 -04:00
|
|
|
|
|
|
|
|
from flowlayout import FlowLayout
|
2020-10-14 12:56:25 -04:00
|
|
|
from util import tr
|
|
|
|
|
from kle_serial import Serial as KleSerial
|
2020-10-14 02:39:59 -04:00
|
|
|
|
|
|
|
|
class TabbedKeycodes(QTabWidget):
|
|
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
super().__init__(parent)
|
|
|
|
|
self.tab_basic = QWidget()
|
|
|
|
|
layout = FlowLayout()
|
|
|
|
|
|
2020-10-14 12:56:25 -04:00
|
|
|
for lbl in ["", "hello", "Esc", "A", "B", "C", "D", "E", "F"]:
|
2020-10-14 02:39:59 -04:00
|
|
|
btn = QPushButton(lbl)
|
|
|
|
|
btn.setFixedSize(50, 50)
|
|
|
|
|
layout.addWidget(btn)
|
|
|
|
|
self.tab_basic.setLayout(layout)
|
|
|
|
|
|
|
|
|
|
self.tab_media = QWidget()
|
|
|
|
|
self.tab_macro = QWidget()
|
|
|
|
|
|
2020-10-14 12:56:25 -04:00
|
|
|
self.addTab(self.tab_basic, tr("TabbedKeycodes", "Basic"))
|
|
|
|
|
self.addTab(self.tab_media, tr("TabbedKeycodes", "Media"))
|
|
|
|
|
self.addTab(self.tab_macro, tr("TabbedKeycodes", "Macro"))
|
2020-10-14 02:39:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
KEY_WIDTH = 40
|
|
|
|
|
KEY_HEIGHT = KEY_WIDTH
|
2020-10-14 12:56:25 -04:00
|
|
|
KEY_SPACING = 4
|
2020-10-14 02:39:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class KeyboardContainer(QWidget):
|
|
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
super().__init__(parent)
|
|
|
|
|
|
2020-10-14 12:56:25 -04:00
|
|
|
serial = KleSerial()
|
|
|
|
|
data = open("g60.json", "r").read()
|
|
|
|
|
data = json.loads(data)
|
|
|
|
|
kb = serial.deserialize(data["layouts"]["keymap"])
|
2020-10-14 02:39:59 -04:00
|
|
|
|
2020-10-14 12:56:25 -04:00
|
|
|
max_w = max_h = 0
|
|
|
|
|
|
|
|
|
|
for key in kb.keys:
|
|
|
|
|
widget = QLabel(str(key.labels[0]))
|
2020-10-14 02:39:59 -04:00
|
|
|
widget.setParent(self)
|
2020-10-14 12:56:25 -04:00
|
|
|
widget.setStyleSheet('background-color:white; border: 1px solid black')
|
2020-10-14 02:39:59 -04:00
|
|
|
widget.setAlignment(Qt.AlignCenter)
|
2020-10-14 12:56:25 -04:00
|
|
|
|
|
|
|
|
x = (KEY_WIDTH + KEY_SPACING) * key.x
|
|
|
|
|
y = (KEY_HEIGHT + KEY_SPACING) * key.y
|
|
|
|
|
w = (KEY_WIDTH + KEY_SPACING) * key.width - KEY_SPACING
|
|
|
|
|
h = (KEY_HEIGHT + KEY_SPACING) * key.height - KEY_SPACING
|
|
|
|
|
|
|
|
|
|
widget.setFixedSize(w, h)
|
|
|
|
|
widget.move(x, y)
|
|
|
|
|
print("{} {}x{}+{}x{}".format(key.labels, key.x, key.y, key.width, key.height))
|
|
|
|
|
|
|
|
|
|
max_w = max(max_w, x + w)
|
|
|
|
|
max_h = max(max_h, y + h)
|
2020-10-14 02:39:59 -04:00
|
|
|
|
2020-10-14 12:56:25 -04:00
|
|
|
self.setFixedSize(max_w, max_h)
|
2020-10-14 02:39:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindow(QWidget):
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
|
|
self.keyboard_container = KeyboardContainer()
|
|
|
|
|
|
|
|
|
|
self.tabbed_keycodes = TabbedKeycodes()
|
|
|
|
|
|
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
|
layout.addWidget(self.keyboard_container)
|
2020-10-14 12:56:25 -04:00
|
|
|
layout.setAlignment(self.keyboard_container, Qt.AlignHCenter)
|
2020-10-14 02:39:59 -04:00
|
|
|
layout.addWidget(self.tabbed_keycodes)
|
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
appctxt = ApplicationContext() # 1. Instantiate ApplicationContext
|
|
|
|
|
window = MainWindow()
|
|
|
|
|
window.resize(1024, 768)
|
|
|
|
|
window.show()
|
|
|
|
|
exit_code = appctxt.app.exec_() # 2. Invoke appctxt.app.exec_()
|
|
|
|
|
sys.exit(exit_code)
|