quantumgui 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. quantumgui/__init__.py +9 -0
  2. quantumgui/__main__.py +6 -0
  3. quantumgui/cli.py +341 -0
  4. quantumgui/core/__init__.py +39 -0
  5. quantumgui/core/animation.py +221 -0
  6. quantumgui/core/audit.py +323 -0
  7. quantumgui/core/context.py +54 -0
  8. quantumgui/core/data_source.py +426 -0
  9. quantumgui/core/draw.py +428 -0
  10. quantumgui/core/enterprise.py +402 -0
  11. quantumgui/core/enterprise_app.py +419 -0
  12. quantumgui/core/events.py +34 -0
  13. quantumgui/core/geometry.py +108 -0
  14. quantumgui/core/native_dialogs.py +276 -0
  15. quantumgui/core/pdf_report.py +390 -0
  16. quantumgui/core/rules.py +284 -0
  17. quantumgui/core/state.py +42 -0
  18. quantumgui/core/task_runner.py +181 -0
  19. quantumgui/core/widget.py +498 -0
  20. quantumgui/core/window.py +920 -0
  21. quantumgui/core/xlsx_export.py +145 -0
  22. quantumgui/py.typed +0 -0
  23. quantumgui/theme/__init__.py +32 -0
  24. quantumgui/theme/hct.py +191 -0
  25. quantumgui/theme/theme.py +93 -0
  26. quantumgui/theme/tokens.py +423 -0
  27. quantumgui/ui.py +2142 -0
  28. quantumgui/widgets/__init__.py +168 -0
  29. quantumgui/widgets/advanced.py +499 -0
  30. quantumgui/widgets/button.py +224 -0
  31. quantumgui/widgets/charts.py +625 -0
  32. quantumgui/widgets/charts_bi.py +528 -0
  33. quantumgui/widgets/charts_extra.py +430 -0
  34. quantumgui/widgets/charts_pro.py +568 -0
  35. quantumgui/widgets/checkbox.py +199 -0
  36. quantumgui/widgets/chip.py +219 -0
  37. quantumgui/widgets/containers.py +321 -0
  38. quantumgui/widgets/data_controls.py +487 -0
  39. quantumgui/widgets/data_grid.py +956 -0
  40. quantumgui/widgets/data_table.py +551 -0
  41. quantumgui/widgets/date_picker.py +407 -0
  42. quantumgui/widgets/display_media.py +372 -0
  43. quantumgui/widgets/display_pro.py +407 -0
  44. quantumgui/widgets/drawer.py +252 -0
  45. quantumgui/widgets/enterprise_controls.py +934 -0
  46. quantumgui/widgets/fab.py +261 -0
  47. quantumgui/widgets/forms_pro.py +703 -0
  48. quantumgui/widgets/forms_pro_media.py +587 -0
  49. quantumgui/widgets/inputs.py +870 -0
  50. quantumgui/widgets/layout_pro.py +162 -0
  51. quantumgui/widgets/list_view.py +307 -0
  52. quantumgui/widgets/masked_input.py +131 -0
  53. quantumgui/widgets/master_detail.py +155 -0
  54. quantumgui/widgets/navigation.py +382 -0
  55. quantumgui/widgets/overlays.py +355 -0
  56. quantumgui/widgets/productivity.py +500 -0
  57. quantumgui/widgets/productivity_boards.py +544 -0
  58. quantumgui/widgets/radio.py +209 -0
  59. quantumgui/widgets/scroll_view.py +129 -0
  60. quantumgui/widgets/select.py +373 -0
  61. quantumgui/widgets/sheets.py +249 -0
  62. quantumgui/widgets/slider.py +209 -0
  63. quantumgui/widgets/switch.py +196 -0
  64. quantumgui/widgets/tabs.py +175 -0
  65. quantumgui/widgets/text.py +101 -0
  66. quantumgui/widgets/text_field.py +490 -0
  67. quantumgui/widgets/time_picker.py +499 -0
  68. quantumgui-1.0.0.dist-info/METADATA +137 -0
  69. quantumgui-1.0.0.dist-info/RECORD +73 -0
  70. quantumgui-1.0.0.dist-info/WHEEL +5 -0
  71. quantumgui-1.0.0.dist-info/entry_points.txt +2 -0
  72. quantumgui-1.0.0.dist-info/licenses/LICENSE +32 -0
  73. quantumgui-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,544 @@
