Skip to content

Commit 5b47095

Browse files
fix: adressed copilot
Signed-off-by: Omkar Sarkar <omkarsarkar24@gmail.com>
1 parent d2e9c58 commit 5b47095

4 files changed

Lines changed: 42 additions & 8 deletions

File tree

ardupilot_methodic_configurator/frontend_tkinter_parameter_editor_table.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,15 @@ def _apply_scroll_position(self, scroll_to_bottom: bool) -> None:
226226
self.canvas.yview_moveto(position)
227227

228228
def _update_table(self, params: dict[str, ArduPilotParameter], gui_complexity: str) -> None:
229-
"""Initialize scroll load."""
229+
"""
230+
Update the table from a new parameter set and start incremental rendering.
231+
232+
This method is the entry point used when the table is rebuilt for a
233+
fresh ``params`` mapping. It resets the incremental-load state, stores
234+
the active GUI complexity, renders the first batch of rows immediately
235+
(currently 20 parameters), and then starts the page-scroll/polling
236+
mechanism that loads additional chunks as needed.
237+
"""
230238
self._params_list = list(params.items())
231239
self._total_params = len(self._params_list)
232240
self._current_idx = 0
@@ -291,18 +299,42 @@ def _load_next_chunk(self, chunk_size: int = 15) -> None:
291299
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
292300
self._is_loading = False
293301

302+
def _cancel_page_scroll_after(self) -> None:
303+
"""Cancel any scheduled page-scroll polling callback."""
304+
after_id = getattr(self, "_page_scroll_after_id", None)
305+
if not after_id:
306+
return
307+
try:
308+
self.after_cancel(after_id)
309+
except tk.TclError:
310+
pass
311+
finally:
312+
self._page_scroll_after_id = None
313+
314+
def _on_destroy_cancel_page_scroll(self, _event: Optional[tk.Event] = None) -> None:
315+
"""Stop page-scroll polling when the widget is being destroyed."""
316+
self._cancel_page_scroll_after()
317+
294318
def _page_scroll(self) -> None:
295319
"""Load more items when reaching the bottom."""
320+
self._page_scroll_after_id = None
321+
if not getattr(self, "_page_scroll_destroy_binding_registered", False):
322+
self.bind("<Destroy>", self._on_destroy_cancel_page_scroll, add="+")
323+
self._page_scroll_destroy_binding_registered = True
296324
if not self.winfo_exists() or self._current_idx >= self._total_params:
325+
self._cancel_page_scroll_after()
297326
return
298327

299328
try:
300329
if self.canvas.yview()[1] > 0.85:
301330
self._load_next_chunk(chunk_size=15)
302331
except tk.TclError:
303-
pass
304-
305-
self.after(150, self._page_scroll)
332+
return
333+
if self.winfo_exists() and self._current_idx < self._total_params:
334+
try:
335+
self._page_scroll_after_id = self.after(150, self._page_scroll)
336+
except tk.TclError:
337+
self._page_scroll_after_id = None
306338

307339
def _create_column_widgets(self, param_name: str, param: ArduPilotParameter, show_upload_column: bool) -> list[tk.Widget]:
308340
"""Create all column widgets for a parameter row."""

ardupilot_methodic_configurator/frontend_tkinter_scroll_frame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def on_mouse_wheel(self, event: tk.Event) -> None: # cross platform scroll whee
8888
if not hasattr(self, "canvas") or not self.canvas.winfo_exists():
8989
return # The widget was destroyed, ignore the scroll event
9090
canvas_height = self.canvas.winfo_height()
91-
rows_height = self.canvas.bbox("all")[3]
91+
bbox = self.canvas.bbox("all")
92+
rows_height = bbox[3] if bbox is not None else 0
9293

9394
if rows_height > canvas_height: # only scroll if the rows overflow the frame
9495
if platform_system() == "Windows":

ardupilot_methodic_configurator/frontend_tkinter_show.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def schedule_show(self, _event: Optional[tk.Event] = None) -> None:
525525
self.timers["show"] = self.widget.after(TOOLTIP_SHOW_DELAY_MS, self.create_show)
526526

527527
def create_show(self, _event: Optional[tk.Event] = None) -> None:
528-
"""On macOS, only create the tooltip when the mouse enters the widget."""
528+
"""Create and show the tooltip when the pointer is still over the widget after the delay."""
529529
self._cancel_show()
530530
self._cancel_hide()
531531

tests/bdd_frontend_tkinter_show.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ def test_tooltip_no_position_when_tooltip_none(self, mock_widget) -> None:
990990

991991
def test_tooltip_force_hide_destroys_globally(self, mock_widget, mock_toplevel) -> None:
992992
"""
993-
Test tooltip _do_hide withdraws tooltip on non-macOS.
993+
Test tooltip force_hide destroys the tooltip globally across all OSs and clears the active tooltip.
994994
995995
GIVEN: Tooltip on non-macOS platform
996996
WHEN: _do_hide is called
@@ -1074,7 +1074,8 @@ def test_tooltip_with_custom_toplevel_class(self, mock_widget, mock_toplevel) ->
10741074
tooltip.create_show() # Trigger lazy load
10751075

10761076
# Assert: Custom class was used
1077-
custom_toplevel_class.assert_called_once()
1077+
custom_toplevel_class.assert_called_once_with(mock_widget)
1078+
assert tooltip.tooltip == mock_toplevel
10781079

10791080
def test_tooltip_position_below_false(self, mock_widget, mock_toplevel) -> None:
10801081
"""

0 commit comments

Comments
 (0)