diff --git a/.gitignore b/.gitignore index 75595ae8..4f84b351 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ .settings/org.eclipse.core.resources.prefs .vscode .vimrc +desktop.ini ExportTest Notes.t2t dist diff --git a/manuskript/main.py b/manuskript/main.py index 3f36d553..5f5bd682 100644 --- a/manuskript/main.py +++ b/manuskript/main.py @@ -13,6 +13,7 @@ from manuskript.functions import appPath, writablePath from manuskript.version import getVersion +from manuskript.ui import themes try: faulthandler.enable() @@ -56,6 +57,14 @@ def prepare(arguments, tests=False): style = settings.value("applicationStyle") app.setStyle(style) + # Set palette from QSettings + app.setPalette(themes.light) # Start off with light theme + if settings.contains("applicationPalette"): + palette = settings.value("applicationPalette") + if hasattr(themes, palette): + # If settings has valid theme name, use requested + app.setPalette(getattr(themes, palette)) + # Translation process appTranslator = QTranslator(app) diff --git a/manuskript/settingsWindow.py b/manuskript/settingsWindow.py index 3e3311d0..d3b17896 100644 --- a/manuskript/settingsWindow.py +++ b/manuskript/settingsWindow.py @@ -23,8 +23,7 @@ from manuskript.ui.settings_ui import Ui_Settings from manuskript.ui.views.outlineView import outlineView from manuskript.ui.views.textEditView import textEditView -from manuskript.ui.welcome import welcome -from manuskript.ui import style as S +from manuskript.ui import style as S, themes as T class settingsWindow(QWidget, Ui_Settings): @@ -60,16 +59,31 @@ def __init__(self, mainWindow): self.lstMenu.setMinimumWidth(140) lowerKeys = [i.lower() for i in list(QStyleFactory.keys())] + palettes = [T.light, T.dark] + paletteNames = [qApp.translate("Palette", "Light Theme"), qApp.translate("Palette", "Dark Theme")] # General self.cmbStyle.addItems(list(QStyleFactory.keys())) + self.cmbPalette.addItems(paletteNames) try: self.cmbStyle.setCurrentIndex(lowerKeys.index(qApp.style().objectName())) except ValueError: self.cmbStyle.setCurrentIndex(0) + try: + self.cmbPalette.setCurrentIndex(palettes.index(qApp.palette())) + except ValueError: + self.cmbPalette.setCurrentIndex(0) + + def _setPaletteByName(paletteName: str): + try: + qApp.setPalette(palettes[paletteNames.index(paletteName)]) + except ValueError: + return + self.cmbStyle.currentIndexChanged[str].connect(self.setStyle) + self.cmbPalette.currentIndexChanged[str].connect(_setPaletteByName) self.cmbTranslation.clear() tr = OrderedDict() diff --git a/manuskript/ui/settings_ui.py b/manuskript/ui/settings_ui.py index a8d77808..b6db735c 100644 --- a/manuskript/ui/settings_ui.py +++ b/manuskript/ui/settings_ui.py @@ -88,25 +88,37 @@ def setupUi(self, Settings): font.setBold(False) self.label_57.setFont(font) self.label_57.setObjectName("label_57") - self.formLayout_14.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_57) + self.formLayout_14.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_57) self.cmbTranslation = QtWidgets.QComboBox(self.groupBox_2) font = QtGui.QFont() font.setBold(False) self.cmbTranslation.setFont(font) self.cmbTranslation.setObjectName("cmbTranslation") - self.formLayout_14.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.cmbTranslation) + self.formLayout_14.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.cmbTranslation) self.label_58 = QtWidgets.QLabel(self.groupBox_2) font = QtGui.QFont() font.setBold(False) self.label_58.setFont(font) self.label_58.setObjectName("label_58") - self.formLayout_14.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_58) + self.formLayout_14.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_58) self.spnGeneralFontSize = QtWidgets.QSpinBox(self.groupBox_2) font = QtGui.QFont() font.setBold(False) self.spnGeneralFontSize.setFont(font) self.spnGeneralFontSize.setObjectName("spnGeneralFontSize") - self.formLayout_14.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.spnGeneralFontSize) + self.formLayout_14.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.spnGeneralFontSize) + self.cmbPalette = QtWidgets.QComboBox(self.groupBox_2) + font = QtGui.QFont() + font.setBold(False) + self.cmbPalette.setFont(font) + self.cmbPalette.setObjectName("cmbPalette") + self.formLayout_14.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.cmbPalette) + self.label_59 = QtWidgets.QLabel(self.groupBox_2) + font = QtGui.QFont() + font.setBold(False) + self.label_59.setFont(font) + self.label_59.setObjectName("label_59") + self.formLayout_14.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_59) self.horizontalLayout_12.addLayout(self.formLayout_14) self.formLayout_15 = QtWidgets.QFormLayout() self.formLayout_15.setObjectName("formLayout_15") @@ -1785,6 +1797,7 @@ def retranslateUi(self, Settings): self.label_56.setText(_translate("Settings", "Style:")) self.label_57.setText(_translate("Settings", "Language:")) self.label_58.setText(_translate("Settings", "Font size:")) + self.label_59.setText(_translate("Settings", "Palette:")) self.chkProgressChars.setText(_translate("Settings", "Show progress in chars next\n" " to words")) self.groupBox_10.setTitle(_translate("Settings", "Loading")) diff --git a/manuskript/ui/settings_ui.ui b/manuskript/ui/settings_ui.ui index 0cc0576d..6ac51bfe 100644 --- a/manuskript/ui/settings_ui.ui +++ b/manuskript/ui/settings_ui.ui @@ -145,7 +145,7 @@ - + @@ -157,7 +157,7 @@ - + @@ -166,7 +166,7 @@ - + @@ -178,7 +178,7 @@ - + @@ -187,6 +187,27 @@ + + + + + false + + + + + + + + + false + + + + Palette: + + + diff --git a/manuskript/ui/themes/__init__.py b/manuskript/ui/themes/__init__.py new file mode 100644 index 00000000..e91f2661 --- /dev/null +++ b/manuskript/ui/themes/__init__.py @@ -0,0 +1,2 @@ +from .dark import palette as dark +from .light import palette as light \ No newline at end of file diff --git a/manuskript/ui/themes/dark.py b/manuskript/ui/themes/dark.py new file mode 100644 index 00000000..a4f1a518 --- /dev/null +++ b/manuskript/ui/themes/dark.py @@ -0,0 +1,23 @@ +from PyQt5.QtGui import QColor, QPalette + +__all__ = ("colors", "palette") + +colors = { + QPalette.Window: QColor(53, 53, 53), + QPalette.WindowText: QColor("white"), + QPalette.Base: QColor(25, 25, 25), + QPalette.AlternateBase: QColor(53, 53, 53), + QPalette.ToolTipBase: QColor("white"), + QPalette.ToolTipText: QColor("white"), + QPalette.Text: QColor("white"), + QPalette.Button: QColor(53, 53, 53), + QPalette.ButtonText: QColor("white"), + QPalette.BrightText: QColor("red"), + QPalette.Link: QColor(42, 130, 218), + QPalette.Highlight: QColor(42, 130, 218), + QPalette.HighlightedText: QColor("black"), +} + +palette = QPalette() +for key, val in colors.items(): + palette.setColor(key, val) \ No newline at end of file diff --git a/manuskript/ui/themes/light.py b/manuskript/ui/themes/light.py new file mode 100644 index 00000000..e08ded86 --- /dev/null +++ b/manuskript/ui/themes/light.py @@ -0,0 +1,23 @@ +from PyQt5.QtGui import QColor, QPalette + +__all__ = ("colors", "palette") + +colors = { + QPalette.Window: QColor("#f2f2f2"), + QPalette.WindowText: QColor("black"), + QPalette.Base: QColor("white"), + QPalette.AlternateBase: QColor(202, 202, 202), + QPalette.ToolTipBase: QColor("black"), + QPalette.ToolTipText: QColor("black"), + QPalette.Text: QColor("black"), + QPalette.Button: QColor(202, 202, 202), + QPalette.ButtonText: QColor("black"), + QPalette.BrightText: QColor("red"), + QPalette.Link: QColor(42, 130, 218), + QPalette.Highlight: QColor(42, 130, 218), + QPalette.HighlightedText: QColor("white"), +} + +palette = QPalette() +for key, val in colors.items(): + palette.setColor(key, val) \ No newline at end of file