mirror of
https://git.srhtnin.garden/sarah/SaraFem.git
synced 2026-10-15 10:23:17 +02:00
Shared SaraSuite settings (theme, font, title bar) with a SaraSuite settings tab
This commit is contained in:
1 parent
089dfc005f
commit
a5f5c5ca79
3 files changed
+159
-19
No files matched your search
+74
-11
@@ -9,12 +9,15 @@ from typing import Callable
|
||||
|
||||
import flet as ft
|
||||
|
||||
from Core import AppConfig, AvailableThemes, ChipButtonStyle, Palette
|
||||
from Core import (
|
||||
AppConfig, AvailableThemes, ChipButtonStyle, InstalledFontFamilies, LoadSharedSettings, Palette,
|
||||
SharedSettings,
|
||||
)
|
||||
|
||||
# Settings Browser can already hot-apply live (dotfiles, breadcrumbs, preview, tags).
|
||||
# The window title bar, sidebar (bookmarks/filetree) layout, theme, and SaraTag's
|
||||
# dynamically-loaded module need a restart to take effect.
|
||||
RestartRequiredNote = "Window title bar, Theme, Sidebar and SaraTag settings need a restart to take effect."
|
||||
RestartRequiredNote = "Window title bar, Theme, Font, Sidebar and SaraTag settings need a restart to take effect."
|
||||
|
||||
DialogWidth = 700
|
||||
DialogHeight = 520
|
||||
@@ -64,13 +67,53 @@ def BuildSettingsDialog(
|
||||
OnSave: Callable[[], None],
|
||||
OnDismiss: Callable[[], None],
|
||||
) -> ft.AlertDialog:
|
||||
ThemeDropdown = ft.Dropdown(
|
||||
value=Config.Theme,
|
||||
label="Theme (shared across SaraSuite)",
|
||||
options=[ft.DropdownOption(key=Name, text=Name) for Name in AvailableThemes()],
|
||||
)
|
||||
DotfilesSwitch = ft.Switch(label="Show dotfiles", value=Config.ShowDotfiles)
|
||||
Themes = AvailableThemes()
|
||||
Fonts = InstalledFontFamilies()
|
||||
|
||||
def ThemePicker(Value: str) -> ft.Dropdown:
|
||||
return ft.Dropdown(
|
||||
value=Value, label="Theme", options=[ft.DropdownOption(key=Name, text=Name) for Name in Themes],
|
||||
)
|
||||
|
||||
def FontPicker(Value: str) -> ft.Dropdown:
|
||||
# Installed fonts plus the bundled one; type to filter the long list.
|
||||
Names = Fonts if Value in Fonts else [Value] + Fonts
|
||||
return ft.Dropdown(
|
||||
value=Value, label="Font", editable=True, enable_filter=True, menu_height=320,
|
||||
options=[ft.DropdownOption(key=Name, text=Name) for Name in Names],
|
||||
)
|
||||
|
||||
# "SaraSuite" tab: the shared settings every SaraSuite program reads from
|
||||
# ~/.config/SaraSuite/Config.toml, and whether SaraFem follows them.
|
||||
Shared = LoadSharedSettings(Config)
|
||||
UseSharedSwitch = ft.Switch(label="SaraFem uses these shared settings", value=Config.UseSharedSettings)
|
||||
SharedThemeDropdown = ThemePicker(Shared.Theme)
|
||||
SharedFontDropdown = FontPicker(Shared.FontFamily)
|
||||
SharedTitleBarSwitch = ft.Switch(label="Hide window title bar", value=Shared.HideWindowTitleBar)
|
||||
|
||||
# SaraFem's own values ("General" tab), only used with shared settings off.
|
||||
ThemeDropdown = ThemePicker(Config.Theme)
|
||||
FontDropdown = FontPicker(Config.FontFamily)
|
||||
TitleBarSwitch = ft.Switch(label="Hide window title bar", value=Config.HideWindowTitleBar)
|
||||
OwnAppearance = ft.Column(
|
||||
[
|
||||
_SectionLabel("SaraFem's own appearance, used when shared settings are off (SaraSuite tab)"),
|
||||
ThemeDropdown,
|
||||
FontDropdown,
|
||||
TitleBarSwitch,
|
||||
],
|
||||
spacing=12,
|
||||
disabled=Config.UseSharedSettings,
|
||||
opacity=0.5 if Config.UseSharedSettings else 1,
|
||||
)
|
||||
|
||||
def OnUseSharedChanged(e) -> None:
|
||||
OwnAppearance.disabled = UseSharedSwitch.value
|
||||
OwnAppearance.opacity = 0.5 if UseSharedSwitch.value else 1
|
||||
OwnAppearance.update()
|
||||
|
||||
UseSharedSwitch.on_change = OnUseSharedChanged
|
||||
DotfilesSwitch = ft.Switch(label="Show dotfiles", value=Config.ShowDotfiles)
|
||||
BatchRenamePatternField = ft.TextField(
|
||||
value=Config.BatchRenamePattern,
|
||||
label="Batch rename pattern (~ = name, ! = counter, ^ = extension)",
|
||||
@@ -166,17 +209,30 @@ def BuildSettingsDialog(
|
||||
)
|
||||
|
||||
Categories: dict[str, ft.Control] = {
|
||||
"SaraSuite": ft.Column(
|
||||
[
|
||||
_SectionLabel("Shared by every SaraSuite program (~/.config/SaraSuite/Config.toml). "
|
||||
"Other programs pick changes up the next time they start."),
|
||||
UseSharedSwitch,
|
||||
ft.Divider(height=1, color=Palette.Surface1),
|
||||
SharedThemeDropdown,
|
||||
SharedFontDropdown,
|
||||
SharedTitleBarSwitch,
|
||||
],
|
||||
spacing=12,
|
||||
),
|
||||
"General": ft.Column(
|
||||
[
|
||||
ThemeDropdown,
|
||||
DotfilesSwitch,
|
||||
TitleBarSwitch,
|
||||
BatchRenamePatternField,
|
||||
DeleteZipSwitch,
|
||||
_SectionLabel("Default compress format"),
|
||||
ArchiveFormatPicker,
|
||||
ft.Divider(height=1, color=Palette.Surface1),
|
||||
OwnAppearance,
|
||||
],
|
||||
spacing=12,
|
||||
scroll=ft.ScrollMode.AUTO,
|
||||
),
|
||||
"Toolbar": ft.Column(
|
||||
[
|
||||
@@ -270,9 +326,16 @@ def BuildSettingsDialog(
|
||||
)
|
||||
|
||||
def DoSave(e=None) -> None:
|
||||
Config.UseSharedSettings = UseSharedSwitch.value
|
||||
Config.Theme = ThemeDropdown.value
|
||||
Config.ShowDotfiles = DotfilesSwitch.value
|
||||
Config.FontFamily = FontDropdown.value or Config.FontFamily
|
||||
Config.HideWindowTitleBar = TitleBarSwitch.value
|
||||
SharedSettings(
|
||||
Theme=SharedThemeDropdown.value,
|
||||
FontFamily=SharedFontDropdown.value or Shared.FontFamily,
|
||||
HideWindowTitleBar=SharedTitleBarSwitch.value,
|
||||
).Save()
|
||||
Config.ShowDotfiles = DotfilesSwitch.value
|
||||
Config.BatchRenamePattern = BatchRenamePatternField.value.strip() or "~!^"
|
||||
Config.DeleteZipAfterExtract = DeleteZipSwitch.value
|
||||
Config.DefaultArchiveFormat = GetArchiveFormat()
|
||||
|
||||
Reference in new issue
Block a user