diff --git a/docs/example_config.ini b/docs/example_config.ini index 246ab35..e19bbfa 100644 --- a/docs/example_config.ini +++ b/docs/example_config.ini @@ -5,6 +5,9 @@ working_directory = ~/Documents/typst_projects/ # working_directory = . # Resume last session on startup resume_last_session = True +# The default application theme +# It can be default, one_dark_two, catppuccin_macchiato, modern_light, github_light, blender, dracula, nord, catppuccin_latte, catppuccin_mocha, catppuccin_frappe, modern_dark, github_dark, monokai, atom_one +theme = default [Compiler] # The name of the Typst compiler on your system (in almost all cases simply typst) diff --git a/pyproject.toml b/pyproject.toml index d4947e6..5941b74 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,8 @@ dependencies = [ "qtpy >= 2.3", "pyside6 >= 6.4.0", "pygments >= 2.18", -"platformdirs >= 4.0" +"platformdirs >= 4.0", +"qt-themes >= 0.3.0" ] dynamic = ["version"] diff --git a/typstwriter/actions.py b/typstwriter/actions.py index ade13bf..2be6cb6 100644 --- a/typstwriter/actions.py +++ b/typstwriter/actions.py @@ -2,6 +2,8 @@ from qtpy import QtCore from qtpy import QtWidgets +import qt_themes + from typstwriter import util from typstwriter import logging @@ -117,6 +119,23 @@ def __init__(self, parent): self.layout.addAction(self.layout_editorL) self.layout.addAction(self.layout_editorR) + self.themes = QtWidgets.QActionGroup(self) + theme = QtWidgets.QAction(self) + theme.setData(None) + theme.setText("System Default") + theme.setCheckable(True) + theme.setChecked(True) + theme.triggered.connect(lambda: qt_themes.set_theme(None)) + self.themes.addAction(theme) + + for t in sorted(qt_themes.get_themes().keys()): + theme = QtWidgets.QAction(self) + theme.setData(t) + theme.setText(t.replace("_", " ").title()) + theme.setCheckable(True) + theme.triggered.connect(lambda s, t=t: qt_themes.set_theme(t)) + self.themes.addAction(theme) + self.show_fs_explorer = QtWidgets.QAction(self) self.show_fs_explorer.setText("Show FS Explorer") self.show_fs_explorer.setCheckable(True) diff --git a/typstwriter/configuration.py b/typstwriter/configuration.py index da84404..0c199a8 100644 --- a/typstwriter/configuration.py +++ b/typstwriter/configuration.py @@ -19,7 +19,8 @@ "./typstwriter.ini"] # fmt: skip default_config = {"General": {"working_directory": "~/", - "resume_last_session": False}, + "resume_last_session": False, + "theme": "default"}, "Compiler": {"name": "typst", "mode": "on_demand"}, "Editor": {"font_size": 10, diff --git a/typstwriter/mainwindow.py b/typstwriter/mainwindow.py index e062443..59efe03 100644 --- a/typstwriter/mainwindow.py +++ b/typstwriter/mainwindow.py @@ -162,6 +162,9 @@ def __init__(self): # Use default layout self.use_default_layout() + # Use default theme + self.use_default_theme() + # Load last session if config.get("General", "resume_last_session", "bool"): self.load_session() @@ -224,6 +227,13 @@ def use_default_layout(self): self.splitter.setSizes([1e6, 1e6]) + def use_default_theme(self): + """Apply theme set in the config.""" + default_theme = config.get("General", "theme") + for theme in self.actions.themes.actions(): + if theme.data() == default_theme: + theme.trigger() + def set_fs_explorer_visibility(self, visibility): """Set the visibility of the fs explplorer.""" self.FSdock.setVisible(visibility) diff --git a/typstwriter/menubar.py b/typstwriter/menubar.py index 0145562..1e57a02 100644 --- a/typstwriter/menubar.py +++ b/typstwriter/menubar.py @@ -60,6 +60,10 @@ def __init__(self, actions): self.layout_menu.setTitle("Layout") self.layout_menu.addActions(actions.layout.actions()) + self.theme_menu = QtWidgets.QMenu(self) + self.theme_menu.setTitle("Theme") + self.theme_menu.addActions(actions.themes.actions()) + self.editor_zoom_menu = QtWidgets.QMenu(self) self.editor_zoom_menu.setTitle("Editor Zoom") self.editor_zoom_menu.addAction(actions.font_size_up) @@ -67,6 +71,7 @@ def __init__(self, actions): self.editor_zoom_menu.addAction(actions.font_size_reset) self.menuView.addMenu(self.layout_menu) + self.menuView.addMenu(self.theme_menu) self.menuView.addSeparator() self.menuView.addAction(actions.show_fs_explorer) self.menuView.addAction(actions.show_compiler_options)