Public repository: timo / schach

Reader

Ein aufgeräumtes Schach-Programm für GNOME

refactor(ui): threat split button with sword icon, shortcuts tab

public

refactor(ui): threat split button with sword icon, shortcuts tab

- threat gets its own split button and a symbolic sword icon; the
  threat source moves out of the hint menu into it
- keyboard shortcuts become a tab in preferences (Ctrl+? and the
  menu entry open it there) instead of a separate dialog

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changeset8bf9c5fb2e1bd70120880b687bd824584839708a
Author (claimed)Timo Stolz <timo.stolz@nullachtvierzehn.de>,
Parents246791c0cf23
Childrenba0992267590
Pushlog
by timo via ssh
by timo via ssh

modified README.md +4 −3

@@ -8,10 +8,11 @@ Schlichtes GNOME-Schachprogramm (Python,
88
 - **Hinweis** (Taste `H`): Erster Druck lässt die Figur leuchten, zweiter Druck auch
99
   das Zielfeld. Wer hilft, steht im Pfeil-Menü daneben: Maia 1500, 2000 (Standard) oder
1010
   2500 – jeweils von Stockfish geprüft – oder Stockfish selbst.
11
-- **Drohung** (Taste `B`, Warndreieck): umgekehrt zum Hinweis. Erster Druck zeigt das
11
+- **Drohung** (Taste `B`, Schwert): umgekehrt zum Hinweis. Erster Druck zeigt das
1212
   bedrohte Feld (orange), zweiter die drohende Figur mit Pfeil. Die Drohung passt zum
1313
   Gegner: Maia in seiner Stärke schlägt vor, was er sehen würde, Stockfish prüft nur, ob es
14
-  wirklich etwas gewinnt. Im Pfeil-Menü lässt sich auf „Stockfish“ (objektiv) umstellen.
14
+  wirklich etwas gewinnt. Im Pfeil-Menü neben dem Schwert lässt sich auf „Stockfish“
15
+  (objektiv) umstellen.
1516
   Bei Rätseln zählt die Drohung wie ein Hinweis.
1617
 - **Zugbewertung:** Stockfish denkt mit, während du überlegst (Top-3-Züge, live
1718
   immer tiefer); andere Züge werden nur bei Bedarf einzeln nachgerechnet.
@@ -71,7 +72,7 @@ Schlichtes GNOME-Schachprogramm (Python,
7172
   Durchklicken (Pfeiltasten, F dreht), sie öffnet bei der Stellung, die beim Export gezeigt
7273
   war, und die FEN markiert sich mit einem Klick. Alles außer PDF geht auch in die
7374
   Zwischenablage – Bilder als Bild, HTML als formatierter Text.
74
-- **Einstellungen** (Strg+,): Standardfarbe, Streuung von Maia, Brettfarben (Holz,
75
+- **Einstellungen** (Strg+,; Reiter „Tastenkürzel“ auch mit Strg+?): Standardfarbe, Streuung von Maia, Brettfarben (Holz,
7576
   Schiefer, Grün), Notation (deutsch Sf3 oder englisch Nf3 – gilt für Zugliste und
7677
   Erklärungen; PGN-Dateien bleiben international), Figurensätze aus PyChess (`/usr/share/pychess/pieces`), Lichess-Konto.
7778
 

modified schach/app.py +38 −30

@@ -47,6 +47,29 @@ FEATURED_THEMES = [
4747
     "maestro", "companion", "fresca", "leipzig", "chessnut", "python-chess",
4848
 ]
4949
 
50
+# Übersicht für den Reiter „Tastenkürzel“ in den Einstellungen
51
+SHORTCUTS = [
52
+    ("Partie", [
53
+        ("Neue Partie", "<Control>n"), ("Zug zurücknehmen", "<Control>z"),
54
+        ("Hinweis", "h"), ("Drohung zeigen", "b"), ("Neues Rätsel", "r"),
55
+    ]),
56
+    ("Ansicht", [
57
+        ("Brett drehen", "f"), ("Zugliste und Bewertung", "a"),
58
+        ("Zurück zur aktuellen Stellung", "Escape"),
59
+    ]),
60
+    ("Spielstände", [
61
+        ("Spielstand speichern", "<Control>s"), ("Spielstände öffnen", "<Control>o"),
62
+        ("Exportieren (PGN, Bild, PDF, HTML …)", "<Control><Shift>s"),
63
+    ]),
64
+    ("Zwischenablage", [
65
+        ("Partie als PGN kopieren", "<Control>c"),
66
+        ("Stellung als FEN kopieren", "<Control><Shift>c"),
67
+        ("Partie, Stellung oder Lichess-Link einfügen", "<Control>v"),
68
+    ]),
69
+    ("Allgemein", [("Einstellungen", "<Control>comma"), ("Tastenkürzel", "<Control>question")]),
70
+]
71
+ICON_DIR = os.path.join(os.path.dirname(__file__), "icons")
72
+
5073
 SETTINGS_PATH = os.path.join(GLib.get_user_config_dir(), "schach", "settings.json")
5174
 DEFAULTS = {
5275
     "elo": 1200, "color": "white", "theme": "cburnett", "puzzle_difficulty": "normal",
@@ -232,7 +255,8 @@ class Window(OnlineMixin, PuzzleMixin, O
232255
             sources.append(label, f"win.threat-source::{key}")
233256
         helper_menu = Gio.Menu()
234257
         helper_menu.append_section("Hinweis von", helpers)
235
-        helper_menu.append_section("Drohung von", sources)
258
+        threat_menu = Gio.Menu()
259
+        threat_menu.append_section("Drohung von", sources)
236260
         self.helper_menu = helper_menu
237261
         self.hint_content = Adw.ButtonContent(icon_name="dialog-information-symbolic", label="Hinweis")
238262
         self.hint_btn = Adw.SplitButton(
@@ -241,7 +265,9 @@ class Window(OnlineMixin, PuzzleMixin, O
241265
         self.hint_btn.set_action_name("win.hint")
242266
         self.help_box = Gtk.Box(spacing=6)
243267
         self.help_box.append(self.hint_btn)
244
-        self.threat_btn = Gtk.Button(icon_name="dialog-warning-symbolic")
268
+        self.threat_btn = Adw.SplitButton(
269
+            icon_name="schach-threat-symbolic", menu_model=threat_menu, dropdown_tooltip="Wer droht?",
270
+        )
245271
         self.threat_btn.set_action_name("win.threat")
246272
         self.help_box.append(self.threat_btn)
247273
         self.help_box.append(self._build_duo_button())
@@ -1373,16 +1399,20 @@ class Window(OnlineMixin, PuzzleMixin, O
13731399
             self.movelist.notation = self._notation()
13741400
             self._refresh()
13751401
 
1376
-    def _preferences_dialog(self, *_):
1402
+    def _preferences_dialog(self, *_, page=None):
13771403
         if self.prefs_dialog is not None:
1404
+            if page:
1405
+                self.prefs_dialog.show_page(page)
13781406
             return
13791407
         installed = set(available_themes())
13801408
         themes = [
13811409
             (name, "Eingebaut" if name == "python-chess" else name.capitalize())
13821410
             for name in FEATURED_THEMES if name in installed
13831411
         ]
1384
-        dialog = self.prefs_dialog = Preferences(self, themes)
1412
+        dialog = self.prefs_dialog = Preferences(self, themes, SHORTCUTS)
13851413
         dialog.connect("closed", lambda *_: setattr(self, "prefs_dialog", None))
1414
+        if page:
1415
+            dialog.show_page(page)
13861416
         dialog.present(self)
13871417
 
13881418
     # --- Dialoge -----------------------------------------------------------
@@ -1452,32 +1482,8 @@ class Window(OnlineMixin, PuzzleMixin, O
14521482
             Gtk.UriLauncher.new(f"https://lichess.org/{self.online_id}").launch(self, None, None, None)
14531483
 
14541484
     def _shortcuts_dialog(self, *_):
1455
-        dialog = Adw.ShortcutsDialog()
1456
-        for title, items in [
1457
-            ("Partie", [
1458
-                ("Neue Partie", "<Control>n"), ("Zug zurücknehmen", "<Control>z"),
1459
-                ("Hinweis", "h"), ("Drohung zeigen", "b"), ("Neues Rätsel", "r"),
1460
-            ]),
1461
-            ("Ansicht", [
1462
-                ("Brett drehen", "f"), ("Zugliste und Bewertung", "a"),
1463
-                ("Zurück zur aktuellen Stellung", "Escape"),
1464
-            ]),
1465
-            ("Spielstände", [
1466
-                ("Spielstand speichern", "<Control>s"), ("Spielstände öffnen", "<Control>o"),
1467
-                ("Exportieren (PGN, Bild, PDF, HTML …)", "<Control><Shift>s"),
1468
-            ]),
1469
-            ("Zwischenablage", [
1470
-                ("Partie als PGN kopieren", "<Control>c"),
1471
-                ("Stellung als FEN kopieren", "<Control><Shift>c"),
1472
-                ("Partie, Stellung oder Lichess-Link einfügen", "<Control>v"),
1473
-            ]),
1474
-            ("Allgemein", [("Einstellungen", "<Control>comma"), ("Tastenkürzel", "<Control>question")]),
1475
-        ]:
1476
-            section = Adw.ShortcutsSection(title=title)
1477
-            for label, accel in items:
1478
-                section.add(Adw.ShortcutsItem.new(label, accel))
1479
-            dialog.add(section)
1480
-        dialog.present(self)
1485
+        """Tastenkürzel stehen als eigener Reiter in den Einstellungen."""
1486
+        self._preferences_dialog(page="shortcuts")
14811487
 
14821488
     def _about_dialog(self, *_):
14831489
         about = Adw.AboutDialog(
@@ -1721,6 +1727,8 @@ class SchachApp(Adw.Application):
17211727
 
17221728
     def do_startup(self):
17231729
         Adw.Application.do_startup(self)
1730
+        # eigene Symbole (z. B. das Schwert für Drohungen), eingefärbt wie die GNOME-Symbole
1731
+        Gtk.IconTheme.get_for_display(Gdk.Display.get_default()).add_search_path(ICON_DIR)
17241732
         self.maia = EngineWorker(MAIA_CMD, on_ready=self._on_maia_ready)
17251733
         self.stockfish = EngineWorker(
17261734
             STOCKFISH_CMD, options={"Threads": min(8, os.cpu_count() or 2), "Hash": 256}

added schach/icons/hicolor/scalable/actions/schach-threat-symbolic.svg +9 −0

@@ -0,0 +1,9 @@
1
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
2
+  <!-- Schwert, schräg: Klinge nach rechts oben, Griff links unten -->
3
+  <g fill="#2e3436" transform="rotate(45 8 8)">
4
+    <path d="M8 0.4 L9.15 2.2 L9.15 10 L6.85 10 L6.85 2.2 Z"/>
5
+    <rect x="4.4" y="10" width="7.2" height="1.6" rx="0.8"/>
6
+    <rect x="7.2" y="11.6" width="1.6" height="2.6"/>
7
+    <circle cx="8" cy="14.9" r="1.1"/>
8
+  </g>
9
+</svg>

modified schach/prefs.py +26 −4

@@ -13,16 +13,38 @@ COLORS = [("white", "Weiß"), ("black", "Schwarz"), ("random", "Zufällig")]
1313
 
1414
 
1515
 class Preferences(Adw.PreferencesDialog):
16
-    def __init__(self, win, themes):
16
+    def __init__(self, win, themes, shortcuts=()):
1717
         super().__init__(title="Einstellungen", search_enabled=False)
1818
         self.win = win
1919
         self.app = win.get_application()
2020
         self._themes = themes  # [(name, label)]
21
-        self.add(self._general_page())
22
-        self.add(self._appearance_page())
23
-        self.add(self._lichess_page())
21
+        self.pages = {
22
+            "general": self._general_page(),
23
+            "appearance": self._appearance_page(),
24
+            "lichess": self._lichess_page(),
25
+            "shortcuts": self._shortcuts_page(shortcuts),
26
+        }
27
+        for page in self.pages.values():
28
+            self.add(page)
2429
         self.refresh_lichess()
2530
 
31
+    def show_page(self, name):
32
+        if name in self.pages:
33
+            self.set_visible_page(self.pages[name])
34
+
35
+    # --- Tastenkürzel ------------------------------------------------------
36
+
37
+    def _shortcuts_page(self, shortcuts):
38
+        page = Adw.PreferencesPage(title="Tastenkürzel", icon_name="preferences-desktop-keyboard-shortcuts-symbolic")
39
+        for title, items in shortcuts:
40
+            group = Adw.PreferencesGroup(title=title)
41
+            for label, accel in items:
42
+                row = Adw.ActionRow(title=label, use_markup=False)
43
+                row.add_suffix(Gtk.ShortcutLabel(accelerator=accel, valign=Gtk.Align.CENTER))
44
+                group.add(row)
45
+            page.add(group)
46
+        return page
47
+
2648
     def _set(self, key, value):
2749
         """Wert in allen Fenstern übernehmen und speichern."""
2850
         self.app.update_setting(key, value)