From bc4e28d3f77adc7e1399e172d70783f43b98928c Mon Sep 17 00:00:00 2001 From: Arda Aydin Date: Tue, 6 Oct 2026 21:14:30 +0300 Subject: [PATCH] Palette: reopen the last chosen kit instead of starting empty The chosen kit is remembered in editor.properties [Palette]; a file without it opens on its first kit. Saving preferences now keeps the other sections. Co-Authored-By: Claude Opus 5.5 --- app_state.py | 38 ++++++++++++++++++++++++++++++++++++-- main.py | 12 +++++++++--- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/app_state.py b/app_state.py index 65c510e..5d39cb0 100644 --- a/app_state.py +++ b/app_state.py @@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it. import configparser import os -VERSION = "0.0.0.153" +VERSION = "0.0.0.154" PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties") DEFAULT_GRID_SIZE = 10 DEFAULT_ADD_TIMESTAMP = True @@ -148,8 +148,15 @@ def load_preferences(): def save_preferences(): - """Writes the current preference values back to editor.properties.""" + """Writes the current preference values back to editor.properties. + + The file is read first so the sections other code owns ([Device], [Palette]) survive. + """ config = configparser.ConfigParser() + try: + config.read(PROPERTIES_FILE) + except Exception: + pass config["Editor"] = { "sedona.home": SEDONA_HOME, "grid_size": str(GRID_SIZE), @@ -162,6 +169,32 @@ def save_preferences(): config.write(configfile) +def load_last_palette_kit(): + """The kit the palette dropdown showed last, or "" when none was ever chosen.""" + config = configparser.ConfigParser() + try: + config.read(PROPERTIES_FILE) + return config.get("Palette", "kit", fallback="").strip() + except Exception: + return "" + + +def save_last_palette_kit(kit_name): + """Remembers the palette's kit so the next start, or a kit refresh, reopens it.""" + global LAST_PALETTE_KIT + LAST_PALETTE_KIT = kit_name + config = configparser.ConfigParser() + try: + config.read(PROPERTIES_FILE) + if "Palette" not in config: + config["Palette"] = {} + config["Palette"]["kit"] = kit_name + with open(PROPERTIES_FILE, "w") as configfile: + config.write(configfile) + except Exception: + pass + + def base_window_title(): """The window title with no file context, which handlers extend with their own suffix.""" return f"Sedona SAX Offline Program Editor [v{VERSION}]" @@ -221,3 +254,4 @@ def base_window_title_live(): SEDONA_HOME, GRID_SIZE, ADD_TIMESTAMP, BOX_WIDTH, LEFT_PANE_WIDTH, TRACE_DASP = load_preferences() +LAST_PALETTE_KIT = load_last_palette_kit() diff --git a/main.py b/main.py index d24acc7..7be3b21 100644 --- a/main.py +++ b/main.py @@ -2980,6 +2980,8 @@ def populate_palette_types(event=None): return kit_name = palette_kit_names[index] + if event is not None and kit_name != app_state.LAST_PALETTE_KIT: + app_state.save_last_palette_kit(kit_name) types = palette.list_component_types(kit_name) for type_name, base in types: @@ -3024,9 +3026,13 @@ def refresh_palette_kits(): palette_kit_var.set("") return - palette_status.config(text=f"{len(palette_kit_names)} kits") - palette_kit_var.set("") - fit_tree_column(palette_tree) + # Reopen the kit chosen last so the palette is never left empty; a file without that + # kit opens on its first kit instead, without forgetting the remembered one. + if app_state.LAST_PALETTE_KIT in palette_kit_names: + palette_kit_combo.current(palette_kit_names.index(app_state.LAST_PALETTE_KIT)) + else: + palette_kit_combo.current(0) + populate_palette_types()