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,209 @@
1
+ """Material Design 3 Radio button and RadioGroup."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Callable, Literal, Sequence
6
+
7
+ import skia
8
+
9
+ from ..core.animation import SpringPresets, SpringValue
10
+ from ..core.draw import draw_text_centered_y, font_for_style, measure_text
11
+ from ..core.events import MouseEvent
12
+ from ..core.geometry import Constraints, Size
13
+ from ..core.state import State
14
+ from ..core.widget import Widget
15
+ from ..theme import Theme
16
+ from .containers import Column, Row
17
+
18
+ RadioDirection = Literal["vertical", "horizontal"]
19
+
20
+
21
+ class Radio(Widget):
22
+ """Single Material Design 3 Radio option (20dp outer ring, animated 10dp dot)."""
23
+
24
+ interactive = True
25
+ focusable = True
26
+ cursor = "pointer"
27
+
28
+ TARGET_SIZE = 32.0
29
+
30
+ def __init__(
31
+ self,
32
+ *,
33
+ label: str,
34
+ selected: bool = False,
35
+ disabled: bool = False,
36
+ on_select: Callable[[], None] | None = None,
37
+ ) -> None:
38
+ super().__init__()
39
+ self.label = label
40
+ self._selected = selected
41
+ self.disabled = disabled
42
+ self.on_select = on_select
43
+ self._dot_anim = SpringValue(1.0 if selected else 0.0, SpringPresets.EXPRESSIVE_FAST_SPATIAL)
44
+
45
+ @property
46
+ def selected(self) -> bool:
47
+ return self._selected
48
+
49
+ @selected.setter
50
+ def selected(self, val: bool) -> None:
51
+ b = bool(val)
52
+ if b != self._selected:
53
+ self._selected = b
54
+ self._dot_anim.animate_to(1.0 if b else 0.0)
55
+ self.invalidate()
56
+
57
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
58
+ font = font_for_style(theme.font_family, theme.typography.body_large)
59
+ w = self.TARGET_SIZE + 8.0 + measure_text(font, self.label)
60
+ h = max(self.TARGET_SIZE, theme.typography.body_large.line_height)
61
+ return Size(w, h)
62
+
63
+ def tick(self, now: float) -> bool:
64
+ return self._dot_anim.update(now)
65
+
66
+ def on_mouse_up(self, event: MouseEvent) -> None:
67
+ was_pressed = self.pressed
68
+ super().on_mouse_up(event)
69
+ if not self.disabled and was_pressed and self.rect.contains(event.x, event.y):
70
+ if self.on_select is not None:
71
+ self.on_select()
72
+
73
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
74
+ c = theme.colors
75
+ cx = self.rect.x + self.TARGET_SIZE * 0.5
76
+ cy = self.rect.center_y
77
+ t = max(0.0, min(1.0, self._dot_anim.current))
78
+ dot_scale = max(0.0, self._dot_anim.current)
79
+
80
+ # State halo
81
+ if not self.disabled and (self.hovered or self.pressed or self.focused):
82
+ sl = theme.state_layers
83
+ alpha = sl.pressed if self.pressed else (sl.hover if self.hovered else sl.focus)
84
+ halo = c.primary if self._selected else c.on_surface
85
+ canvas.drawCircle(
86
+ cx,
87
+ cy,
88
+ 18.0,
89
+ skia.Paint(AntiAlias=True, Color=halo.with_alpha(alpha).to_skia()),
90
+ )
91
+
92
+ if self.disabled:
93
+ ring_color = c.on_surface.with_alpha(0.38)
94
+ dot_color = c.on_surface.with_alpha(0.38)
95
+ fg = c.on_surface.with_alpha(0.38)
96
+ else:
97
+ ring_color = c.on_surface_variant.blend(c.primary, t)
98
+ dot_color = c.primary
99
+ fg = c.on_surface
100
+
101
+ # 20dp diameter outer ring (radius 9dp + 2dp stroke)
102
+ canvas.drawCircle(
103
+ cx,
104
+ cy,
105
+ 9.0,
106
+ skia.Paint(
107
+ AntiAlias=True,
108
+ Color=ring_color.to_skia(),
109
+ Style=skia.Paint.kStroke_Style,
110
+ StrokeWidth=2.0,
111
+ ),
112
+ )
113
+
114
+ # Animated 10dp diameter inner dot (radius 5dp) with M3 Expressive spring pop
115
+ if dot_scale > 0.01:
116
+ canvas.drawCircle(
117
+ cx,
118
+ cy,
119
+ 5.0 * dot_scale,
120
+ skia.Paint(AntiAlias=True, Color=dot_color.to_skia()),
121
+ )
122
+
123
+ font = font_for_style(theme.font_family, theme.typography.body_large)
124
+ draw_text_centered_y(canvas, self.label, self.rect.x + self.TARGET_SIZE + 8.0, cy, font, fg)
125
+
126
+
127
+ class RadioGroup(Widget):
128
+ """Material Design 3 RadioGroup managing exclusive selection among options."""
129
+
130
+ def __init__(
131
+ self,
132
+ options: Sequence[str],
133
+ *,
134
+ value: str | None = None,
135
+ direction: RadioDirection = "vertical",
136
+ gap: float = 8.0,
137
+ disabled: bool = False,
138
+ bind: State[str | None] | None = None,
139
+ on_change: Callable[[str], None] | None = None,
140
+ ) -> None:
141
+ super().__init__()
142
+ self._options = list(options)
143
+ self._bind = bind
144
+ initial = bind.value if bind is not None else (value if value is not None else (self._options[0] if self._options else None))
145
+ self._value: str | None = initial
146
+ self.disabled = disabled
147
+ self.on_change = on_change
148
+ self._radios: list[tuple[str, Radio]] = []
149
+
150
+ # Build internal layout container without attaching to external `with` stack
151
+ container: Widget = (
152
+ Row(gap=gap, wrap=True)
153
+ if direction == "horizontal"
154
+ else Column(gap=gap, align="start")
155
+ )
156
+ # Re-parent container cleanly as our sole child
157
+ if container.parent is not None:
158
+ container.parent.children.remove(container)
159
+ container.parent = None
160
+ self.add_child(container)
161
+
162
+ for opt in self._options:
163
+ r = Radio(
164
+ label=opt,
165
+ selected=(opt == self._value),
166
+ disabled=disabled,
167
+ on_select=lambda o=opt: self._select(o),
168
+ )
169
+ if r.parent is not None:
170
+ r.parent.children.remove(r)
171
+ r.parent = None
172
+ container.add_child(r)
173
+ self._radios.append((opt, r))
174
+
175
+ if bind is not None:
176
+ bind.subscribe(self._on_bound_change)
177
+
178
+ def _on_bound_change(self, new_val: str | None) -> None:
179
+ if new_val != self._value:
180
+ self._value = new_val
181
+ for opt, r in self._radios:
182
+ r.selected = (opt == new_val)
183
+ self.invalidate()
184
+
185
+ def _select(self, opt: str) -> None:
186
+ if self.disabled or opt == self._value:
187
+ return
188
+ self.value = opt
189
+ if self.on_change is not None:
190
+ self.on_change(opt)
191
+
192
+ @property
193
+ def value(self) -> str | None:
194
+ return self._value
195
+
196
+ @value.setter
197
+ def value(self, val: str | None) -> None:
198
+ if val != self._value:
199
+ self._value = val
200
+ for opt, r in self._radios:
201
+ r.selected = (opt == val)
202
+ if self._bind is not None and self._bind.value != val:
203
+ self._bind.value = val
204
+ self.invalidate()
205
+
206
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
207
+ if not self.children:
208
+ return Size(0.0, 0.0)
209
+ return self.children[0].measure(constraints, theme)
@@ -0,0 +1,129 @@
1
+ """Material Design 3 ScrollView container with clipped viewport and M3 scrollbar."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import skia
6
+
7
+ from ..core.draw import make_rrect
8
+ from ..core.events import ScrollEvent
9
+ from ..core.geometry import Constraints, Rect, Size
10
+ from ..core.widget import Widget
11
+ from ..theme import Theme
12
+ from .containers import Column, CrossAlign
13
+
14
+
15
+ class ScrollView(Column):
16
+ """Scrollable vertical container with an official Material Design 3 scrollbar."""
17
+
18
+ interactive = True
19
+
20
+ def __init__(
21
+ self,
22
+ *,
23
+ gap: float = 0.0,
24
+ align: CrossAlign = "stretch",
25
+ show_scrollbar: bool = True,
26
+ wheel_step: float = 44.0,
27
+ ) -> None:
28
+ super().__init__(gap=gap, align=align)
29
+ self.show_scrollbar = show_scrollbar
30
+ self.wheel_step = float(wheel_step)
31
+ self._scroll_y: float = 0.0
32
+ self._content_h: float = 0.0
33
+ self._fill_width = True
34
+
35
+ @property
36
+ def scroll_y(self) -> float:
37
+ return self._scroll_y
38
+
39
+ @scroll_y.setter
40
+ def scroll_y(self, val: float) -> None:
41
+ max_s = self.max_scroll
42
+ clamped = max(0.0, min(float(val), max_s))
43
+ if abs(clamped - self._scroll_y) > 1e-4:
44
+ self._scroll_y = clamped
45
+ self.invalidate()
46
+
47
+ @property
48
+ def max_scroll(self) -> float:
49
+ return max(0.0, self._content_h - self.rect.height)
50
+
51
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
52
+ content_sz = super()._measure_content(
53
+ Constraints(constraints.min_width, constraints.max_width, 0.0, float("inf")),
54
+ theme,
55
+ )
56
+ self._content_h = content_sz.height
57
+ h = content_sz.height if constraints.max_height == float("inf") else min(content_sz.height, constraints.max_height)
58
+ return Size(content_sz.width, h)
59
+
60
+ def layout(self, rect: Rect, theme: Theme) -> None:
61
+ self.rect = rect
62
+ # Measure natural content height so max_scroll is always accurate
63
+ content_sz = super()._measure_content(Constraints(0.0, rect.width, 0.0, float("inf")), theme)
64
+ self._content_h = content_sz.height
65
+ self._scroll_y = max(0.0, min(self._scroll_y, self.max_scroll))
66
+
67
+ inner = rect.inset(self._padding)
68
+ # Reserve thin right gutter for scrollbar if scrollable
69
+ gutter = 10.0 if (self.show_scrollbar and self.max_scroll > 0.0) else 0.0
70
+ scrolled_rect = Rect(
71
+ inner.x,
72
+ inner.y - self._scroll_y,
73
+ max(0.0, inner.width - gutter),
74
+ max(inner.height, self._content_h - self._padding.vertical),
75
+ )
76
+ self._layout_children(scrolled_rect, theme)
77
+
78
+ def on_scroll(self, event: ScrollEvent) -> bool:
79
+ if self.max_scroll <= 0.0:
80
+ return False
81
+ prev = self._scroll_y
82
+ self.scroll_y = self._scroll_y - event.dy * self.wheel_step
83
+ return abs(self._scroll_y - prev) > 1e-4
84
+
85
+ def hit_test(self, x: float, y: float) -> Widget | None:
86
+ if not self._visible or not self.rect.contains(x, y):
87
+ return None
88
+ for child in reversed(self.children):
89
+ hit = child.hit_test(x, y)
90
+ if hit is not None:
91
+ return hit
92
+ return self
93
+
94
+ def paint(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
95
+ if not self._visible or self._opacity <= 0.0:
96
+ return
97
+ use_layer = self._opacity < 0.999
98
+ if use_layer:
99
+ canvas.saveLayerAlpha(
100
+ skia.Rect.MakeXYWH(self.rect.x - 24.0, self.rect.y - 24.0, self.rect.width + 48.0, self.rect.height + 48.0),
101
+ round(self._opacity * 255),
102
+ )
103
+ self._paint_universal_bg(canvas, theme)
104
+ canvas.save()
105
+ canvas.clipRect(
106
+ skia.Rect.MakeXYWH(self.rect.x, self.rect.y, self.rect.width, self.rect.height)
107
+ )
108
+ for child in self.children:
109
+ if child._visible and child.rect.bottom >= self.rect.y and child.rect.y <= self.rect.bottom:
110
+ child.paint(canvas, theme, now)
111
+
112
+ # Sleek M3 rounded scrollbar thumb
113
+ if self.show_scrollbar and self.max_scroll > 0.0 and self.rect.height > 20.0:
114
+ track_h = self.rect.height - 8.0
115
+ ratio = self.rect.height / max(self._content_h, 1.0)
116
+ thumb_h = max(28.0, track_h * ratio)
117
+ scroll_frac = self._scroll_y / self.max_scroll
118
+ thumb_y = self.rect.y + 4.0 + scroll_frac * (track_h - thumb_h)
119
+ thumb_rect = Rect(self.rect.right - 8.0, thumb_y, 5.0, thumb_h)
120
+ alpha = 0.55 if self.hovered else 0.35
121
+ canvas.drawRRect(
122
+ make_rrect(thumb_rect, 2.5),
123
+ skia.Paint(AntiAlias=True, Color=theme.colors.on_surface_variant.with_alpha(alpha).to_skia()),
124
+ )
125
+
126
+ canvas.restore()
127
+ self._paint_universal_border(canvas, theme)
128
+ if use_layer:
129
+ canvas.restore()