67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
|
|
# coding:utf-8
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
from PySide6.QtCore import Qt, QLocale, QTranslator
|
||
|
|
from PySide6.QtGui import QIcon, QColor
|
||
|
|
from PySide6.QtWidgets import QApplication, QHBoxLayout
|
||
|
|
|
||
|
|
from qframelesswindow import FramelessWindow, StandardTitleBar
|
||
|
|
from qfluentwidgets import isDarkTheme, FluentTranslator
|
||
|
|
from setting_interface import SettingInterface
|
||
|
|
from config import cfg, Language
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
class Window(FramelessWindow):
|
||
|
|
|
||
|
|
def __init__(self, parent=None):
|
||
|
|
super().__init__(parent=parent)
|
||
|
|
self.setTitleBar(StandardTitleBar(self))
|
||
|
|
|
||
|
|
self.hBoxLayout = QHBoxLayout(self)
|
||
|
|
self.settingInterface = SettingInterface(self)
|
||
|
|
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
|
||
|
|
self.hBoxLayout.addWidget(self.settingInterface)
|
||
|
|
|
||
|
|
self.setWindowIcon(QIcon(":/qfluentwidgets/images/logo.png"))
|
||
|
|
self.setWindowTitle("PySide6-Fluent-Widgets")
|
||
|
|
|
||
|
|
self.resize(1080, 784)
|
||
|
|
desktop = QApplication.primaryScreen().size()
|
||
|
|
w, h = desktop.width(), desktop.height()
|
||
|
|
self.move(w//2 - self.width()//2, h//2 - self.height()//2)
|
||
|
|
|
||
|
|
self.titleBar.raise_()
|
||
|
|
|
||
|
|
self.setQss()
|
||
|
|
cfg.themeChanged.connect(self.setQss)
|
||
|
|
|
||
|
|
def setQss(self):
|
||
|
|
theme = 'dark' if isDarkTheme() else 'light'
|
||
|
|
with open(f'resource/qss/{theme}/demo.qss', encoding='utf-8') as f:
|
||
|
|
self.setStyleSheet(f.read())
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
# enable dpi scale
|
||
|
|
if cfg.get(cfg.dpiScale) != "Auto":
|
||
|
|
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0"
|
||
|
|
os.environ["QT_SCALE_FACTOR"] = str(cfg.get(cfg.dpiScale))
|
||
|
|
|
||
|
|
app = QApplication(sys.argv)
|
||
|
|
app.setAttribute(Qt.ApplicationAttribute.AA_DontCreateNativeWidgetSiblings)
|
||
|
|
|
||
|
|
# internationalization
|
||
|
|
locale = cfg.get(cfg.language).value
|
||
|
|
fluentTranslator = FluentTranslator(locale)
|
||
|
|
settingTranslator = QTranslator()
|
||
|
|
settingTranslator.load(locale, "settings", ".", "resource/i18n")
|
||
|
|
|
||
|
|
app.installTranslator(fluentTranslator)
|
||
|
|
app.installTranslator(settingTranslator)
|
||
|
|
|
||
|
|
# create main window
|
||
|
|
w = Window()
|
||
|
|
w.show()
|
||
|
|
app.exec()
|