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 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 21:14:30 +03:00
co-authored by Claude Opus 5.5
parent b63655462f
commit bc4e28d3f7
2 changed files with 45 additions and 5 deletions
+36 -2
View File
@@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it.
import configparser import configparser
import os 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") PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties")
DEFAULT_GRID_SIZE = 10 DEFAULT_GRID_SIZE = 10
DEFAULT_ADD_TIMESTAMP = True DEFAULT_ADD_TIMESTAMP = True
@@ -148,8 +148,15 @@ def load_preferences():
def save_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() config = configparser.ConfigParser()
try:
config.read(PROPERTIES_FILE)
except Exception:
pass
config["Editor"] = { config["Editor"] = {
"sedona.home": SEDONA_HOME, "sedona.home": SEDONA_HOME,
"grid_size": str(GRID_SIZE), "grid_size": str(GRID_SIZE),
@@ -162,6 +169,32 @@ def save_preferences():
config.write(configfile) 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(): def base_window_title():
"""The window title with no file context, which handlers extend with their own suffix.""" """The window title with no file context, which handlers extend with their own suffix."""
return f"Sedona SAX Offline Program Editor [v{VERSION}]" 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() SEDONA_HOME, GRID_SIZE, ADD_TIMESTAMP, BOX_WIDTH, LEFT_PANE_WIDTH, TRACE_DASP = load_preferences()
LAST_PALETTE_KIT = load_last_palette_kit()
+9 -3
View File
@@ -2980,6 +2980,8 @@ def populate_palette_types(event=None):
return return
kit_name = palette_kit_names[index] 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) types = palette.list_component_types(kit_name)
for type_name, base in types: for type_name, base in types:
@@ -3024,9 +3026,13 @@ def refresh_palette_kits():
palette_kit_var.set("") palette_kit_var.set("")
return return
palette_status.config(text=f"{len(palette_kit_names)} kits") # Reopen the kit chosen last so the palette is never left empty; a file without that
palette_kit_var.set("") # kit opens on its first kit instead, without forgetting the remembered one.
fit_tree_column(palette_tree) 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()