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,261 @@
1
+ """Material Design 3 Floating Action Button (FAB) & IconButton."""
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_icon,
13
+ draw_state_layer_and_ripple,
14
+ draw_text_centered_y,
15
+ font_for_style,
16
+ make_rrect,
17
+ make_rrect_spec,
18
+ measure_text,
19
+ resolve_color,
20
+ )
21
+ from ..core.events import MouseEvent
22
+ from ..core.geometry import Constraints, Rect, Size
23
+ from ..core.widget import Widget
24
+ from ..theme import Color, Theme
25
+
26
+ FABVariant = Literal["primary", "secondary", "tertiary", "surface"]
27
+ FABSize = Literal["small", "medium", "large"]
28
+
29
+
30
+ class IconButton(Widget):
31
+ """Material Design 3 Standard IconButton (40dp circular touch target)."""
32
+
33
+ interactive = True
34
+ focusable = True
35
+ manages_own_box = True
36
+ cursor = "pointer"
37
+
38
+ def __init__(
39
+ self,
40
+ icon: str,
41
+ *,
42
+ variant: Literal["standard", "filled", "tonal", "outlined"] = "standard",
43
+ disabled: bool = False,
44
+ on_click: Callable[[], None] | None = None,
45
+ ) -> None:
46
+ super().__init__()
47
+ self.icon = icon
48
+ self.variant = variant
49
+ self.disabled = disabled
50
+ self.on_click = on_click
51
+ self._ripple = RippleController()
52
+
53
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
54
+ return Size(40.0, 40.0)
55
+
56
+ def tick(self, now: float) -> bool:
57
+ return self._ripple.update(now)
58
+
59
+ def on_mouse_down(self, event: MouseEvent) -> None:
60
+ if self.disabled:
61
+ return
62
+ super().on_mouse_down(event)
63
+ self._ripple.start(event.x - self.rect.x, event.y - self.rect.y, self.rect.width, self.rect.height)
64
+
65
+ def on_mouse_up(self, event: MouseEvent) -> None:
66
+ was_pressed = self.pressed
67
+ super().on_mouse_up(event)
68
+ self._ripple.release()
69
+ if not self.disabled and was_pressed and self.rect.contains(event.x, event.y):
70
+ if self.on_click is not None:
71
+ self.on_click()
72
+
73
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
74
+ c = theme.colors
75
+ rad_spec = self._shape_override if self._shape_override is not None else 20.0
76
+ radius = rad_spec[0] if isinstance(rad_spec, tuple) else theme.shape.resolve(rad_spec)
77
+ rrect = make_rrect_spec(self.rect, rad_spec, theme)
78
+
79
+ if self.disabled:
80
+ bg: Color | None = c.on_surface.with_alpha(0.12) if self.variant in ("filled", "tonal") else None
81
+ fg = c.on_surface.with_alpha(0.38)
82
+ border: Color | None = c.on_surface.with_alpha(0.12) if self.variant == "outlined" else None
83
+ elif self.variant == "filled":
84
+ bg, fg, border = c.primary, c.on_primary, None
85
+ elif self.variant == "tonal":
86
+ bg, fg, border = c.secondary_container, c.on_secondary_container, None
87
+ elif self.variant == "outlined":
88
+ bg, fg, border = None, c.on_surface_variant, c.outline
89
+ else:
90
+ bg, fg, border = None, c.on_surface_variant, None
91
+
92
+ if not self.disabled:
93
+ if self._bg_override is not None:
94
+ bg = resolve_color(self._bg_override, theme, bg)
95
+ if self._fg_override is not None:
96
+ fg = resolve_color(self._fg_override, theme, fg) or fg
97
+ if self._border_color_override is not None:
98
+ border = resolve_color(self._border_color_override, theme, border)
99
+
100
+ if self._elevation_override and not self.disabled:
101
+ sh = resolve_color(self._shadow_color_override, theme, c.shadow)
102
+ assert sh is not None
103
+ draw_elevation_shadow(canvas, self.rect, radius, self._elevation_override, sh)
104
+
105
+ if bg is not None:
106
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
107
+
108
+ if not self.disabled:
109
+ sl = theme.state_layers
110
+ alpha = sl.pressed if self.pressed else (sl.hover if self.hovered else (sl.focus if self.focused else 0.0))
111
+ draw_state_layer_and_ripple(canvas, self.rect, radius, fg, alpha, self._ripple, now)
112
+
113
+ if border is not None:
114
+ bw = self._border_width_override if self._border_width_override is not None else 1.0
115
+ if bw > 0.0:
116
+ inset = min(bw * 0.5, self.rect.width * 0.5, self.rect.height * 0.5)
117
+ inner_rect = Rect(
118
+ self.rect.x + inset,
119
+ self.rect.y + inset,
120
+ max(0.0, self.rect.width - inset * 2.0),
121
+ max(0.0, self.rect.height - inset * 2.0),
122
+ )
123
+ canvas.drawRRect(
124
+ make_rrect(inner_rect, max(0.0, radius - inset)),
125
+ skia.Paint(AntiAlias=True, Color=border.to_skia(), Style=skia.Paint.kStroke_Style, StrokeWidth=bw),
126
+ )
127
+
128
+ draw_icon(canvas, self.icon, self.rect.center_x, self.rect.center_y, 20.0, fg)
129
+
130
+
131
+ class FAB(Widget):
132
+ """Official Material Design 3 Floating Action Button (Small, Medium, Large, or Extended)."""
133
+
134
+ interactive = True
135
+ focusable = True
136
+ manages_own_box = True
137
+ cursor = "pointer"
138
+
139
+ def __init__(
140
+ self,
141
+ icon: str = "add",
142
+ *,
143
+ label: str | None = None,
144
+ variant: FABVariant = "primary",
145
+ size: FABSize = "medium",
146
+ disabled: bool = False,
147
+ on_click: Callable[[], None] | None = None,
148
+ ) -> None:
149
+ super().__init__()
150
+ self.icon = icon
151
+ self.label = label
152
+ self.variant: FABVariant = variant
153
+ self.fab_size: FABSize = size
154
+ self.disabled = disabled
155
+ self.on_click = on_click
156
+ self._ripple = RippleController()
157
+
158
+ def _spec(self, theme: Theme) -> tuple[float, float, float]:
159
+ """Return (box_height, corner_radius, icon_size)."""
160
+ if self.label:
161
+ return (56.0, theme.shape.large, 22.0)
162
+ if self.fab_size == "small":
163
+ return (40.0, theme.shape.medium, 20.0)
164
+ if self.fab_size == "large":
165
+ return (96.0, theme.shape.extra_large, 32.0)
166
+ return (56.0, theme.shape.large, 22.0)
167
+
168
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
169
+ h, _, icon_sz = self._spec(theme)
170
+ if self.label:
171
+ font = font_for_style(theme.font_family, theme.typography.label_large)
172
+ w = 16.0 + icon_sz + 12.0 + measure_text(font, self.label) + 20.0
173
+ return Size(max(80.0, w), h)
174
+ return Size(h, h)
175
+
176
+ def tick(self, now: float) -> bool:
177
+ return self._ripple.update(now)
178
+
179
+ def on_mouse_down(self, event: MouseEvent) -> None:
180
+ if self.disabled:
181
+ return
182
+ super().on_mouse_down(event)
183
+ self._ripple.start(event.x - self.rect.x, event.y - self.rect.y, self.rect.width, self.rect.height)
184
+
185
+ def on_mouse_up(self, event: MouseEvent) -> None:
186
+ was_pressed = self.pressed
187
+ super().on_mouse_up(event)
188
+ self._ripple.release()
189
+ if not self.disabled and was_pressed and self.rect.contains(event.x, event.y):
190
+ if self.on_click is not None:
191
+ self.on_click()
192
+
193
+ def _colors(self, theme: Theme) -> tuple[Color, Color]:
194
+ c = theme.colors
195
+ if self.disabled:
196
+ return (c.on_surface.with_alpha(0.12), c.on_surface.with_alpha(0.38))
197
+ if self.variant == "secondary":
198
+ return (c.secondary_container, c.on_secondary_container)
199
+ if self.variant == "tertiary":
200
+ return (c.tertiary_container, c.on_tertiary_container)
201
+ if self.variant == "surface":
202
+ return (c.surface_container_high, c.primary)
203
+ return (c.primary_container, c.on_primary_container)
204
+
205
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
206
+ _, default_radius, icon_sz = self._spec(theme)
207
+ rad_spec = self._shape_override if self._shape_override is not None else default_radius
208
+ radius = rad_spec[0] if isinstance(rad_spec, tuple) else theme.shape.resolve(rad_spec)
209
+ bg, fg = self._colors(theme)
210
+ if not self.disabled:
211
+ if self._bg_override is not None:
212
+ bg = resolve_color(self._bg_override, theme, bg) or bg
213
+ if self._fg_override is not None:
214
+ fg = resolve_color(self._fg_override, theme, fg) or fg
215
+ elev = self._elevation_override if self._elevation_override is not None else (
216
+ 0 if self.disabled else (4 if self.hovered and not self.pressed else 3)
217
+ )
218
+
219
+ if elev > 0:
220
+ sh = resolve_color(self._shadow_color_override, theme, theme.colors.shadow)
221
+ assert sh is not None
222
+ draw_elevation_shadow(canvas, self.rect, radius, elev, sh)
223
+
224
+ rrect = make_rrect_spec(self.rect, rad_spec, theme)
225
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
226
+
227
+ if not self.disabled:
228
+ sl = theme.state_layers
229
+ alpha = sl.pressed if self.pressed else (sl.hover if self.hovered else (sl.focus if self.focused else 0.0))
230
+ draw_state_layer_and_ripple(canvas, self.rect, radius, fg, alpha, self._ripple, now)
231
+
232
+ if self._border_color_override is not None:
233
+ bc = resolve_color(self._border_color_override, theme)
234
+ if bc is not None:
235
+ bw = self._border_width_override if self._border_width_override is not None else 1.0
236
+ if bw > 0.0:
237
+ inset = min(bw * 0.5, self.rect.width * 0.5, self.rect.height * 0.5)
238
+ inner_rect = Rect(
239
+ self.rect.x + inset,
240
+ self.rect.y + inset,
241
+ max(0.0, self.rect.width - inset * 2.0),
242
+ max(0.0, self.rect.height - inset * 2.0),
243
+ )
244
+ canvas.drawRRect(
245
+ make_rrect(inner_rect, max(0.0, radius - inset)),
246
+ skia.Paint(AntiAlias=True, Color=bc.to_skia(), Style=skia.Paint.kStroke_Style, StrokeWidth=bw),
247
+ )
248
+
249
+ if self.label:
250
+ font = font_for_style(theme.font_family, theme.typography.label_large)
251
+ draw_icon(canvas, self.icon, self.rect.x + 16.0 + icon_sz * 0.5, self.rect.center_y, icon_sz, fg)
252
+ draw_text_centered_y(
253
+ canvas,
254
+ self.label,
255
+ self.rect.x + 16.0 + icon_sz + 12.0,
256
+ self.rect.center_y,
257
+ font,
258
+ fg,
259
+ )
260
+ else:
261
+ draw_icon(canvas, self.icon, self.rect.center_x, self.rect.center_y, icon_sz, fg)