flet-datatable2 0.1.0__py3-none-any.whl → 0.2.0.dev40__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.
- flet_datatable2/__init__.py +4 -5
- flet_datatable2/datacolumn2.py +18 -164
- flet_datatable2/datarow2.py +45 -207
- flet_datatable2/datatable2.py +108 -834
- flet_datatable2/types.py +18 -0
- flet_datatable2-0.2.0.dev40.dist-info/METADATA +63 -0
- flet_datatable2-0.2.0.dev40.dist-info/RECORD +20 -0
- {flet_datatable2-0.1.0.dist-info → flet_datatable2-0.2.0.dev40.dist-info}/WHEEL +1 -1
- flet_datatable2-0.2.0.dev40.dist-info/licenses/LICENSE +201 -0
- flutter/flet_datatable2/lib/flet_datatable2.dart +3 -1
- flutter/flet_datatable2/lib/src/datatable2.dart +162 -276
- flutter/flet_datatable2/lib/src/extension.dart +16 -0
- flutter/flet_datatable2/lib/src/utils/datatable.dart +11 -0
- flutter/flet_datatable2/pubspec.lock +93 -68
- flutter/flet_datatable2/pubspec.yaml +8 -3
- flet_datatable2-0.1.0.dist-info/METADATA +0 -38
- flet_datatable2-0.1.0.dist-info/RECORD +0 -17
- flutter/flet_datatable2/lib/src/create_control.dart +0 -22
- {flet_datatable2-0.1.0.dist-info → flet_datatable2-0.2.0.dev40.dist-info}/top_level.txt +0 -0
flet_datatable2/__init__.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
from flet_datatable2.datatable2 import DataTable2
|
|
1
|
+
from .datacolumn2 import DataColumn2
|
|
2
|
+
from .datarow2 import DataRow2
|
|
3
|
+
from .datatable2 import DataTable2
|
|
4
|
+
from .types import DataColumnSize
|
flet_datatable2/datacolumn2.py
CHANGED
|
@@ -1,173 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
from enum import Enum
|
|
3
|
-
from typing import Any, Optional
|
|
1
|
+
from typing import Optional
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
from
|
|
7
|
-
from flet.core.event_handler import EventHandler
|
|
8
|
-
from flet.core.types import MainAxisAlignment, OptionalEventCallable
|
|
3
|
+
import flet as ft
|
|
4
|
+
from .types import DataColumnSize
|
|
9
5
|
|
|
6
|
+
__all__ = ["DataColumn2"]
|
|
10
7
|
|
|
11
|
-
class Size(Enum):
|
|
12
|
-
"""Relative size of a column determines the share of total table width allocated to each individual column.
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
@ft.control("DataColumn2")
|
|
10
|
+
class DataColumn2(ft.DataColumn):
|
|
16
11
|
"""
|
|
12
|
+
Extends Flet [`DataColumn`](https://flet.dev/docs/controls/datatable/#datacolumn),
|
|
13
|
+
adding the ability to set relative column size and fixed column width.
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
M = "m"
|
|
20
|
-
L = "l"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class DataColumnSortEvent(ControlEvent):
|
|
24
|
-
def __init__(self, e: ControlEvent):
|
|
25
|
-
super().__init__(e.target, e.name, e.data, e.control, e.page)
|
|
26
|
-
d = json.loads(e.data)
|
|
27
|
-
self.column_index: int = d.get("i")
|
|
28
|
-
self.ascending: bool = d.get("a")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class DataColumn2(Control):
|
|
32
|
-
"""Column configuration for a [DataTable2](datatable2.md).
|
|
33
|
-
|
|
34
|
-
One column configuration must be provided for each column to display in the table.
|
|
35
|
-
|
|
36
|
-
Additional to Flet [DataColumn](https://flet.dev/docs/controls/datatable/#datacolumn), adds the capability to set relative column size via size property.
|
|
37
|
-
|
|
15
|
+
Meant to be used as an item of [`DataTable2.columns`][(p).].
|
|
38
16
|
"""
|
|
39
17
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
numeric: Optional[bool] = None,
|
|
45
|
-
tooltip: Optional[str] = None,
|
|
46
|
-
fixed_width: OptionalNumber = None,
|
|
47
|
-
heading_row_alignment: Optional[MainAxisAlignment] = None,
|
|
48
|
-
on_sort: OptionalEventCallable[DataColumnSortEvent] = None,
|
|
49
|
-
#
|
|
50
|
-
# Control
|
|
51
|
-
#
|
|
52
|
-
ref=None,
|
|
53
|
-
visible: Optional[bool] = None,
|
|
54
|
-
disabled: Optional[bool] = None,
|
|
55
|
-
data: Any = None,
|
|
56
|
-
):
|
|
57
|
-
Control.__init__(self, ref=ref, visible=visible, disabled=disabled, data=data)
|
|
58
|
-
|
|
59
|
-
self.__on_sort = EventHandler(lambda e: DataColumnSortEvent(e))
|
|
60
|
-
self._add_event_handler("sort", self.__on_sort.get_handler())
|
|
61
|
-
|
|
62
|
-
self.label = label
|
|
63
|
-
self.size = size
|
|
64
|
-
self.fixed_width = fixed_width
|
|
65
|
-
self.numeric = numeric
|
|
66
|
-
self.tooltip = tooltip
|
|
67
|
-
self.heading_row_alignment = heading_row_alignment
|
|
68
|
-
self.on_sort = on_sort
|
|
69
|
-
|
|
70
|
-
def _get_control_name(self):
|
|
71
|
-
return "datacolumn2"
|
|
72
|
-
|
|
73
|
-
def _get_children(self):
|
|
74
|
-
self.__label._set_attr_internal("n", "label")
|
|
75
|
-
return [self.__label]
|
|
76
|
-
|
|
77
|
-
def before_update(self):
|
|
78
|
-
super().before_update()
|
|
79
|
-
assert self.__label.visible, "label must be visible"
|
|
80
|
-
|
|
81
|
-
# label
|
|
82
|
-
@property
|
|
83
|
-
def label(self) -> Control:
|
|
84
|
-
"""
|
|
85
|
-
See DataColumn [label](https://flet.dev/docs/controls/datatable#label).
|
|
86
|
-
"""
|
|
87
|
-
return self.__label
|
|
88
|
-
|
|
89
|
-
@label.setter
|
|
90
|
-
def label(self, value: Control):
|
|
91
|
-
self.__label = value
|
|
92
|
-
|
|
93
|
-
# size
|
|
94
|
-
@property
|
|
95
|
-
def size(self) -> Optional[Size]:
|
|
96
|
-
"""
|
|
97
|
-
**NEW**
|
|
98
|
-
|
|
99
|
-
Column sizes are determined based on available width by distributing it to individual columns accounting for their relative sizes.
|
|
100
|
-
|
|
101
|
-
Value is of type `Size` and defaults to `Size.S`.
|
|
102
|
-
"""
|
|
103
|
-
return self.__size
|
|
104
|
-
|
|
105
|
-
@size.setter
|
|
106
|
-
def size(self, value: Optional[Size]):
|
|
107
|
-
self.__size = value
|
|
108
|
-
self._set_enum_attr("size", value, Size)
|
|
109
|
-
|
|
110
|
-
# numeric
|
|
111
|
-
@property
|
|
112
|
-
def numeric(self) -> bool:
|
|
113
|
-
"""
|
|
114
|
-
See DataColumn [numeric](https://flet.dev/docs/controls/datatable#numeric).
|
|
115
|
-
"""
|
|
116
|
-
|
|
117
|
-
return self._get_attr("numeric", data_type="bool", def_value=False)
|
|
118
|
-
|
|
119
|
-
@numeric.setter
|
|
120
|
-
def numeric(self, value: Optional[bool]):
|
|
121
|
-
self._set_attr("numeric", value)
|
|
122
|
-
|
|
123
|
-
# fixed_width
|
|
124
|
-
@property
|
|
125
|
-
def fixed_width(self) -> OptionalNumber:
|
|
126
|
-
"""
|
|
127
|
-
**NEW**
|
|
128
|
-
|
|
129
|
-
Defines absolute width of the column in pixel (as opposed to relative `size` used by default).
|
|
130
|
-
"""
|
|
131
|
-
return self._get_attr("fixedWidth")
|
|
132
|
-
|
|
133
|
-
@fixed_width.setter
|
|
134
|
-
def fixed_width(self, value: OptionalNumber):
|
|
135
|
-
self._set_attr("fixedWidth", value)
|
|
136
|
-
|
|
137
|
-
# tooltip
|
|
138
|
-
@property
|
|
139
|
-
def tooltip(self) -> Optional[str]:
|
|
140
|
-
"""
|
|
141
|
-
See DataColumn [tooltip](https://flet.dev/docs/controls/datatable#tooltip).
|
|
142
|
-
"""
|
|
143
|
-
return self._get_attr("tooltip")
|
|
144
|
-
|
|
145
|
-
@tooltip.setter
|
|
146
|
-
def tooltip(self, value: Optional[str]):
|
|
147
|
-
self._set_attr("tooltip", value)
|
|
148
|
-
|
|
149
|
-
# heading_row_alignment
|
|
150
|
-
@property
|
|
151
|
-
def heading_row_alignment(self) -> Optional[MainAxisAlignment]:
|
|
152
|
-
"""
|
|
153
|
-
See DataColumn [heading_row_alignment](https://flet.dev/docs/controls/datatable#heading_row_alignment).
|
|
154
|
-
"""
|
|
155
|
-
return self.__heading_row_alignment
|
|
156
|
-
|
|
157
|
-
@heading_row_alignment.setter
|
|
158
|
-
def heading_row_alignment(self, value: Optional[MainAxisAlignment]):
|
|
159
|
-
self.__heading_row_alignment = value
|
|
160
|
-
self._set_enum_attr("headingRowAlignment", value, MainAxisAlignment)
|
|
161
|
-
|
|
162
|
-
# on_sort
|
|
163
|
-
@property
|
|
164
|
-
def on_sort(self) -> OptionalEventCallable["DataColumnSortEvent"]:
|
|
165
|
-
"""
|
|
166
|
-
See DataColumn [on_sort](https://flet.dev/docs/controls/datatable#on_sort).
|
|
167
|
-
"""
|
|
168
|
-
return self.__on_sort.handler
|
|
18
|
+
fixed_width: Optional[ft.Number] = None
|
|
19
|
+
"""
|
|
20
|
+
Defines absolute width of the column in pixels (as opposed to relative [`size`][..] used by default).
|
|
21
|
+
"""
|
|
169
22
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
23
|
+
size: Optional[DataColumnSize] = DataColumnSize.S
|
|
24
|
+
"""
|
|
25
|
+
Column sizes are determined based on available width by distributing
|
|
26
|
+
it to individual columns accounting for their relative sizes.
|
|
27
|
+
"""
|
flet_datatable2/datarow2.py
CHANGED
|
@@ -1,220 +1,58 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Optional
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
from flet.core.control import Control, OptionalNumber
|
|
5
|
-
from flet.core.datatable import DataCell
|
|
6
|
-
from flet.core.types import ColorValue, ControlStateValue, OptionalControlEventCallable
|
|
3
|
+
import flet as ft
|
|
7
4
|
|
|
5
|
+
__all__ = ["DataRow2"]
|
|
8
6
|
|
|
9
|
-
class DataRow2(Control):
|
|
10
|
-
"""
|
|
11
|
-
Extension of [DataRow](https://flet.dev/docs/controls/datatable#datarow).
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
@ft.control("DataRow2")
|
|
9
|
+
class DataRow2(ft.DataRow):
|
|
14
10
|
"""
|
|
11
|
+
Extends [`DataRow`](https://flet.dev/docs/controls/datatable#datarow).
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
color: ControlStateValue[ColorValue] = None,
|
|
20
|
-
decoration: Optional[BoxDecoration] = None,
|
|
21
|
-
specific_row_height: OptionalNumber = None,
|
|
22
|
-
selected: Optional[bool] = None,
|
|
23
|
-
on_long_press: OptionalControlEventCallable = None,
|
|
24
|
-
on_select_changed: OptionalControlEventCallable = None,
|
|
25
|
-
on_double_tap: OptionalControlEventCallable = None,
|
|
26
|
-
on_secondary_tap: OptionalControlEventCallable = None,
|
|
27
|
-
on_secondary_tap_down: OptionalControlEventCallable = None,
|
|
28
|
-
on_tap: OptionalControlEventCallable = None,
|
|
29
|
-
#
|
|
30
|
-
# Control
|
|
31
|
-
#
|
|
32
|
-
ref=None,
|
|
33
|
-
visible: Optional[bool] = None,
|
|
34
|
-
disabled: Optional[bool] = None,
|
|
35
|
-
data: Any = None,
|
|
36
|
-
):
|
|
37
|
-
Control.__init__(self, ref=ref, visible=visible, disabled=disabled, data=data)
|
|
38
|
-
|
|
39
|
-
self.cells = cells
|
|
40
|
-
self.color = color
|
|
41
|
-
self.decoration = decoration
|
|
42
|
-
self.specific_row_height = specific_row_height
|
|
43
|
-
self.selected = selected
|
|
44
|
-
self.on_long_press = on_long_press
|
|
45
|
-
self.on_select_changed = on_select_changed
|
|
46
|
-
self.on_double_tap = on_double_tap
|
|
47
|
-
self.on_secondary_tap = on_secondary_tap
|
|
48
|
-
self.on_secondary_tap_down = on_secondary_tap_down
|
|
49
|
-
self.on_tap = on_tap
|
|
50
|
-
|
|
51
|
-
def _get_control_name(self):
|
|
52
|
-
return "datarow2"
|
|
53
|
-
|
|
54
|
-
def __contains__(self, item):
|
|
55
|
-
return item in self.__cells
|
|
56
|
-
|
|
57
|
-
def before_update(self):
|
|
58
|
-
super().before_update()
|
|
59
|
-
assert any(
|
|
60
|
-
cell.visible for cell in self.__cells
|
|
61
|
-
), "cells must contain at minimum one visible DataCell"
|
|
62
|
-
self._set_attr_json("color", self.__color, wrap_attr_dict=True)
|
|
63
|
-
self._set_attr_json("decoration", self.__decoration)
|
|
64
|
-
|
|
65
|
-
def _get_children(self):
|
|
66
|
-
return self.__cells
|
|
67
|
-
|
|
68
|
-
# cells
|
|
69
|
-
@property
|
|
70
|
-
def cells(self) -> List[DataCell]:
|
|
71
|
-
"""
|
|
72
|
-
See DataRow [cells](https://flet.dev/docs/controls/datatable#cells).
|
|
73
|
-
"""
|
|
74
|
-
return self.__cells
|
|
75
|
-
|
|
76
|
-
@cells.setter
|
|
77
|
-
def cells(self, value: List[DataCell]):
|
|
78
|
-
# assert all(
|
|
79
|
-
# isinstance(cell, DataCell) for cell in value
|
|
80
|
-
# ), "cells must contain only DataCell instances"
|
|
81
|
-
self.__cells = value
|
|
82
|
-
|
|
83
|
-
# color
|
|
84
|
-
@property
|
|
85
|
-
def color(self) -> ControlStateValue[str]:
|
|
86
|
-
"""
|
|
87
|
-
See DataRow [color](https://flet.dev/docs/controls/datatable#color).
|
|
88
|
-
"""
|
|
89
|
-
return self.__color
|
|
90
|
-
|
|
91
|
-
@color.setter
|
|
92
|
-
def color(self, value: ControlStateValue[str]):
|
|
93
|
-
self.__color = value
|
|
94
|
-
|
|
95
|
-
# decoration
|
|
96
|
-
@property
|
|
97
|
-
def decoration(self) -> Optional[BoxDecoration]:
|
|
98
|
-
"""
|
|
99
|
-
**NEW**
|
|
100
|
-
|
|
101
|
-
Decoration to be applied to the given row. Value is an instance of [BoxDecoration](https://flet.dev/docs/reference/types/boxdecoration).
|
|
102
|
-
When applied, it `divider_thickness` won't take effect.
|
|
103
|
-
"""
|
|
104
|
-
return self.__decoration
|
|
105
|
-
|
|
106
|
-
@decoration.setter
|
|
107
|
-
def decoration(self, value: Optional[BoxDecoration]):
|
|
108
|
-
self.__decoration = value
|
|
109
|
-
|
|
110
|
-
# specific_row_height
|
|
111
|
-
@property
|
|
112
|
-
def specific_row_height(self) -> OptionalNumber:
|
|
113
|
-
"""
|
|
114
|
-
**NEW**
|
|
115
|
-
|
|
116
|
-
Specific row height. If not provided, `data_row_height` will be applied.
|
|
117
|
-
"""
|
|
118
|
-
return self._get_attr("specificRowHeight")
|
|
119
|
-
|
|
120
|
-
@specific_row_height.setter
|
|
121
|
-
def specific_row_height(self, value: OptionalNumber):
|
|
122
|
-
self._set_attr("specificRowHeight", value)
|
|
123
|
-
|
|
124
|
-
# selected
|
|
125
|
-
@property
|
|
126
|
-
def selected(self) -> bool:
|
|
127
|
-
"""
|
|
128
|
-
See DataRow [selected](https://flet.dev/docs/controls/datatable#selected).
|
|
129
|
-
"""
|
|
130
|
-
return self._get_attr("selected", data_type="bool", def_value=False)
|
|
131
|
-
|
|
132
|
-
@selected.setter
|
|
133
|
-
def selected(self, value: Optional[bool]):
|
|
134
|
-
self._set_attr("selected", value)
|
|
135
|
-
|
|
136
|
-
# on_long_press
|
|
137
|
-
@property
|
|
138
|
-
def on_long_press(self) -> OptionalControlEventCallable:
|
|
139
|
-
"""
|
|
140
|
-
See DataRow [on_long_press](https://flet.dev/docs/controls/datatable#on_long_press).
|
|
141
|
-
"""
|
|
142
|
-
return self._get_event_handler("long_press")
|
|
143
|
-
|
|
144
|
-
@on_long_press.setter
|
|
145
|
-
def on_long_press(self, handler: OptionalControlEventCallable):
|
|
146
|
-
self._add_event_handler("long_press", handler)
|
|
147
|
-
self._set_attr("onLongPress", True if handler is not None else None)
|
|
148
|
-
|
|
149
|
-
# on_tap
|
|
150
|
-
@property
|
|
151
|
-
def on_tap(self) -> OptionalControlEventCallable:
|
|
152
|
-
"""
|
|
153
|
-
**NEW**
|
|
154
|
-
|
|
155
|
-
Row tap handler. Won't be called if tapped cell has `tap` event handler.
|
|
156
|
-
"""
|
|
157
|
-
return self._get_event_handler("tap")
|
|
158
|
-
|
|
159
|
-
@on_tap.setter
|
|
160
|
-
def on_tap(self, handler: OptionalControlEventCallable):
|
|
161
|
-
self._add_event_handler("tap", handler)
|
|
162
|
-
self._set_attr("onTap", True if handler is not None else None)
|
|
163
|
-
|
|
164
|
-
# on_double_tap
|
|
165
|
-
@property
|
|
166
|
-
def on_double_tap(self) -> OptionalControlEventCallable:
|
|
167
|
-
"""
|
|
168
|
-
**NEW**
|
|
169
|
-
|
|
170
|
-
Row double tap handler. Won't be called if tapped cell has `tap` event handler.
|
|
171
|
-
"""
|
|
172
|
-
return self._get_event_handler("double_tap")
|
|
173
|
-
|
|
174
|
-
@on_double_tap.setter
|
|
175
|
-
def on_double_tap(self, handler: OptionalControlEventCallable):
|
|
176
|
-
self._add_event_handler("double_tap", handler)
|
|
177
|
-
self._set_attr("onDoubleTap", True if handler is not None else None)
|
|
178
|
-
|
|
179
|
-
# on_secondary_tap
|
|
180
|
-
@property
|
|
181
|
-
def on_secondary_tap(self) -> OptionalControlEventCallable:
|
|
182
|
-
"""
|
|
183
|
-
**NEW**
|
|
13
|
+
Adds row-level `tap` events. There are also [`on_secondary_tap`][(c).] and [`on_secondary_tap_down`][(c).],
|
|
14
|
+
which are not available in `DataCell`s and can be useful in desktop settings to handle right-click actions.
|
|
15
|
+
"""
|
|
184
16
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
17
|
+
decoration: Optional[ft.BoxDecoration] = None
|
|
18
|
+
"""
|
|
19
|
+
Decoration to be applied to the row.
|
|
20
|
+
|
|
21
|
+
Overrides `divider_thickness`.
|
|
22
|
+
"""
|
|
188
23
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
24
|
+
specific_row_height: Optional[ft.Number] = None
|
|
25
|
+
"""
|
|
26
|
+
Specific row height.
|
|
27
|
+
|
|
28
|
+
Falls back to `data_row_height` if not set.
|
|
29
|
+
"""
|
|
193
30
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
31
|
+
on_double_tap: ft.OptionalControlEventHandler["DataRow2"] = None
|
|
32
|
+
"""
|
|
33
|
+
Fires when the row is double-tapped.
|
|
34
|
+
|
|
35
|
+
Ignored if the tapped cell has a `tap` handler.
|
|
36
|
+
"""
|
|
199
37
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
38
|
+
on_secondary_tap: ft.OptionalControlEventHandler["DataRow2"] = None
|
|
39
|
+
"""
|
|
40
|
+
Fires when the row is right-clicked (secondary tap).
|
|
41
|
+
|
|
42
|
+
Ignored if the tapped cell has a `tap` handler.
|
|
43
|
+
"""
|
|
203
44
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
45
|
+
on_secondary_tap_down: ft.OptionalControlEventHandler["DataRow2"] = None
|
|
46
|
+
"""
|
|
47
|
+
Fires when the row is right-clicked (secondary tap down).
|
|
48
|
+
|
|
49
|
+
Ignored if the tapped cell has a `tap` handler.
|
|
50
|
+
"""
|
|
208
51
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return self._get_event_handler("select_changed")
|
|
52
|
+
on_tap: ft.OptionalEventHandler[ft.TapEvent["DataRow2"]] = None
|
|
53
|
+
"""
|
|
54
|
+
Fires when the row is tapped.
|
|
55
|
+
|
|
56
|
+
Ignored if the tapped cell has a `tap` handler.
|
|
57
|
+
"""
|
|
216
58
|
|
|
217
|
-
@on_select_changed.setter
|
|
218
|
-
def on_select_changed(self, handler: OptionalControlEventCallable):
|
|
219
|
-
self._add_event_handler("select_changed", handler)
|
|
220
|
-
self._set_attr("onSelectChanged", True if handler is not None else None)
|