From e867bc36e5a4b0f1fc36e91c77d9a6930b30c199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Morais?= Date: Thu, 20 Nov 2025 12:34:52 +0100 Subject: [PATCH 1/3] FEAT: Show/hide traceback on extension raised exception --- src/ansys/aedt/core/extensions/misc.py | 55 ++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/src/ansys/aedt/core/extensions/misc.py b/src/ansys/aedt/core/extensions/misc.py index fee9cacd9f5..4d51b4c172f 100644 --- a/src/ansys/aedt/core/extensions/misc.py +++ b/src/ansys/aedt/core/extensions/misc.py @@ -36,6 +36,7 @@ import tkinter from tkinter import ttk from tkinter.messagebox import showerror +import traceback from typing import List from typing import Optional from typing import Tuple @@ -375,11 +376,52 @@ def log_message(self, message: str): def __init_root(self, title: str, withdraw: bool) -> tkinter.Tk: """Init Tk root window with error handling and icon.""" - def report_callback_exception(self, exc, val, tb): - """Custom exception showing an error message.""" - if not val: - val = "An error occurred when using the extension." - showerror("Error", message=f"{val}") + def show_error_with_details(self, exc, val, tb): + """Custom exception showing an error message with details button.""" + win = tkinter.Toplevel() + win.title("Error") + win.resizable(False, False) + win.grab_set() + + label = tkinter.Label(win, text=val, justify="left") + label.grid(row=0, column=0, columnspan=2, **DEFAULT_PADDING) + + details_frame = ttk.Frame(win) + details_shown = False + + tb_str = "".join(traceback.format_exception(exc, val, tb)) + + text = tkinter.Text(details_frame, width=80, height=20, wrap="none") + text.insert("1.0", tb_str) + text.configure(state="disabled") + text.grid(row=0, column=0, sticky="nsew") + + scrollbar = ttk.Scrollbar(details_frame, orient="vertical", command=text.yview) + scrollbar.grid(row=0, column=1, sticky="ns") + text.configure(yscrollcommand=scrollbar.set) + + details_frame.grid_columnconfigure(0, weight=1) + details_frame.grid_rowconfigure(0, weight=1) + + def toggle_details(): + nonlocal details_shown + details_shown = not details_shown + if details_shown: + details_frame.grid(row=2, column=0, columnspan=2, sticky="nsew", **DEFAULT_PADDING) + button_details.config(text="Hide Traceback") + win.resizable(True, True) + else: + details_frame.grid_remove() + button_details.config(text="Show Traceback") + win.resizable(False, False) + + button_details = ttk.Button(win, text="Show Traceback", command=toggle_details) + button_details.grid(row=1, column=0, sticky="w", **DEFAULT_PADDING) + + button_ok = ttk.Button(win, text="OK", command=win.destroy) + button_ok.grid(row=1, column=1, sticky="e", **DEFAULT_PADDING) + + details_frame.grid_remove() def report_callback_exception_withdraw(self, exc, val, tb): """Custom exception that raises the error without showing a message box.""" @@ -388,7 +430,7 @@ def report_callback_exception_withdraw(self, exc, val, tb): if withdraw: tkinter.Tk.report_callback_exception = report_callback_exception_withdraw else: - tkinter.Tk.report_callback_exception = report_callback_exception + tkinter.Tk.report_callback_exception = show_error_with_details root = tkinter.Tk() root.title(title) @@ -676,7 +718,6 @@ def check_design_type(self): def create_default_ui(title, withdraw=False): import tkinter from tkinter import ttk - from tkinter.messagebox import showerror import PIL.Image import PIL.ImageTk From 5d78d60fc7c3cdfadd0a3adf1ac506d9c413a8cf Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Thu, 20 Nov 2025 11:38:15 +0000 Subject: [PATCH 2/3] chore: adding changelog file 6909.added.md [dependabot-skip] --- doc/changelog.d/6909.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/6909.added.md diff --git a/doc/changelog.d/6909.added.md b/doc/changelog.d/6909.added.md new file mode 100644 index 00000000000..b4c4c3efea9 --- /dev/null +++ b/doc/changelog.d/6909.added.md @@ -0,0 +1 @@ +Show/hide traceback on extension raised exception From 6fa6e1141a3e7454fe6e6fc66004fb6b686f7250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Morais?= Date: Mon, 24 Nov 2025 09:33:22 +0100 Subject: [PATCH 3/3] CHORE: Disable coverage of GUI feature --- src/ansys/aedt/core/extensions/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/aedt/core/extensions/misc.py b/src/ansys/aedt/core/extensions/misc.py index 4d51b4c172f..3236a9575b0 100644 --- a/src/ansys/aedt/core/extensions/misc.py +++ b/src/ansys/aedt/core/extensions/misc.py @@ -376,7 +376,7 @@ def log_message(self, message: str): def __init_root(self, title: str, withdraw: bool) -> tkinter.Tk: """Init Tk root window with error handling and icon.""" - def show_error_with_details(self, exc, val, tb): + def show_error_with_details(self, exc, val, tb): # pragma: no cover """Custom exception showing an error message with details button.""" win = tkinter.Toplevel() win.title("Error")