Skip to content

Commit 0862e98

Browse files
committed
fix(ui): center FC init progress bar on active screen on Windows
On Windows, a withdrawn tk.Tk() root can report winfo_width() > 1, causing ProgressWindow to use parent-relative centering instead of screen centering. This placed the "Initializing Flight Controller" progress bar in the top-left corner instead of screen center. Added winfo_viewable() check alongside the existing winfo_width() check to reliably detect withdrawn parent windows on all platforms. Added test to verify screen centering is used when parent is withdrawn. Signed-off-by: Yash Goel <yashhzd@users.noreply.github.com>
1 parent 1eb515a commit 0862e98

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

ardupilot_methodic_configurator/frontend_tkinter_progress_window.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen
6363
self.progress_window.deiconify() # needs to be done before centering, but it does flicker :(
6464

6565
# Center the progress window on screen or on parent
66-
# Use screen centering if parent is a minimal temp root (like in FlightControllerConnectionProgress)
67-
if isinstance(self.parent, tk.Tk) and self.parent.winfo_width() <= 1:
66+
# Use screen centering if parent is not viewable (e.g., withdrawn temp root on Windows can report winfo_width() > 1)
67+
if isinstance(self.parent, tk.Tk) and (self.parent.winfo_width() <= 1 or not self.parent.winfo_viewable()):
6868
BaseWindow.center_window_on_screen(self.progress_window)
6969
else:
7070
BaseWindow.center_window(self.progress_window, self.parent)
@@ -100,8 +100,8 @@ def update_progress_bar(self, current_value: int, max_value: int) -> None:
100100
if self.only_show_when_update_progress_called and not self._shown:
101101
self.progress_window.deiconify()
102102
# Re-center the window when it's first shown
103-
# Use screen centering if parent is a minimal temp root
104-
if isinstance(self.parent, tk.Tk) and self.parent.winfo_width() <= 1:
103+
# On Windows, withdrawn parents can report winfo_width() > 1, so also check winfo_viewable()
104+
if isinstance(self.parent, tk.Tk) and (self.parent.winfo_width() <= 1 or not self.parent.winfo_viewable()):
105105
BaseWindow.center_window_on_screen(self.progress_window)
106106
else:
107107
BaseWindow.center_window(self.progress_window, self.parent)

tests/test_frontend_tkinter_progress_window.py

100755100644
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,37 @@ def test_user_sees_progress_window_handle_lazy_window_relift(self, progress_wind
251251

252252
# Should be lifted again
253253
progress_window.progress_window.lift.assert_called_once()
254+
255+
def test_user_sees_fc_init_progress_centered_on_screen_with_withdrawn_parent(self, tk_root) -> None:
256+
"""
257+
User sees FC init progress window centered on screen when parent is withdrawn.
258+
259+
GIVEN: A progress window created with a withdrawn parent (like FC connection progress)
260+
WHEN: The window is first shown via update_progress_bar
261+
THEN: Screen centering is used instead of parent-relative centering
262+
"""
263+
tk_root.withdraw()
264+
265+
with (
266+
patch(
267+
"ardupilot_methodic_configurator.frontend_tkinter_base_window.BaseWindow.center_window_on_screen"
268+
) as mock_center_screen,
269+
patch(
270+
"ardupilot_methodic_configurator.frontend_tkinter_base_window.BaseWindow.center_window"
271+
) as mock_center_parent,
272+
):
273+
window = ProgressWindow(
274+
tk_root,
275+
title="FC Init",
276+
message="Init: {}/{}",
277+
only_show_when_update_progress_called=True,
278+
)
279+
280+
window.update_progress_bar(10, 100)
281+
282+
# Screen centering should be used, not parent-relative
283+
assert mock_center_screen.call_count >= 1
284+
mock_center_parent.assert_not_called()
285+
286+
with contextlib.suppress(Exception):
287+
window.destroy()

0 commit comments

Comments
 (0)