Fix log tags + SAVE_LANG bridge bug

panel_base: add _MODE_LOG_TAG map + _tag() function so Panel
registered/opened use [LAYERS], [TOOLBAR] etc. instead of [EBENEN]/[OBERLEISTE]

toolbar: _open_dossier_settings_panel now uses a custom _SettingsBridge
that actually handles SAVE_LANG -> writes lang to settings + reloads
all panels. Previously the default _SatelliteBridge only handled SAVE/CANCEL
so language switching did nothing.
This commit is contained in:
2026-06-06 13:09:54 +02:00
parent b9a2124026
commit 220a1e2bb3
2 changed files with 69 additions and 23 deletions
+45 -23
View File
@@ -24,6 +24,28 @@ _SETTINGS_PATH = os.path.expanduser(
"~/Library/Application Support/ch.gabrielevarano.Dossier/dossier_settings.json")
_MODE_LOG_TAG = {
"ebenen": "LAYERS",
"zeichnungsebenen": "DRAWING-LEVELS",
"oberleiste": "TOOLBAR",
"gestaltung": "STYLES",
"werkzeuge": "TOOLS",
"dimensionen": "DIMENSIONS",
"ausschnitte": "VIEWPORTS",
"massstab": "SCALE",
"overrides": "OVERRIDES",
"layouts": "LAYOUTS",
"elemente": "ELEMENTS",
"kamera": "CAMERA",
"layer_combinations": "LAYER-COMBINATIONS",
"dossier_settings": "DOSSIER-SETTINGS",
"project_settings": "PROJECT-SETTINGS",
}
def _tag(mode):
return _MODE_LOG_TAG.get(mode, mode.upper())
def _read_lang():
"""Liest die UI-Sprache aus dossier_settings.json. Default: 'de'."""
try:
@@ -207,7 +229,7 @@ class BaseBridge(object):
try:
data = json.loads(raw_str)
except Exception as ex:
print("[{}] JSON-Fehler: {}".format(self._mode.upper(), ex))
print("[{}] JSON-Fehler: {}".format(_tag(self._mode), ex))
return
if not isinstance(data, dict):
return
@@ -223,8 +245,8 @@ class BaseBridge(object):
self.handle(json.loads(full))
except Exception as ex:
import traceback
print("[{}] Chunk-Reassembly: {}".format(self._mode.upper(), ex))
print("[{}] Traceback:\n{}".format(self._mode.upper(), traceback.format_exc()))
print("[{}] Chunk-Reassembly: {}".format(_tag(self._mode), ex))
print("[{}] Traceback:\n{}".format(_tag(self._mode), traceback.format_exc()))
else:
self.handle(data)
@@ -327,7 +349,7 @@ def load_inline(wv, mode, params=None):
if _INLINE_TEMPLATE is None or _INLINE_TEMPLATE[0] != cur_mtime:
sig, tmpl = _build_inline_template()
if tmpl is None:
print("[{}] dist not found".format(mode.upper()))
print("[{}] dist not found".format(_tag(mode)))
return
_INLINE_TEMPLATE = (sig, tmpl)
@@ -338,7 +360,7 @@ def load_inline(wv, mode, params=None):
try:
parts.append('window.PANEL_PARAMS=' + json.dumps(params, ensure_ascii=False) + ';')
except Exception as ex:
print("[{}] PANEL_PARAMS serialize: {}".format(mode.upper(), ex))
print("[{}] PANEL_PARAMS serialize: {}".format(_tag(mode), ex))
mode_script = ''.join(parts)
html = _INLINE_TEMPLATE[1].replace(_MODE_SCRIPT_PLACEHOLDER, mode_script)
t_loadhtml = time.time()
@@ -359,10 +381,10 @@ def attach_webview(panel, bridge, mode):
try:
bridge.handle_raw(title[10:])
except Exception as ex:
print("[{}] Message-Fehler: {}".format(mode.upper(), ex))
print("[{}] Message-Fehler: {}".format(_tag(mode), ex))
finally:
try:
wv.ExecuteScript("document.title='{}';".format(mode.upper()))
wv.ExecuteScript("document.title='{}';".format(_tag(mode)))
except Exception:
pass
@@ -386,7 +408,7 @@ def attach_webview(panel, bridge, mode):
try:
load_inline(wv, mode)
except Exception as ex:
print("[{}] Inline-Fehler: {}".format(mode.upper(), ex))
print("[{}] Inline-Fehler: {}".format(_tag(mode), ex))
wv.DocumentTitleChanged += on_title
wv.DocumentLoaded += on_loaded
@@ -438,7 +460,7 @@ def open_satellite_window(mode, params=None, title=None, size=(420, 560),
if on_save is not None:
try: on_save(p)
except Exception as ex:
print("[{}] on_save: {}".format(mode.upper(), ex))
print("[{}] on_save: {}".format(_tag(mode), ex))
try: form.Close()
except Exception: pass
elif t == "CANCEL":
@@ -457,10 +479,10 @@ def open_satellite_window(mode, params=None, title=None, size=(420, 560),
try:
bridge.handle_raw(title_str[10:])
except Exception as ex:
print("[{}] Message-Fehler: {}".format(mode.upper(), ex))
print("[{}] Message-Fehler: {}".format(_tag(mode), ex))
finally:
try:
wv.ExecuteScript("document.title='{}';".format(mode.upper()))
wv.ExecuteScript("document.title='{}';".format(_tag(mode)))
except Exception:
pass
@@ -486,7 +508,7 @@ def open_satellite_window(mode, params=None, title=None, size=(420, 560),
try:
load_inline(wv, mode, params=params)
except Exception as ex:
print("[{}] Inline-Fehler: {}".format(mode.upper(), ex))
print("[{}] Inline-Fehler: {}".format(_tag(mode), ex))
return form
@@ -860,7 +882,7 @@ def register_and_open(mode, caption, guid_str, bridge_factory, icon_spec=None, m
t_reg = time.time()
plugin = find_plugin()
if plugin is None:
print("[{}] Plugin not found".format(mode.upper()))
print("[{}] Plugin not found".format(_tag(mode)))
return
try:
type_name = "DynPanel_" + mode
@@ -874,7 +896,7 @@ def register_and_open(mode, caption, guid_str, bridge_factory, icon_spec=None, m
try:
panel.MinimumSize = drawing.Size(int(min_size[0]), int(min_size[1]))
except Exception as ex:
print("[{}] MinimumSize konnte nicht set werden: {}".format(mode.upper(), ex))
print("[{}] MinimumSize konnte nicht set werden: {}".format(_tag(mode), ex))
# Auf einigen Eto-Versionen gibt es zusaetzlich Size/ClientSize
for attr in ("Size", "ClientSize"):
try:
@@ -893,7 +915,7 @@ def register_and_open(mode, caption, guid_str, bridge_factory, icon_spec=None, m
try:
icon = make_panel_icon(icon_spec[0], icon_spec[1])
except Exception as ex:
print("[{}] Icon-Erstellung uebersprungen: {}".format(mode.upper(), ex))
print("[{}] Icon-Erstellung uebersprungen: {}".format(_tag(mode), ex))
icon = None
_t_mark("icon", mode, t_icon)
registered = False
@@ -910,24 +932,24 @@ def register_and_open(mode, caption, guid_str, bridge_factory, icon_spec=None, m
registered_with_icon = with_icon
if with_icon:
print("[{}] Panel registered with icon ({})".format(
mode.upper(), type(arg).__name__))
_tag(mode), type(arg).__name__))
break
except Exception as ex:
if with_icon:
print("[{}] RegisterPanel mit Icon failed: {}".format(
mode.upper(), ex))
_tag(mode), ex))
else:
print("[{}] RegisterPanel failed: {}".format(
mode.upper(), ex))
_tag(mode), ex))
if registered and not registered_with_icon and icon is not None:
print("[{}] Panel ohne Icon registriert (Fallback)".format(mode.upper()))
print("[{}] Panel ohne Icon registriert (Fallback)".format(_tag(mode)))
if not registered:
return
sc.sticky[sticky_reg] = True
sc.sticky[sticky_guid] = System.Guid(guid_str)
print("[{}] Panel registered".format(mode.upper()))
print("[{}] Panel registered".format(_tag(mode)))
except Exception as ex:
print("[{}] Registrierung failed: {}".format(mode.upper(), ex))
print("[{}] Registrierung failed: {}".format(_tag(mode), ex))
return
_t_mark("register", mode, t_reg)
@@ -936,7 +958,7 @@ def register_and_open(mode, caption, guid_str, bridge_factory, icon_spec=None, m
guid = sc.sticky.get(sticky_guid, System.Guid(guid_str))
RhinoUI.Panels.OpenPanel(guid)
_t_mark("OpenPanel", mode, t_open)
print("[{}] Panel opened".format(mode.upper()))
print("[{}] Panel opened".format(_tag(mode)))
except Exception as ex:
print("[{}] OpenPanel failed: {}".format(mode.upper(), ex))
print("[{}] OpenPanel failed: {}".format(_tag(mode), ex))
_t_mark("register_and_open", mode, t_outer)
+24
View File
@@ -2216,6 +2216,29 @@ def _open_dossier_settings_panel():
try:
import panel_base
class _SettingsBridge(panel_base.BaseBridge):
def __init__(self):
panel_base.BaseBridge.__init__(self, "dossier_settings")
def handle(self, data):
t = data.get("type", "")
p = data.get("payload") or {}
if t == "SAVE_LANG":
lang = p.get("lang", "de")
if lang not in ("de", "en"):
lang = "de"
cfg2 = _settings_load()
cfg2["lang"] = lang
_settings_save(cfg2)
_reload_all_panel_langs()
elif t in ("CANCEL", "SAVE"):
try:
f = sc.sticky.get("_dossier_settings_form")
if f: f.Close()
except Exception: pass
sc.sticky["_dossier_settings_form"] = None
bridge = _SettingsBridge()
form = panel_base.open_satellite_window(
"dossier_settings",
params={
@@ -2224,6 +2247,7 @@ def _open_dossier_settings_panel():
},
title="Dossier-Einstellungen",
size=(340, 320),
bridge=bridge,
)
sc.sticky["_dossier_settings_form"] = form
except Exception as ex: