[main] add funct to detect light or darkmode, unifinshed
This commit is contained in:
parent
ea49a6f4f9
commit
da06011b44
@ -1,23 +1,29 @@
|
||||
from PySide6.QtCore import QSize, Qt
|
||||
from PySide6.QtWidgets import QMainWindow, QWidget, QToolBar, QMenu, QMenuBar, QSizePolicy, QFileDialog
|
||||
from PySide6.QtWidgets import QDialog, QVBoxLayout
|
||||
from PySide6.QtGui import QKeySequence, QAction, QIcon
|
||||
from PySide6.QtGui import QKeySequence, QAction, QIcon, QPalette
|
||||
|
||||
import fixtracks.resources
|
||||
from fixtracks.widgets.centralwidget import CentralWidget
|
||||
from fixtracks.dialogs.previewdialog import PreviewDialog
|
||||
from fixtracks.utils.reader import ImageReader, DataFrameReader
|
||||
from fixtracks.dialogs.about import AboutDialog
|
||||
from fixtracks.dialogs.help import HelpDialog
|
||||
import fixtracks.resources
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
def __init__(self, darkmode):
|
||||
super().__init__()
|
||||
self.create_actions()
|
||||
self._toolbar = None
|
||||
self._top_toolbar = None
|
||||
self._side_toolbar = None
|
||||
cw = CentralWidget()
|
||||
self.setCentralWidget(cw)
|
||||
self._iconsuffix = "_dark" if darkmode else "_light"
|
||||
# cw.exit_signal.connect(self.exit_request)
|
||||
|
||||
def create_actions(self):
|
||||
self._file_open_action = QAction(QIcon(":/icons/open"), "Open", self)
|
||||
self._file_open_action = QAction(QIcon(":/icons/open" + self._iconsuffix), "Open", self)
|
||||
self._file_open_action.setStatusTip("Open nix file")
|
||||
self._file_open_action.setShortcut(QKeySequence("Ctrl+o"))
|
||||
self._file_open_action.triggered.connect(self.on_file_open)
|
||||
@ -103,7 +109,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
# settings = QSettings(info.ORGANIZATION, info.NAME)
|
||||
# tb_orientation = settings.value("app/toolbar_area", "left")
|
||||
# self.addToolBar(Qt.LeftToolBarArea if tb_orientation == "left" else Qt.TopToolBarArea, self._toolbar)
|
||||
self.addToolBar(Qt.LeftToolBarArea if tb_orientation == "left" else Qt.TopToolBarArea, self._toolbar)
|
||||
# self._toolbar.topLevelChanged.connect(self.tb_changed)
|
||||
# del settings
|
||||
|
||||
@ -123,10 +129,12 @@ class MainWindow(QMainWindow):
|
||||
dlg.exec()
|
||||
|
||||
def on_about(self, s):
|
||||
pass
|
||||
about = AboutDialog(self)
|
||||
about.show()
|
||||
|
||||
def on_help(self, s):
|
||||
pass
|
||||
help = HelpDialog(self)
|
||||
help.show()
|
||||
|
||||
# @Slot(None)
|
||||
def exit_request(self):
|
||||
|
@ -1,5 +1,10 @@
|
||||
import pathlib
|
||||
from packaging.version import Version
|
||||
|
||||
organization_name = "de.bendalab"
|
||||
application_name = "FixTracks"
|
||||
application_version = Version("0.0.1")
|
||||
|
||||
|
||||
PACKAGE_ROOT = pathlib.Path(__file__).resolve().parent.parent
|
||||
DOCS_ROOT_FILE = pathlib.PosixPath.joinpath(PACKAGE_ROOT, "fixtracks", "docs", "index.md")
|
36
main.py
36
main.py
@ -7,19 +7,37 @@ import platform
|
||||
import logging
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from PySide6.QtCore import QSettings
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtGui import QIcon, QPalette
|
||||
|
||||
from fixtracks import fixtracks, info
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG, force=True)
|
||||
|
||||
|
||||
def is_dark_mode(app: QApplication) -> bool:
|
||||
palette = app.palette()
|
||||
# Check the brightness of the window text and base colors
|
||||
text_color = palette.color(QPalette.ColorRole.WindowText)
|
||||
base_color = palette.color(QPalette.ColorRole.Base)
|
||||
|
||||
# Calculate brightness (0 for dark, 255 for bright)
|
||||
def brightness(color):
|
||||
return (color.red() * 299 + color.green() * 587 + color.blue() * 114) // 1000
|
||||
|
||||
return brightness(base_color) < brightness(text_color)
|
||||
|
||||
|
||||
# import resources # needs to be imported somewhere in the project to be picked up by qt
|
||||
|
||||
if platform.system() == "Windows":
|
||||
# from PySide6.QtWinExtras import QtWin
|
||||
myappid = f"{info.organization_name}.{info.application_version}"
|
||||
# QtWin.setCurrentProcessExplicitAppUserModelID(myappid)
|
||||
|
||||
settings = QSettings()
|
||||
width = int(settings.value("app/width", 1024))
|
||||
height = int(settings.value("app/height", 768))
|
||||
x = int(settings.value("app/pos_x", 100))
|
||||
y = int(settings.value("app/pos_y", 100))
|
||||
app = QApplication(sys.argv)
|
||||
app.setApplicationName(info.application_name)
|
||||
app.setApplicationVersion(str(info.application_version))
|
||||
@ -29,13 +47,19 @@ app.setOrganizationDomain(info.organization_name)
|
||||
# icn = QIcon(":/icons/app_icon")
|
||||
# app.setWindowIcon(icn)
|
||||
# Create a Qt widget, which will be our window.
|
||||
window = fixtracks.MainWindow()
|
||||
window = fixtracks.MainWindow(is_dark_mode())
|
||||
window.setGeometry(100, 100, 1024, 768)
|
||||
window.setWindowTitle("FixTracks")
|
||||
# window.setWindowFlags(Qt.FramelessWindowHint) # Remove window frame
|
||||
# window.setFixedSize(1024, 768)
|
||||
|
||||
window.setMinimumWidth(1024)
|
||||
window.setMinimumHeight(768)
|
||||
window.resize(width, height)
|
||||
window.move(x, y)
|
||||
window.show()
|
||||
|
||||
# Start the event loop.
|
||||
app.exec()
|
||||
pos = window.pos()
|
||||
settings.setValue("app/width", window.width())
|
||||
settings.setValue("app/height", window.height())
|
||||
settings.setValue("app/pos_x", pos.x())
|
||||
settings.setValue("app/pos_y", pos.y())
|
||||
|
Loading…
Reference in New Issue
Block a user