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,355 @@
1
+ """Material Design 3 Overlays & Feedback: Dialog, Snackbar, and ProgressIndicator."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ import time
7
+ from typing import TYPE_CHECKING, Callable, Literal
8
+
9
+ import skia
10
+
11
+ from ..core.context import context
12
+ from ..core.draw import (
13
+ draw_elevation_shadow,
14
+ draw_icon,
15
+ draw_text_centered_y,
16
+ font_for_style,
17
+ make_rrect,
18
+ measure_text,
19
+ )
20
+ from ..core.events import MouseEvent
21
+ from ..core.geometry import Constraints, EdgeInsets, Rect, Size
22
+ from ..core.state import State
23
+ from ..core.widget import Widget
24
+ from ..theme import Theme
25
+ from .containers import Column
26
+
27
+ if TYPE_CHECKING:
28
+ from ..core.window import Window
29
+
30
+
31
+ class Dialog(Widget):
32
+ """Official Material Design 3 Basic Dialog (`extra_large` 28dp corners + scrim).
33
+
34
+ Example:
35
+ with ui.dialog("Confirmar acción", icon="info") as dlg:
36
+ ui.text("¿Seguro que querés continuar?")
37
+ with ui.row(gap=8, justify="end").fill_width():
38
+ ui.button("Cancelar", variant="text", on_click=dlg.close)
39
+ ui.button("Aceptar", variant="filled", on_click=dlg.close)
40
+ dlg.open()
41
+ """
42
+
43
+ interactive = True
44
+ auto_attach = False
45
+
46
+ def __init__(
47
+ self,
48
+ title: str,
49
+ *,
50
+ icon: str | None = None,
51
+ width: float = 420.0,
52
+ dismissible: bool = True,
53
+ window: Window | None = None,
54
+ ) -> None:
55
+ super().__init__()
56
+ # Detach from normal flow; Dialog is presented as a modal overlay
57
+ if self.parent is not None:
58
+ self.parent.children.remove(self)
59
+ self.parent = None
60
+ self._owner_window: Window | None = window or context.current_window or context.last_window
61
+ self.title = title
62
+ self.icon = icon
63
+ self.dialog_width = float(width)
64
+ self.dismiss_on_outside_click = dismissible
65
+
66
+ with context.detached():
67
+ self._body = Column(gap=14.0, align="stretch")
68
+ self.add_child(self._body)
69
+ self._card_rect = Rect(0.0, 0.0, 0.0, 0.0)
70
+
71
+ def __enter__(self) -> Dialog:
72
+ context.push_container(self._body)
73
+ return self
74
+
75
+ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
76
+ context.pop_container()
77
+
78
+ def open(self) -> None:
79
+ win = self._owner_window or context.last_window
80
+ if win is not None:
81
+ self._owner_window = win
82
+ win.open_overlay(self)
83
+
84
+ def close(self) -> None:
85
+ win = self._owner_window or self.window
86
+ if win is not None:
87
+ win.close_overlay(self)
88
+
89
+ def layout(self, rect: Rect, theme: Theme) -> None:
90
+ self.rect = rect
91
+ card_w = min(self.dialog_width, max(280.0, rect.width - 48.0))
92
+ header_h = 32.0 + (36.0 if self.icon else 0.0)
93
+ body_c = Constraints(0.0, card_w - 48.0, 0.0, max(100.0, rect.height - 160.0))
94
+ body_sz = self._body.measure(body_c, theme)
95
+ card_h = 24.0 + header_h + 16.0 + body_sz.height + 24.0
96
+
97
+ cx = rect.x + (rect.width - card_w) * 0.5
98
+ cy = rect.y + (rect.height - card_h) * 0.5
99
+ self._card_rect = Rect(cx, cy, card_w, card_h)
100
+ self._body.layout(
101
+ Rect(cx + 24.0, cy + 24.0 + header_h + 16.0, card_w - 48.0, body_sz.height),
102
+ theme,
103
+ )
104
+
105
+ def hit_test(self, x: float, y: float) -> Widget | None:
106
+ if not self.rect.contains(x, y):
107
+ return None
108
+ # Capture all clicks while modal dialog is open
109
+ if self._card_rect.contains(x, y):
110
+ hit = self._body.hit_test(x, y)
111
+ return hit if hit is not None else self
112
+ return self
113
+
114
+ def on_mouse_up(self, event: MouseEvent) -> None:
115
+ was_pressed = self.pressed
116
+ super().on_mouse_up(event)
117
+ if was_pressed and self.dismiss_on_outside_click and not self._card_rect.contains(event.x, event.y):
118
+ self.close()
119
+
120
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
121
+ c = theme.colors
122
+ # Full-screen M3 scrim
123
+ canvas.drawRect(
124
+ skia.Rect.MakeXYWH(self.rect.x, self.rect.y, self.rect.width, self.rect.height),
125
+ skia.Paint(AntiAlias=True, Color=c.scrim.with_alpha(0.36).to_skia()),
126
+ )
127
+
128
+ # Elevated M3 Dialog surface (28dp extra_large radius)
129
+ radius = theme.shape.resolve(self._shape_override or "extra_large")
130
+ draw_elevation_shadow(canvas, self._card_rect, radius, 3, c.shadow)
131
+ rrect = make_rrect(self._card_rect, radius)
132
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=c.surface_container_high.to_skia()))
133
+
134
+ y = self._card_rect.y + 24.0
135
+ title_font = font_for_style(theme.font_family, theme.typography.headline_small)
136
+ if self.icon:
137
+ draw_icon(canvas, self.icon, self._card_rect.center_x, y + 12.0, 24.0, c.secondary)
138
+ y += 36.0
139
+ tw = measure_text(title_font, self.title)
140
+ draw_text_centered_y(canvas, self.title, self._card_rect.center_x - tw * 0.5, y + 16.0, title_font, c.on_surface)
141
+ else:
142
+ draw_text_centered_y(canvas, self.title, self._card_rect.x + 24.0, y + 16.0, title_font, c.on_surface)
143
+
144
+
145
+ class Snackbar(Widget):
146
+ """Official Material Design 3 Snackbar (non-modal toast with optional action)."""
147
+
148
+ interactive = True
149
+ auto_attach = False
150
+ dismiss_on_outside_click = False
151
+
152
+ HEIGHT = 48.0
153
+
154
+ def __init__(
155
+ self,
156
+ message: str,
157
+ *,
158
+ action: str | None = None,
159
+ on_action: Callable[[], None] | None = None,
160
+ duration: float = 3.5,
161
+ window: Window | None = None,
162
+ ) -> None:
163
+ super().__init__()
164
+ if self.parent is not None:
165
+ self.parent.children.remove(self)
166
+ self.parent = None
167
+ self.message = message
168
+ self.action = action
169
+ self.on_action = on_action
170
+ self.duration = float(duration)
171
+ self._owner_window: Window | None = window or context.current_window or context.last_window
172
+ self._created_at = time.perf_counter()
173
+ self._bar_rect = Rect(0.0, 0.0, 0.0, 0.0)
174
+ self._action_rect = Rect(0.0, 0.0, 0.0, 0.0)
175
+ self._action_hovered = False
176
+
177
+ def show(self) -> Snackbar:
178
+ win = self._owner_window or context.last_window
179
+ if win is not None:
180
+ self._owner_window = win
181
+ # Replace any existing snackbar so they don't stack awkwardly
182
+ for ov in list(win._overlays):
183
+ if isinstance(ov, Snackbar):
184
+ win.close_overlay(ov)
185
+ self._created_at = time.perf_counter()
186
+ win.open_overlay(self)
187
+ return self
188
+
189
+ def dismiss(self) -> None:
190
+ win = self._owner_window or self.window
191
+ if win is not None:
192
+ win.close_overlay(self)
193
+
194
+ def layout(self, rect: Rect, theme: Theme) -> None:
195
+ self.rect = rect
196
+ msg_font = font_for_style(theme.font_family, theme.typography.body_medium)
197
+ act_font = font_for_style(theme.font_family, theme.typography.label_large)
198
+ msg_w = measure_text(msg_font, self.message)
199
+ act_w = (measure_text(act_font, self.action) + 24.0) if self.action else 0.0
200
+ bar_w = min(rect.width - 32.0, max(280.0, 16.0 + msg_w + (16.0 + act_w if self.action else 16.0) + 8.0))
201
+ bx = rect.x + (rect.width - bar_w) * 0.5
202
+ by = rect.bottom - self.HEIGHT - 20.0
203
+ self._bar_rect = Rect(bx, by, bar_w, self.HEIGHT)
204
+ if self.action:
205
+ self._action_rect = Rect(self._bar_rect.right - act_w - 8.0, by + 6.0, act_w, self.HEIGHT - 12.0)
206
+ else:
207
+ self._action_rect = Rect(0.0, 0.0, 0.0, 0.0)
208
+
209
+ def hit_test(self, x: float, y: float) -> Widget | None:
210
+ return self if self._bar_rect.contains(x, y) else None
211
+
212
+ def tick(self, now: float) -> bool:
213
+ if self.duration > 0 and (now - self._created_at) >= self.duration:
214
+ self.dismiss()
215
+ return False
216
+ return True
217
+
218
+ def on_mouse_move(self, event: MouseEvent) -> None:
219
+ hov = bool(self.action and self._action_rect.contains(event.x, event.y))
220
+ if hov != self._action_hovered:
221
+ self._action_hovered = hov
222
+ self.invalidate()
223
+
224
+ def on_mouse_up(self, event: MouseEvent) -> None:
225
+ was_pressed = self.pressed
226
+ super().on_mouse_up(event)
227
+ if was_pressed and self.action and self._action_rect.contains(event.x, event.y):
228
+ if self.on_action is not None:
229
+ self.on_action()
230
+ self.dismiss()
231
+
232
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
233
+ c = theme.colors
234
+ radius = theme.shape.resolve("extra_small")
235
+ draw_elevation_shadow(canvas, self._bar_rect, radius, 3, c.shadow)
236
+ rrect = make_rrect(self._bar_rect, radius)
237
+ canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=c.inverse_surface.to_skia()))
238
+
239
+ msg_font = font_for_style(theme.font_family, theme.typography.body_medium)
240
+ draw_text_centered_y(
241
+ canvas,
242
+ self.message,
243
+ self._bar_rect.x + 16.0,
244
+ self._bar_rect.center_y,
245
+ msg_font,
246
+ c.inverse_on_surface,
247
+ )
248
+
249
+ if self.action:
250
+ if self._action_hovered:
251
+ canvas.drawRRect(
252
+ make_rrect(self._action_rect, 4.0),
253
+ skia.Paint(AntiAlias=True, Color=c.inverse_primary.with_alpha(0.12).to_skia()),
254
+ )
255
+ act_font = font_for_style(theme.font_family, theme.typography.label_large)
256
+ tw = measure_text(act_font, self.action)
257
+ draw_text_centered_y(
258
+ canvas,
259
+ self.action,
260
+ self._action_rect.center_x - tw * 0.5,
261
+ self._action_rect.center_y,
262
+ act_font,
263
+ c.inverse_primary,
264
+ )
265
+
266
+
267
+ class ProgressIndicator(Widget):
268
+ """Official Material Design 3 Linear or Circular ProgressIndicator."""
269
+
270
+ def __init__(
271
+ self,
272
+ *,
273
+ value: float | None = None,
274
+ variant: Literal["linear", "circular"] = "linear",
275
+ bind: State[float | None] | None = None,
276
+ ) -> None:
277
+ super().__init__()
278
+ self._bind = bind
279
+ self._value: float | None = bind.value if bind is not None else value
280
+ self.variant = variant
281
+ if bind is not None:
282
+ bind.subscribe(lambda v: self._set_val(v))
283
+
284
+ def _set_val(self, v: float | None) -> None:
285
+ self._value = None if v is None else max(0.0, min(1.0, float(v)))
286
+ self.invalidate()
287
+
288
+ @property
289
+ def value(self) -> float | None:
290
+ return self._value
291
+
292
+ @value.setter
293
+ def value(self, v: float | None) -> None:
294
+ self._set_val(v)
295
+ if self._bind is not None and self._bind.value != self._value:
296
+ self._bind.value = self._value
297
+
298
+ def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
299
+ if self.variant == "circular":
300
+ return Size(40.0, 40.0)
301
+ w = 240.0 if constraints.max_width == float("inf") else min(240.0, constraints.max_width)
302
+ return Size(w, 8.0)
303
+
304
+ def tick(self, now: float) -> bool:
305
+ return self._value is None
306
+
307
+ def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
308
+ c = theme.colors
309
+ if self.variant == "circular":
310
+ cx, cy = self.rect.center_x, self.rect.center_y
311
+ r = 16.0
312
+ oval = skia.Rect.MakeXYWH(cx - r, cy - r, r * 2.0, r * 2.0)
313
+ track_p = skia.Paint(
314
+ AntiAlias=True,
315
+ Color=c.secondary_container.to_skia(),
316
+ Style=skia.Paint.kStroke_Style,
317
+ StrokeWidth=4.0,
318
+ )
319
+ canvas.drawOval(oval, track_p)
320
+ active_p = skia.Paint(
321
+ AntiAlias=True,
322
+ Color=c.primary.to_skia(),
323
+ Style=skia.Paint.kStroke_Style,
324
+ StrokeWidth=4.0,
325
+ StrokeCap=skia.Paint.kRound_Cap,
326
+ )
327
+ if self._value is None:
328
+ start = (now * 240.0) % 360.0
329
+ sweep = 90.0 + 70.0 * (0.5 + 0.5 * math.sin(now * 3.0))
330
+ canvas.drawArc(oval, start, sweep, False, active_p)
331
+ else:
332
+ canvas.drawArc(oval, -90.0, 360.0 * self._value, False, active_p)
333
+ return
334
+
335
+ # Linear
336
+ cy = self.rect.center_y
337
+ track = Rect(self.rect.x, cy - 2.0, self.rect.width, 4.0)
338
+ canvas.drawRRect(make_rrect(track, 2.0), skia.Paint(AntiAlias=True, Color=c.secondary_container.to_skia()))
339
+
340
+ if self._value is None:
341
+ t = (now * 0.75) % 1.0
342
+ seg_w = self.rect.width * 0.35
343
+ sx = self.rect.x + t * (self.rect.width + seg_w) - seg_w
344
+ x1 = max(self.rect.x, sx)
345
+ x2 = min(self.rect.right, sx + seg_w)
346
+ if x2 > x1:
347
+ canvas.drawRRect(
348
+ make_rrect(Rect(x1, cy - 2.0, x2 - x1, 4.0), 2.0),
349
+ skia.Paint(AntiAlias=True, Color=c.primary.to_skia()),
350
+ )
351
+ elif self._value > 0.0:
352
+ canvas.drawRRect(
353
+ make_rrect(Rect(self.rect.x, cy - 2.0, self.rect.width * self._value, 4.0), 2.0),
354
+ skia.Paint(AntiAlias=True, Color=c.primary.to_skia()),
355
+ )