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:
+45
-23
@@ -24,6 +24,28 @@ _SETTINGS_PATH = os.path.expanduser(
|
|||||||
"~/Library/Application Support/ch.gabrielevarano.Dossier/dossier_settings.json")
|
"~/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():
|
def _read_lang():
|
||||||
"""Liest die UI-Sprache aus dossier_settings.json. Default: 'de'."""
|
"""Liest die UI-Sprache aus dossier_settings.json. Default: 'de'."""
|
||||||
try:
|
try:
|
||||||
@@ -207,7 +229,7 @@ class BaseBridge(object):
|
|||||||
try:
|
try:
|
||||||
data = json.loads(raw_str)
|
data = json.loads(raw_str)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] JSON-Fehler: {}".format(self._mode.upper(), ex))
|
print("[{}] JSON-Fehler: {}".format(_tag(self._mode), ex))
|
||||||
return
|
return
|
||||||
if not isinstance(data, dict):
|
if not isinstance(data, dict):
|
||||||
return
|
return
|
||||||
@@ -223,8 +245,8 @@ class BaseBridge(object):
|
|||||||
self.handle(json.loads(full))
|
self.handle(json.loads(full))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
import traceback
|
import traceback
|
||||||
print("[{}] Chunk-Reassembly: {}".format(self._mode.upper(), ex))
|
print("[{}] Chunk-Reassembly: {}".format(_tag(self._mode), ex))
|
||||||
print("[{}] Traceback:\n{}".format(self._mode.upper(), traceback.format_exc()))
|
print("[{}] Traceback:\n{}".format(_tag(self._mode), traceback.format_exc()))
|
||||||
else:
|
else:
|
||||||
self.handle(data)
|
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:
|
if _INLINE_TEMPLATE is None or _INLINE_TEMPLATE[0] != cur_mtime:
|
||||||
sig, tmpl = _build_inline_template()
|
sig, tmpl = _build_inline_template()
|
||||||
if tmpl is None:
|
if tmpl is None:
|
||||||
print("[{}] dist not found".format(mode.upper()))
|
print("[{}] dist not found".format(_tag(mode)))
|
||||||
return
|
return
|
||||||
_INLINE_TEMPLATE = (sig, tmpl)
|
_INLINE_TEMPLATE = (sig, tmpl)
|
||||||
|
|
||||||
@@ -338,7 +360,7 @@ def load_inline(wv, mode, params=None):
|
|||||||
try:
|
try:
|
||||||
parts.append('window.PANEL_PARAMS=' + json.dumps(params, ensure_ascii=False) + ';')
|
parts.append('window.PANEL_PARAMS=' + json.dumps(params, ensure_ascii=False) + ';')
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] PANEL_PARAMS serialize: {}".format(mode.upper(), ex))
|
print("[{}] PANEL_PARAMS serialize: {}".format(_tag(mode), ex))
|
||||||
mode_script = ''.join(parts)
|
mode_script = ''.join(parts)
|
||||||
html = _INLINE_TEMPLATE[1].replace(_MODE_SCRIPT_PLACEHOLDER, mode_script)
|
html = _INLINE_TEMPLATE[1].replace(_MODE_SCRIPT_PLACEHOLDER, mode_script)
|
||||||
t_loadhtml = time.time()
|
t_loadhtml = time.time()
|
||||||
@@ -359,10 +381,10 @@ def attach_webview(panel, bridge, mode):
|
|||||||
try:
|
try:
|
||||||
bridge.handle_raw(title[10:])
|
bridge.handle_raw(title[10:])
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] Message-Fehler: {}".format(mode.upper(), ex))
|
print("[{}] Message-Fehler: {}".format(_tag(mode), ex))
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
wv.ExecuteScript("document.title='{}';".format(mode.upper()))
|
wv.ExecuteScript("document.title='{}';".format(_tag(mode)))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -386,7 +408,7 @@ def attach_webview(panel, bridge, mode):
|
|||||||
try:
|
try:
|
||||||
load_inline(wv, mode)
|
load_inline(wv, mode)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] Inline-Fehler: {}".format(mode.upper(), ex))
|
print("[{}] Inline-Fehler: {}".format(_tag(mode), ex))
|
||||||
|
|
||||||
wv.DocumentTitleChanged += on_title
|
wv.DocumentTitleChanged += on_title
|
||||||
wv.DocumentLoaded += on_loaded
|
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:
|
if on_save is not None:
|
||||||
try: on_save(p)
|
try: on_save(p)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] on_save: {}".format(mode.upper(), ex))
|
print("[{}] on_save: {}".format(_tag(mode), ex))
|
||||||
try: form.Close()
|
try: form.Close()
|
||||||
except Exception: pass
|
except Exception: pass
|
||||||
elif t == "CANCEL":
|
elif t == "CANCEL":
|
||||||
@@ -457,10 +479,10 @@ def open_satellite_window(mode, params=None, title=None, size=(420, 560),
|
|||||||
try:
|
try:
|
||||||
bridge.handle_raw(title_str[10:])
|
bridge.handle_raw(title_str[10:])
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] Message-Fehler: {}".format(mode.upper(), ex))
|
print("[{}] Message-Fehler: {}".format(_tag(mode), ex))
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
wv.ExecuteScript("document.title='{}';".format(mode.upper()))
|
wv.ExecuteScript("document.title='{}';".format(_tag(mode)))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -486,7 +508,7 @@ def open_satellite_window(mode, params=None, title=None, size=(420, 560),
|
|||||||
try:
|
try:
|
||||||
load_inline(wv, mode, params=params)
|
load_inline(wv, mode, params=params)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] Inline-Fehler: {}".format(mode.upper(), ex))
|
print("[{}] Inline-Fehler: {}".format(_tag(mode), ex))
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
@@ -860,7 +882,7 @@ def register_and_open(mode, caption, guid_str, bridge_factory, icon_spec=None, m
|
|||||||
t_reg = time.time()
|
t_reg = time.time()
|
||||||
plugin = find_plugin()
|
plugin = find_plugin()
|
||||||
if plugin is None:
|
if plugin is None:
|
||||||
print("[{}] Plugin not found".format(mode.upper()))
|
print("[{}] Plugin not found".format(_tag(mode)))
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
type_name = "DynPanel_" + mode
|
type_name = "DynPanel_" + mode
|
||||||
@@ -874,7 +896,7 @@ def register_and_open(mode, caption, guid_str, bridge_factory, icon_spec=None, m
|
|||||||
try:
|
try:
|
||||||
panel.MinimumSize = drawing.Size(int(min_size[0]), int(min_size[1]))
|
panel.MinimumSize = drawing.Size(int(min_size[0]), int(min_size[1]))
|
||||||
except Exception as ex:
|
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
|
# Auf einigen Eto-Versionen gibt es zusaetzlich Size/ClientSize
|
||||||
for attr in ("Size", "ClientSize"):
|
for attr in ("Size", "ClientSize"):
|
||||||
try:
|
try:
|
||||||
@@ -893,7 +915,7 @@ def register_and_open(mode, caption, guid_str, bridge_factory, icon_spec=None, m
|
|||||||
try:
|
try:
|
||||||
icon = make_panel_icon(icon_spec[0], icon_spec[1])
|
icon = make_panel_icon(icon_spec[0], icon_spec[1])
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] Icon-Erstellung uebersprungen: {}".format(mode.upper(), ex))
|
print("[{}] Icon-Erstellung uebersprungen: {}".format(_tag(mode), ex))
|
||||||
icon = None
|
icon = None
|
||||||
_t_mark("icon", mode, t_icon)
|
_t_mark("icon", mode, t_icon)
|
||||||
registered = False
|
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
|
registered_with_icon = with_icon
|
||||||
if with_icon:
|
if with_icon:
|
||||||
print("[{}] Panel registered with icon ({})".format(
|
print("[{}] Panel registered with icon ({})".format(
|
||||||
mode.upper(), type(arg).__name__))
|
_tag(mode), type(arg).__name__))
|
||||||
break
|
break
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
if with_icon:
|
if with_icon:
|
||||||
print("[{}] RegisterPanel mit Icon failed: {}".format(
|
print("[{}] RegisterPanel mit Icon failed: {}".format(
|
||||||
mode.upper(), ex))
|
_tag(mode), ex))
|
||||||
else:
|
else:
|
||||||
print("[{}] RegisterPanel failed: {}".format(
|
print("[{}] RegisterPanel failed: {}".format(
|
||||||
mode.upper(), ex))
|
_tag(mode), ex))
|
||||||
if registered and not registered_with_icon and icon is not None:
|
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:
|
if not registered:
|
||||||
return
|
return
|
||||||
sc.sticky[sticky_reg] = True
|
sc.sticky[sticky_reg] = True
|
||||||
sc.sticky[sticky_guid] = System.Guid(guid_str)
|
sc.sticky[sticky_guid] = System.Guid(guid_str)
|
||||||
print("[{}] Panel registered".format(mode.upper()))
|
print("[{}] Panel registered".format(_tag(mode)))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("[{}] Registrierung failed: {}".format(mode.upper(), ex))
|
print("[{}] Registrierung failed: {}".format(_tag(mode), ex))
|
||||||
return
|
return
|
||||||
_t_mark("register", mode, t_reg)
|
_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))
|
guid = sc.sticky.get(sticky_guid, System.Guid(guid_str))
|
||||||
RhinoUI.Panels.OpenPanel(guid)
|
RhinoUI.Panels.OpenPanel(guid)
|
||||||
_t_mark("OpenPanel", mode, t_open)
|
_t_mark("OpenPanel", mode, t_open)
|
||||||
print("[{}] Panel opened".format(mode.upper()))
|
print("[{}] Panel opened".format(_tag(mode)))
|
||||||
except Exception as ex:
|
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)
|
_t_mark("register_and_open", mode, t_outer)
|
||||||
|
|||||||
@@ -2216,6 +2216,29 @@ def _open_dossier_settings_panel():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import panel_base
|
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(
|
form = panel_base.open_satellite_window(
|
||||||
"dossier_settings",
|
"dossier_settings",
|
||||||
params={
|
params={
|
||||||
@@ -2224,6 +2247,7 @@ def _open_dossier_settings_panel():
|
|||||||
},
|
},
|
||||||
title="Dossier-Einstellungen",
|
title="Dossier-Einstellungen",
|
||||||
size=(340, 320),
|
size=(340, 320),
|
||||||
|
bridge=bridge,
|
||||||
)
|
)
|
||||||
sc.sticky["_dossier_settings_form"] = form
|
sc.sticky["_dossier_settings_form"] = form
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|||||||
Reference in New Issue
Block a user