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,321 @@
1
+ """Material Design 3 layout containers: Column, Row, Box, and Card."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Callable, Literal
6
+
7
+ import skia
8
+
9
+ from ..core.animation import RippleController
10
+ from ..core.draw import (
11
+ draw_elevation_shadow,
12
+ draw_state_layer_and_ripple,
13
+ make_rrect_spec,
14
+ resolve_color,
15
+ )
16
+ from ..core.events import MouseEvent
17
+ from ..core.geometry import Constraints, EdgeInsets, Rect, Size
18
+ from ..core.widget import Widget
19
+ from ..theme import Color, Theme
20
+
21
+ CrossAlign = Literal["start", "center", "end", "stretch"]
22
+ MainJustify = Literal["start", "center", "end", "space_between"]
23
+ CardVariant = Literal["filled", "elevated", "outlined"]
24
+
25
+
26
+ class Column(Widget):
27
+ """Vertical flex-style layout container."""
28
+
29
+ def __init__(
30
+ self,
31
+ *,
32
+ gap: float = 0.0,
33
+ align: CrossAlign = "start",
34
+ justify: MainJustify = "start",
35
+ ) -> None:
36
+ super().__init__()
37
+ self.gap = float(gap)
38
+ self.align: CrossAlign = align
39
+ self.justify: MainJustify = justify
40
+
41
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
42
+ inner = constraints.deflate(self._padding)
43
+ visible = [c for c in self.children if c._visible]
44
+ total_h = 0.0
45
+ max_w = 0.0
46
+ for i, child in enumerate(visible):
47
+ cw_max = max(0.0, inner.max_width - child._margin.horizontal) if inner.max_width != float("inf") else float("inf")
48
+ child_c = Constraints(0.0, cw_max, 0.0, float("inf"))
49
+ sz = child.measure(child_c, theme)
50
+ max_w = max(max_w, sz.width + child._margin.horizontal)
51
+ total_h += sz.height + child._margin.vertical
52
+ if i > 0:
53
+ total_h += self.gap
54
+ return Size(max_w + self._padding.horizontal, total_h + self._padding.vertical)
55
+
56
+ def _layout_children(self, content_rect: Rect, theme: Theme) -> None:
57
+ visible = [c for c in self.children if c._visible]
58
+ if not visible:
59
+ return
60
+
61
+ total_gaps = self.gap * max(0, len(visible) - 1)
62
+ fixed_h = 0.0
63
+ total_flex = 0.0
64
+ sizes: list[Size | None] = [None] * len(visible)
65
+
66
+ for i, child in enumerate(visible):
67
+ if child._flex > 0.0:
68
+ total_flex += child._flex
69
+ else:
70
+ cw_max = max(0.0, content_rect.width - child._margin.horizontal)
71
+ sz = child.measure(Constraints(0.0, cw_max, 0.0, float("inf")), theme)
72
+ sizes[i] = sz
73
+ fixed_h += sz.height + child._margin.vertical
74
+
75
+ remaining_h = max(0.0, content_rect.height - fixed_h - total_gaps)
76
+ if total_flex > 0.0:
77
+ for i, child in enumerate(visible):
78
+ if child._flex > 0.0:
79
+ alloc_h = max(0.0, (remaining_h * (child._flex / total_flex)) - child._margin.vertical)
80
+ cw_max = max(0.0, content_rect.width - child._margin.horizontal)
81
+ sizes[i] = child.measure(Constraints(0.0, cw_max, alloc_h, alloc_h), theme)
82
+ remaining_h = 0.0
83
+
84
+ # Main-axis positioning
85
+ y = content_rect.y
86
+ extra_gap = 0.0
87
+ if self.justify == "center":
88
+ y += remaining_h * 0.5
89
+ elif self.justify == "end":
90
+ y += remaining_h
91
+ elif self.justify == "space_between" and len(visible) > 1:
92
+ extra_gap = remaining_h / (len(visible) - 1)
93
+
94
+ for i, child in enumerate(visible):
95
+ sz = sizes[i]
96
+ assert sz is not None
97
+ effective_align = self.align if child._align_self == "auto" else child._align_self
98
+ avail_w = max(0.0, content_rect.width - child._margin.horizontal)
99
+ w = avail_w if (effective_align == "stretch" or child._fill_width) else min(sz.width, avail_w)
100
+
101
+ if effective_align == "center":
102
+ x = content_rect.x + child._margin.left + (avail_w - w) * 0.5
103
+ elif effective_align == "end":
104
+ x = content_rect.right - child._margin.right - w
105
+ else:
106
+ x = content_rect.x + child._margin.left
107
+
108
+ child.layout(Rect(x, y + child._margin.top, w, sz.height), theme)
109
+ y += sz.height + child._margin.vertical + self.gap + extra_gap
110
+
111
+
112
+ class Row(Widget):
113
+ """Horizontal flex-style layout container with optional line wrapping."""
114
+
115
+ def __init__(
116
+ self,
117
+ *,
118
+ gap: float = 0.0,
119
+ align: CrossAlign = "center",
120
+ justify: MainJustify = "start",
121
+ wrap: bool = False,
122
+ run_gap: float | None = None,
123
+ ) -> None:
124
+ super().__init__()
125
+ self.gap = float(gap)
126
+ self.align: CrossAlign = align
127
+ self.justify: MainJustify = justify
128
+ self.wrap = wrap
129
+ self.run_gap = float(gap if run_gap is None else run_gap)
130
+
131
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
132
+ inner = constraints.deflate(self._padding)
133
+ visible = [c for c in self.children if c._visible]
134
+ if not visible:
135
+ return Size(self._padding.horizontal, self._padding.vertical)
136
+
137
+ if self.wrap and inner.max_width != float("inf"):
138
+ line_w = 0.0
139
+ line_h = 0.0
140
+ total_w = 0.0
141
+ total_h = 0.0
142
+ for child in visible:
143
+ sz = child.measure(Constraints(0.0, inner.max_width, 0.0, float("inf")), theme)
144
+ cw = sz.width + child._margin.horizontal
145
+ ch = sz.height + child._margin.vertical
146
+ if line_w > 0 and line_w + self.gap + cw > inner.max_width:
147
+ total_w = max(total_w, line_w)
148
+ total_h += line_h + self.run_gap
149
+ line_w = cw
150
+ line_h = ch
151
+ else:
152
+ line_w = cw if line_w == 0 else line_w + self.gap + cw
153
+ line_h = max(line_h, ch)
154
+ total_w = max(total_w, line_w)
155
+ total_h += line_h
156
+ return Size(total_w + self._padding.horizontal, total_h + self._padding.vertical)
157
+
158
+ total_w = 0.0
159
+ max_h = 0.0
160
+ for i, child in enumerate(visible):
161
+ sz = child.measure(Constraints(0.0, inner.max_width, 0.0, inner.max_height), theme)
162
+ total_w += sz.width + child._margin.horizontal
163
+ max_h = max(max_h, sz.height + child._margin.vertical)
164
+ if i > 0:
165
+ total_w += self.gap
166
+ return Size(total_w + self._padding.horizontal, max_h + self._padding.vertical)
167
+
168
+ def _layout_children(self, content_rect: Rect, theme: Theme) -> None:
169
+ visible = [c for c in self.children if c._visible]
170
+ if not visible:
171
+ return
172
+
173
+ if self.wrap:
174
+ x = content_rect.x
175
+ y = content_rect.y
176
+ line_h = 0.0
177
+ for child in visible:
178
+ sz = child.measure(Constraints(0.0, content_rect.width, 0.0, float("inf")), theme)
179
+ cw = sz.width + child._margin.horizontal
180
+ ch = sz.height + child._margin.vertical
181
+ if x > content_rect.x and (x - content_rect.x) + cw > content_rect.width:
182
+ x = content_rect.x
183
+ y += line_h + self.run_gap
184
+ line_h = 0.0
185
+ child.layout(Rect(x + child._margin.left, y + child._margin.top, sz.width, sz.height), theme)
186
+ x += cw + self.gap
187
+ line_h = max(line_h, ch)
188
+ return
189
+
190
+ total_gaps = self.gap * max(0, len(visible) - 1)
191
+ fixed_w = 0.0
192
+ total_flex = 0.0
193
+ sizes: list[Size | None] = [None] * len(visible)
194
+
195
+ for i, child in enumerate(visible):
196
+ if child._flex > 0.0:
197
+ total_flex += child._flex
198
+ else:
199
+ sz = child.measure(Constraints(0.0, content_rect.width, 0.0, content_rect.height), theme)
200
+ sizes[i] = sz
201
+ fixed_w += sz.width + child._margin.horizontal
202
+
203
+ remaining_w = max(0.0, content_rect.width - fixed_w - total_gaps)
204
+ if total_flex > 0.0:
205
+ for i, child in enumerate(visible):
206
+ if child._flex > 0.0:
207
+ alloc_w = max(0.0, (remaining_w * (child._flex / total_flex)) - child._margin.horizontal)
208
+ sizes[i] = child.measure(Constraints(alloc_w, alloc_w, 0.0, content_rect.height), theme)
209
+ remaining_w = 0.0
210
+
211
+ x = content_rect.x
212
+ extra_gap = 0.0
213
+ if self.justify == "center":
214
+ x += remaining_w * 0.5
215
+ elif self.justify == "end":
216
+ x += remaining_w
217
+ elif self.justify == "space_between" and len(visible) > 1:
218
+ extra_gap = remaining_w / (len(visible) - 1)
219
+
220
+ for i, child in enumerate(visible):
221
+ sz = sizes[i]
222
+ assert sz is not None
223
+ effective_align = self.align if child._align_self == "auto" else child._align_self
224
+ avail_h = max(0.0, content_rect.height - child._margin.vertical)
225
+ h = avail_h if (effective_align == "stretch" or child._fill_height) else min(sz.height, avail_h)
226
+
227
+ if effective_align == "center":
228
+ y = content_rect.y + child._margin.top + (avail_h - h) * 0.5
229
+ elif effective_align == "end":
230
+ y = content_rect.bottom - child._margin.bottom - h
231
+ else:
232
+ y = content_rect.y + child._margin.top
233
+
234
+ child.layout(Rect(x + child._margin.left, y, sz.width, h), theme)
235
+ x += sz.width + child._margin.horizontal + self.gap + extra_gap
236
+
237
+
238
+ class Card(Column):
239
+ """Material Design 3 Card (`filled`, `elevated`, or `outlined`) with optional `on_click`."""
240
+
241
+ manages_own_box = True
242
+
243
+ def __init__(
244
+ self,
245
+ *,
246
+ variant: CardVariant = "filled",
247
+ gap: float = 12.0,
248
+ align: CrossAlign = "stretch",
249
+ padding: float | tuple[float, float] | tuple[float, float, float, float] = 16.0,
250
+ on_click: Callable[[], None] | None = None,
251
+ ) -> None:
252
+ super().__init__(gap=gap, align=align)
253
+ self.variant: CardVariant = variant
254
+ self._padding = EdgeInsets.parse(padding)
255
+ self.on_click = on_click
256
+ self._ripple = RippleController() if on_click is not None else None
257
+ if on_click is not None:
258
+ self.interactive = True
259
+ self.cursor = "pointer"
260
+
261
+ def tick(self, now: float) -> bool:
262
+ a = self._ripple.update(now) if self._ripple is not None else False
263
+ b = super().tick(now)
264
+ return a or b
265
+
266
+ def on_mouse_down(self, event: MouseEvent) -> None:
267
+ super().on_mouse_down(event)
268
+ if self._ripple is not None:
269
+ self._ripple.start(event.x - self.rect.x, event.y - self.rect.y, self.rect.width, self.rect.height)
270
+
271
+ def on_mouse_up(self, event: MouseEvent) -> None:
272
+ was_pressed = self.pressed
273
+ super().on_mouse_up(event)
274
+ if self._ripple is not None:
275
+ self._ripple.release()
276
+ if was_pressed and self.on_click is not None and self.rect.contains(event.x, event.y):
277
+ self.on_click()
278
+
279
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
280
+ c = theme.colors
281
+ rad_spec = self._shape_override if self._shape_override is not None else "medium"
282
+ rad_num = rad_spec[0] if isinstance(rad_spec, tuple) else theme.shape.resolve(rad_spec)
283
+ elev = self._elevation_override if self._elevation_override is not None else (
284
+ 1 if self.variant == "elevated" else 0
285
+ )
286
+
287
+ if elev > 0:
288
+ sh = resolve_color(self._shadow_color_override, theme, c.shadow)
289
+ assert sh is not None
290
+ draw_elevation_shadow(canvas, self.rect, rad_num, elev, sh)
291
+
292
+ if self._bg_override is not None:
293
+ bg = resolve_color(self._bg_override, theme, c.surface_container_highest)
294
+ assert bg is not None
295
+ elif self.variant == "elevated":
296
+ bg = c.surface_container_low
297
+ elif self.variant == "outlined":
298
+ bg = c.surface
299
+ else:
300
+ bg = c.surface_container_highest
301
+
302
+ rrect = make_rrect_spec(self.rect, rad_spec, theme)
303
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
304
+
305
+ if self.on_click is not None:
306
+ sl = theme.state_layers
307
+ alpha = sl.pressed if self.pressed else (sl.hover if self.hovered else 0.0)
308
+ draw_state_layer_and_ripple(canvas, self.rect, rad_num, c.on_surface, alpha, self._ripple, now)
309
+
310
+ border_c = resolve_color(self._border_color_override, theme)
311
+ if border_c is None and self.variant == "outlined":
312
+ border_c = c.outline_variant
313
+ if border_c is not None:
314
+ bw = self._border_width_override if self._border_width_override is not None else 1.0
315
+ border = skia.Paint(
316
+ AntiAlias=True,
317
+ Color=border_c.to_skia(),
318
+ Style=skia.Paint.kStroke_Style,
319
+ StrokeWidth=bw,
320
+ )
321
+ canvas.drawRRect(rrect, border)