diff options
| author | historia <historiavg@proton.me> | 2026-08-24 18:57:09 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-24 18:57:09 -0400 |
| commit | 0522e73b68291af62e43c387ab8f9b8ffa2cab47 (patch) | |
| tree | 1800168c1ed5de7540624265945faba8251a7cab /app/ui/tui.py | |
| parent | d950fc8e64ee508334e608f6045d687d73a464be (diff) | |
| download | tts-audiobook-generator-0522e73b68291af62e43c387ab8f9b8ffa2cab47.tar.gz | |
feat: configure [backend] loads existing backend config rather than just overwriting it
Diffstat (limited to 'app/ui/tui.py')
| -rw-r--r-- | app/ui/tui.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/app/ui/tui.py b/app/ui/tui.py index 83ec43d..95130cf 100644 --- a/app/ui/tui.py +++ b/app/ui/tui.py @@ -1113,7 +1113,8 @@ def browse_directory(scr, title: str, def checkbox_tree(scr, title: str, families: List[dict], footer: Optional[str] = None, expand_all: bool = False, - back_value: object = None) -> List[Tuple[int, str]]: + back_value: object = None, + checked: Optional[set] = None) -> List[Tuple[int, str]]: """Pick model families and packages from an expandable tree. FAMILIES is a list of dicts (one per family) shaped like:: @@ -1134,9 +1135,12 @@ def checkbox_tree(scr, title: str, families: List[dict], cursor. Enter returns the flat list of (family_index, option_key) pairs for every checked option, in tree order; at least one checked option is required. Nothing is checked by default, and with - EXPAND_ALL every family starts expanded. A "[recommended]" tag is - shown only when a - family has more than one option — a single option needs no tag. + EXPAND_ALL every family starts expanded. CHECKED (a set of + (family_index, option_key) pairs) pre-checks those options instead, + expanding every family that holds a checked option and placing the + cursor on the first such family — the "modify an existing config" + entry point. A "[recommended]" tag is shown only when a family has + more than one option — a single option needs no tag. Family and option rows are left-justified like a DOS list. Esc (or 'q') aborts the wizard unless BACK_VALUE is given (not None), in which case either key returns it so the caller can fall back a @@ -1148,9 +1152,14 @@ def checkbox_tree(scr, title: str, families: List[dict], "Enter = accept Esc = cancel") frame = Frame(scr, title, footer) expanded = {index for index in range(len(families))} if expand_all else set() - checked = set() # (family_index, option_key) + checked = set(checked or ()) # (family_index, option_key) - expanded.add(0) + if checked: + for index, _option_key in checked: + expanded.add(index) + expanded.add(0) + else: + expanded.add(0) def family_checked(index: int) -> bool: return any(pair[0] == index for pair in checked) @@ -1170,9 +1179,17 @@ def checkbox_tree(scr, title: str, families: List[dict], nodes.append(("option", index, option["key"])) return nodes + first_checked = min((index for index, _option_key in checked), + default=None) cursor = 0 while True: nodes = visible_nodes() + if first_checked is not None: + for position, node in enumerate(nodes): + if node[0] == "family" and node[1] == first_checked: + cursor = position + break + first_checked = None cursor = max(0, min(cursor, len(nodes) - 1)) frame.rows = [] for node in nodes: |
