feat(training): pick the course colour first in the opening dialog
public
feat(training): pick the course colour first in the opening dialog Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | 2253b73de93afa7baea64304a841366a0f52813b |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | b4ae4e5df046 |
| Children | 447ade111494 |
| Pushlog | by timo via ssh by timo via ssh |
modified schach/training.py +25 −8
| @@ -160,21 +160,38 @@ class OpeningMixin: | ||
| 160 | 160 | dialog.set_response_appearance("start", Adw.ResponseAppearance.SUGGESTED) |
| 161 | 161 | dialog.set_default_response("start") |
| 162 | 162 | dialog.set_close_response("cancel") |
| 163 | - row = Adw.ComboRow(title="Kurs", model=Gtk.StringList.new([c.title for c in available])) | |
| 164 | - last = self.settings.get("course", "") | |
| 165 | - titles = [c.title for c in available] | |
| 166 | - if last in titles: | |
| 167 | - row.set_selected(titles.index(last)) | |
| 163 | + sides = [s for s in (chess.WHITE, chess.BLACK) if any(c.color == s for c in available)] | |
| 164 | + side_row = Adw.ComboRow( | |
| 165 | + title="Farbe", | |
| 166 | + model=Gtk.StringList.new(["Weiß" if s == chess.WHITE else "Schwarz" for s in sides]), | |
| 167 | + ) | |
| 168 | + row = Adw.ComboRow(title="Kurs") | |
| 169 | + shown = [] # Kurse der gewählten Farbe, in der Reihenfolge der Liste | |
| 168 | 170 | intro = Gtk.Label(wrap=True, xalign=0, css_classes=["dim-label"], margin_top=6, width_chars=36, max_width_chars=44) |
| 169 | 171 | |
| 170 | 172 | def show_intro(*_): |
| 171 | - course = available[row.get_selected()] | |
| 173 | + if not shown or row.get_selected() >= len(shown): | |
| 174 | + return | |
| 175 | + course = shown[row.get_selected()] | |
| 172 | 176 | side = "Weiß" if course.color == chess.WHITE else "Schwarz" |
| 173 | 177 | intro.set_label(f"Du spielst {side}. {course.intro}") |
| 174 | 178 | |
| 179 | + def fill_courses(*_, select=None): | |
| 180 | + side = sides[side_row.get_selected()] | |
| 181 | + shown[:] = [c for c in available if c.color == side] | |
| 182 | + titles = [c.title for c in shown] | |
| 183 | + row.set_model(Gtk.StringList.new(titles)) | |
| 184 | + row.set_selected(titles.index(select) if select in titles else 0) | |
| 185 | + show_intro() | |
| 186 | + | |
| 187 | + last = next((c for c in available if c.title == self.settings.get("course", "")), None) | |
| 188 | + if last is not None: | |
| 189 | + side_row.set_selected(sides.index(last.color)) | |
| 190 | + fill_courses(select=last.title if last else None) | |
| 191 | + side_row.connect("notify::selected", fill_courses) | |
| 175 | 192 | row.connect("notify::selected", show_intro) |
| 176 | - show_intro() | |
| 177 | 193 | group = Adw.PreferencesGroup() |
| 194 | + group.add(side_row) | |
| 178 | 195 | group.add(row) |
| 179 | 196 | box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) |
| 180 | 197 | box.append(group) |
| @@ -184,7 +201,7 @@ class OpeningMixin: | ||
| 184 | 201 | def on_response(_d, response): |
| 185 | 202 | if response != "start": |
| 186 | 203 | return |
| 187 | - course = available[row.get_selected()] | |
| 204 | + course = shown[row.get_selected()] | |
| 188 | 205 | self.get_application().update_setting("course", course.title) |
| 189 | 206 | if self._busy(): |
| 190 | 207 | self.get_application().open_window(None, blank=True).start_opening(course) |