feat(ui): rework header bar around game mode
public
feat(ui): rework header bar around game mode HIG: few controls, no label-only buttons, header follows mode. - + becomes split button holding all game kinds (puzzle, Lichess) - open button dropped, saves stay in menu and on Ctrl+O - mode slot: hint (lightbulb) or Lichess account menu with draw, resign, view on lichess.org - menu section title shows Lichess login; add shortcuts and about - narrow windows move the mode slot to a bottom bar Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | 65c63618cf6263c576f1ce1136d64f490ed48d1d |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | ec708f031861 |
| Children | d72be2c475c2 |
| Pushlog | by timo via ssh by timo via ssh |
modified schach/app.py +155 −44
| @@ -127,67 +127,94 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 127 | 127 | def _build_ui(self): |
| 128 | 128 | self.title = Adw.WindowTitle(title="Schach") |
| 129 | 129 | header = Adw.HeaderBar(title_widget=self.title) |
| 130 | + self.header = header | |
| 130 | 131 | |
| 131 | - new_btn = Gtk.Button(icon_name="list-add-symbolic", tooltip_text="Neue Partie (Strg+N)") | |
| 132 | + # Neu ▾: alle Spielarten an einer Stelle statt eigener Knöpfe in der Titelleiste | |
| 133 | + difficulty = Gio.Menu() | |
| 134 | + for label, key in lichess.DIFFICULTIES: | |
| 135 | + difficulty.append(label, f"win.puzzle-difficulty::{key}") | |
| 136 | + games = Gio.Menu() | |
| 137 | + games.append("Partie gegen _Maia …", "win.new-game") | |
| 138 | + games.append("_Rätsel", "win.puzzle") | |
| 139 | + games.append_submenu("Rätsel-_Schwierigkeit", difficulty) | |
| 140 | + online = Gio.Menu() | |
| 141 | + online.append("Freund auf _Lichess herausfordern …", "win.challenge") | |
| 142 | + new_menu = Gio.Menu() | |
| 143 | + new_menu.append_section(None, games) | |
| 144 | + new_menu.append_section(None, online) | |
| 145 | + new_btn = Adw.SplitButton( | |
| 146 | + icon_name="list-add-symbolic", menu_model=new_menu, | |
| 147 | + tooltip_text="Neue Partie (Strg+N)", dropdown_tooltip="Weitere Spielarten", | |
| 148 | + ) | |
| 132 | 149 | new_btn.set_action_name("win.new-game") |
| 133 | 150 | header.pack_start(new_btn) |
| 134 | 151 | undo_btn = Gtk.Button(icon_name="edit-undo-symbolic", tooltip_text="Zug zurücknehmen (Strg+Z)") |
| 135 | 152 | undo_btn.set_action_name("win.undo") |
| 136 | 153 | header.pack_start(undo_btn) |
| 137 | - saves_btn = Gtk.Button(icon_name="document-open-symbolic", tooltip_text="Spielstände (Strg+O)") | |
| 138 | - saves_btn.set_action_name("win.open-saves") | |
| 139 | - header.pack_start(saves_btn) | |
| 140 | 154 | self.undo_btn = undo_btn |
| 141 | 155 | |
| 142 | - difficulty = Gio.Menu() | |
| 143 | - for label, key in lichess.DIFFICULTIES: | |
| 144 | - difficulty.append(label, f"win.puzzle-difficulty::{key}") | |
| 145 | - puzzle_menu = Gio.Menu() | |
| 146 | - puzzle_menu.append_section("Schwierigkeit", difficulty) | |
| 147 | - puzzle_btn = Adw.SplitButton( | |
| 148 | - label="Rätsel", menu_model=puzzle_menu, tooltip_text="Neues Lichess-Rätsel (R)", | |
| 149 | - dropdown_tooltip="Schwierigkeit", | |
| 150 | - ) | |
| 151 | - puzzle_btn.set_action_name("win.puzzle") | |
| 152 | - header.pack_start(puzzle_btn) | |
| 153 | - | |
| 154 | - menu = Gio.Menu() | |
| 155 | - section = Gio.Menu() | |
| 156 | - section.append("Spielstand speichern …", "win.save-game") | |
| 157 | - section.append("Spielstände …", "win.open-saves") | |
| 158 | - section.append("Als PGN exportieren …", "win.save-pgn") | |
| 159 | - menu.append_section(None, section) | |
| 156 | + # Hauptmenü (HIG: Datei-Aktionen, Ansicht, dann Tastenkürzel und Info) | |
| 157 | + menu = self.primary_menu = Gio.Menu() | |
| 158 | + files = Gio.Menu() | |
| 159 | + files.append("Spielstand _speichern …", "win.save-game") | |
| 160 | + files.append("Spielstände _öffnen …", "win.open-saves") | |
| 161 | + files.append("Als PGN _exportieren …", "win.save-pgn") | |
| 162 | + menu.append_section(None, files) | |
| 160 | 163 | self.lichess_section = Gio.Menu() |
| 161 | 164 | menu.append_section("Lichess", self.lichess_section) |
| 162 | - self.update_lichess_menu() | |
| 163 | - menu.append("Brett drehen", "win.flip") | |
| 165 | + view = Gio.Menu() | |
| 166 | + view.append("Brett _drehen", "win.flip") | |
| 164 | 167 | themes = Gio.Menu() |
| 165 | 168 | installed = set(available_themes()) |
| 166 | 169 | for name in FEATURED_THEMES: |
| 167 | 170 | if name in installed: |
| 168 | 171 | label = "Eingebaut" if name == "python-chess" else name.capitalize() |
| 169 | 172 | themes.append(label, f"win.theme::{name}") |
| 170 | - menu.append_submenu("Figuren", themes) | |
| 171 | - header.pack_end(Gtk.MenuButton(icon_name="open-menu-symbolic", menu_model=menu)) | |
| 173 | + view.append_submenu("_Figuren", themes) | |
| 174 | + menu.append_section(None, view) | |
| 175 | + about = Gio.Menu() | |
| 176 | + about.append("_Tastenkürzel", "win.shortcuts") | |
| 177 | + about.append("_Info zu Schach", "win.about") | |
| 178 | + menu.append_section(None, about) | |
| 179 | + self.update_lichess_menu() | |
| 180 | + header.pack_end(Gtk.MenuButton( | |
| 181 | + icon_name="open-menu-symbolic", menu_model=menu, primary=True, tooltip_text="Hauptmenü", | |
| 182 | + )) | |
| 172 | 183 | |
| 173 | 184 | self.list_btn = Gtk.ToggleButton( |
| 174 | 185 | icon_name="sidebar-show-right-symbolic", tooltip_text="Zugliste und Bewertung (A)" |
| 175 | 186 | ) |
| 176 | 187 | header.pack_end(self.list_btn) |
| 177 | 188 | |
| 178 | - self.hint_btn = Gtk.Button(label="Hinweis", tooltip_text="Hinweis von Maia 2000 (H)") | |
| 189 | + # Modus-Slot: zeigt, was in der aktuellen Spielart gebraucht wird | |
| 190 | + self.mode_stack = Gtk.Stack( | |
| 191 | + transition_type=Gtk.StackTransitionType.CROSSFADE, hhomogeneous=False, interpolate_size=True, | |
| 192 | + ) | |
| 193 | + self.hint_content = Adw.ButtonContent(icon_name="dialog-information-symbolic", label="Hinweis") | |
| 194 | + self.hint_btn = Gtk.Button(child=self.hint_content) | |
| 179 | 195 | self.hint_btn.set_action_name("win.hint") |
| 180 | - header.pack_end(self.hint_btn) | |
| 196 | + self.mode_stack.add_named(self.hint_btn, "help") | |
| 181 | 197 | |
| 182 | - # nur während einer Online-Partie | |
| 183 | - self.online_box = Gtk.Box(spacing=6, visible=False) | |
| 184 | - draw_btn = Gtk.Button(label="Remis anbieten") | |
| 185 | - draw_btn.set_action_name("win.offer-draw") | |
| 186 | - resign_btn = Gtk.Button(label="Aufgeben", css_classes=["destructive-action"]) | |
| 187 | - resign_btn.set_action_name("win.resign") | |
| 188 | - self.online_box.append(draw_btn) | |
| 189 | - self.online_box.append(resign_btn) | |
| 190 | - header.pack_end(self.online_box) | |
| 198 | + online_menu = Gio.Menu() | |
| 199 | + game = Gio.Menu() | |
| 200 | + game.append("_Remis anbieten", "win.offer-draw") | |
| 201 | + game.append("Auf lichess.org _ansehen", "win.open-lichess-game") | |
| 202 | + online_menu.append_section(None, game) | |
| 203 | + end = Gio.Menu() | |
| 204 | + end.append("_Aufgeben …", "win.resign") | |
| 205 | + online_menu.append_section(None, end) | |
| 206 | + self.online_content = Adw.ButtonContent(icon_name="avatar-default-symbolic", label="Lichess") | |
| 207 | + self.online_btn = Gtk.MenuButton( | |
| 208 | + child=self.online_content, menu_model=online_menu, | |
| 209 | + tooltip_text="Lichess-Partie: Remis, Aufgeben, im Browser ansehen", | |
| 210 | + ) | |
| 211 | + self.mode_stack.add_named(self.online_btn, "online") | |
| 212 | + self.mode_stack.add_named(Gtk.Box(), "none") | |
| 213 | + header.pack_end(self.mode_stack) | |
| 214 | + | |
| 215 | + # schmale Fenster: Modus-Slot wandert in eine Leiste unter dem Brett (HIG „Adaptive“) | |
| 216 | + self.bottom_bar = Gtk.ActionBar() | |
| 217 | + self.narrow = False | |
| 191 | 218 | |
| 192 | 219 | self.banner = Adw.Banner(button_label="Neue Partie") |
| 193 | 220 | self.banner.set_action_name("win.new-game") |
| @@ -217,8 +244,30 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 217 | 244 | self.toasts = Adw.ToastOverlay(child=self.split) |
| 218 | 245 | toolbar = Adw.ToolbarView(content=self.toasts) |
| 219 | 246 | toolbar.add_top_bar(header) |
| 247 | + toolbar.add_bottom_bar(self.bottom_bar) | |
| 248 | + toolbar.set_reveal_bottom_bars(False) | |
| 249 | + self.toolbar = toolbar | |
| 220 | 250 | self.set_content(toolbar) |
| 221 | 251 | |
| 252 | + self.set_size_request(360, 480) | |
| 253 | + breakpoint = Adw.Breakpoint.new(Adw.BreakpointCondition.parse("max-width: 560sp")) | |
| 254 | + breakpoint.connect("apply", lambda *_: self._set_narrow(True)) | |
| 255 | + breakpoint.connect("unapply", lambda *_: self._set_narrow(False)) | |
| 256 | + self.add_breakpoint(breakpoint) | |
| 257 | + | |
| 258 | + def _set_narrow(self, narrow): | |
| 259 | + if narrow == self.narrow: | |
| 260 | + return | |
| 261 | + self.narrow = narrow | |
| 262 | + if narrow: | |
| 263 | + self.header.remove(self.mode_stack) | |
| 264 | + self.bottom_bar.set_center_widget(self.mode_stack) | |
| 265 | + else: | |
| 266 | + self.bottom_bar.set_center_widget(None) | |
| 267 | + self.header.pack_end(self.mode_stack) | |
| 268 | + if self.lookup_action("hint") is not None: | |
| 269 | + self._refresh_chrome() | |
| 270 | + | |
| 222 | 271 | def _install_actions(self): |
| 223 | 272 | for name, handler in [ |
| 224 | 273 | ("new-game", self._new_game_dialog), |
| @@ -237,6 +286,9 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 237 | 286 | ("lichess-games", self._lichess_games_dialog), |
| 238 | 287 | ("offer-draw", self._offer_draw), |
| 239 | 288 | ("resign", self._resign), |
| 289 | + ("open-lichess-game", self._open_lichess_game), | |
| 290 | + ("shortcuts", self._shortcuts_dialog), | |
| 291 | + ("about", self._about_dialog), | |
| 240 | 292 | ]: |
| 241 | 293 | action = Gio.SimpleAction.new(name, None) |
| 242 | 294 | action.connect("activate", handler) |
| @@ -265,6 +317,7 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 265 | 317 | app.set_accels_for_action("win.toggle-list", ["a"]) |
| 266 | 318 | app.set_accels_for_action("win.end-browse", ["Escape"]) |
| 267 | 319 | app.set_accels_for_action("win.puzzle", ["r"]) |
| 320 | + app.set_accels_for_action("win.shortcuts", ["<Control>question"]) | |
| 268 | 321 | |
| 269 | 322 | def _action(self, name): |
| 270 | 323 | return self.lookup_action(name) |
| @@ -273,11 +326,15 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 273 | 326 | user = self.get_application().lichess_user |
| 274 | 327 | self.lichess_section.remove_all() |
| 275 | 328 | if user is None: |
| 276 | - self.lichess_section.append("Bei Lichess anmelden …", "win.lichess-login") | |
| 329 | + label = "Lichess" | |
| 330 | + self.lichess_section.append("Bei Lichess _anmelden …", "win.lichess-login") | |
| 277 | 331 | else: |
| 278 | - self.lichess_section.append("Freund herausfordern …", "win.challenge") | |
| 279 | - self.lichess_section.append("Meine Lichess-Partien …", "win.lichess-games") | |
| 332 | + label = f"Lichess · {user.get('username', '')}" | |
| 333 | + self.lichess_section.append("Meine Lichess-_Partien …", "win.lichess-games") | |
| 280 | 334 | self.lichess_section.append(f"Abmelden ({user.get('username', '')})", "win.lichess-logout") |
| 335 | + # Abschnittsüberschrift zeigt den Anmeldestatus; dafür den Abschnitt neu einhängen | |
| 336 | + self.primary_menu.remove(1) | |
| 337 | + self.primary_menu.insert_section(1, label, self.lichess_section) | |
| 281 | 338 | |
| 282 | 339 | # --- Zustand → Anzeige ------------------------------------------------- |
| 283 | 340 | |
| @@ -410,15 +467,20 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 410 | 467 | and not self._browsing() |
| 411 | 468 | ) |
| 412 | 469 | self._action("hint").set_enabled(can_hint) |
| 413 | - self.hint_btn.set_visible(hints) | |
| 414 | - self.hint_btn.set_label("Zug zeigen" if self.hint_level == 1 else "Hinweis") | |
| 470 | + self.hint_content.set_label("Zug zeigen" if self.hint_level == 1 else "Hinweis") | |
| 415 | 471 | self.hint_btn.set_tooltip_text( |
| 416 | 472 | "Hinweis (H) – das Rätsel zählt dann nicht als gelöst" if self.mode == "puzzle" |
| 417 | - else "Hinweis von Maia 2000 (H)" | |
| 473 | + else f"Hinweis von Maia {HINT_ELO} (H)" | |
| 418 | 474 | ) |
| 475 | + user = self.get_application().lichess_user | |
| 476 | + self.online_content.set_label((user or {}).get("username") or "Lichess") | |
| 477 | + slot = "help" if hints else "online" if self.mode == "online" else "none" | |
| 478 | + self.mode_stack.set_visible_child_name(slot) | |
| 479 | + self.mode_stack.set_visible(slot != "none") | |
| 480 | + self.toolbar.set_reveal_bottom_bars(self.narrow and slot != "none") | |
| 481 | + self._action("open-lichess-game").set_enabled(self.mode == "online" and bool(self.online_id)) | |
| 419 | 482 | self._action("undo").set_enabled(self.mode == "maia" and self._human_has_moved()) |
| 420 | 483 | self.undo_btn.set_visible(self.mode == "maia") |
| 421 | - self.online_box.set_visible(self._online_running()) | |
| 422 | 484 | self._action("offer-draw").set_enabled(self._online_running() and len(self.board.move_stack) >= 2) |
| 423 | 485 | self._action("resign").set_enabled(self._online_running() and self.online_full is not None) |
| 424 | 486 | self._action("end-browse").set_enabled(self.browse_ply is not None) |
| @@ -858,6 +920,55 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 858 | 920 | dialog.connect("response", on_response) |
| 859 | 921 | dialog.present(self) |
| 860 | 922 | |
| 923 | + def _open_lichess_game(self, *_): | |
| 924 | + if self.online_id: | |
| 925 | + Gtk.UriLauncher.new(f"https://lichess.org/{self.online_id}").launch(self, None, None, None) | |
| 926 | + | |
| 927 | + def _shortcuts_dialog(self, *_): | |
| 928 | + dialog = Adw.ShortcutsDialog() | |
| 929 | + for title, items in [ | |
| 930 | + ("Partie", [ | |
| 931 | + ("Neue Partie", "<Control>n"), ("Zug zurücknehmen", "<Control>z"), | |
| 932 | + ("Hinweis", "h"), ("Neues Rätsel", "r"), | |
| 933 | + ]), | |
| 934 | + ("Ansicht", [ | |
| 935 | + ("Brett drehen", "f"), ("Zugliste und Bewertung", "a"), | |
| 936 | + ("Zurück zur aktuellen Stellung", "Escape"), | |
| 937 | + ]), | |
| 938 | + ("Spielstände", [ | |
| 939 | + ("Spielstand speichern", "<Control>s"), ("Spielstände öffnen", "<Control>o"), | |
| 940 | + ("Als PGN exportieren", "<Control><Shift>s"), | |
| 941 | + ]), | |
| 942 | + ("Allgemein", [("Tastenkürzel", "<Control>question")]), | |
| 943 | + ]: | |
| 944 | + section = Adw.ShortcutsSection(title=title) | |
| 945 | + for label, accel in items: | |
| 946 | + section.add(Adw.ShortcutsItem.new(label, accel)) | |
| 947 | + dialog.add(section) | |
| 948 | + dialog.present(self) | |
| 949 | + | |
| 950 | + def _about_dialog(self, *_): | |
| 951 | + about = Adw.AboutDialog( | |
| 952 | + application_name="Schach", | |
| 953 | + application_icon="org.gnome.Chess", | |
| 954 | + developer_name="Timo Stolz", | |
| 955 | + version="0.1", | |
| 956 | + comments="Schach gegen Maia-3 – mit Hinweisen, Zugbewertung von Stockfish, " | |
| 957 | + "Rätseln und Online-Partien auf Lichess.", | |
| 958 | + license_type=Gtk.License.AGPL_3_0, | |
| 959 | + ) | |
| 960 | + about.add_credit_section("Engines", [ | |
| 961 | + "Maia-3 (CSSLab, University of Toronto) https://maiachess.com", | |
| 962 | + "Stockfish https://stockfishchess.org", | |
| 963 | + ]) | |
| 964 | + about.add_credit_section("Figuren und Rätsel", [ | |
| 965 | + "Figurensätze aus PyChess https://pychess.github.io", | |
| 966 | + "Rätsel und Online-Partien: Lichess https://lichess.org", | |
| 967 | + ]) | |
| 968 | + about.add_legal_section("Maia-3", "© CSSLab, University of Toronto", Gtk.License.AGPL_3_0, None) | |
| 969 | + about.add_legal_section("Stockfish", "© The Stockfish developers", Gtk.License.GPL_3_0, None) | |
| 970 | + about.present(self) | |
| 971 | + | |
| 861 | 972 | # --- Spielstände ------------------------------------------------------- |
| 862 | 973 | |
| 863 | 974 | def state(self): |