feat(movelist): context menu replaces hover buttons
public
feat(movelist): context menu replaces hover buttons - Same menu for all moves: Warum nicht?, Weiterspielen, FEN, Löschen - Open via long press, Menu key and Shift+F10 too - ? button always visible right after ?!/?/?? marks
| Changeset | 98294dedb48f110b496259bb4e3872078dce5465 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | 05e3473ace04 |
| Children | a181d06471b4 |
| Pushlog | by timo via ssh by timo via ssh |
modified roadmap/nachbesprechung.md +4 −1
| @@ -51,7 +51,10 @@ später wieder öffnet. | ||
| 51 | 51 | mit Kommentar („Besser war …“). Mögliche Antworten stehen als anklickbare Pfeile daneben |
| 52 | 52 | („Maia oft“, „Maia selten“, „Bester Zug“); erst der Klick hängt den Zug ein. |
| 53 | 53 | - Variantenzüge lassen sich löschen (Rechtsklick oder Entf), samt allem danach. Züge der |
| 54 | - Partie bleiben. Im Kontextmenü außerdem „Weiterspielen“ und „FEN kopieren“. | |
| 54 | + Partie bleiben. Im Kontextmenü außerdem „Warum nicht?“ (bei ?!, ?, ??), „Weiterspielen“ | |
| 55 | + und „FEN kopieren“, für alle Züge gleich; es öffnet per Rechtsklick, langem Drücken (Touch), | |
| 56 | + Menütaste oder Umschalt+F10. Die Hover-Knöpfe sind weg, nur der ?-Knopf steht fest hinter | |
| 57 | + dem Zeichen. | |
| 55 | 58 | - Rücktaste und Strg+Z nehmen den gezeigten Variantenzug zurück (wie Entf), gegen Vertipper |
| 56 | 59 | beim Anlegen einer Variante; auf Zügen der Partie tun sie nichts. |
| 57 | 60 | - Die Zugzeichen rechnet Stockfish trotzdem gleich nach dem Ende aus, im Hintergrund. |
modified schach/movelist.py +48 −41
| @@ -33,7 +33,7 @@ CSS = b""" | ||
| 33 | 33 | font-size: smaller; |
| 34 | 34 | font-feature-settings: "tnum"; |
| 35 | 35 | } |
| 36 | -.move-row-buttons button { min-height: 22px; min-width: 22px; padding: 1px; } | |
| 36 | +.why-not { min-height: 22px; min-width: 22px; padding: 1px; } | |
| 37 | 37 | .move-pill.variation-move { background: mix(@accent_bg_color, white, 0.82); } |
| 38 | 38 | .move-pill.variation-move.selected-move { background: @accent_bg_color; color: @accent_fg_color; } |
| 39 | 39 | .tree-toggle { min-height: 20px; min-width: 20px; padding: 0; } |
| @@ -45,6 +45,9 @@ def _hex(rgb): | ||
| 45 | 45 | return "#" + "".join(f"{int(c * 255):02x}" for c in rgb) |
| 46 | 46 | |
| 47 | 47 | |
| 48 | +WHY_NOT = ("?!", "?", "??") # Zeichen, zu denen „Warum nicht?“ erklärt, was dagegen spricht | |
| 49 | + | |
| 50 | + | |
| 48 | 51 | class MoveList(Gtk.Box): |
| 49 | 52 | def __init__(self): |
| 50 | 53 | super().__init__(orientation=Gtk.Orientation.VERTICAL, width_request=240) |
| @@ -81,10 +84,13 @@ class MoveList(Gtk.Box): | ||
| 81 | 84 | menu_click = Gtk.GestureClick(button=Gdk.BUTTON_SECONDARY) |
| 82 | 85 | menu_click.connect("pressed", self._on_menu_click) |
| 83 | 86 | self.listbox.add_controller(menu_click) |
| 87 | + long_press = Gtk.GestureLongPress(touch_only=True) # Touch: lange drücken statt Rechtsklick | |
| 88 | + long_press.connect("pressed", lambda gesture, x, y: self._on_menu_click(gesture, 1, x, y)) | |
| 89 | + self.listbox.add_controller(long_press) | |
| 84 | 90 | self._menu_row = None # Zeile, zu der das Kontextmenü gerade offen ist |
| 85 | 91 | actions = Gio.SimpleActionGroup() |
| 86 | - for name, handler in (("continue", self._menu_continue), ("copy", self._menu_copy), | |
| 87 | - ("delete", self._menu_delete)): | |
| 92 | + for name, handler in (("why-not", self._menu_why_not), ("continue", self._menu_continue), | |
| 93 | + ("copy", self._menu_copy), ("delete", self._menu_delete)): | |
| 88 | 94 | action = Gio.SimpleAction.new(name, None) |
| 89 | 95 | action.connect("activate", lambda _a, _p, handler=handler: handler()) |
| 90 | 96 | actions.add_action(action) |
| @@ -142,9 +148,9 @@ class MoveList(Gtk.Box): | ||
| 142 | 148 | san = notation.move(replay, move, self.notation) |
| 143 | 149 | replay.push(move) |
| 144 | 150 | key = ("zug", ply) if after.get(ply) else None |
| 145 | - row, buttons = self._make_row(ply, prefix, san, symbols.get(ply), evals.get(ply), times.get(ply), | |
| 146 | - key, indent=bool(after)) | |
| 147 | - self._rows.append((row, buttons)) | |
| 151 | + row = self._make_row(ply, prefix, san, symbols.get(ply), evals.get(ply), times.get(ply), | |
| 152 | + key, indent=bool(after)) | |
| 153 | + self._rows.append(row) | |
| 148 | 154 | ordered.append(row) |
| 149 | 155 | ordered += self._fork_rows(after.get(ply, ()), (key,), row, 1) |
| 150 | 156 | for row in ordered: |
| @@ -178,36 +184,22 @@ class MoveList(Gtk.Box): | ||
| 178 | 184 | pill = Gtk.Label(use_markup=True, label=text, valign=Gtk.Align.CENTER, |
| 179 | 185 | css_classes=["move-pill"] + (["variation-move"] if token is not None else [])) |
| 180 | 186 | |
| 181 | - copy_btn = Gtk.Button( | |
| 182 | - icon_name="edit-copy-symbolic", tooltip_text="Stellung als FEN kopieren", css_classes=["osd", "circular"] | |
| 183 | - ) | |
| 184 | - copy_btn.connect("clicked", lambda *_: self.on_copy and self.on_copy(ply)) | |
| 185 | - play_btn = Gtk.Button( | |
| 186 | - icon_name="media-playback-start-symbolic", tooltip_text="Von hier weiterspielen", | |
| 187 | - css_classes=["osd", "circular"], | |
| 188 | - ) | |
| 189 | - play_btn.connect("clicked", lambda *_: self.on_continue and self.on_continue(ply)) | |
| 190 | - buttons = Gtk.Box(spacing=4, css_classes=["move-row-buttons"], valign=Gtk.Align.CENTER, visible=False) | |
| 191 | - if symbol in ("?!", "?", "??"): | |
| 192 | - why_btn = Gtk.Button(icon_name="dialog-question-symbolic", css_classes=["osd", "circular"], | |
| 193 | - tooltip_text="Warum nicht? – zeigt beim Nachspielen, was dagegen spricht") | |
| 194 | - why_btn.connect("clicked", lambda *_: self.on_why_not and self.on_why_not(ply)) | |
| 195 | - buttons.append(why_btn) | |
| 196 | - if token is None: | |
| 197 | - buttons.append(copy_btn) | |
| 198 | - buttons.append(play_btn) | |
| 199 | - | |
| 200 | 187 | content = Gtk.Box(spacing=6, margin_start=(2 if indent else 8) + 16 * depth, margin_end=8) |
| 201 | 188 | if key is not None: |
| 202 | 189 | content.append(self._toggle_button(key, "Varianten zeigen")) |
| 203 | 190 | elif indent: # Platz wie der Knopf daneben, damit die Züge untereinander stehen |
| 204 | 191 | content.append(Gtk.Box(width_request=20)) |
| 205 | 192 | content.append(pill) |
| 193 | + if symbol in WHY_NOT: # dauerhaft sichtbar hinter dem Zeichen: lädt zum Nachfragen ein | |
| 194 | + why_btn = Gtk.Button(icon_name="dialog-question-symbolic", css_classes=["osd", "circular", "why-not"], | |
| 195 | + valign=Gtk.Align.CENTER, | |
| 196 | + tooltip_text="Warum nicht? – zeigt beim Nachspielen, was dagegen spricht") | |
| 197 | + why_btn.connect("clicked", lambda *_: self.on_why_not and self.on_why_not(ply)) | |
| 198 | + content.append(why_btn) | |
| 206 | 199 | content.append(Gtk.Box(hexpand=True)) |
| 207 | 200 | if ms is not None: |
| 208 | 201 | content.append(Gtk.Label(label=notation.format_time(ms), css_classes=["move-time"], |
| 209 | 202 | valign=Gtk.Align.CENTER, tooltip_text="Bedenkzeit")) |
| 210 | - content.append(buttons) | |
| 211 | 203 | |
| 212 | 204 | overlay = Gtk.Overlay(child=bar) |
| 213 | 205 | overlay.add_overlay(content) |
| @@ -215,16 +207,11 @@ class MoveList(Gtk.Box): | ||
| 215 | 207 | row.ply = ply |
| 216 | 208 | row.variation = token |
| 217 | 209 | row.pill = pill |
| 210 | + row.symbol = symbol | |
| 218 | 211 | row.key, row.needs, row.parent_row = key, (), None |
| 219 | 212 | if token is not None: |
| 220 | 213 | row.set_tooltip_text("Variante") |
| 221 | - return row, buttons | |
| 222 | - # Knöpfe schon beim Darüberfahren zeigen | |
| 223 | - hover = Gtk.EventControllerMotion() | |
| 224 | - hover.connect("enter", lambda *_: buttons.set_visible(True)) | |
| 225 | - hover.connect("leave", lambda *_: buttons.set_visible(ply == self._selected)) | |
| 226 | - row.add_controller(hover) | |
| 227 | - return row, buttons | |
| 214 | + return row | |
| 228 | 215 | |
| 229 | 216 | def _fork_rows(self, branches, needs, parent_row, depth): |
| 230 | 217 | """Varianten, die nach ``parent_row`` abzweigen: eine direkt als Folge, mehrere je unter einer |
| @@ -257,7 +244,7 @@ class MoveList(Gtk.Box): | ||
| 257 | 244 | rows = [] |
| 258 | 245 | for token, prefix, san, subs, white, _name in branch: |
| 259 | 246 | key = ("zweig", token) if subs else None |
| 260 | - row, _ = self._make_row(None, prefix, san, None, white, key=key, indent=True, token=token, depth=depth) | |
| 247 | + row = self._make_row(None, prefix, san, None, white, key=key, indent=True, token=token, depth=depth) | |
| 261 | 248 | row.needs, row.parent_row = needs, parent_row |
| 262 | 249 | self._token_rows[token] = row |
| 263 | 250 | self._variation_rows.append(row) |
| @@ -287,11 +274,24 @@ class MoveList(Gtk.Box): | ||
| 287 | 274 | |
| 288 | 275 | def _on_menu_click(self, gesture, _n, x, y): |
| 289 | 276 | row = self.listbox.get_row_at_y(int(y)) |
| 277 | + if self._popup_menu(row, x, y): | |
| 278 | + gesture.set_state(Gtk.EventSequenceState.CLAIMED) | |
| 279 | + | |
| 280 | + def _popup_row_menu(self): | |
| 281 | + """Menütaste oder Umschalt+F10: Kontextmenü zur ausgewählten Zeile.""" | |
| 282 | + row = self.listbox.get_selected_row() | |
| 283 | + ok, bounds = row.compute_bounds(self.listbox) if row is not None else (False, None) | |
| 284 | + if not ok: | |
| 285 | + return False | |
| 286 | + return self._popup_menu(row, bounds.get_x() + 24, bounds.get_y() + bounds.get_height()) | |
| 287 | + | |
| 288 | + def _popup_menu(self, row, x, y): | |
| 290 | 289 | if row is None or (row.ply is None and row.variation is None): |
| 291 | - return # Kopfzeile „Variante n“ | |
| 292 | - gesture.set_state(Gtk.EventSequenceState.CLAIMED) | |
| 290 | + return False # Kopfzeile „Variante n“ | |
| 293 | 291 | self._menu_row = row |
| 294 | 292 | menu = Gio.Menu() |
| 293 | + if row.symbol in WHY_NOT: | |
| 294 | + menu.append("Warum _nicht?", "zug.why-not") | |
| 295 | 295 | menu.append("_Weiterspielen", "zug.continue") |
| 296 | 296 | menu.append("Stellung als _FEN kopieren", "zug.copy") |
| 297 | 297 | if row.variation is not None: # Züge der Partie bleiben; löschen kann man nur Varianten |
| @@ -303,11 +303,17 @@ class MoveList(Gtk.Box): | ||
| 303 | 303 | popover.set_pointing_to(rect) |
| 304 | 304 | popover.connect("closed", lambda p: GLib.idle_add(p.unparent)) |
| 305 | 305 | popover.popup() |
| 306 | + return True | |
| 306 | 307 | |
| 307 | 308 | def _menu_target(self): |
| 308 | 309 | row, self._menu_row = self._menu_row, None |
| 309 | 310 | return row |
| 310 | 311 | |
| 312 | + def _menu_why_not(self): | |
| 313 | + row = self._menu_target() | |
| 314 | + if row is not None and row.ply is not None and self.on_why_not: | |
| 315 | + GLib.idle_add(lambda: self.on_why_not(row.ply) and False) | |
| 316 | + | |
| 311 | 317 | def _menu_continue(self): |
| 312 | 318 | row = self._menu_target() |
| 313 | 319 | if row is not None and row.variation is not None and self.on_variation_continue: |
| @@ -329,6 +335,8 @@ class MoveList(Gtk.Box): | ||
| 329 | 335 | GLib.idle_add(lambda: self.on_variation_delete(token) and False) # baut die Liste neu |
| 330 | 336 | |
| 331 | 337 | def _on_key(self, _controller, keyval, _keycode, state): |
| 338 | + if keyval == Gdk.KEY_Menu or (keyval == Gdk.KEY_F10 and state & Gdk.ModifierType.SHIFT_MASK): | |
| 339 | + return self._popup_row_menu() | |
| 332 | 340 | if state & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK | Gdk.ModifierType.SHIFT_MASK): |
| 333 | 341 | return False |
| 334 | 342 | if keyval in (Gdk.KEY_Delete, Gdk.KEY_KP_Delete): |
| @@ -395,9 +403,9 @@ class MoveList(Gtk.Box): | ||
| 395 | 403 | elif selected is None or selected < 0 or selected >= len(self._rows): |
| 396 | 404 | self.listbox.unselect_all() |
| 397 | 405 | else: |
| 398 | - self.listbox.select_row(self._rows[selected][0]) | |
| 406 | + self.listbox.select_row(self._rows[selected]) | |
| 399 | 407 | self._updating = False |
| 400 | - self._show_buttons(None if selected_variation is not None else selected) | |
| 408 | + self._mark_selected(None if selected_variation is not None else selected) | |
| 401 | 409 | for row in self._variation_rows: |
| 402 | 410 | if row.variation is None: |
| 403 | 411 | continue |
| @@ -407,10 +415,9 @@ class MoveList(Gtk.Box): | ||
| 407 | 415 | row.pill.remove_css_class("selected-move") |
| 408 | 416 | self.live_btn.set_sensitive(selected is not None or holder is not None) |
| 409 | 417 | |
| 410 | - def _show_buttons(self, selected): | |
| 418 | + def _mark_selected(self, selected): | |
| 411 | 419 | self._selected = selected |
| 412 | - for ply, (row, buttons) in enumerate(self._rows): | |
| 413 | - buttons.set_visible(ply == selected) | |
| 420 | + for ply, row in enumerate(self._rows): | |
| 414 | 421 | if ply == selected: |
| 415 | 422 | row.pill.add_css_class("selected-move") |
| 416 | 423 | else: |