Skip to content

Commit 522621c

Browse files
authored
Merge pull request #6 from flet-dev/inesa/test-folder
Tests folder, updated examples
2 parents fb43eed + bd4d473 commit 522621c

File tree

12 files changed

+553
-31
lines changed

12 files changed

+553
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
/src/flet_datatable2.egg-info
1111
.DS_Store
1212
uv.lock
13+
__pycache__/

docs/types/datacolumn_size.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
::: flet_datatable2.types.DataColumnSize
1+
::: flet_datatable2.types.DataColumnSize
2+
options:
3+
separate_signature: false

examples/datatable2_example/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[project]
22
name = "flet-datatable2-example"
33
version = "1.0.0"
4-
description = ""
4+
description = "flet-datatable2-example"
55
readme = "README.md"
66
requires-python = ">=3.10"
77
authors = [{ name = "Flet Contributors", email = "[email protected]" }]
88
dependencies = [
9-
"flet-datatable2",
10-
"flet",
9+
"flet-datatable2 >=0.2.0.dev0",
10+
"flet >=0.70.0.dev0",
1111
]
1212

1313
# Docs: https://flet.dev/docs/publish

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ plugins:
126126
show_labels: false
127127
show_if_no_docstring: true
128128
docstring_section_style: spacy
129+
separate_signature: true
129130
inherited_members: true
130131
preload_modules: [ flet ]
131132
filters:

src/flet_datatable2/datacolumn2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
@ft.control("DataColumn2")
1010
class DataColumn2(ft.DataColumn):
1111
"""
12-
Extends Flet [`DataColumn`](https://flet.dev/docs/controls/datatable/#datacolumn),
12+
Extends [`flet.DataColumn`][flet.DataColumn],
1313
adding the ability to set relative column size and fixed column width.
1414
1515
Meant to be used as an item of [`DataTable2.columns`][(p).].
1616
"""
1717

1818
fixed_width: Optional[ft.Number] = None
1919
"""
20-
Defines absolute width of the column in pixels (as opposed to relative [`size`][..] used by default).
20+
Defines absolute width of the column in pixels
21+
(as opposed to relative [`size`][..] used by default).
2122
"""
2223

2324
size: Optional[DataColumnSize] = DataColumnSize.S

src/flet_datatable2/datarow2.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,77 @@
88
@ft.control("DataRow2")
99
class DataRow2(ft.DataRow):
1010
"""
11-
Extends [`DataRow`](https://flet.dev/docs/controls/datatable#datarow).
11+
Extends [`flet.DataRow`][flet.DataRow], adding row-level `tap` events.
1212
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.
13+
There are also [`on_secondary_tap`][(c).] and [`on_secondary_tap_down`][(c).],
14+
which are not available in [`DataCell`][flet.DataCell]s and can be useful in
15+
desktop settings to handle right-click actions.
1516
"""
1617

1718
decoration: Optional[ft.BoxDecoration] = None
1819
"""
19-
Decoration to be applied to the row.
20+
Decoration to be applied to this row.
2021
21-
Overrides `divider_thickness`.
22+
Note:
23+
If provided, [`DataTable2.divider_thickness`][(p).] has no effect.
2224
"""
2325

2426
specific_row_height: Optional[ft.Number] = None
2527
"""
2628
Specific row height.
2729
28-
Falls back to `data_row_height` if not set.
30+
Falls back to [`DataTable2.data_row_height`][(p).] if not set.
2931
"""
3032

31-
on_double_tap: ft.OptionalControlEventHandler["DataRow2"] = None
33+
on_double_tap: Optional[ft.ControlEventHandler["DataRow2"]] = None
3234
"""
3335
Fires when the row is double-tapped.
3436
35-
Ignored if the tapped cell has a `tap` handler.
37+
Note:
38+
Won't be called if tapped cell has any tap event handlers
39+
([`on_tap`][flet.DataCell.on_tap],
40+
[`on_double_tap`][flet.DataCell.on_double_tap],
41+
[`on_long_press`][flet.DataCell.on_long_press],
42+
[`on_tap_cancel`][flet.DataCell.on_tap_cancel],
43+
[`on_tap_down`][flet.DataCell.on_tap_down]) set.
3644
"""
3745

38-
on_secondary_tap: ft.OptionalControlEventHandler["DataRow2"] = None
46+
on_secondary_tap: Optional[ft.ControlEventHandler["DataRow2"]] = None
3947
"""
4048
Fires when the row is right-clicked (secondary tap).
4149
42-
Ignored if the tapped cell has a `tap` handler.
50+
Note:
51+
Won't be called if tapped cell has any tap event handlers
52+
([`on_tap`][flet.DataCell.on_tap],
53+
[`on_double_tap`][flet.DataCell.on_double_tap],
54+
[`on_long_press`][flet.DataCell.on_long_press],
55+
[`on_tap_cancel`][flet.DataCell.on_tap_cancel],
56+
[`on_tap_down`][flet.DataCell.on_tap_down]) set.
4357
"""
4458

