dark theme yay (#3)
* add basic dark theme implementation and change the layer buttons to actual pushbuttons * change default theme * add theme selection menu and persistent theme storage * add system theme option * remove redundand functions * add suggestionsmain
parent
7540ef6af9
commit
0cd150afb7
|
|
@ -1,7 +1,8 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, Qt
|
from PyQt5.QtCore import pyqtSignal, Qt
|
||||||
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout
|
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QVBoxLayout, QPushButton, QApplication
|
||||||
|
from PyQt5.QtGui import QPalette
|
||||||
|
|
||||||
from clickable_label import ClickableLabel
|
from clickable_label import ClickableLabel
|
||||||
from keyboard_widget import KeyboardWidget, EncoderWidget
|
from keyboard_widget import KeyboardWidget, EncoderWidget
|
||||||
|
|
@ -36,7 +37,7 @@ class KeyboardContainer(QWidget):
|
||||||
layout.setAlignment(self.container, Qt.AlignHCenter)
|
layout.setAlignment(self.container, Qt.AlignHCenter)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
self.layer_labels = []
|
self.layer_buttons = []
|
||||||
self.keyboard = None
|
self.keyboard = None
|
||||||
self.current_layer = 0
|
self.current_layer = 0
|
||||||
|
|
||||||
|
|
@ -46,18 +47,19 @@ class KeyboardContainer(QWidget):
|
||||||
|
|
||||||
def rebuild_layers(self):
|
def rebuild_layers(self):
|
||||||
# delete old layer labels
|
# delete old layer labels
|
||||||
for label in self.layer_labels:
|
for label in self.layer_buttons:
|
||||||
label.hide()
|
label.hide()
|
||||||
label.deleteLater()
|
label.deleteLater()
|
||||||
self.layer_labels = []
|
self.layer_buttons = []
|
||||||
|
|
||||||
# create new layer labels
|
# create new layer labels
|
||||||
for x in range(self.keyboard.layers):
|
for x in range(self.keyboard.layers):
|
||||||
label = ClickableLabel(str(x))
|
btn = QPushButton(str(x))
|
||||||
label.setAlignment(Qt.AlignCenter)
|
btn.setFixedSize(25, 25)
|
||||||
label.clicked.connect(lambda idx=x: self.switch_layer(idx))
|
btn.setCheckable(True)
|
||||||
self.layout_layers.addWidget(label)
|
btn.clicked.connect(lambda state, idx=x: self.switch_layer(idx))
|
||||||
self.layer_labels.append(label)
|
self.layout_layers.addWidget(btn)
|
||||||
|
self.layer_buttons.append(btn)
|
||||||
|
|
||||||
def rebuild(self, keyboard):
|
def rebuild(self, keyboard):
|
||||||
self.keyboard = keyboard
|
self.keyboard = keyboard
|
||||||
|
|
@ -86,9 +88,11 @@ class KeyboardContainer(QWidget):
|
||||||
|
|
||||||
self.container.update_layout()
|
self.container.update_layout()
|
||||||
|
|
||||||
for label in self.layer_labels:
|
for btn in self.layer_buttons:
|
||||||
label.setStyleSheet(LAYER_BTN_STYLE)
|
btn.setEnabled(True)
|
||||||
self.layer_labels[self.current_layer].setStyleSheet(ACTIVE_LAYER_BTN_STYLE)
|
btn.setChecked(False)
|
||||||
|
self.layer_buttons[self.current_layer].setEnabled(False)
|
||||||
|
self.layer_buttons[self.current_layer].setChecked(True)
|
||||||
|
|
||||||
for widget in self.container.widgets:
|
for widget in self.container.widgets:
|
||||||
if widget.desc.row is not None:
|
if widget.desc.row is not None:
|
||||||
|
|
@ -107,7 +111,7 @@ class KeyboardContainer(QWidget):
|
||||||
widget.setMaskText(mask_text)
|
widget.setMaskText(mask_text)
|
||||||
widget.setToolTip(tooltip)
|
widget.setToolTip(tooltip)
|
||||||
if self.code_is_overriden(code):
|
if self.code_is_overriden(code):
|
||||||
widget.setColor(Qt.blue)
|
widget.setColor(QApplication.palette().color(QPalette.Link))
|
||||||
else:
|
else:
|
||||||
widget.setColor(None)
|
widget.setColor(None)
|
||||||
self.container.update()
|
self.container.update()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from PyQt5.QtGui import QPainter, QColor, QPainterPath, QTransform, QBrush, QPolygonF
|
from PyQt5.QtGui import QPainter, QColor, QPainterPath, QTransform, QBrush, QPolygonF, QPalette
|
||||||
from PyQt5.QtWidgets import QWidget, QToolTip
|
from PyQt5.QtWidgets import QWidget, QToolTip, QApplication
|
||||||
from PyQt5.QtCore import Qt, QSize, QRect, QPointF, pyqtSignal, QEvent, QRectF
|
from PyQt5.QtCore import Qt, QSize, QRect, QPointF, pyqtSignal, QEvent, QRectF
|
||||||
|
|
||||||
from constants import KEY_WIDTH, KEY_SPACING, KEY_HEIGHT, KEYBOARD_WIDGET_PADDING, KEYBOARD_WIDGET_MASK_PADDING
|
from constants import KEY_WIDTH, KEY_SPACING, KEY_HEIGHT, KEYBOARD_WIDGET_PADDING, KEYBOARD_WIDGET_MASK_PADDING
|
||||||
|
|
@ -226,20 +226,20 @@ class KeyboardWidget(QWidget):
|
||||||
|
|
||||||
# for regular keycaps
|
# for regular keycaps
|
||||||
regular_pen = qp.pen()
|
regular_pen = qp.pen()
|
||||||
regular_pen.setColor(QColor("black"))
|
regular_pen.setColor(QApplication.palette().color(QPalette.ButtonText))
|
||||||
qp.setPen(regular_pen)
|
qp.setPen(regular_pen)
|
||||||
|
|
||||||
regular_brush = QBrush()
|
regular_brush = QBrush()
|
||||||
regular_brush.setColor(QColor("white"))
|
regular_brush.setColor(QApplication.palette().color(QPalette.Button))
|
||||||
regular_brush.setStyle(Qt.SolidPattern)
|
regular_brush.setStyle(Qt.SolidPattern)
|
||||||
qp.setBrush(regular_brush)
|
qp.setBrush(regular_brush)
|
||||||
|
|
||||||
# for currently selected keycap
|
# for currently selected keycap
|
||||||
active_pen = qp.pen()
|
active_pen = qp.pen()
|
||||||
active_pen.setColor(QColor("white"))
|
active_pen.setColor(QApplication.palette().color(QPalette.Button))
|
||||||
|
|
||||||
active_brush = QBrush()
|
active_brush = QBrush()
|
||||||
active_brush.setColor(QColor("black"))
|
active_brush.setColor(QApplication.palette().color(QPalette.ButtonText))
|
||||||
active_brush.setStyle(Qt.SolidPattern)
|
active_brush.setStyle(Qt.SolidPattern)
|
||||||
|
|
||||||
mask_font = qp.font()
|
mask_font = qp.font()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt, QSettings
|
||||||
from PyQt5.QtWidgets import QWidget, QComboBox, QToolButton, QHBoxLayout, QVBoxLayout, QMainWindow, QAction, qApp, \
|
from PyQt5.QtWidgets import QWidget, QComboBox, QToolButton, QHBoxLayout, QVBoxLayout, QMainWindow, QAction, qApp, \
|
||||||
QFileDialog, QDialog, QTabWidget, QActionGroup
|
QFileDialog, QDialog, QTabWidget, QActionGroup
|
||||||
|
|
||||||
|
|
@ -15,12 +15,17 @@ from unlocker import Unlocker
|
||||||
from util import tr, find_vial_devices
|
from util import tr, find_vial_devices
|
||||||
from vial_device import VialKeyboard
|
from vial_device import VialKeyboard
|
||||||
|
|
||||||
|
import themes
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
self.settings = QSettings("Vial", "Vial")
|
||||||
|
themes.set_theme(self.settings.value("theme"))
|
||||||
|
|
||||||
self.current_device = None
|
self.current_device = None
|
||||||
self.devices = []
|
self.devices = []
|
||||||
self.sideload_json = None
|
self.sideload_json = None
|
||||||
|
|
@ -112,6 +117,24 @@ class MainWindow(QMainWindow):
|
||||||
self.security_menu.addSeparator()
|
self.security_menu.addSeparator()
|
||||||
self.security_menu.addAction(keyboard_reset_act)
|
self.security_menu.addAction(keyboard_reset_act)
|
||||||
|
|
||||||
|
theme_set_default = QAction(tr("MenuTheme", "System"), self)
|
||||||
|
theme_set_default.triggered.connect(lambda: self.set_theme("default"))
|
||||||
|
|
||||||
|
theme_set_light = QAction(tr("MenuTheme", "Light"), self)
|
||||||
|
theme_set_light.triggered.connect(lambda: self.set_theme("light"))
|
||||||
|
|
||||||
|
theme_set_dark = QAction(tr("MenuTheme", "Dark"), self)
|
||||||
|
theme_set_dark.triggered.connect(lambda: self.set_theme("dark"))
|
||||||
|
|
||||||
|
theme_set_arc = QAction(tr("MenuTheme", "Arc"), self)
|
||||||
|
theme_set_arc.triggered.connect(lambda: self.set_theme("arc"))
|
||||||
|
|
||||||
|
self.theme_menu = self.menuBar().addMenu(tr("Menu", "Theme"))
|
||||||
|
self.theme_menu.addAction(theme_set_default)
|
||||||
|
self.theme_menu.addAction(theme_set_light)
|
||||||
|
self.theme_menu.addAction(theme_set_dark)
|
||||||
|
self.theme_menu.addAction(theme_set_arc)
|
||||||
|
|
||||||
def on_layout_load(self):
|
def on_layout_load(self):
|
||||||
dialog = QFileDialog()
|
dialog = QFileDialog()
|
||||||
dialog.setDefaultSuffix("vil")
|
dialog.setDefaultSuffix("vil")
|
||||||
|
|
@ -214,3 +237,7 @@ class MainWindow(QMainWindow):
|
||||||
|
|
||||||
def change_keyboard_layout(self, index):
|
def change_keyboard_layout(self, index):
|
||||||
self.keymap_editor.set_keymap_override(KEYMAPS[index][1])
|
self.keymap_editor.set_keymap_override(KEYMAPS[index][1])
|
||||||
|
|
||||||
|
def set_theme(self, theme):
|
||||||
|
themes.set_theme(theme)
|
||||||
|
self.settings.setValue("theme", theme)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, pyqtSignal
|
from PyQt5.QtCore import Qt, pyqtSignal
|
||||||
from PyQt5.QtWidgets import QTabWidget, QWidget, QPushButton, QScrollArea
|
from PyQt5.QtWidgets import QTabWidget, QWidget, QPushButton, QScrollArea, QApplication
|
||||||
|
from PyQt5.QtGui import QPalette
|
||||||
|
|
||||||
from constants import KEYCODE_BTN_WIDTH, KEYCODE_BTN_HEIGHT
|
from constants import KEYCODE_BTN_WIDTH, KEYCODE_BTN_HEIGHT
|
||||||
from flowlayout import FlowLayout
|
from flowlayout import FlowLayout
|
||||||
|
|
@ -93,7 +94,8 @@ class TabbedKeycodes(QTabWidget):
|
||||||
qmk_id = widget.keycode.qmk_id
|
qmk_id = widget.keycode.qmk_id
|
||||||
if qmk_id in self.keymap_override:
|
if qmk_id in self.keymap_override:
|
||||||
label = self.keymap_override[qmk_id]
|
label = self.keymap_override[qmk_id]
|
||||||
widget.setStyleSheet("QPushButton {color: blue;}")
|
highlight_color = QApplication.palette().color(QPalette.Link).getRgb()
|
||||||
|
widget.setStyleSheet("QPushButton {color: rgb"+str(highlight_color)+";}")
|
||||||
else:
|
else:
|
||||||
label = widget.keycode.label
|
label = widget.keycode.label
|
||||||
widget.setStyleSheet("QPushButton {}")
|
widget.setStyleSheet("QPushButton {}")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
from PyQt5.QtCore import Qt, QSettings
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from PyQt5.QtGui import QPalette, QColor
|
||||||
|
|
||||||
|
dark_palette = QPalette()
|
||||||
|
dark_palette.setColor(QPalette.Window, QColor(53, 53, 53))
|
||||||
|
dark_palette.setColor(QPalette.WindowText, Qt.white)
|
||||||
|
dark_palette.setColor(QPalette.Base, QColor(35, 35, 35))
|
||||||
|
dark_palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
|
||||||
|
dark_palette.setColor(QPalette.ToolTipBase, QColor(25, 25, 25))
|
||||||
|
dark_palette.setColor(QPalette.ToolTipText, Qt.white)
|
||||||
|
dark_palette.setColor(QPalette.Text, Qt.white)
|
||||||
|
dark_palette.setColor(QPalette.Button, QColor(53, 53, 53))
|
||||||
|
dark_palette.setColor(QPalette.ButtonText, Qt.white)
|
||||||
|
dark_palette.setColor(QPalette.BrightText, Qt.red)
|
||||||
|
dark_palette.setColor(QPalette.Link, QColor(247, 169, 72))
|
||||||
|
dark_palette.setColor(QPalette.Highlight, QColor(186, 186, 186))
|
||||||
|
dark_palette.setColor(QPalette.HighlightedText, QColor(35, 35, 35))
|
||||||
|
dark_palette.setColor(QPalette.Active, QPalette.Button, QColor(53, 53, 53))
|
||||||
|
dark_palette.setColor(QPalette.Disabled, QPalette.ButtonText, Qt.darkGray)
|
||||||
|
dark_palette.setColor(QPalette.Disabled, QPalette.WindowText, Qt.darkGray)
|
||||||
|
dark_palette.setColor(QPalette.Disabled, QPalette.Text, Qt.darkGray)
|
||||||
|
dark_palette.setColor(QPalette.Disabled, QPalette.Light, QColor(53, 53, 53))
|
||||||
|
|
||||||
|
arc_palette = QPalette()
|
||||||
|
arc_palette.setColor(QPalette.Window, QColor("#353945"))
|
||||||
|
arc_palette.setColor(QPalette.WindowText, QColor("#d3dae3"))
|
||||||
|
arc_palette.setColor(QPalette.Base, QColor("#353945"))
|
||||||
|
arc_palette.setColor(QPalette.AlternateBase, QColor("#404552"))
|
||||||
|
arc_palette.setColor(QPalette.ToolTipBase, QColor("#4B5162"))
|
||||||
|
arc_palette.setColor(QPalette.ToolTipText, QColor("#d3dae3"))
|
||||||
|
arc_palette.setColor(QPalette.Text, QColor("#d3dae3"))
|
||||||
|
arc_palette.setColor(QPalette.Button, QColor("#353945"))
|
||||||
|
arc_palette.setColor(QPalette.ButtonText, QColor("#d3dae3"))
|
||||||
|
arc_palette.setColor(QPalette.BrightText, QColor("#5294e2"))
|
||||||
|
arc_palette.setColor(QPalette.Link, QColor("#89b1e0"))
|
||||||
|
arc_palette.setColor(QPalette.Highlight, QColor("#5294e2"))
|
||||||
|
arc_palette.setColor(QPalette.HighlightedText, QColor("#d3dae3"))
|
||||||
|
arc_palette.setColor(QPalette.Active, QPalette.Button, QColor("#353945"))
|
||||||
|
arc_palette.setColor(QPalette.Disabled, QPalette.ButtonText, QColor("#d3dae3"))
|
||||||
|
arc_palette.setColor(QPalette.Disabled, QPalette.WindowText, QColor("#d3dae3"))
|
||||||
|
arc_palette.setColor(QPalette.Disabled, QPalette.Text, QColor("#d3dae3"))
|
||||||
|
arc_palette.setColor(QPalette.Disabled, QPalette.Light, QColor("#404552"))
|
||||||
|
|
||||||
|
|
||||||
|
def set_theme(theme):
|
||||||
|
if theme == "light":
|
||||||
|
QApplication.setPalette(QApplication.style().standardPalette())
|
||||||
|
QApplication.setStyle("Fusion")
|
||||||
|
elif theme == "dark":
|
||||||
|
QApplication.setPalette(dark_palette)
|
||||||
|
QApplication.setStyle("Fusion")
|
||||||
|
elif theme == "arc":
|
||||||
|
QApplication.setPalette(arc_palette)
|
||||||
|
QApplication.setStyle("Fusion")
|
||||||
|
else:
|
||||||
|
QApplication.setPalette(QApplication.style().standardPalette())
|
||||||
|
QApplication.setStyle(None)
|
||||||
Loading…
Reference in New Issue