1
+ """Phase 9 Desktop Productivity Controls (Part 2): CalendarView, KanbanBoard, PropertyGrid."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import calendar
6
+ from dataclasses import dataclass, field
7
+ from datetime import date
8
+ from typing import Any, Callable, Literal, Sequence
9
+
10
+ import glfw
11
+ import skia
12
+
13
+ from ..core.draw import (
14
+ draw_elevation_shadow,
15
+ draw_icon,
16
+ draw_text_centered_y,
17
+ font_for_style,
18
+ make_rrect,
19
+ make_rrect_spec,
20
+ measure_text,
21
+ resolve_color,
22
+ )
23
+ from ..core.events import CharEvent, KeyEvent, MouseEvent
24
+ from ..core.geometry import Constraints, Rect, Size
25
+ from ..core.widget import Widget
26
+ from ..theme import Color, Theme
27
+
28
+ EventTone = Literal["primary", "secondary", "tertiary", "error"]
29
+
30
+ _MONTHS = (
31
+ "",
32
+ "Enero",
33
+ "Febrero",
34
+ "Marzo",
35
+ "Abril",
36
+ "Mayo",
37
+ "Junio",
38
+ "Julio",
39
+ "Agosto",
40
+ "Septiembre",
41
+ "Octubre",
42
+ "Noviembre",
43
+ "Diciembre",
44
+ )
45
+
46
+
47
+ def _event_colors(tone: EventTone, theme: Theme) -> tuple[Color, Color]:
48
+ c = theme.colors
49
+ if tone == "secondary":
50
+ return (c.secondary_container, c.on_secondary_container)
51
+ if tone == "tertiary":
52
+ return (c.tertiary_container, c.on_tertiary_container)
53
+ if tone == "error":
54
+ return (c.error_container, c.on_error_container)
55
+ return (c.primary_container, c.on_primary_container)
56
+
57
+
58
+ # ---------------------------------------------------------------------------
59
+ # 5. CalendarView (Full Monthly Agenda with Events)
60
+ # ---------------------------------------------------------------------------
61
+
62
+
63
+ @dataclass
64
+ class CalendarEvent:
65
+ day: date
66
+ title: str
67
+ tone: EventTone = "primary"
68
+ data: Any = None
69
+
70
+
71
+ class CalendarView(Widget):
72
+ """Full monthly Material Design 3 CalendarView displaying color-coded event pills."""
73
+
74
+ interactive = True
75
+ manages_own_box = True
76
+ cursor = "pointer"
77
+
78
+ def __init__(
79
+ self,
80
+ events: Sequence[CalendarEvent] = (),
81
+ *,
82
+ year: int | None = None,
83
+ month: int | None = None,
84
+ height: float = 380.0,
85
+ on_day_click: Callable[[date], None] | None = None,
86
+ on_event_click: Callable[[CalendarEvent], None] | None = None,
87
+ ) -> None:
88
+ super().__init__()
89
+ today = date.today()
90
+ self.year = year or today.year
91
+ self.month = month or today.month
92
+ self.events: list[CalendarEvent] = list(events)
93
+ self.cal_height = float(height)
94
+ self.on_day_click = on_day_click
95
+ self.on_event_click = on_event_click
96
+ self._prev_rect: Rect = Rect(0, 0, 0, 0)
97
+ self._next_rect: Rect = Rect(0, 0, 0, 0)
98
+ self._day_rects: list[tuple[date, Rect]] = []
99
+ self._ev_rects: list[tuple[CalendarEvent, Rect]] = []
100
+ self._fill_width = True
101
+
102
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
103
+ w = constraints.max_width if constraints.max_width != float("inf") else 560.0
104
+ return Size(w, self.cal_height)
105
+
106
+ def on_mouse_up(self, event: MouseEvent) -> None:
107
+ was_pressed = self.pressed
108
+ super().on_mouse_up(event)
109
+ if not was_pressed:
110
+ return
111
+ if self._prev_rect.contains(event.x, event.y):
112
+ if self.month == 1:
113
+ self.month = 12
114
+ self.year -= 1
115
+ else:
116
+ self.month -= 1
117
+ self.invalidate()
118
+ return
119
+ if self._next_rect.contains(event.x, event.y):
120
+ if self.month == 12:
121
+ self.month = 1
122
+ self.year += 1
123
+ else:
124
+ self.month += 1
125
+ self.invalidate()
126
+ return
127
+ for ev, er in self._ev_rects:
128
+ if er.contains(event.x, event.y):
129
+ if self.on_event_click is not None:
130
+ self.on_event_click(ev)
131
+ return
132
+ for d, dr in self._day_rects:
133
+ if dr.contains(event.x, event.y):
134
+ if self.on_day_click is not None:
135
+ self.on_day_click(d)
136
+ return
137
+
138
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
139
+ c = theme.colors
140
+ r = self.rect
141
+ rad_spec = self._shape_override if self._shape_override is not None else "medium"
142
+ rrect = make_rrect_spec(r, rad_spec, theme)
143
+ bg = resolve_color(self._bg_override, theme, c.surface) or c.surface
144
+
145
+ canvas.save()
146
+ canvas.clipRRect(rrect, doAntiAlias=True)
147
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
148
+
149
+ # Top header bar
150
+ hdr_h = 40.0
151
+ canvas.drawRect(skia.Rect.MakeXYWH(r.x, r.y, r.width, hdr_h), skia.Paint(Color=c.surface_container.to_skia()))
152
+ tfont = font_for_style(theme.font_family, theme.typography.title_medium)
153
+ title = f"{_MONTHS[self.month]} {self.year}"
154
+ draw_text_centered_y(canvas, title, r.x + 16.0, r.y + hdr_h * 0.5, tfont, c.on_surface)
155
+
156
+ self._prev_rect = Rect(r.right - 76.0, r.y + 4.0, 32.0, 32.0)
157
+ self._next_rect = Rect(r.right - 38.0, r.y + 4.0, 32.0, 32.0)
158
+ draw_icon(canvas, "chevron_left", self._prev_rect.center_x, self._prev_rect.center_y, 18.0, c.on_surface_variant)
159
+ draw_icon(canvas, "chevron_right", self._next_rect.center_x, self._next_rect.center_y, 18.0, c.on_surface_variant)
160
+
161
+ # Weekday strip
162
+ wd_h = 22.0
163
+ wfont = font_for_style(theme.font_family, theme.typography.label_small)
164
+ cell_w = r.width / 7.0
165
+ for i, wd in enumerate(("Lun", "Mar", "Mié", "Jue", "Vie", "Sáb", "Dom")):
166
+ cx = r.x + i * cell_w + cell_w * 0.5
167
+ draw_text_centered_y(canvas, wd, cx - measure_text(wfont, wd) * 0.5, r.y + hdr_h + wd_h * 0.5, wfont, c.on_surface_variant)
168
+
169
+ # Month cells
170
+ cal = calendar.monthcalendar(self.year, self.month)
171
+ grid_top = r.y + hdr_h + wd_h
172
+ cell_h = max(32.0, (r.bottom - grid_top) / max(1, len(cal)))
173
+ div_paint = skia.Paint(Color=c.outline_variant.to_skia(), StrokeWidth=1.0)
174
+ today = date.today()
175
+
176
+ by_day: dict[date, list[CalendarEvent]] = {}
177
+ for ev in self.events:
178
+ by_day.setdefault(ev.day, []).append(ev)
179
+
180
+ self._day_rects = []
181
+ self._ev_rects = []
182
+
183
+ for ri, week in enumerate(cal):
184
+ ry = grid_top + ri * cell_h
185
+ canvas.drawLine(r.x, ry, r.right, ry, div_paint)
186
+ for ci, day_num in enumerate(week):
187
+ rx = r.x + ci * cell_w
188
+ if ci > 0:
189
+ canvas.drawLine(rx, ry, rx, ry + cell_h, div_paint)
190
+ if day_num == 0:
191
+ continue
192
+ d = date(self.year, self.month, day_num)
193
+ dr = Rect(rx, ry, cell_w, cell_h)
194
+ self._day_rects.append((d, dr))
195
+
196
+ num_s = str(day_num)
197
+ if d == today:
198
+ canvas.drawCircle(rx + 14.0, ry + 10.0, 8.5, skia.Paint(AntiAlias=True, Color=c.primary.to_skia()))
199
+ draw_text_centered_y(canvas, num_s, rx + 14.0 - measure_text(wfont, num_s) * 0.5, ry + 10.0, wfont, c.on_primary)
200
+ else:
201
+ draw_text_centered_y(canvas, num_s, rx + 7.0, ry + 10.0, wfont, c.on_surface_variant)
202
+
203
+ ey = ry + 18.0
204
+ for ev in by_day.get(d, [])[:2]:
205
+ if ey + 14.0 > ry + cell_h:
206
+ break
207
+ er = Rect(rx + 4.0, ey, max(12.0, cell_w - 8.0), 15.0)
208
+ ebg, efg = _event_colors(ev.tone, theme)
209
+ canvas.drawRRect(make_rrect(er, 4.0), skia.Paint(AntiAlias=True, Color=ebg.to_skia()))
210
+ canvas.save()
211
+ canvas.clipRect(skia.Rect.MakeXYWH(er.x + 2.0, er.y, max(0.0, er.width - 4.0), er.height))
212
+ draw_text_centered_y(canvas, ev.title, er.x + 4.0, er.center_y, wfont, efg)
213
+ canvas.restore()
214
+ self._ev_rects.append((ev, er))
215
+ ey += 16.5
216
+
217
+ canvas.restore()
218
+ bc = resolve_color(self._border_color_override, theme, c.outline_variant) or c.outline_variant
219
+ bw = self._border_width_override if self._border_width_override is not None else 1.0
220
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bc.to_skia(), Style=skia.Paint.kStroke_Style, StrokeWidth=bw))
221
+
222
+
223
+ # ---------------------------------------------------------------------------
224
+ # 6. KanbanBoard (GPU Drag & Drop Columns + Cards)
225
+ # ---------------------------------------------------------------------------
226
+
227
+
228
+ @dataclass
229
+ class KanbanCard:
230
+ title: str
231
+ tag: str = ""
232
+ tone: EventTone = "primary"
233
+ assignee: str = ""
234
+ data: Any = None
235
+
236
+
237
+ class KanbanBoard(Widget):
238
+ """GPU-accelerated Kanban Board with drag & drop cards between columns."""
239
+
240
+ interactive = True
241
+ manages_own_box = False
242
+ cursor = "pointer"
243
+
244
+ def __init__(
245
+ self,
246
+ columns: dict[str, list[KanbanCard]],
247
+ *,
248
+ height: float = 340.0,
249
+ on_move: Callable[[KanbanCard, str, str], None] | None = None,
250
+ ) -> None:
251
+ super().__init__()
252
+ self.columns: dict[str, list[KanbanCard]] = {k: list(v) for k, v in columns.items()}
253
+ self.board_height = float(height)
254
+ self.on_move = on_move
255
+ self._col_rects: dict[str, Rect] = {}
256
+ self._card_rects: list[tuple[str, int, Rect]] = []
257
+ self._dragging: tuple[str, int, KanbanCard] | None = None
258
+ self._drag_pos: tuple[float, float] = (0.0, 0.0)
259
+ self._fill_width = True
260
+
261
+ def move_card(self, from_col: str, card_idx: int, to_col: str) -> bool:
262
+ if from_col not in self.columns or to_col not in self.columns:
263
+ return False
264
+ if not (0 <= card_idx < len(self.columns[from_col])):
265
+ return False
266
+ if from_col == to_col:
267
+ return False
268
+ card = self.columns[from_col].pop(card_idx)
269
+ self.columns[to_col].append(card)
270
+ if self.on_move is not None:
271
+ self.on_move(card, from_col, to_col)
272
+ self.invalidate()
273
+ return True
274
+
275
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
276
+ w = constraints.max_width if constraints.max_width != float("inf") else 640.0
277
+ return Size(w, self.board_height)
278
+
279
+ def on_mouse_down(self, event: MouseEvent) -> None:
280
+ super().on_mouse_down(event)
281
+ for col_name, idx, cr in self._card_rects:
282
+ if cr.contains(event.x, event.y):
283
+ self._dragging = (col_name, idx, self.columns[col_name][idx])
284
+ self._drag_pos = (event.x, event.y)
285
+ self.invalidate()
286
+ return
287
+
288
+ def on_mouse_move(self, event: MouseEvent) -> None:
289
+ if self._dragging is not None:
290
+ self._drag_pos = (event.x, event.y)
291
+ self.invalidate()
292
+
293
+ def on_mouse_up(self, event: MouseEvent) -> None:
294
+ super().on_mouse_up(event)
295
+ if self._dragging is None:
296
+ return
297
+ from_col, idx, _card = self._dragging
298
+ self._dragging = None
299
+ for col_name, cr in self._col_rects.items():
300
+ if cr.contains(event.x, event.y) and col_name != from_col:
301
+ self.move_card(from_col, idx, col_name)
302
+ return
303
+ self.invalidate()
304
+
305
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
306
+ c = theme.colors
307
+ r = self.rect
308
+ names = list(self.columns.keys())
309
+ if not names:
310
+ return
311
+ gap = 12.0
312
+ col_w = (r.width - gap * (len(names) - 1)) / len(names)
313
+
314
+ hfont = font_for_style(theme.font_family, theme.typography.title_small)
315
+ bfont = font_for_style(theme.font_family, theme.typography.body_medium)
316
+ sfont = font_for_style(theme.font_family, theme.typography.label_small)
317
+
318
+ self._col_rects = {}
319
+ self._card_rects = []
320
+
321
+ for ci, name in enumerate(names):
322
+ cx = r.x + ci * (col_w + gap)
323
+ col_r = Rect(cx, r.y, col_w, r.height)
324
+ self._col_rects[name] = col_r
325
+
326
+ is_drop_target = self._dragging is not None and col_r.contains(*self._drag_pos) and self._dragging[0] != name
327
+ col_bg = c.primary_container.with_alpha(0.35) if is_drop_target else c.surface_container_low
328
+ canvas.drawRRect(make_rrect(col_r, 12.0), skia.Paint(AntiAlias=True, Color=col_bg.to_skia()))
329
+
330
+ cards = self.columns[name]
331
+ draw_text_centered_y(canvas, name, col_r.x + 12.0, col_r.y + 22.0, hfont, c.on_surface)
332
+ cnt = str(len(cards))
333
+ cw = measure_text(sfont, cnt) + 12.0
334
+ cnt_r = Rect(col_r.right - cw - 10.0, col_r.y + 12.0, cw, 20.0)
335
+ canvas.drawRRect(make_rrect(cnt_r, 10.0), skia.Paint(AntiAlias=True, Color=c.surface_container_highest.to_skia()))
336
+ draw_text_centered_y(canvas, cnt, cnt_r.center_x - (cw - 12.0) * 0.5, cnt_r.center_y, sfont, c.on_surface_variant)
337
+
338
+ cy = col_r.y + 44.0
339
+ for idx, card in enumerate(cards):
340
+ card_h = 66.0 if card.tag else 46.0
341
+ if cy + card_h > col_r.bottom - 8.0:
342
+ break
343
+ card_r = Rect(col_r.x + 8.0, cy, col_w - 16.0, card_h)
344
+ self._card_rects.append((name, idx, card_r))
345
+
346
+ is_dragged = self._dragging is not None and self._dragging[0] == name and self._dragging[1] == idx
347
+ alpha = 0.35 if is_dragged else 1.0
348
+ if not is_dragged:
349
+ draw_elevation_shadow(canvas, card_r, 10.0, 1, c.shadow)
350
+ canvas.drawRRect(
351
+ make_rrect(card_r, 10.0),
352
+ skia.Paint(AntiAlias=True, Color=c.surface.with_alpha(alpha).to_skia()),
353
+ )
354
+ draw_text_centered_y(canvas, card.title, card_r.x + 10.0, card_r.y + 20.0, bfont, c.on_surface.with_alpha(alpha))
355
+ if card.tag:
356
+ tbg, tfg = _event_colors(card.tone, theme)
357
+ tw = measure_text(sfont, card.tag) + 12.0
358
+ tr = Rect(card_r.x + 10.0, card_r.y + 38.0, tw, 18.0)
359
+ canvas.drawRRect(make_rrect(tr, 9.0), skia.Paint(AntiAlias=True, Color=tbg.with_alpha(alpha).to_skia()))
360
+ draw_text_centered_y(canvas, card.tag, tr.x + 6.0, tr.center_y, sfont, tfg.with_alpha(alpha))
361
+ cy += card_h + 8.0
362
+
363
+ # Floating dragged card ghost
364
+ if self._dragging is not None:
365
+ card = self._dragging[2]
366
+ gx, gy = self._drag_pos
367
+ ghost = Rect(gx - col_w * 0.4, gy - 24.0, col_w - 16.0, 56.0)
368
+ draw_elevation_shadow(canvas, ghost, 10.0, 3, c.shadow)
369
+ canvas.drawRRect(make_rrect(ghost, 10.0), skia.Paint(AntiAlias=True, Color=c.surface_container_high.to_skia()))
370
+ draw_text_centered_y(canvas, card.title, ghost.x + 12.0, ghost.center_y, bfont, c.on_surface)
371
+
372
+
373
+ # ---------------------------------------------------------------------------
374
+ # 7. PropertyGrid / Inspector (Key-Value IDE Property Editor)
375
+ # ---------------------------------------------------------------------------
376
+
377
+
378
+ @dataclass
379
+ class PropertyItem:
380
+ key: str
381
+ value: Any
382
+ type: Literal["text", "number", "bool", "choice", "color"] = "text"
383
+ choices: list[str] = field(default_factory=list)
384
+ label: str | None = None
385
+
386
+
387
+ class PropertyGrid(Widget):
388
+ """IDE / RAD Studio style key-value Property Inspector with inline editing."""
389
+
390
+ interactive = True
391
+ focusable = True
392
+ manages_own_box = True
393
+
394
+ ROW_H = 36.0
395
+
396
+ def __init__(
397
+ self,
398
+ items: Sequence[PropertyItem],
399
+ *,
400
+ on_change: Callable[[str, Any], None] | None = None,
401
+ ) -> None:
402
+ super().__init__()
403
+ self.items: list[PropertyItem] = list(items)
404
+ self.on_change = on_change
405
+ self._editing_idx: int | None = None
406
+ self._edit_buf: str = ""
407
+ self._hover_idx: int = -1
408
+ self._fill_width = True
409
+
410
+ def get(self, key: str) -> Any:
411
+ for it in self.items:
412
+ if it.key == key:
413
+ return it.value
414
+ return None
415
+
416
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
417
+ w = constraints.max_width if constraints.max_width != float("inf") else 340.0
418
+ return Size(w, max(self.ROW_H, len(self.items) * self.ROW_H + 8.0))
419
+
420
+ def _idx_at(self, y: float) -> int:
421
+ idx = int((y - (self.rect.y + 4.0)) // self.ROW_H)
422
+ return idx if 0 <= idx < len(self.items) else -1
423
+
424
+ def _commit(self) -> None:
425
+ if self._editing_idx is None:
426
+ return
427
+ it = self.items[self._editing_idx]
428
+ self._editing_idx = None
429
+ if it.type == "number":
430
+ try:
431
+ it.value = float(self._edit_buf) if "." in self._edit_buf else int(self._edit_buf)
432
+ except ValueError:
433
+ pass
434
+ else:
435
+ it.value = self._edit_buf
436
+ if self.on_change is not None:
437
+ self.on_change(it.key, it.value)
438
+ self.invalidate()
439
+
440
+ def on_mouse_move(self, event: MouseEvent) -> None:
441
+ idx = self._idx_at(event.y)
442
+ if idx != self._hover_idx:
443
+ self._hover_idx = idx
444
+ self.invalidate()
445
+
446
+ def on_mouse_down(self, event: MouseEvent) -> None:
447
+ super().on_mouse_down(event)
448
+ idx = self._idx_at(event.y)
449
+ if idx == -1:
450
+ self._commit()
451
+ return
452
+ it = self.items[idx]
453
+ if it.type == "bool":
454
+ self._commit()
455
+ it.value = not bool(it.value)
456
+ if self.on_change is not None:
457
+ self.on_change(it.key, it.value)
458
+ self.invalidate()
459
+ elif it.type == "choice" and it.choices:
460
+ self._commit()
461
+ cur = it.choices.index(it.value) if it.value in it.choices else -1
462
+ it.value = it.choices[(cur + 1) % len(it.choices)]
463
+ if self.on_change is not None:
464
+ self.on_change(it.key, it.value)
465
+ self.invalidate()
466
+ else:
467
+ if self._editing_idx is not None and self._editing_idx != idx:
468
+ self._commit()
469
+ self._editing_idx = idx
470
+ self._edit_buf = str(it.value)
471
+ self.invalidate()
472
+
473
+ def on_char(self, event: CharEvent) -> None:
474
+ if self._editing_idx is not None:
475
+ self._edit_buf += event.char
476
+ self.invalidate()
477
+
478
+ def on_key(self, event: KeyEvent) -> None:
479
+ if self._editing_idx is None or event.action not in (glfw.PRESS, glfw.REPEAT):
480
+ return
481
+ if event.key == glfw.KEY_BACKSPACE:
482
+ self._edit_buf = self._edit_buf[:-1]
483
+ self.invalidate()
484
+ elif event.key in (glfw.KEY_ENTER, glfw.KEY_KP_ENTER):
485
+ self._commit()
486
+ elif event.key == glfw.KEY_ESCAPE:
487
+ self._editing_idx = None
488
+ self.invalidate()
489
+
490
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
491
+ c = theme.colors
492
+ r = self.rect
493
+ rad_spec = self._shape_override if self._shape_override is not None else "medium"
494
+ rrect = make_rrect_spec(r, rad_spec, theme)
495
+ bg = resolve_color(self._bg_override, theme, c.surface) or c.surface
496
+
497
+ canvas.save()
498
+ canvas.clipRRect(rrect, doAntiAlias=True)
499
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
500
+
501
+ kfont = font_for_style(theme.font_family, theme.typography.label_medium)
502
+ vfont = font_for_style(theme.font_family, theme.typography.body_medium)
503
+ split_x = r.x + r.width * 0.44
504
+ div_paint = skia.Paint(Color=c.outline_variant.to_skia(), StrokeWidth=1.0)
505
+
506
+ for i, it in enumerate(self.items):
507
+ ry = r.y + 4.0 + i * self.ROW_H
508
+ if i == self._hover_idx:
509
+ canvas.drawRect(
510
+ skia.Rect.MakeXYWH(r.x, ry, r.width, self.ROW_H),
511
+ skia.Paint(Color=c.on_surface.with_alpha(theme.state_layers.hover).to_skia()),
512
+ )
513
+ draw_text_centered_y(canvas, it.label or it.key, r.x + 12.0, ry + self.ROW_H * 0.5, kfont, c.on_surface_variant)
514
+
515
+ vx = split_x + 12.0
516
+ cy = ry + self.ROW_H * 0.5
517
+ if self._editing_idx == i:
518
+ er = Rect(split_x + 6.0, ry + 4.0, max(20.0, r.right - split_x - 12.0), self.ROW_H - 8.0)
519
+ canvas.drawRRect(make_rrect(er, 6.0), skia.Paint(AntiAlias=True, Color=c.surface_container_low.to_skia()))
520
+ canvas.drawRRect(make_rrect(er, 6.0), skia.Paint(AntiAlias=True, Color=c.primary.to_skia(), Style=skia.Paint.kStroke_Style, StrokeWidth=1.8))
521
+ draw_text_centered_y(canvas, self._edit_buf + "|", er.x + 8.0, er.center_y, vfont, c.on_surface)
522
+ elif it.type == "bool":
523
+ pill_c = c.primary if it.value else c.surface_container_highest
524
+ pill_fg = c.on_primary if it.value else c.on_surface_variant
525
+ pr = Rect(vx, cy - 10.0, 44.0, 20.0)
526
+ canvas.drawRRect(make_rrect(pr, 10.0), skia.Paint(AntiAlias=True, Color=pill_c.to_skia()))
527
+ txt = "True" if it.value else "False"
528
+ draw_text_centered_y(canvas, txt, pr.center_x - measure_text(kfont, txt) * 0.5, pr.center_y, kfont, pill_fg)
529
+ elif it.type == "color":
530
+ col = resolve_color(str(it.value), theme, c.primary) or c.primary
531
+ canvas.drawCircle(vx + 8.0, cy, 8.0, skia.Paint(AntiAlias=True, Color=col.to_skia()))
532
+ draw_text_centered_y(canvas, str(it.value), vx + 24.0, cy, vfont, c.on_surface)
533
+ else:
534
+ draw_text_centered_y(canvas, str(it.value), vx, cy, vfont, c.on_surface)
535
+
536
+ if i < len(self.items) - 1:
537
+ canvas.drawLine(r.x, ry + self.ROW_H, r.right, ry + self.ROW_H, div_paint)
538
+
539
+ canvas.drawLine(split_x, r.y, split_x, r.bottom, div_paint)
540
+ canvas.restore()
541
+
542
+ bc = resolve_color(self._border_color_override, theme, c.outline_variant) or c.outline_variant
543
+ bw = self._border_width_override if self._border_width_override is not None else 1.0
544
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bc.to_skia(), Style=skia.Paint.kStroke_Style, StrokeWidth=bw))