mirror of
https://git.srhtnin.garden/sarah/SaraSuite.git
synced 2026-10-15 10:33:17 +02:00
Settings dialog, per-program install defaults, Options after install; Update only when needed
This commit is contained in:
1 parent
7018d57dbc
commit
08c9071b48
8 files changed
+360
-30
No files matched your search
+27
-3
@@ -6,7 +6,7 @@ from typing import Callable
|
||||
import flet as ft
|
||||
|
||||
from Core import ChipButtonStyle, Home, Palette
|
||||
from Installer import ConfigPlan, RemovalItem, RemovalPlan, Status
|
||||
from Installer import ConfigPlan, DefaultAnswers, DefaultOptions, RemovalItem, RemovalPlan, Status
|
||||
from Manifests import Program
|
||||
|
||||
_MaxListedItems = 12
|
||||
@@ -57,8 +57,12 @@ def _Dialog(Page: ft.Page, Title: str, Body: list[ft.Control], ConfirmText: str,
|
||||
|
||||
|
||||
def ShowInstallDialog(Page: ft.Page, Program: Program, OnConfirm: Callable[[dict[str, bool], dict[str, str]], None]) -> None:
|
||||
Fields = {Question.Id: ft.TextField(label=Question.Prompt, value=Question.Default) for Question in Program.Questions}
|
||||
Boxes = {Option.Id: ft.Checkbox(label=Option.Label, value=Option.Default) for Option in Program.Options}
|
||||
# Start from the user's defaults (Settings → this program's tab), which
|
||||
# fall back to the manifest's.
|
||||
Answers = DefaultAnswers(Program)
|
||||
Ticked = DefaultOptions(Program)
|
||||
Fields = {Question.Id: ft.TextField(label=Question.Prompt, value=Answers[Question.Id]) for Question in Program.Questions}
|
||||
Boxes = {Option.Id: ft.Checkbox(label=Option.Label, value=Ticked[Option.Id]) for Option in Program.Options}
|
||||
|
||||
Body: list[ft.Control] = [ft.Text(Program.Description, size=13, color=Palette.Overlay0)]
|
||||
Body += list(Fields.values())
|
||||
@@ -75,6 +79,26 @@ def ShowInstallDialog(Page: ft.Page, Program: Program, OnConfirm: Callable[[dict
|
||||
))
|
||||
|
||||
|
||||
def ShowOptionsDialog(Page: ft.Page, Program: Program, Current: Status, OnConfirm: Callable[[dict[str, bool]], None]) -> None:
|
||||
"""Change an installed program's options. Turning one off takes out what
|
||||
it placed (and puts back any file it had replaced); turning one on places it."""
|
||||
Recorded = Current.Receipt.Options if Current.Receipt else {}
|
||||
Ticked = DefaultOptions(Program)
|
||||
Boxes = {
|
||||
Option.Id: ft.Checkbox(label=Option.Label, value=bool(Recorded.get(Option.Id, Ticked[Option.Id])))
|
||||
for Option in Program.Options
|
||||
}
|
||||
Body: list[ft.Control] = list(Boxes.values())
|
||||
Body.append(ft.Text(
|
||||
"Only what these options control changes; the program stays at the version it's on.",
|
||||
size=12, color=Palette.Overlay0,
|
||||
))
|
||||
Page.show_dialog(_Dialog(
|
||||
Page, f"{Program.Name} options", Body, "Apply",
|
||||
lambda: OnConfirm({Id: bool(Box.value) for Id, Box in Boxes.items()}),
|
||||
))
|
||||
|
||||
|
||||
def ShowUpdateDialog(
|
||||
Page: ft.Page, Program: Program, Current: Status, NewVersion: str, NewCommit: str,
|
||||
Plans: list[ConfigPlan], OnConfirm: Callable[[], None],
|
||||
|
||||
Reference in new issue
Block a user