45-
on_secondary_tap_down: ft.OptionalControlEventHandler["DataRow2"] = None
59+
on_secondary_tap_down: Optional[ft.ControlEventHandler["DataRow2"]] = None
4660
"""
4761
Fires when the row is right-clicked (secondary tap down).
4862
49-
Ignored if the tapped cell has a `tap` handler.
63+
Note:
64+
Won't be called if tapped cell has any tap event handlers
65+
([`on_tap`][flet.DataCell.on_tap],
66+
[`on_double_tap`][flet.DataCell.on_double_tap],
67+
[`on_long_press`][flet.DataCell.on_long_press],
68+
[`on_tap_cancel`][flet.DataCell.on_tap_cancel],
69+
[`on_tap_down`][flet.DataCell.on_tap_down]) set.
5070
"""
5171

52-
on_tap: ft.OptionalEventHandler[ft.TapEvent["DataRow2"]] = None
72+
on_tap: Optional[ft.EventHandler[ft.TapEvent["DataRow2"]]] = None
5373
"""
5474
Fires when the row is tapped.
5575
56-
Ignored if the tapped cell has a `tap` handler.
76+
Note:
77+
Won't be called if tapped cell has any tap event handlers
78+
([`on_tap`][flet.DataCell.on_tap],
79+
[`on_double_tap`][flet.DataCell.on_double_tap],
80+
[`on_long_press`][flet.DataCell.on_long_press],
81+
[`on_tap_cancel`][flet.DataCell.on_tap_cancel],
82+
[`on_tap_down`][flet.DataCell.on_tap_down]) set.
5783
"""
5884

src/flet_datatable2/datatable2.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
@ft.control("DataTable2")
1313
class DataTable2(ft.DataTable):
1414
"""
15-
Extends [`DataTable`](https://flet.dev/docs/controls/datatable).
15+
Extends [`flet.DataTable`][flet.DataTable].
1616
1717
Provides sticky header row, scrollable data rows,
1818
and additional layout flexibility with [`DataColumn2`][(p).]
1919
and [`DataRow2`][(p).].
20+
21+
Note:
22+
`DataTable2` doesn't support
23+
[`flet.DataTable.data_row_min_height`][flet.DataTable.data_row_min_height]
24+
and [`flet.DataTable.data_row_max_height`][flet.DataTable.data_row_max_height]
25+
properties present in the parent [`flet.DataTable`][flet.DataTable].
26+
Use [`data_row_height`][(c).] instead.
2027
"""
2128

2229
columns: list[Union[DataColumn2, ft.DataColumn]]
@@ -117,7 +124,7 @@ class DataTable2(ft.DataTable):
117124
"""
118125

119126
checkbox_alignment: ft.Alignment = field(
120-
default_factory=lambda: ft.Alignment.center()
127+
default_factory=lambda: ft.Alignment.CENTER
121128
)
122129
"""
123130
Alignment of the checkbox.
@@ -126,13 +133,8 @@ class DataTable2(ft.DataTable):
126133
data_row_height: Optional[ft.Number] = None
127134
"""
128135
Height of each data row.
129-
130-
Note:
131-
`DataTable2` doesn't support
132-
`DataTable.data_row_min_height` and `DataTable.data_row_max_height`.
133136
"""
134137

135-
# present in parent but of no use in DataTable2
136-
data_row_min_height: None = field(init=False, repr=False, compare=False)
137-
data_row_max_height: None = field(init=False, repr=False, compare=False)
138-
138+
# present in parent (DataTable) but of no use in DataTable2
139+
data_row_min_height: None = field(init=False, repr=False, compare=False, metadata={"skip": True})
140+
data_row_max_height: None = field(init=False, repr=False, compare=False, metadata={"skip": True})

src/flutter/flet_datatable2/lib/src/datatable2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class _DataTable2ControlState extends State<DataTable2Control> {
8787
sortArrowAnimationDuration: widget.control.getDuration(
8888
"sort_arrow_animation_duration", Duration(microseconds: 150))!,
8989
checkboxAlignment:
90-
widget.control.getAlignment("checkboxAlignment", Alignment.center)!,
90+
widget.control.getAlignment("checkbox_alignment", Alignment.center)!,
9191
headingCheckboxTheme: widget.control
9292
.getCheckboxTheme("heading_checkbox_theme", Theme.of(context)),
9393
datarowCheckboxTheme: widget.control

tests/basic_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import flet as ft
2+
3+
import flet_datatable2 as fdt
4+
5+
6+
def main(page: ft.Page):
7+
page.add(
8+
fdt.DataTable2(
9+
empty=ft.Text("This table is empty."),
10+
columns=[
11+
fdt.DataColumn2(ft.Text("First name")),
12+
fdt.DataColumn2(ft.Text("Last name")),
13+
fdt.DataColumn2(ft.Text("Age"), numeric=True),
14+
],
15+
),
16+
)
17+
18+
19+
ft.run(main)

0 commit comments

Comments
 (0)