Updated kivymd

This commit is contained in:
Mark Qvist 2022-10-02 17:16:59 +02:00
parent c6df8b851b
commit abcf173cc8
160 changed files with 11617 additions and 6545 deletions

View file

@ -1,5 +1,4 @@
#:import DEVICE_TYPE kivymd.material_resources.DEVICE_TYPE
#:import FakeRectangularElevationBehavior kivymd.uix.behaviors.FakeRectangularElevationBehavior
<CellRow>
@ -66,7 +65,7 @@
size_hint_y: None
height: self.minimum_height
spacing: "4dp"
tooltip_text: root.text
tooltip_text: root.tooltip if root.tooltip else root.text
BoxLayout:
id: box
@ -175,7 +174,11 @@
font_size: "14sp"
on_release: root.table_data.open_pagination_menu()
text:
f"{root.table_data.rows_num if root.table_data.rows_num < len(root.table_data.row_data) else len(root.table_data.row_data)}"
"{}".format( \
root.table_data.rows_num \
if root.table_data.rows_num < len(root.table_data.row_data) else \
len(root.table_data.row_data) \
)
Widget:
size_hint_x: None
@ -192,9 +195,11 @@
if root.theme_cls.theme_style == "Dark" else \
(0, 0, 0, 1)
text:
f"1-" \
f"{root.table_data.rows_num if root.table_data.rows_num > len(root.table_data.row_data) else len(root.table_data.row_data)} " \
f"of {len(root.table_data.row_data)}"
"1-{} of {}".format( \
root.table_data.rows_num \
if root.table_data.rows_num > len(root.table_data.row_data) else \
len(root.table_data.row_data), len(root.table_data.row_data) \
)
MDIconButton:
id: button_back
@ -217,7 +222,7 @@
on_release: root.table_data.set_next_row_data_parts("forward")
<TableContainer@MDCard+FakeRectangularElevationBehavior>
<TableContainer@MDCard>
<MDDataTable>

View file

