Phase 7 tests: bounds-change hook + geometry refresh + debugger label placement

- CanvasState on_bounds_change: programmatic resize, set_prop width,
  set_bounds/move_to and handle drags fire it; selection changes and
  unrelated prop edits do not.
- Inspector refresh_geometry: programmatic resize updates the width/
  height spins in place (same editor widgets, no rebuild) and a spin
  edit still live-applies; no-op with nothing selected.
- DebuggerWindow: Breakpoints label is the first child of its pane
  (above the list) and sits above the tree in window coordinates;
  Output label has a 6px top margin.
This commit is contained in:
cnmcdee committed 2026-12-01 04:08:21 +00:00
1 parent 6eabe93b65
commit c8263b2035
3 files changed
+112

No files matched your search

+59
View File
@@ -161,5 +161,64 @@ class CanvasDragTests(unittest.TestCase):
self.state.viewport_height), (1280, 720))
class BoundsChangeTests(unittest.TestCase):
"""Phase 7 fix B: the Inspector must learn about a programmatic
resize of the selected widget without a selection change."""
def setUp(self):
self.state = CanvasState(Project())
self.bounds_calls = []
self.selection_calls = []
self.state.on_bounds_change = lambda: self.bounds_calls.append(1)
self.state.on_selection_change = (
lambda: self.selection_calls.append(1))
def test_programmatic_resize_fires_bounds_hook(self):
widget = self.state.place("GtkButton", 10, 10, 150, 36)
# place() selects: selection hook fires, bounds hook does not
# (the selection change already refreshes the Inspector).
self.assertEqual(self.selection_calls, [1])
self.assertEqual(self.bounds_calls, [])
widget.resize_to(260, 60)
self.assertEqual(len(self.bounds_calls), 1)
widget.set_prop("width", "300")
self.assertEqual(len(self.bounds_calls), 2)
self.assertEqual(widget.width, 300)
def test_selection_change_does_not_fire_bounds_hook(self):
self.state.place("GtkButton", 10, 10, 150, 36)
self.state.place("GtkLabel", 300, 10, 180, 30)
self.assertEqual(self.bounds_calls, [])
def test_unrelated_prop_change_does_not_fire_bounds_hook(self):
widget = self.state.place("GtkButton", 10, 10, 150, 36)
widget.set_prop("label", "New caption")
self.assertEqual(self.bounds_calls, [])
def test_set_bounds_and_move_fire_bounds_hook(self):
widget = self.state.place("GtkButton", 10, 10, 150, 36)
widget.set_bounds(20, 20, 200, 50)
self.assertEqual(len(self.bounds_calls), 1)
widget.move_to(30, 30)
self.assertEqual(len(self.bounds_calls), 2)
def test_handle_drag_fires_bounds_hook(self):
# The drag path (CanvasDragTests) must keep working: a handle
# drag resizes the widget and fires the hook, so the
# Inspector geometry rows track the drag live.
widget = self.state.place("GtkButton", 100, 80, 150, 36)
self.state.button_press(150, 100, now_ms=1000.0)
self.state.button_release(150, 100)
self.state.button_press(152, 101, now_ms=1200.0)
self.assertTrue(self.state.handles_on)
# SE handle centre is (250, 116); grab it and drag +20/+10.
self.state.button_press(250, 116, now_ms=1300.0)
self.assertTrue(self.state.handle_drag)
before = len(self.bounds_calls)
self.state.motion(270, 126)
self.assertGreater(len(self.bounds_calls), before)
self.assertEqual((widget.width, widget.height), (170, 46))
if __name__ == "__main__":
unittest.main()
+26
View File
@@ -352,6 +352,32 @@ class DebuggerWindowTests(unittest.TestCase):
for col in self.win.bp_tree.get_columns()]
self.assertIn(BP_LOCATION_MIN_WIDTH, widths)
def test_breakpoint_label_is_above_list(self):
# Phase 7 fix A: "Breakpoints" sits above its list (like
# "Locals"), not below it crowding the "Output" label.
# Packing order in the pane box is the structural check;
# window-relative y (via translate_coordinates, since
# allocations are parent-relative) is the visual check.
pane = self.win.bp_label.get_parent()
children = pane.get_children()
self.assertIs(children[0], self.win.bp_label)
self.assertIn(self.win.bp_tree.get_parent(), children)
self.assertLess(
children.index(self.win.bp_label),
children.index(self.win.bp_tree.get_parent()))
self.win.show()
while Gtk.events_pending():
Gtk.main_iteration()
window = self.win.window
bp_y = self.win.bp_label.translate_coordinates(window, 0, 0)[1]
tree_y = self.win.bp_tree.translate_coordinates(window, 0, 0)[1]
out_y = self.win.output_label.translate_coordinates(
window, 0, 0)[1]
self.assertLess(bp_y, tree_y)
self.assertGreater(out_y, tree_y)
self.assertGreaterEqual(
self.win.output_label.get_margin_top(), 6)
def test_watch_and_locals_trees_have_no_search(self):
# Bug 7: clicking a watch/locals row must not open a search
# popup — search is disabled on both trees.
+27
View File
@@ -326,6 +326,33 @@ class InspectorGtkTests(unittest.TestCase):
self.assertEqual(self.inspector.selected_label.get_text(),
"Window (Root)")
def test_programmatic_resize_refreshes_geometry_rows(self):
# Phase 7 fix B: resize without a selection change must
# update the geometry spins (they used to lag until the
# next selection). No rebuild: the same editor widgets stay
# in place, so focus is never stolen.
state = CanvasState(self.project)
state._wire(self.button)
state.on_selection_change = self.inspector.refresh
state.on_bounds_change = self.inspector.refresh_geometry
state.select(self.button.id) # primes selection/bounds memory
width_spin = self.inspector.editor_for("width")
height_spin = self.inspector.editor_for("height")
label_entry = self.inspector.entry_for("label")
self.button.resize_to(260, 60)
self.assertEqual(width_spin.get_value(), 260)
self.assertEqual(height_spin.get_value(), 60)
self.assertIs(self.inspector.editor_for("width"), width_spin)
self.assertIs(self.inspector.entry_for("label"), label_entry)
# A spin edit still live-applies afterwards.
width_spin.set_value(200)
self.assertEqual(self.button.width, 200)
def test_refresh_geometry_is_noop_without_selection(self):
self.project.clear_selection()
self.inspector.refresh()
self.inspector.refresh_geometry() # root rows: must not raise
def test_bulk_buttons_apply_to_right_widgets(self):
label = self.project.add_widget("GtkLabel", 300, 10, 180, 30)
self.project.clear_selection()