diff --git a/src/amc/gui.py b/src/amc/gui.py index 1d0c34e..83a5b4c 100644 --- a/src/amc/gui.py +++ b/src/amc/gui.py @@ -109,6 +109,10 @@ # gets its own row, one per line. The flattened field set must stay a # partition of _EDIT_TEXT_FIELDS + _EDIT_INTEGER_FIELDS + _EDIT_FLOAT_FIELDS — # enforced by test_edit_field_groups_cover_every_edit_field_exactly_once. +# The "Checked" checkbox has no dedicated field and is appended to this one +# group's frame after the fields below are built; referenced by this +# constant rather than a repeated literal so the two spots can't desync. +_EDIT_CHECKED_GROUP_TITLE = "Classification" _EDIT_FIELD_GROUPS: tuple[tuple[str, tuple[tuple[str, ...], ...]], ...] = ( ( "Identification", @@ -122,7 +126,7 @@ ), ), ( - "Classification", + _EDIT_CHECKED_GROUP_TITLE, ( ("category", "certification"), ("country", "year", "length"), @@ -2370,7 +2374,11 @@ def _dialog(self, movie: Movie, *, is_new: bool) -> None: canvas_window = canvas.create_window((0, 0), window=fields_frame, anchor="nw") canvas.configure(yscrollcommand=scrollbar.set) canvas.grid(row=0, column=0, sticky="nsew") - scrollbar.grid(row=0, column=1, sticky="ns") + # sticky="w" (not just "ns"): column 1 also holds the Save button + # (row 1), which is wider than the scrollbar, so column 1 is sized + # to the button's width. Without "w" the scrollbar centers in that + # wider column instead of hugging the canvas it scrolls. + scrollbar.grid(row=0, column=1, sticky="nsw") dialog.rowconfigure(0, weight=1) dialog.columnconfigure(0, weight=1) @@ -2390,7 +2398,7 @@ def _dialog(self, movie: Movie, *, is_new: bool) -> None: for group_title, group_rows in _EDIT_FIELD_GROUPS: group = ttk.LabelFrame(fields_frame, text=group_title) group.pack(fill="x", padx=8, pady=(4, 8)) - if group_title == "Classification": + if group_title == _EDIT_CHECKED_GROUP_TITLE: classification_group = group for row_fields in group_rows: row_frame = ttk.Frame(group) diff --git a/tests/gui/test_gui_display.py b/tests/gui/test_gui_display.py index 6564cf3..dd25aab 100644 --- a/tests/gui/test_gui_display.py +++ b/tests/gui/test_gui_display.py @@ -922,3 +922,27 @@ def test_edit_dialog_stacks_every_field_on_its_own_row_when_narrow( assert year_entry.grid_info()["row"] != length_entry.grid_info()["row"] dialog.destroy() + + +def test_edit_dialog_scrollbar_has_no_gap_from_its_canvas(real_root: tk.Tk, tmp_path: Path): + """The scrollbar shares its grid column with the wider Save button + (a different row), so it must stick to the canvas's edge explicitly — + without that, it centers in the wider column and floats away from the + content it scrolls.""" + window = _open_window(real_root, tmp_path) + movie = next(iter(window.service.catalog)) + + window._dialog(movie, is_new=False) + real_root.update_idletasks() + real_root.update() + dialog = [item for item in _toplevels(real_root) if item.title() == "Edit movie"][0] + dialog.geometry("900x700") + real_root.update_idletasks() + real_root.update() + + canvas = next(c for c in dialog.winfo_children() if isinstance(c, tk.Canvas)) + scrollbar = next(c for c in dialog.winfo_children() if isinstance(c, ttk.Scrollbar)) + + assert scrollbar.winfo_x() == canvas.winfo_x() + canvas.winfo_width() + + dialog.destroy()