@ -11,19 +11,6 @@ Components/DataTables
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-previous.png
:align: center
Warnings
---------
.. warning:: Data tables are still far from perfect. The class is in constant
change, because of optimizations and bug fixes. If you find a bug or have
an improvement you want to share, take some time and share your discoveries
with us over the main git repo.
Any help is well appreciated.
.. warning:: In versions prior to `Kivy 2.1.0-dev0` exists an error in which is
the table has only one row in the current page, the table will only render
one column instead of the whole row.
.. note:: `MDDataTable` allows developers to sort the data provided by column.
This happens thanks to the use of an external function that you can bind
while you're defining the table columns. Be aware that the sorting function
@ -159,6 +146,15 @@ class CellHeader(MDTooltip, BoxLayout):
and defaults to `''`.
"""
tooltip = StringProperty()
"""
Tooltip containing descriptive text for the column.
If the tooltip is not provided, column `text` shall be used instead.
:attr:`tooltip` is a :class:`~kivy.properties.StringProperty`
and defaults to `''`.
"""
# TODO: Added example.
sort_action = ObjectProperty()
"""
@ -340,11 +336,19 @@ class TableHeader(ThemableBehavior, ScrollView):
CellHeader(
text=col_heading[0],
sort_action=col_heading[2],
tooltip=col_heading[3],
width=self.cols_minimum[i],
table_data=self.table_data,
is_sorted=(col_heading[0] == self.sorted_on),
sorted_order=self.sorted_order,
)
if len(col_heading) == 4
else CellHeader(
text=col_heading[0],
sort_action=col_heading[2],
width=self.cols_minimum[i],
table_data=self.table_data,
)
if len(col_heading) == 3
else CellHeader(
text=col_heading[0],
@ -356,6 +360,9 @@ class TableHeader(ThemableBehavior, ScrollView):
else:
# Sets the text in the first cell.
self.ids.first_cell.text = col_heading[0]
self.ids.first_cell.tooltip = (
col_heading[3] if len(col_heading) == 4 else ""
)
self.ids.first_cell.ids.separator.height = 0
self.ids.first_cell.width = self.cols_minimum[i]
@ -765,6 +772,9 @@ class TablePagination(ThemableBehavior, MDBoxLayout):
class MDDataTable(ThemableBehavior, AnchorLayout):
"""
See :class:`~kivy.uix.anchorlayout.AnchorLayout` class documentation for
more information.
:Events:
:attr:`on_row_press`
Called when a table row is clicked.
@ -775,7 +785,6 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
.. code-block:: python
from kivy.metrics import dp
from kivymd.app import MDApp
@ -914,38 +923,82 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
"""
Data for header columns.
.. code-block:: python
.. tabs::
from kivy.metrics import dp
.. tab:: Imperative python style
from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable
from kivy.uix.anchorlayout import AnchorLayout
.. code-block:: python
from kivy.metrics import dp
from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable
from kivy.uix.anchorlayout import AnchorLayout
class Example(MDApp):
def build(self):
layout = AnchorLayout()
self.data_tables = MDDataTable(
size_hint=(0.7, 0.6),
use_pagination=True,
check=True,
# name column, width column, sorting function column(optional)
column_data=[
("No.", dp(30)),
("Status", dp(30)),
("Signal Name", dp(60)),
("Severity", dp(30)),
("Stage", dp(30)),
("Schedule", dp(30), lambda *args: print("Sorted using Schedule")),
("Team Lead", dp(30)),
],
)
layout.add_widget(self.data_tables)
return layout
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
layout = AnchorLayout()
self.data_tables = MDDataTable(
size_hint=(0.7, 0.6),
use_pagination=True,
check=True,
# name column, width column, sorting function column(optional), custom tooltip
column_data=[
("No.", dp(30), None, "Custom tooltip"),
("Status", dp(30)),
("Signal Name", dp(60)),
("Severity", dp(30)),
("Stage", dp(30)),
("Schedule", dp(30), lambda *args: print("Sorted using Schedule")),
("Team Lead", dp(30)),
],
)
layout.add_widget(self.data_tables)
return layout
Example().run()
Example().run()
.. tab:: Declarative python style
.. code-block:: python
from kivy.metrics import dp
from kivymd.app import MDApp
from kivymd.uix.anchorlayout import MDAnchorLayout
from kivymd.uix.datatables import MDDataTable
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return MDAnchorLayout(
MDDataTable(
size_hint=(0.7, 0.6),
use_pagination=True,
check=True,
# name column, width column, sorting function column(optional)
column_data=[
("No.", dp(30)),
("Status", dp(30)),
("Signal Name", dp(60)),
("Severity", dp(30)),
("Stage", dp(30)),
("Schedule", dp(30),
lambda *args: print("Sorted using Schedule")),
("Team Lead", dp(30)),
],
)
)
Example().run()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-column-data.png
:align: center
@ -1060,6 +1113,9 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
layout = AnchorLayout()
data_tables = MDDataTable(
size_hint=(0.9, 0.6),
@ -1187,7 +1243,7 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
"""
Use or not use checkboxes for rows.
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-check.gif
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-check.png
:align: center
:attr:`check` is an :class:`~kivy.properties.BooleanProperty`
@ -1209,6 +1265,9 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
layout = AnchorLayout()
data_tables = MDDataTable(
size_hint=(0.9, 0.6),
@ -1238,19 +1297,19 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
and defaults to `False`.
"""
elevation = NumericProperty(8)
elevation = NumericProperty(4)
"""
Table elevation.
:attr:`elevation` is an :class:`~kivy.properties.NumericProperty`
and defaults to `8`.
and defaults to `4`.
"""
rows_num = NumericProperty(5)
"""
The number of rows displayed on one page of the table.
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-use-pagination.gif
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-use-pagination-rows-num.png
:align: center
:attr:`rows_num` is an :class:`~kivy.properties.NumericProperty`
@ -1266,7 +1325,7 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
.. rubric:: Center
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-menu-pos-center.png
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-menu-pos-top.png
:align: center
.. rubric:: Auto
@ -1282,11 +1341,6 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
"""
Menu height for selecting the number of displayed rows.
.. rubric:: 140dp
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-menu-height-140.png
:align: center
.. rubric:: 240dp
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-menu-height-240.png
@ -1298,7 +1352,7 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
background_color = ColorProperty([0, 0, 0, 0])
"""
Background color in the format (r, g, b, a).
Background color in the format (r, g, b, a) or string format.
See :attr:`~kivy.uix.modalview.ModalView.background_color`.
Use markup strings
@ -1315,6 +1369,9 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
layout = AnchorLayout()
data_tables = MDDataTable(
size_hint=(0.9, 0.6),
@ -1354,7 +1411,8 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
background_color_header = ColorProperty(None)
"""
Background color for :class:`~TableHeader` class.
Background color in the format (r, g, b, a) or string format for
:class:`~TableHeader` class.
.. versionadded:: 1.0.0
@ -1374,7 +1432,8 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
background_color_cell = ColorProperty(None)
"""
Background color for :class:`~CellRow` class.
Background color in the format (r, g, b, a) or string format for
:class:`~CellRow` class.
.. versionadded:: 1.0.0
@ -1395,7 +1454,8 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
background_color_selected_cell = ColorProperty(None)
"""
Background selected color for :class:`~CellRow` class.
Background selected color in the format (r, g, b, a) or string format for
:class:`~CellRow` class.
.. versionadded:: 1.0.0
@ -1408,7 +1468,7 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
background_color_selected_cell="e4514f",
)
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-background-color-selected-cell.gif
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/data-tables-background-color-selected-cell.png
:align: center
:attr:`background_color_selected_cell` is a :class:`~kivy.properties.ColorProperty` and
@ -1503,6 +1563,9 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
data_tables = None
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
layout = MDFloatLayout() # root layout
# Creating control buttons.
button_box = MDBoxLayout(
@ -1604,6 +1667,9 @@ class MDDataTable(ThemableBehavior, AnchorLayout):
data_tables = None
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
layout = MDFloatLayout()
layout.add_widget(
MDRaisedButton(