Add dark/light toggle button to sidebar
This commit is contained in:
+38
-17
@@ -30,7 +30,7 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from time import time
|
||||
|
||||
from PyQt6.QtCore import Qt, QTimer, pyqtSlot
|
||||
from PyQt6.QtCore import QEvent, Qt, QTimer, pyqtSlot
|
||||
from PyQt6.QtGui import QCloseEvent, QCursor, QIcon, QShortcut
|
||||
from PyQt6.QtWidgets import (
|
||||
QApplication, QFileDialog, QHBoxLayout, QMainWindow, QMessageBox,
|
||||
@@ -902,10 +902,46 @@ class GuiMain(QMainWindow):
|
||||
|
||||
return not self.splitView.isVisible()
|
||||
|
||||
def checkThemeUpdate(self) -> None:
|
||||
"""Load theme if mode changed."""
|
||||
if SHARED.theme.loadTheme():
|
||||
self.refreshThemeColors(syntax=True)
|
||||
self.docEditor.initEditor()
|
||||
self.docViewer.initViewer()
|
||||
return
|
||||
|
||||
def refreshThemeColors(self, syntax: bool) -> None:
|
||||
"""Refresh the GUI theme."""
|
||||
SHARED.theme.loadTheme()
|
||||
self.setPalette(QApplication.palette())
|
||||
self.docEditor.updateTheme()
|
||||
self.docViewer.updateTheme()
|
||||
self.docViewerPanel.updateTheme()
|
||||
self.sideBar.updateTheme()
|
||||
self.projView.updateTheme()
|
||||
self.novelView.updateTheme()
|
||||
self.projSearch.updateTheme()
|
||||
self.outlineView.updateTheme()
|
||||
self.itemDetails.updateTheme()
|
||||
self.mainStatus.updateTheme()
|
||||
SHARED.project.tree.refreshAllItems()
|
||||
|
||||
if syntax:
|
||||
self.docEditor.updateSyntaxColors()
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Events
|
||||
##
|
||||
|
||||
def changeEvent(self, event: QEvent) -> None:
|
||||
"""Capture application change events."""
|
||||
if int(event.type()) == 210:
|
||||
# ThemeChange
|
||||
self.checkThemeUpdate()
|
||||
return
|
||||
|
||||
def closeEvent(self, event: QCloseEvent) -> None:
|
||||
"""Capture the closing event of the GUI and call the close
|
||||
function to handle all the close process steps.
|
||||
@@ -1054,22 +1090,7 @@ class GuiMain(QMainWindow):
|
||||
self.novelView.refreshCurrentTree()
|
||||
|
||||
if theme:
|
||||
SHARED.theme.loadTheme()
|
||||
self.setPalette(QApplication.palette())
|
||||
self.docEditor.updateTheme()
|
||||
self.docViewer.updateTheme()
|
||||
self.docViewerPanel.updateTheme()
|
||||
self.sideBar.updateTheme()
|
||||
self.projView.updateTheme()
|
||||
self.novelView.updateTheme()
|
||||
self.projSearch.updateTheme()
|
||||
self.outlineView.updateTheme()
|
||||
self.itemDetails.updateTheme()
|
||||
self.mainStatus.updateTheme()
|
||||
SHARED.project.tree.refreshAllItems()
|
||||
|
||||
if syntax:
|
||||
self.docEditor.updateSyntaxColors()
|
||||
self.refreshThemeColors(syntax=syntax)
|
||||
|
||||
self.docEditor.initEditor()
|
||||
self.docViewer.initViewer()
|
||||
|
||||
Reference in New Issue
Block a user