Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/example_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
19 changes: 19 additions & 0 deletions typstwriter/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from qtpy import QtCore
from qtpy import QtWidgets

import qt_themes

from typstwriter import util

from typstwriter import logging
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion typstwriter/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions typstwriter/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions typstwriter/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ 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)
self.editor_zoom_menu.addAction(actions.font_size_dn)
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)
Expand Down