Skip to content

Commit 215dab1

Browse files
committed
fix(gui): stabilize Tk image ownership and add tuning report seed file
Fix Tk image lifecycle issues in the base window to avoid icon/image fallback and missing-image runtime errors: - keep a persistent PhotoImage reference for window iconphoto - bind buffered PhotoImage instances to the target parent widget
1 parent d943c61 commit 215dab1

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

ardupilot_methodic_configurator/frontend_tkinter_base_window.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ def _setup_application_icon(self) -> None:
140140
# https://pythonassets.com/posts/window-icon-in-tk-tkinter/
141141
try:
142142
icon_path = ProgramSettings.application_icon_filepath()
143-
self.root.iconphoto(True, tk.PhotoImage(file=icon_path)) # noqa: FBT003
143+
self._icon_photo = tk.PhotoImage(master=self.root, file=icon_path)
144+
self.root.iconphoto(True, self._icon_photo) # noqa: FBT003
144145
except (tk.TclError, FileNotFoundError) as e:
145146
# Silently ignore icon loading errors (common in test environments)
146147
logging_error(_("Could not load application icon: %s"), e)
@@ -524,7 +525,7 @@ def put_image_in_label( # pylint: disable=too-many-locals
524525
buffer.seek(0)
525526

526527
# Create PhotoImage from buffer
527-
photo = tk.PhotoImage(data=buffer.getvalue())
528+
photo = tk.PhotoImage(master=parent, data=buffer.getvalue())
528529

529530
if is_debugging():
530531
return ttk.Label(parent) # the vscode debugger can not cope with the images

tests/test_frontend_tkinter_base_window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def test_user_sees_properly_sized_images(self, image_test_context, sample_image_
301301
mocks["open_mock"].assert_called_once_with(sample_image_file)
302302
mocks["image"].resize.assert_called_once()
303303
# Check that PhotoImage was called with data parameter (our new implementation)
304-
mocks["photo_mock"].assert_called_once_with(data=b"fake_png_data")
304+
mocks["photo_mock"].assert_called_once_with(master=parent_frame, data=b"fake_png_data")
305305

306306
def test_user_sees_fallback_when_image_unavailable(self, image_test_context, mocked_base_window) -> None:
307307
"""

0 commit comments

Comments
 (0)