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.
- quantumgui/__init__.py +9 -0
- quantumgui/__main__.py +6 -0
- quantumgui/cli.py +341 -0
- quantumgui/core/__init__.py +39 -0
- quantumgui/core/animation.py +221 -0
- quantumgui/core/audit.py +323 -0
- quantumgui/core/context.py +54 -0
- quantumgui/core/data_source.py +426 -0
- quantumgui/core/draw.py +428 -0
- quantumgui/core/enterprise.py +402 -0
- quantumgui/core/enterprise_app.py +419 -0
- quantumgui/core/events.py +34 -0
- quantumgui/core/geometry.py +108 -0
- quantumgui/core/native_dialogs.py +276 -0
- quantumgui/core/pdf_report.py +390 -0
- quantumgui/core/rules.py +284 -0
- quantumgui/core/state.py +42 -0
- quantumgui/core/task_runner.py +181 -0
- quantumgui/core/widget.py +498 -0
- quantumgui/core/window.py +920 -0
- quantumgui/core/xlsx_export.py +145 -0
- quantumgui/py.typed +0 -0
- quantumgui/theme/__init__.py +32 -0
- quantumgui/theme/hct.py +191 -0
- quantumgui/theme/theme.py +93 -0
- quantumgui/theme/tokens.py +423 -0
- quantumgui/ui.py +2142 -0
- quantumgui/widgets/__init__.py +168 -0
- quantumgui/widgets/advanced.py +499 -0
- quantumgui/widgets/button.py +224 -0
- quantumgui/widgets/charts.py +625 -0
- quantumgui/widgets/charts_bi.py +528 -0
- quantumgui/widgets/charts_extra.py +430 -0
- quantumgui/widgets/charts_pro.py +568 -0
- quantumgui/widgets/checkbox.py +199 -0
- quantumgui/widgets/chip.py +219 -0
- quantumgui/widgets/containers.py +321 -0
- quantumgui/widgets/data_controls.py +487 -0
- quantumgui/widgets/data_grid.py +956 -0
- quantumgui/widgets/data_table.py +551 -0
- quantumgui/widgets/date_picker.py +407 -0
- quantumgui/widgets/display_media.py +372 -0
- quantumgui/widgets/display_pro.py +407 -0
- quantumgui/widgets/drawer.py +252 -0
- quantumgui/widgets/enterprise_controls.py +934 -0
- quantumgui/widgets/fab.py +261 -0
- quantumgui/widgets/forms_pro.py +703 -0
- quantumgui/widgets/forms_pro_media.py +587 -0
- quantumgui/widgets/inputs.py +870 -0
- quantumgui/widgets/layout_pro.py +162 -0
- quantumgui/widgets/list_view.py +307 -0
- quantumgui/widgets/masked_input.py +131 -0
- quantumgui/widgets/master_detail.py +155 -0
- quantumgui/widgets/navigation.py +382 -0
- quantumgui/widgets/overlays.py +355 -0
- quantumgui/widgets/productivity.py +500 -0
- quantumgui/widgets/productivity_boards.py +544 -0
- quantumgui/widgets/radio.py +209 -0
- quantumgui/widgets/scroll_view.py +129 -0
- quantumgui/widgets/select.py +373 -0
- quantumgui/widgets/sheets.py +249 -0
- quantumgui/widgets/slider.py +209 -0
- quantumgui/widgets/switch.py +196 -0
- quantumgui/widgets/tabs.py +175 -0
- quantumgui/widgets/text.py +101 -0
- quantumgui/widgets/text_field.py +490 -0
- quantumgui/widgets/time_picker.py +499 -0
- quantumgui-1.0.0.dist-info/METADATA +137 -0
- quantumgui-1.0.0.dist-info/RECORD +73 -0
- quantumgui-1.0.0.dist-info/WHEEL +5 -0
- quantumgui-1.0.0.dist-info/entry_points.txt +2 -0
- quantumgui-1.0.0.dist-info/licenses/LICENSE +32 -0
- quantumgui-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""Material Design 3 Desktop Layouts: Grid and draggable SplitView."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
|
|
7
|
+
import skia
|
|
8
|
+
|
|
9
|
+
from ..core.draw import make_rrect
|
|
10
|
+
from ..core.events import MouseEvent
|
|
11
|
+
from ..core.geometry import Constraints, Rect, Size
|
|
12
|
+
from ..core.widget import Widget
|
|
13
|
+
from ..theme import Theme
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Grid(Widget):
|
|
17
|
+
"""Equal-column responsive Grid layout container (`columns`, `gap`)."""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
*,
|
|
22
|
+
columns: int = 3,
|
|
23
|
+
gap: float = 16.0,
|
|
24
|
+
row_gap: float | None = None,
|
|
25
|
+
) -> None:
|
|
26
|
+
super().__init__()
|
|
27
|
+
self.columns = max(1, int(columns))
|
|
28
|
+
self.gap = float(gap)
|
|
29
|
+
self.row_gap = float(gap if row_gap is None else row_gap)
|
|
30
|
+
self._fill_width = True
|
|
31
|
+
|
|
32
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
33
|
+
inner = constraints.deflate(self._padding)
|
|
34
|
+
visible = [c for c in self.children if c._visible]
|
|
35
|
+
if not visible:
|
|
36
|
+
return Size(self._padding.horizontal, self._padding.vertical)
|
|
37
|
+
|
|
38
|
+
avail_w = inner.max_width if inner.max_width != float("inf") else self.columns * 200.0
|
|
39
|
+
col_w = max(20.0, (avail_w - self.gap * (self.columns - 1)) / self.columns)
|
|
40
|
+
n_rows = math.ceil(len(visible) / self.columns)
|
|
41
|
+
total_h = 0.0
|
|
42
|
+
for r in range(n_rows):
|
|
43
|
+
row_h = 0.0
|
|
44
|
+
for c_idx in range(self.columns):
|
|
45
|
+
idx = r * self.columns + c_idx
|
|
46
|
+
if idx >= len(visible):
|
|
47
|
+
break
|
|
48
|
+
sz = visible[idx].measure(Constraints(col_w, col_w, 0.0, float("inf")), theme)
|
|
49
|
+
row_h = max(row_h, sz.height)
|
|
50
|
+
total_h += row_h
|
|
51
|
+
if r > 0:
|
|
52
|
+
total_h += self.row_gap
|
|
53
|
+
return Size(avail_w + self._padding.horizontal, total_h + self._padding.vertical)
|
|
54
|
+
|
|
55
|
+
def _layout_children(self, content_rect: Rect, theme: Theme) -> None:
|
|
56
|
+
visible = [c for c in self.children if c._visible]
|
|
57
|
+
if not visible:
|
|
58
|
+
return
|
|
59
|
+
col_w = max(20.0, (content_rect.width - self.gap * (self.columns - 1)) / self.columns)
|
|
60
|
+
n_rows = math.ceil(len(visible) / self.columns)
|
|
61
|
+
y = content_rect.y
|
|
62
|
+
for r in range(n_rows):
|
|
63
|
+
row_items = visible[r * self.columns : (r + 1) * self.columns]
|
|
64
|
+
heights = [
|
|
65
|
+
ch.measure(Constraints(col_w, col_w, 0.0, float("inf")), theme).height
|
|
66
|
+
for ch in row_items
|
|
67
|
+
]
|
|
68
|
+
row_h = max(heights, default=0.0)
|
|
69
|
+
for ci, ch in enumerate(row_items):
|
|
70
|
+
x = content_rect.x + ci * (col_w + self.gap)
|
|
71
|
+
ch.layout(Rect(x, y, col_w, row_h), theme)
|
|
72
|
+
y += row_h + self.row_gap
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class SplitView(Widget):
|
|
76
|
+
"""Two-pane horizontal resizable SplitView with draggable M3 handle."""
|
|
77
|
+
|
|
78
|
+
interactive = True
|
|
79
|
+
cursor = "ew_resize"
|
|
80
|
+
|
|
81
|
+
HANDLE_W = 12.0
|
|
82
|
+
|
|
83
|
+
def __init__(
|
|
84
|
+
self,
|
|
85
|
+
*,
|
|
86
|
+
ratio: float = 0.35,
|
|
87
|
+
min_ratio: float = 0.15,
|
|
88
|
+
max_ratio: float = 0.85,
|
|
89
|
+
height: float = 260.0,
|
|
90
|
+
) -> None:
|
|
91
|
+
super().__init__()
|
|
92
|
+
self.min_ratio = float(min_ratio)
|
|
93
|
+
self.max_ratio = float(max_ratio)
|
|
94
|
+
self._ratio = max(self.min_ratio, min(self.max_ratio, float(ratio)))
|
|
95
|
+
self._fixed_height = float(height)
|
|
96
|
+
self._fill_width = True
|
|
97
|
+
self._dragging = False
|
|
98
|
+
self._handle_rect = Rect(0.0, 0.0, 0.0, 0.0)
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def ratio(self) -> float:
|
|
102
|
+
return self._ratio
|
|
103
|
+
|
|
104
|
+
@ratio.setter
|
|
105
|
+
def ratio(self, val: float) -> None:
|
|
106
|
+
r = max(self.min_ratio, min(self.max_ratio, float(val)))
|
|
107
|
+
if abs(r - self._ratio) > 1e-4:
|
|
108
|
+
self._ratio = r
|
|
109
|
+
self.invalidate()
|
|
110
|
+
|
|
111
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
112
|
+
w = constraints.max_width if constraints.max_width != float("inf") else 560.0
|
|
113
|
+
return Size(w, self._fixed_height or 260.0)
|
|
114
|
+
|
|
115
|
+
def _layout_children(self, content_rect: Rect, theme: Theme) -> None:
|
|
116
|
+
visible = [c for c in self.children if c._visible]
|
|
117
|
+
avail_w = max(0.0, content_rect.width - self.HANDLE_W)
|
|
118
|
+
left_w = avail_w * self._ratio
|
|
119
|
+
right_w = avail_w - left_w
|
|
120
|
+
self._handle_rect = Rect(content_rect.x + left_w, content_rect.y, self.HANDLE_W, content_rect.height)
|
|
121
|
+
|
|
122
|
+
if len(visible) >= 1:
|
|
123
|
+
visible[0].layout(Rect(content_rect.x, content_rect.y, left_w, content_rect.height), theme)
|
|
124
|
+
if len(visible) >= 2:
|
|
125
|
+
visible[1].layout(Rect(self._handle_rect.right, content_rect.y, right_w, content_rect.height), theme)
|
|
126
|
+
|
|
127
|
+
def hit_test(self, x: float, y: float) -> Widget | None:
|
|
128
|
+
if not self._visible or not self.rect.contains(x, y):
|
|
129
|
+
return None
|
|
130
|
+
if self._handle_rect.contains(x, y):
|
|
131
|
+
return self
|
|
132
|
+
for child in reversed(self.children):
|
|
133
|
+
hit = child.hit_test(x, y)
|
|
134
|
+
if hit is not None:
|
|
135
|
+
return hit
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
def on_mouse_down(self, event: MouseEvent) -> None:
|
|
139
|
+
super().on_mouse_down(event)
|
|
140
|
+
if self._handle_rect.contains(event.x, event.y):
|
|
141
|
+
self._dragging = True
|
|
142
|
+
|
|
143
|
+
def on_mouse_move(self, event: MouseEvent) -> None:
|
|
144
|
+
if self._dragging and self.rect.width > self.HANDLE_W:
|
|
145
|
+
new_r = (event.x - self.rect.x - self.HANDLE_W * 0.5) / (self.rect.width - self.HANDLE_W)
|
|
146
|
+
self.ratio = new_r
|
|
147
|
+
|
|
148
|
+
def on_mouse_up(self, event: MouseEvent) -> None:
|
|
149
|
+
super().on_mouse_up(event)
|
|
150
|
+
self._dragging = False
|
|
151
|
+
|
|
152
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
153
|
+
c = theme.colors
|
|
154
|
+
hr = self._handle_rect
|
|
155
|
+
# Subtle divider line + M3 vertical drag pill
|
|
156
|
+
canvas.drawLine(
|
|
157
|
+
hr.center_x, hr.y + 4.0, hr.center_x, hr.bottom - 4.0,
|
|
158
|
+
skia.Paint(AntiAlias=True, Color=c.outline_variant.to_skia(), StrokeWidth=1.0),
|
|
159
|
+
)
|
|
160
|
+
pill = Rect(hr.center_x - 2.0, hr.center_y - 18.0, 4.0, 36.0)
|
|
161
|
+
pill_c = c.primary if self._dragging else c.on_surface_variant.with_alpha(0.45)
|
|
162
|
+
canvas.drawRRect(make_rrect(pill, 2.0), skia.Paint(AntiAlias=True, Color=pill_c.to_skia()))
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"""Material Design 3 Lists: ListView & ListItem (1, 2, and 3-line specs)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, 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, EdgeInsets, Rect, Size
|
|
23
|
+
from ..core.widget import Widget
|
|
24
|
+
from ..theme import Theme
|
|
25
|
+
from .containers import Column
|
|
26
|
+
from .data_table import _draw_image_cover, _resolve_skia_image
|
|
27
|
+
|
|
28
|
+
ListVariant = Literal["surface", "card", "outlined"]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ListItem(Widget):
|
|
32
|
+
"""Official Material Design 3 ListItem (56dp / 72dp / 88dp heights).
|
|
33
|
+
|
|
34
|
+
Supports:
|
|
35
|
+
- Text slots: `overline`, `headline`, `supporting_text`
|
|
36
|
+
- Leading slots: `leading_icon`, `leading_avatar` (photo or initials), `leading_image` (thumbnail)
|
|
37
|
+
- Trailing slots: `trailing_text`, `trailing_icon`, or custom child widgets via `with ui.list_item(...):`
|
|
38
|
+
- Selection highlight, M3 state layers, and ink Ripple
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
interactive = True
|
|
42
|
+
focusable = True
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
headline: str,
|
|
47
|
+
*,
|
|
48
|
+
supporting_text: str | None = None,
|
|
49
|
+
overline: str | None = None,
|
|
50
|
+
leading_icon: str | None = None,
|
|
51
|
+
leading_avatar: Any = None,
|
|
52
|
+
leading_image: Any = None,
|
|
53
|
+
trailing_text: str | None = None,
|
|
54
|
+
trailing_icon: str | None = None,
|
|
55
|
+
selected: bool = False,
|
|
56
|
+
disabled: bool = False,
|
|
57
|
+
on_click: Callable[[], None] | None = None,
|
|
58
|
+
) -> None:
|
|
59
|
+
super().__init__()
|
|
60
|
+
self.headline = headline
|
|
61
|
+
self.supporting_text = supporting_text
|
|
62
|
+
self.overline = overline
|
|
63
|
+
self.leading_icon = leading_icon
|
|
64
|
+
self.leading_avatar = leading_avatar
|
|
65
|
+
self.leading_image = leading_image
|
|
66
|
+
self.trailing_text = trailing_text
|
|
67
|
+
self.trailing_icon = trailing_icon
|
|
68
|
+
self._selected = selected
|
|
69
|
+
self.disabled = disabled
|
|
70
|
+
self.on_click = on_click
|
|
71
|
+
self._ripple = RippleController()
|
|
72
|
+
self._fill_width = True
|
|
73
|
+
self.cursor = "pointer" if on_click is not None else "default"
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def selected(self) -> bool:
|
|
77
|
+
return self._selected
|
|
78
|
+
|
|
79
|
+
@selected.setter
|
|
80
|
+
def selected(self, val: bool) -> None:
|
|
81
|
+
b = bool(val)
|
|
82
|
+
if b != self._selected:
|
|
83
|
+
self._selected = b
|
|
84
|
+
self.invalidate()
|
|
85
|
+
|
|
86
|
+
def _row_height(self) -> float:
|
|
87
|
+
lines = 1 + (1 if self.supporting_text else 0) + (1 if self.overline else 0)
|
|
88
|
+
if lines >= 3 or self.leading_image is not None:
|
|
89
|
+
return 84.0 if lines >= 3 else 72.0
|
|
90
|
+
if lines == 2:
|
|
91
|
+
return 72.0
|
|
92
|
+
return 56.0
|
|
93
|
+
|
|
94
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
95
|
+
w = constraints.max_width if constraints.max_width != float("inf") else 320.0
|
|
96
|
+
return Size(w, self._row_height())
|
|
97
|
+
|
|
98
|
+
def _layout_children(self, content_rect: Rect, theme: Theme) -> None:
|
|
99
|
+
visible = [c for c in self.children if c._visible]
|
|
100
|
+
if not visible:
|
|
101
|
+
return
|
|
102
|
+
# Lay out custom trailing widgets right-to-left
|
|
103
|
+
x = content_rect.right - 16.0
|
|
104
|
+
if self.trailing_icon:
|
|
105
|
+
x -= 28.0
|
|
106
|
+
for child in reversed(visible):
|
|
107
|
+
sz = child.measure(Constraints(0.0, content_rect.width, 0.0, content_rect.height), theme)
|
|
108
|
+
x -= sz.width
|
|
109
|
+
y = content_rect.center_y - sz.height * 0.5
|
|
110
|
+
child.layout(Rect(x, y, sz.width, sz.height), theme)
|
|
111
|
+
x -= 8.0
|
|
112
|
+
|
|
113
|
+
def tick(self, now: float) -> bool:
|
|
114
|
+
a = self._ripple.update(now)
|
|
115
|
+
b = super().tick(now)
|
|
116
|
+
return a or b
|
|
117
|
+
|
|
118
|
+
def on_mouse_down(self, event: MouseEvent) -> None:
|
|
119
|
+
if self.disabled or self.on_click is None:
|
|
120
|
+
return
|
|
121
|
+
super().on_mouse_down(event)
|
|
122
|
+
self._ripple.start(event.x - self.rect.x, event.y - self.rect.y, self.rect.width, self.rect.height)
|
|
123
|
+
|
|
124
|
+
def on_mouse_up(self, event: MouseEvent) -> None:
|
|
125
|
+
was_pressed = self.pressed
|
|
126
|
+
super().on_mouse_up(event)
|
|
127
|
+
self._ripple.release()
|
|
128
|
+
if not self.disabled and was_pressed and self.on_click is not None and self.rect.contains(event.x, event.y):
|
|
129
|
+
self.on_click()
|
|
130
|
+
|
|
131
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
132
|
+
c = theme.colors
|
|
133
|
+
r = self.rect
|
|
134
|
+
|
|
135
|
+
# Selected background
|
|
136
|
+
if self._selected:
|
|
137
|
+
canvas.drawRect(
|
|
138
|
+
skia.Rect.MakeXYWH(r.x, r.y, r.width, r.height),
|
|
139
|
+
skia.Paint(AntiAlias=True, Color=c.secondary_container.to_skia()),
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# State layer + ripple (only if clickable)
|
|
143
|
+
if not self.disabled and self.on_click is not None:
|
|
144
|
+
sl = theme.state_layers
|
|
145
|
+
alpha = sl.pressed if self.pressed else (sl.hover if self.hovered else (sl.focus if self.focused else 0.0))
|
|
146
|
+
layer_c = c.on_secondary_container if self._selected else c.on_surface
|
|
147
|
+
draw_state_layer_and_ripple(canvas, r, 0.0, layer_c, alpha, self._ripple, now)
|
|
148
|
+
|
|
149
|
+
fg = c.on_surface.with_alpha(0.38) if self.disabled else (
|
|
150
|
+
c.on_secondary_container if self._selected else c.on_surface
|
|
151
|
+
)
|
|
152
|
+
sub_fg = c.on_surface.with_alpha(0.38) if self.disabled else (
|
|
153
|
+
c.on_secondary_container.with_alpha(0.85) if self._selected else c.on_surface_variant
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# Leading slot
|
|
157
|
+
text_x = r.x + 16.0
|
|
158
|
+
if self.leading_image is not None:
|
|
159
|
+
sz = 52.0
|
|
160
|
+
dest = Rect(r.x + 16.0, r.center_y - sz * 0.5, sz, sz)
|
|
161
|
+
rad = theme.shape.small
|
|
162
|
+
img = _resolve_skia_image(self.leading_image)
|
|
163
|
+
if img is not None:
|
|
164
|
+
canvas.save()
|
|
165
|
+
canvas.clipRRect(make_rrect(dest, rad), doAntiAlias=True)
|
|
166
|
+
_draw_image_cover(canvas, img, dest)
|
|
167
|
+
canvas.restore()
|
|
168
|
+
else:
|
|
169
|
+
canvas.drawRRect(make_rrect(dest, rad), skia.Paint(AntiAlias=True, Color=c.surface_container_highest.to_skia()))
|
|
170
|
+
text_x = dest.right + 16.0
|
|
171
|
+
elif self.leading_avatar is not None:
|
|
172
|
+
sz = 40.0
|
|
173
|
+
dest = Rect(r.x + 16.0, r.center_y - sz * 0.5, sz, sz)
|
|
174
|
+
img = _resolve_skia_image(self.leading_avatar)
|
|
175
|
+
if img is not None:
|
|
176
|
+
canvas.save()
|
|
177
|
+
canvas.clipRRect(make_rrect(dest, sz * 0.5), doAntiAlias=True)
|
|
178
|
+
_draw_image_cover(canvas, img, dest)
|
|
179
|
+
canvas.restore()
|
|
180
|
+
else:
|
|
181
|
+
canvas.drawCircle(dest.center_x, dest.center_y, sz * 0.5, skia.Paint(AntiAlias=True, Color=c.primary_container.to_skia()))
|
|
182
|
+
initials = "".join(w[0].upper() for w in str(self.leading_avatar).split()[:2]) or "?"
|
|
183
|
+
afont = font_for_style(theme.font_family, theme.typography.title_small)
|
|
184
|
+
aw = measure_text(afont, initials)
|
|
185
|
+
draw_text_centered_y(canvas, initials, dest.center_x - aw * 0.5, dest.center_y, afont, c.on_primary_container)
|
|
186
|
+
text_x = dest.right + 16.0
|
|
187
|
+
elif self.leading_icon:
|
|
188
|
+
draw_icon(canvas, self.leading_icon, r.x + 28.0, r.center_y, 22.0, sub_fg)
|
|
189
|
+
text_x = r.x + 56.0
|
|
190
|
+
|
|
191
|
+
# Trailing text & icon (right side)
|
|
192
|
+
right_edge = r.right - 16.0
|
|
193
|
+
if self.trailing_icon:
|
|
194
|
+
draw_icon(canvas, self.trailing_icon, right_edge - 10.0, r.center_y, 18.0, sub_fg)
|
|
195
|
+
right_edge -= 28.0
|
|
196
|
+
if self.trailing_text:
|
|
197
|
+
tfont = font_for_style(theme.font_family, theme.typography.label_small)
|
|
198
|
+
tw = measure_text(tfont, self.trailing_text)
|
|
199
|
+
draw_text_centered_y(canvas, self.trailing_text, right_edge - tw, r.center_y, tfont, sub_fg)
|
|
200
|
+
right_edge -= tw + 12.0
|
|
201
|
+
|
|
202
|
+
# Reserve space for trailing child widgets
|
|
203
|
+
for ch in self.children:
|
|
204
|
+
if ch._visible:
|
|
205
|
+
right_edge = min(right_edge, ch.rect.x - 12.0)
|
|
206
|
+
|
|
207
|
+
# Text block (1, 2, or 3 lines vertically centered)
|
|
208
|
+
hl_font = font_for_style(theme.font_family, theme.typography.body_large)
|
|
209
|
+
sup_font = font_for_style(theme.font_family, theme.typography.body_medium)
|
|
210
|
+
ov_font = font_for_style(theme.font_family, theme.typography.label_small)
|
|
211
|
+
|
|
212
|
+
canvas.save()
|
|
213
|
+
canvas.clipRect(skia.Rect.MakeXYWH(text_x, r.y, max(0.0, right_edge - text_x), r.height))
|
|
214
|
+
|
|
215
|
+
if self.overline and self.supporting_text:
|
|
216
|
+
draw_text_centered_y(canvas, self.overline, text_x, r.center_y - 22.0, ov_font, sub_fg)
|
|
217
|
+
draw_text_centered_y(canvas, self.headline, text_x, r.center_y, hl_font, fg)
|
|
218
|
+
draw_text_centered_y(canvas, self.supporting_text, text_x, r.center_y + 21.0, sup_font, sub_fg)
|
|
219
|
+
elif self.overline:
|
|
220
|
+
draw_text_centered_y(canvas, self.overline, text_x, r.center_y - 11.0, ov_font, sub_fg)
|
|
221
|
+
draw_text_centered_y(canvas, self.headline, text_x, r.center_y + 9.0, hl_font, fg)
|
|
222
|
+
elif self.supporting_text:
|
|
223
|
+
draw_text_centered_y(canvas, self.headline, text_x, r.center_y - 10.0, hl_font, fg)
|
|
224
|
+
draw_text_centered_y(canvas, self.supporting_text, text_x, r.center_y + 11.0, sup_font, sub_fg)
|
|
225
|
+
else:
|
|
226
|
+
draw_text_centered_y(canvas, self.headline, text_x, r.center_y, hl_font, fg)
|
|
227
|
+
|
|
228
|
+
canvas.restore()
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class ListView(Column):
|
|
232
|
+
"""Official Material Design 3 List container with optional dividers."""
|
|
233
|
+
|
|
234
|
+
manages_own_box = True
|
|
235
|
+
|
|
236
|
+
def __init__(
|
|
237
|
+
self,
|
|
238
|
+
*,
|
|
239
|
+
dividers: bool = True,
|
|
240
|
+
divider_inset: float = 16.0,
|
|
241
|
+
variant: ListVariant = "outlined",
|
|
242
|
+
) -> None:
|
|
243
|
+
super().__init__(gap=0.0, align="stretch")
|
|
244
|
+
self.dividers = dividers
|
|
245
|
+
self.divider_inset = float(divider_inset)
|
|
246
|
+
self.variant: ListVariant = variant
|
|
247
|
+
self._padding = EdgeInsets.symmetric(vertical=4.0)
|
|
248
|
+
self._fill_width = True
|
|
249
|
+
|
|
250
|
+
def paint(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
251
|
+
if not self._visible or self._opacity <= 0.0:
|
|
252
|
+
return
|
|
253
|
+
use_layer = self._opacity < 0.999
|
|
254
|
+
if use_layer:
|
|
255
|
+
canvas.saveLayerAlpha(
|
|
256
|
+
skia.Rect.MakeXYWH(self.rect.x - 24.0, self.rect.y - 24.0, self.rect.width + 48.0, self.rect.height + 48.0),
|
|
257
|
+
round(self._opacity * 255),
|
|
258
|
+
)
|
|
259
|
+
c = theme.colors
|
|
260
|
+
rad_spec = self._shape_override if self._shape_override is not None else ("none" if self.variant == "surface" else "medium")
|
|
261
|
+
radius = rad_spec[0] if isinstance(rad_spec, tuple) else theme.shape.resolve(rad_spec)
|
|
262
|
+
if self._elevation_override:
|
|
263
|
+
sh = resolve_color(self._shadow_color_override, theme, c.shadow)
|
|
264
|
+
assert sh is not None
|
|
265
|
+
draw_elevation_shadow(canvas, self.rect, radius, self._elevation_override, sh)
|
|
266
|
+
rrect = make_rrect_spec(self.rect, rad_spec, theme)
|
|
267
|
+
|
|
268
|
+
canvas.save()
|
|
269
|
+
if radius > 0 or isinstance(rad_spec, tuple):
|
|
270
|
+
canvas.clipRRect(rrect, doAntiAlias=True)
|
|
271
|
+
|
|
272
|
+
default_bg = c.surface_container_low if self.variant == "card" else c.surface
|
|
273
|
+
bg = resolve_color(self._bg_override, theme, default_bg) or default_bg
|
|
274
|
+
canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
|
|
275
|
+
|
|
276
|
+
visible = [ch for ch in self.children if ch._visible]
|
|
277
|
+
div_paint = skia.Paint(AntiAlias=True, Color=c.outline_variant.to_skia(), StrokeWidth=1.0)
|
|
278
|
+
for i, child in enumerate(visible):
|
|
279
|
+
child.paint(canvas, theme, now)
|
|
280
|
+
if self.dividers and i < len(visible) - 1:
|
|
281
|
+
y = child.rect.bottom
|
|
282
|
+
canvas.drawLine(
|
|
283
|
+
self.rect.x + self.divider_inset,
|
|
284
|
+
y,
|
|
285
|
+
self.rect.right - self.divider_inset,
|
|
286
|
+
y,
|
|
287
|
+
div_paint,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
canvas.restore()
|
|
291
|
+
|
|
292
|
+
bc = resolve_color(self._border_color_override, theme)
|
|
293
|
+
if bc is None and self.variant == "outlined":
|
|
294
|
+
bc = c.outline_variant
|
|
295
|
+
if bc is not None:
|
|
296
|
+
bw = self._border_width_override if self._border_width_override is not None else 1.0
|
|
297
|
+
canvas.drawRRect(
|
|
298
|
+
rrect,
|
|
299
|
+
skia.Paint(
|
|
300
|
+
AntiAlias=True,
|
|
301
|
+
Color=bc.to_skia(),
|
|
302
|
+
Style=skia.Paint.kStroke_Style,
|
|
303
|
+
StrokeWidth=bw,
|
|
304
|
+
),
|
|
305
|
+
)
|
|
306
|
+
if use_layer:
|
|
307
|
+
canvas.restore()
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Enterprise MaskedInput control (CUIT, Phone, Credit Card, Date, CBU, or custom masks)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Callable
|
|
6
|
+
|
|
7
|
+
from ..core.state import State
|
|
8
|
+
from .text_field import TextField, TextFieldVariant
|
|
9
|
+
|
|
10
|
+
MASK_PRESETS: dict[str, str] = {
|
|
11
|
+
"cuit": "##-########-#",
|
|
12
|
+
"phone": "(###) ###-####",
|
|
13
|
+
"card": "#### #### #### ####",
|
|
14
|
+
"date": "##/##/####",
|
|
15
|
+
"time": "##:##",
|
|
16
|
+
"cbu": "######## ##############",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def apply_mask(raw: str, mask: str, *, uppercase: bool = True) -> str:
|
|
21
|
+
"""Format `raw` characters according to `mask` (`#` digit, `A` letter, `*` alnum, else literal)."""
|
|
22
|
+
# Extract only eligible input characters while skipping literals that match the mask
|
|
23
|
+
tokens: list[str] = []
|
|
24
|
+
for ch in raw:
|
|
25
|
+
if ch.isalnum():
|
|
26
|
+
tokens.append(ch.upper() if uppercase else ch)
|
|
27
|
+
|
|
28
|
+
out: list[str] = []
|
|
29
|
+
ti = 0
|
|
30
|
+
for m in mask:
|
|
31
|
+
if ti >= len(tokens):
|
|
32
|
+
break
|
|
33
|
+
if m == "#":
|
|
34
|
+
while ti < len(tokens) and not tokens[ti].isdigit():
|
|
35
|
+
ti += 1
|
|
36
|
+
if ti < len(tokens):
|
|
37
|
+
out.append(tokens[ti])
|
|
38
|
+
ti += 1
|
|
39
|
+
elif m == "A":
|
|
40
|
+
while ti < len(tokens) and not tokens[ti].isalpha():
|
|
41
|
+
ti += 1
|
|
42
|
+
if ti < len(tokens):
|
|
43
|
+
out.append(tokens[ti])
|
|
44
|
+
ti += 1
|
|
45
|
+
elif m == "*":
|
|
46
|
+
out.append(tokens[ti])
|
|
47
|
+
ti += 1
|
|
48
|
+
else:
|
|
49
|
+
out.append(m)
|
|
50
|
+
return "".join(out)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def extract_raw(formatted: str, mask: str) -> str:
|
|
54
|
+
"""Strip literal mask characters and return only the user-entered payload."""
|
|
55
|
+
out: list[str] = []
|
|
56
|
+
for ch, m in zip(formatted, mask):
|
|
57
|
+
if m in ("#", "A", "*"):
|
|
58
|
+
out.append(ch)
|
|
59
|
+
return "".join(out)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class MaskedInput(TextField):
|
|
63
|
+
"""Material Design 3 TextField with real-time input masking (`#` digit, `A` letter, `*` alnum).
|
|
64
|
+
|
|
65
|
+
Accepts built-in presets (`"cuit"`, `"phone"`, `"card"`, `"date"`, `"time"`, `"cbu"`)
|
|
66
|
+
or any custom mask string such as `"AA-###-AA"`.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
def __init__(
|
|
70
|
+
self,
|
|
71
|
+
label: str,
|
|
72
|
+
mask: str,
|
|
73
|
+
*,
|
|
74
|
+
variant: TextFieldVariant = "outlined",
|
|
75
|
+
value: str = "",
|
|
76
|
+
placeholder: str = "",
|
|
77
|
+
supporting_text: str | None = None,
|
|
78
|
+
error_text: str | None = None,
|
|
79
|
+
leading_icon: str | None = None,
|
|
80
|
+
trailing_icon: str | None = None,
|
|
81
|
+
uppercase: bool = True,
|
|
82
|
+
disabled: bool = False,
|
|
83
|
+
bind: State[str] | None = None,
|
|
84
|
+
on_change: Callable[[str], None] | None = None,
|
|
85
|
+
on_submit: Callable[[str], None] | None = None,
|
|
86
|
+
) -> None:
|
|
87
|
+
self.mask: str = MASK_PRESETS.get(mask.lower(), mask)
|
|
88
|
+
self.uppercase: bool = uppercase
|
|
89
|
+
initial_val = apply_mask(bind.value if bind is not None else value, self.mask, uppercase=uppercase)
|
|
90
|
+
eff_placeholder = placeholder or self.mask.replace("#", "0").replace("A", "X").replace("*", "X")
|
|
91
|
+
super().__init__(
|
|
92
|
+
label,
|
|
93
|
+
variant=variant,
|
|
94
|
+
value=initial_val,
|
|
95
|
+
placeholder=eff_placeholder,
|
|
96
|
+
supporting_text=supporting_text,
|
|
97
|
+
error_text=error_text,
|
|
98
|
+
leading_icon=leading_icon,
|
|
99
|
+
trailing_icon=trailing_icon,
|
|
100
|
+
max_length=len(self.mask),
|
|
101
|
+
disabled=disabled,
|
|
102
|
+
bind=bind,
|
|
103
|
+
on_change=on_change,
|
|
104
|
+
on_submit=on_submit,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def value(self) -> str:
|
|
109
|
+
return self._value
|
|
110
|
+
|
|
111
|
+
@value.setter
|
|
112
|
+
def value(self, val: str) -> None:
|
|
113
|
+
masked = apply_mask(str(val), self.mask, uppercase=self.uppercase)
|
|
114
|
+
TextField.value.fset(self, masked) # type: ignore[misc]
|
|
115
|
+
|
|
116
|
+
@property
|
|
117
|
+
def raw_value(self) -> str:
|
|
118
|
+
"""User characters without mask literals (e.g. `'20123456789'` for CUIT)."""
|
|
119
|
+
return extract_raw(self._value, self.mask)
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def is_complete(self) -> bool:
|
|
123
|
+
"""Return True when every placeholder slot in `self.mask` is filled."""
|
|
124
|
+
slots = sum(1 for m in self.mask if m in ("#", "A", "*"))
|
|
125
|
+
return len(self.raw_value) == slots
|
|
126
|
+
|
|
127
|
+
def _set_text(self, new_text: str) -> None:
|
|
128
|
+
masked = apply_mask(new_text, self.mask, uppercase=self.uppercase)
|
|
129
|
+
super()._set_text(masked)
|
|
130
|
+
self._caret = len(self._value)
|
|
131
|
+
self._sel_anchor = None
|