From 6eabe93b65130299352795d3f6db13c0d253de58 Mon Sep 17 00:00:00 2001 From: cnmcdee Date: Tue, 1 Dec 2026 04:08:20 +0000 Subject: [PATCH] Phase 7 fix A+B: debugger labels above their panes; Inspector geometry refresh on programmatic resize Fix A: the Breakpoints label sat below the breakpoint list, directly above the Output label, and the two read as one cramped/overlapping block at the bottom-left of the debugger window. It now sits above its list (like Locals in the right pane) and the Output label has 6px top/start margins so it cannot crowd the middle pane. Fix B: the Inspector only rebuilt on selection change, so a programmatic resize (set_prop/resize_to/set_bounds) left the geometry spins stale until the next selection, while canvas and status bar already showed the new size. CanvasState now fires on_bounds_change when the selected widget bounds move under the same selection; the Inspector answers with refresh_geometry(), which syncs just the four spins in place (no rebuild, no focus loss). Handle drags fire the same hook, so drags keep working and now track live. --- lightgui/app.py | 4 ++++ lightgui/debugger_ui.py | 18 ++++++++++++++---- lightgui/inspector.py | 29 +++++++++++++++++++++++++++++ lightgui/xframe/canvas.py | 22 +++++++++++++++++++++- 4 files changed, 68 insertions(+), 5 deletions(-) diff --git a/lightgui/app.py b/lightgui/app.py index 5b5ee95..663af4c 100644 --- a/lightgui/app.py +++ b/lightgui/app.py @@ -84,6 +84,10 @@ class Application: on_status=self.set_status, on_change=self._on_content_change) self.canvas.state.on_selection_change = self.inspector.refresh + # Phase 7: a programmatic resize of the selected widget + # refreshes just the Inspector geometry rows (no rebuild). + self.canvas.state.on_bounds_change = \ + self.inspector.refresh_geometry paned.pack1(self._build_palette_pane(), False, False) paned.pack2(self.canvas, True, False) diff --git a/lightgui/debugger_ui.py b/lightgui/debugger_ui.py index 649597b..5e38f9b 100644 --- a/lightgui/debugger_ui.py +++ b/lightgui/debugger_ui.py @@ -104,8 +104,13 @@ class DebuggerWindow: mid.pack2(self._build_inspect_pane(), True, False) vbox.pack_start(mid, True, True, 0) - vbox.pack_start(Gtk.Label(label="Output", xalign=0), - False, False, 0) + # Phase 7: margins so the label cannot crowd the middle + # pane above it (it used to butt directly against it, under + # the old bottom-placed "Breakpoints" label). + self.output_label = Gtk.Label(label="Output", xalign=0) + self.output_label.set_margin_start(6) + self.output_label.set_margin_top(6) + vbox.pack_start(self.output_label, False, False, 0) self.output_view = Gtk.TextView() self.output_view.set_editable(False) self.output_view.set_monospace(True) @@ -173,6 +178,13 @@ class DebuggerWindow: box.set_margin_start(4) box.set_margin_end(4) + # Phase 7: the pane label sits ABOVE its list (like "Locals" + # in the right pane). It used to sit below the list, directly + # above the "Output" label, and the two labels read as one + # cramped/overlapping block at the bottom-left. + self.bp_label = Gtk.Label(label="Breakpoints", xalign=0) + box.pack_start(self.bp_label, False, False, 0) + row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=4) self.bp_entry = Gtk.Entry() self.bp_entry.set_placeholder_text("file.py:line") @@ -222,8 +234,6 @@ class DebuggerWindow: scrolled.set_size_request(BP_PANE_MIN_WIDTH, -1) scrolled.add(tree) box.pack_start(scrolled, True, True, 0) - box.pack_start(Gtk.Label(label="Breakpoints", xalign=0), - False, False, 0) return box def _build_inspect_pane(self): diff --git a/lightgui/inspector.py b/lightgui/inspector.py index 0b4892c..b868f37 100644 --- a/lightgui/inspector.py +++ b/lightgui/inspector.py @@ -390,6 +390,35 @@ class Inspector: """CanvasState selection callback — refresh the rows.""" self.refresh() + def refresh_geometry(self): + """Sync just the four geometry spins to the selected widget's + current bounds (Phase 7). A programmatic resize (``set_prop`` + / ``resize_to`` / ``set_bounds``) changes the widget without + changing the selection, so the full refresh — which only runs + on selection change — never saw it, and the spins lagged + until the next selection (canvas + status bar already showed + the new size). This updates the spin values in place under + the ``_syncing`` guard, so no row is rebuilt and focus is + never stolen; it is a no-op with nothing selected, and a + spin already showing the value is left alone (so an + Inspector edit of a spin does not fight itself).""" + widget = self.project.selected + if widget is None: + return + current = {"left": widget.x, "top": widget.y, + "width": widget.width, "height": widget.height} + self._syncing = True + try: + for name in GEOMETRY_NAMES: + editor = self.rows.get(name) + if not isinstance(editor, Gtk.SpinButton): + continue + value = float(current[name]) + if editor.get_value() != value: + editor.set_value(value) + finally: + self._syncing = False + def _build_rows(self, specs, target): row = 0 for tag, value in specs: diff --git a/lightgui/xframe/canvas.py b/lightgui/xframe/canvas.py index 1f6d4e8..6aeaa8d 100644 --- a/lightgui/xframe/canvas.py +++ b/lightgui/xframe/canvas.py @@ -77,7 +77,14 @@ class CanvasState: # (the Inspector refreshes on it; prop edits and drags do # not rebuild the Inspector, or typing would lose focus). self.on_selection_change = None + # Phase 7: called when the SELECTED widget's bounds change + # without a selection change (programmatic resize via + # set_prop / resize_to / set_bounds, or a handle drag). The + # Inspector refreshes only its geometry rows on it — a full + # rebuild would steal focus while typing in a row. + self.on_bounds_change = None self._last_selected_id = None + self._last_bounds = None # --- selection -------------------------------------------------------- @property @@ -254,10 +261,23 @@ class CanvasState: if self.on_change is not None: self.on_change() selected_id = self.project.selected_id - if selected_id != self._last_selected_id: + selection_changed = selected_id != self._last_selected_id + if selection_changed: self._last_selected_id = selected_id if self.on_selection_change is not None: self.on_selection_change() + # Phase 7: bounds moved under the same selection — tell the + # Inspector to re-sync just its geometry rows. A selection + # change already rebuilt the rows, so it needs no hook. + bounds = None + if selected is not None: + bounds = (selected.x, selected.y, + selected.width, selected.height) + if bounds != self._last_bounds: + self._last_bounds = bounds + if (not selection_changed and bounds is not None + and self.on_bounds_change is not None): + self.on_bounds_change() class Canvas(Gtk.DrawingArea):