mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-06-10 14:51:54 +02:00
[ui] add palette variation for dark theme
Crtl+Shift+P allows to toggle between light and dark theme on the fly
This commit is contained in:
parent
b8edf07e8d
commit
83c6d68954
3 changed files with 65 additions and 5 deletions
|
@ -1,8 +1,8 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PySide2.QtCore import Qt
|
from PySide2.QtCore import Qt, QObject, Slot
|
||||||
from PySide2.QtGui import QGuiApplication
|
from PySide2.QtGui import QGuiApplication, QPalette, QColor, QIcon
|
||||||
|
|
||||||
from meshroom.ui.reconstruction import Reconstruction
|
from meshroom.ui.reconstruction import Reconstruction
|
||||||
from meshroom.ui.utils import QmlInstantEngine
|
from meshroom.ui.utils import QmlInstantEngine
|
||||||
|
@ -10,10 +10,60 @@ from meshroom.ui.utils import QmlInstantEngine
|
||||||
from meshroom.ui import components
|
from meshroom.ui import components
|
||||||
|
|
||||||
|
|
||||||
|
class PaletteManager(QObject):
|
||||||
|
|
||||||
|
def __init__(self, qmlEngine, parent=None):
|
||||||
|
super(PaletteManager, self).__init__(parent)
|
||||||
|
self.qmlEngine = qmlEngine
|
||||||
|
darkPalette = QPalette()
|
||||||
|
window = QColor(50, 52, 55)
|
||||||
|
text = QColor(200, 200, 200)
|
||||||
|
disabledText = text.darker(170)
|
||||||
|
base = window.darker(150)
|
||||||
|
button = window.lighter(115)
|
||||||
|
dark = window.darker(170)
|
||||||
|
|
||||||
|
darkPalette.setColor(QPalette.Window, window)
|
||||||
|
darkPalette.setColor(QPalette.WindowText, text)
|
||||||
|
darkPalette.setColor(QPalette.Disabled, QPalette.WindowText, disabledText)
|
||||||
|
darkPalette.setColor(QPalette.Base, base)
|
||||||
|
darkPalette.setColor(QPalette.AlternateBase, QColor(46, 47, 48))
|
||||||
|
darkPalette.setColor(QPalette.ToolTipBase, base)
|
||||||
|
darkPalette.setColor(QPalette.ToolTipText, text)
|
||||||
|
darkPalette.setColor(QPalette.Text, text)
|
||||||
|
darkPalette.setColor(QPalette.Disabled, QPalette.Text, disabledText)
|
||||||
|
darkPalette.setColor(QPalette.Button, button)
|
||||||
|
darkPalette.setColor(QPalette.ButtonText, text)
|
||||||
|
darkPalette.setColor(QPalette.Disabled, QPalette.ButtonText, disabledText)
|
||||||
|
|
||||||
|
darkPalette.setColor(QPalette.Mid, button.lighter(120))
|
||||||
|
darkPalette.setColor(QPalette.Highlight, QColor(42, 130, 218))
|
||||||
|
darkPalette.setColor(QPalette.Disabled, QPalette.Highlight, QColor(80, 80, 80))
|
||||||
|
darkPalette.setColor(QPalette.HighlightedText, Qt.white)
|
||||||
|
darkPalette.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(127, 127, 127))
|
||||||
|
darkPalette.setColor(QPalette.Shadow, Qt.black)
|
||||||
|
|
||||||
|
self.darkPalette = darkPalette
|
||||||
|
self.defaultPalette = QGuiApplication.instance().palette()
|
||||||
|
self.togglePalette()
|
||||||
|
|
||||||
|
@Slot()
|
||||||
|
def togglePalette(self):
|
||||||
|
app = QGuiApplication.instance()
|
||||||
|
if app.palette() == self.darkPalette:
|
||||||
|
app.setPalette(self.defaultPalette)
|
||||||
|
else:
|
||||||
|
app.setPalette(self.darkPalette)
|
||||||
|
if self.qmlEngine.rootObjects():
|
||||||
|
self.qmlEngine.reload()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QGuiApplication([sys.argv[0], '-style', 'fusion'] + sys.argv[1:]) # force Fusion style as default
|
app = QGuiApplication([sys.argv[0], '-style', 'fusion'] + sys.argv[1:]) # force Fusion style as default
|
||||||
app.setAttribute(Qt.AA_EnableHighDpiScaling)
|
app.setAttribute(Qt.AA_EnableHighDpiScaling)
|
||||||
qmlDir = os.path.join(os.path.dirname(__file__), "qml")
|
|
||||||
|
pwd = os.path.dirname(__file__)
|
||||||
|
qmlDir = os.path.join(pwd, "qml")
|
||||||
url = os.path.join(qmlDir, "main.qml")
|
url = os.path.join(qmlDir, "main.qml")
|
||||||
engine = QmlInstantEngine()
|
engine = QmlInstantEngine()
|
||||||
engine.addFilesFromDirectory(qmlDir)
|
engine.addFilesFromDirectory(qmlDir)
|
||||||
|
@ -22,10 +72,13 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
r = Reconstruction(parent=app)
|
r = Reconstruction(parent=app)
|
||||||
engine.rootContext().setContextProperty("_reconstruction", r)
|
engine.rootContext().setContextProperty("_reconstruction", r)
|
||||||
|
pm = PaletteManager(engine, parent=app)
|
||||||
|
engine.rootContext().setContextProperty("_PaletteManager", pm)
|
||||||
|
|
||||||
# Request any potential computation to stop on exit
|
# Request any potential computation to stop on exit
|
||||||
app.aboutToQuit.connect(r.stopExecution)
|
app.aboutToQuit.connect(r.stopExecution)
|
||||||
|
|
||||||
engine.load(os.path.normpath(url))
|
engine.load(os.path.normpath(url))
|
||||||
|
|
||||||
app.exec_()
|
app.exec_()
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,10 @@ ApplicationWindow {
|
||||||
onTriggered: _reconstruction.undoStack.redo()
|
onTriggered: _reconstruction.undoStack.redo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Action {
|
||||||
|
shortcut: "Ctrl+Shift+P"
|
||||||
|
onTriggered: _PaletteManager.togglePalette()
|
||||||
|
}
|
||||||
header: MenuBar {
|
header: MenuBar {
|
||||||
Menu {
|
Menu {
|
||||||
title: "File"
|
title: "File"
|
||||||
|
|
|
@ -175,8 +175,11 @@ class QmlInstantEngine(QQmlApplicationEngine):
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
cptTry += 1
|
cptTry += 1
|
||||||
|
|
||||||
print("Reloading ", self._sourceFile)
|
self.reload()
|
||||||
self.load(self._sourceFile)
|
|
||||||
|
|
||||||
# Finally, read the modified file to the watch system
|
# Finally, read the modified file to the watch system
|
||||||
self.addFile(filepath)
|
self.addFile(filepath)
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
print("Reloading ", self._sourceFile)
|
||||||
|
self.load(self._sourceFile)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue