-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.py
1121 lines (806 loc) · 30.2 KB
/
list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Components/List
===============
.. seealso::
`Material Design spec, Lists <https://material.io/components/lists>`_
.. rubric:: Lists are continuous, vertical indexes of text or images.
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/lists.png
:align: center
The class :class:`~MDList` in combination with a :class:`~BaseListItem` like
:class:`~OneLineListItem` will create a list that expands as items are added to
it, working nicely with `Kivy's` :class:`~kivy.uix.scrollview.ScrollView`.
Due to the variety in sizes and controls in the `Material Design spec`,
this module suffers from a certain level of complexity to keep the widgets
compliant, flexible and performant.
For this `KivyMD` provides list items that try to cover the most common usecases,
when those are insufficient, there's a base class called :class:`~BaseListItem`
which you can use to create your own list items. This documentation will only
cover the provided ones, for custom implementations please refer to this
module's source code.
`KivyMD` provides the following list items classes for use:
Text only ListItems
-------------------
- OneLineListItem_
- TwoLineListItem_
- ThreeLineListItem_
ListItems with widget containers
--------------------------------
These widgets will take other widgets that inherit from :class:`~ILeftBody`,
:class:`ILeftBodyTouch`, :class:`~IRightBody` or :class:`~IRightBodyTouch` and
put them in their corresponding container.
As the name implies, :class:`~ILeftBody` and :class:`~IRightBody` will signal
that the widget goes into the left or right container, respectively.
:class:`~ILeftBodyTouch` and :class:`~IRightBodyTouch` do the same thing,
except these widgets will also receive touch events that occur within their
surfaces.
`KivyMD` provides base classes such as :class:`~ImageLeftWidget`,
:class:`~ImageRightWidget`, :class:`~IconRightWidget`, :class:`~IconLeftWidget`,
based on the above classes.
.. rubric:: Allows the use of items with custom widgets on the left.
- OneLineAvatarListItem_
- TwoLineAvatarListItem_
- ThreeLineAvatarListItem_
- OneLineIconListItem_
- TwoLineIconListItem_
- ThreeLineIconListItem_
.. rubric:: It allows the use of elements with custom widgets on the left
and the right.
- OneLineAvatarIconListItem_
- TwoLineAvatarIconListItem_
- ThreeLineAvatarIconListItem_
Usage
-----
.. code-block:: python
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.list import OneLineListItem
KV = '''
ScrollView:
MDList:
id: container
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
for i in range(20):
self.root.ids.container.add_widget(
OneLineListItem(text=f"Single-line item {i}")
)
Test().run()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/lists.gif
:align: center
Events of List
--------------
.. code-block:: python
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
ScrollView:
MDList:
OneLineAvatarIconListItem:
on_release: print("Click!")
IconLeftWidget:
icon: "github"
OneLineAvatarIconListItem:
on_release: print("Click 2!")
IconLeftWidget:
icon: "gitlab"
'''
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
MainApp().run()
.. OneLineListItem:
OneLineListItem
---------------
.. code-block:: kv
OneLineListItem:
text: "Single-line item"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/OneLineListItem.png
:align: center
.. TwoLineListItem:
TwoLineListItem
---------------
.. code-block:: kv
TwoLineListItem:
text: "Two-line item"
secondary_text: "Secondary text here"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/TwoLineListItem.png
:align: center
.. ThreeLineListItem:
ThreeLineListItem
-----------------
.. code-block:: kv
ThreeLineListItem:
text: "Three-line item"
secondary_text: "This is a multi-line label where you can"
tertiary_text: "fit more text than usual"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ThreeLineListItem.png
:align: center
.. OneLineAvatarListItem:
OneLineAvatarListItem
---------------------
.. code-block:: kv
OneLineAvatarListItem:
text: "Single-line item with avatar"
ImageLeftWidget:
source: "data/logo/kivy-icon-256.png"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/lists-map.png
:align: center
.. TwoLineAvatarListItem:
TwoLineAvatarListItem
---------------------
.. code-block:: kv
TwoLineAvatarListItem:
text: "Two-line item with avatar"
secondary_text: "Secondary text here"
ImageLeftWidget:
source: "data/logo/kivy-icon-256.png"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/TwoLineAvatarListItem.png
:align: center
.. ThreeLineAvatarListItem:
ThreeLineAvatarListItem
-----------------------
.. code-block:: kv
ThreeLineAvatarListItem:
text: "Three-line item with avatar"
secondary_text: "Secondary text here"
tertiary_text: "fit more text than usual"
ImageLeftWidget:
source: "data/logo/kivy-icon-256.png"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ThreeLineAvatarListItem.png
:align: center
.. OneLineIconListItem:
OneLineIconListItem
-------------------
.. code-block:: kv
OneLineIconListItem:
text: "Single-line item with avatar"
IconLeftWidget:
icon: "language-python"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/OneLineIconListItem.png
:align: center
.. TwoLineIconListItem:
TwoLineIconListItem
-------------------
.. code-block:: kv
TwoLineIconListItem:
text: "Two-line item with avatar"
secondary_text: "Secondary text here"
IconLeftWidget:
icon: "language-python"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/TwoLineIconListItem.png
:align: center
.. ThreeLineIconListItem:
ThreeLineIconListItem
---------------------
.. code-block:: kv
ThreeLineIconListItem:
text: "Three-line item with avatar"
secondary_text: "Secondary text here"
tertiary_text: "fit more text than usual"
IconLeftWidget:
icon: "language-python"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ThreeLineIconListItem.png
:align: center
.. OneLineAvatarIconListItem:
OneLineAvatarIconListItem
-------------------------
.. code-block:: kv
OneLineAvatarIconListItem:
text: "One-line item with avatar"
IconLeftWidget:
icon: "plus"
IconRightWidget:
icon: "minus"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/OneLineAvatarIconListItem.png
:align: center
.. TwoLineAvatarIconListItem:
TwoLineAvatarIconListItem
-------------------------
.. code-block:: kv
TwoLineAvatarIconListItem:
text: "Two-line item with avatar"
secondary_text: "Secondary text here"
IconLeftWidget:
icon: "plus"
IconRightWidget:
icon: "minus"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/TwoLineAvatarIconListItem.png
:align: center
.. ThreeLineAvatarIconListItem:
ThreeLineAvatarIconListItem
---------------------------
.. code-block:: kv
ThreeLineAvatarIconListItem:
text: "Three-line item with avatar"
secondary_text: "Secondary text here"
tertiary_text: "fit more text than usual"
IconLeftWidget:
icon: "plus"
IconRightWidget:
icon: "minus"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/ThreeLineAvatarIconListItem.png
:align: center
Custom list item
----------------
.. code-block:: python
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivymd.app import MDApp
from kivymd.uix.list import IRightBodyTouch, OneLineAvatarIconListItem
from kivymd.uix.selectioncontrol import MDCheckbox
from kivymd.icon_definitions import md_icons
KV = '''
<ListItemWithCheckbox>:
IconLeftWidget:
icon: root.icon
RightCheckbox:
BoxLayout:
ScrollView:
MDList:
id: scroll
'''
class ListItemWithCheckbox(OneLineAvatarIconListItem):
'''Custom list item.'''
icon = StringProperty("android")
class RightCheckbox(IRightBodyTouch, MDCheckbox):
'''Custom right container.'''
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
icons = list(md_icons.keys())
for i in range(30):
self.root.ids.scroll.add_widget(
ListItemWithCheckbox(text=f"Item {i}", icon=icons[i])
)
MainApp().run()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/custom-list-item.png
:align: center
.. code-block:: python
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.list import IRightBodyTouch
KV = '''
OneLineAvatarIconListItem:
text: "One-line item with avatar"
on_size:
self.ids._right_container.width = container.width
self.ids._right_container.x = container.width
IconLeftWidget:
icon: "cog"
Container:
id: container
MDIconButton:
icon: "minus"
MDIconButton:
icon: "plus"
'''
class Container(IRightBodyTouch, MDBoxLayout):
adaptive_width = True
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
MainApp().run()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/custom-list-right-container.png
:align: center
Behavior
--------
When using the `AvatarListItem` and `IconListItem` classes, when an icon is clicked,
the event of this icon is triggered:
.. code-block:: kv
OneLineIconListItem:
text: "Single-line item with icon"
IconLeftWidget:
icon: "language-python"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/list-icon-trigger.gif
:align: center
You can disable the icon event using the `WithoutTouch` classes:
.. code-block:: kv
OneLineIconListItem:
text: "Single-line item with icon"
IconLeftWidgetWithoutTouch:
icon: "language-python"
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/list-icon-without-trigger.gif
:align: center
"""
__all__ = (
"MDList",
"ILeftBodyTouch",
"IRightBodyTouch",
"OneLineListItem",
"TwoLineListItem",
"ThreeLineListItem",
"OneLineAvatarListItem",
"TwoLineAvatarListItem",
"ThreeLineAvatarListItem",
"OneLineIconListItem",
"TwoLineIconListItem",
"ThreeLineIconListItem",
"OneLineRightIconListItem",
"TwoLineRightIconListItem",
"ThreeLineRightIconListItem",
"OneLineAvatarIconListItem",
"TwoLineAvatarIconListItem",
"ThreeLineAvatarIconListItem",
"ImageLeftWidget",
"ImageRightWidget",
"IconRightWidget",
"IconLeftWidget",
"CheckboxLeftWidget",
"IconLeftWidgetWithoutTouch",
"IconRightWidgetWithoutTouch",
"ImageRightWidgetWithoutTouch",
"ImageLeftWidgetWithoutTouch",
)
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.properties import (
BooleanProperty,
ColorProperty,
ListProperty,
NumericProperty,
OptionProperty,
StringProperty,
)
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.floatlayout import FloatLayout
import kivymd.material_resources as m_res
from kivymd.theming import ThemableBehavior
from kivymd.uix.behaviors import (
CircularRippleBehavior,
RectangularRippleBehavior,
)
from kivymd.uix.button import MDIconButton
from kivymd.uix.gridlayout import MDGridLayout
from kivymd.uix.selectioncontrol import MDCheckbox
from kivymd.utils.fitimage import FitImage
Builder.load_string(
"""
#:import m_res kivymd.material_resources
<MDList>
cols: 1
adaptive_height: True
padding: 0, self._list_vertical_padding
<BaseListItem>
size_hint_y: None
canvas:
Color:
rgba:
self.theme_cls.divider_color \
if root.divider is not None else \
(0, 0, 0, 0)
Line:
points:
( \
root.x ,root.y, root.x + self.width, root.y) \
if root.divider == "Full" else \
(root.x + root._txt_left_pad, root.y, \
root.x + self.width - root._txt_left_pad-root._txt_right_pad, \
root.y \
)
Color:
rgba: root.bg_color if root.bg_color else (0, 0, 0, 0)
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
id: _text_container
orientation: "vertical"
pos: root.pos
padding:
root._txt_left_pad, root._txt_top_pad, \
root._txt_right_pad, root._txt_bot_pad
MDLabel:
id: _lbl_primary
text: root.text
font_style: root.font_style
theme_text_color: root.theme_text_color
text_color: root.text_color
size_hint_y: None
height: self.texture_size[1]
markup: True
shorten_from: "right"
shorten: True
MDLabel:
id: _lbl_secondary
text: "" if root._num_lines == 1 else root.secondary_text
font_style: root.secondary_font_style
theme_text_color: root.secondary_theme_text_color
text_color: root.secondary_text_color
size_hint_y: None
height: 0 if root._num_lines == 1 else self.texture_size[1]
shorten: True
shorten_from: "right"
markup: True
MDLabel:
id: _lbl_tertiary
text: "" if root._num_lines == 1 else root.tertiary_text
font_style: root.tertiary_font_style
theme_text_color: root.tertiary_theme_text_color
text_color: root.tertiary_text_color
size_hint_y: None
height: 0 if root._num_lines == 1 else self.texture_size[1]
shorten: True
shorten_from: "right"
markup: True
<OneLineAvatarListItem>
BoxLayout:
id: _left_container
size_hint: None, None
x: root.x + dp(16)
y: root.y + root.height / 2 - self.height / 2
size: dp(40), dp(40)
<ThreeLineAvatarListItem>
BoxLayout:
id: _left_container
size_hint: None, None
x: root.x + dp(16)
y: root.y + root.height - root._txt_top_pad - self.height - dp(5)
size: dp(40), dp(40)
<OneLineIconListItem>
BoxLayout:
id: _left_container
size_hint: None, None
x: root.x + dp(16)
y: root.y + root.height / 2 - self.height / 2
size: dp(48), dp(48)
<ThreeLineIconListItem>
BoxLayout:
id: _left_container
size_hint: None, None
x: root.x + dp(16)
y: root.y + root.height - root._txt_top_pad - self.height - dp(5)
size: dp(48), dp(48)
<OneLineRightIconListItem>
BoxLayout:
id: _right_container
size_hint: None, None
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
y: root.y + root.height / 2 - self.height / 2
size: dp(48), dp(48)
<ThreeLineRightIconListItem>
BoxLayout:
id: _right_container
size_hint: None, None
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
y: root.y + root.height / 2 - self.height / 2
size: dp(48), dp(48)
<OneLineAvatarIconListItem>
BoxLayout:
id: _right_container
size_hint: None, None
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
y: root.y + root.height / 2 - self.height / 2
size: dp(48), dp(48)
<TwoLineAvatarIconListItem>
BoxLayout:
id: _right_container
size_hint: None, None
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
y: root.y + root.height / 2 - self.height / 2
size: dp(48), dp(48)
<ThreeLineAvatarIconListItem>
BoxLayout:
id: _right_container
size_hint: None, None
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
y: root.y + root.height - root._txt_top_pad - self.height - dp(5)
size: dp(48), dp(48)
"""
)
class MDList(MDGridLayout):
"""
ListItem container. Best used in conjunction with a
:class:`kivy.uix.ScrollView`.
When adding (or removing) a widget, it will resize itself to fit its
children, plus top and bottom paddings as described by the `MD` spec.
"""
_list_vertical_padding = NumericProperty("8dp")
def add_widget(self, widget, index=0, canvas=None):
super().add_widget(widget, index, canvas)
self.height += widget.height
def remove_widget(self, widget):
super().remove_widget(widget)
self.height -= widget.height
class BaseListItem(
ThemableBehavior, RectangularRippleBehavior, ButtonBehavior, FloatLayout
):
"""
Base class to all ListItems. Not supposed to be instantiated on its own.
"""
text = StringProperty()
"""
Text shown in the first line.
:attr:`text` is a :class:`~kivy.properties.StringProperty`
and defaults to `''`.
"""
text_color = ColorProperty(None)
"""
Text color in ``rgba`` format used if :attr:`~theme_text_color` is set
to `'Custom'`.
:attr:`text_color` is a :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
font_style = StringProperty("Subtitle1")
"""
Text font style. See ``kivymd.font_definitions.py``.
:attr:`font_style` is a :class:`~kivy.properties.StringProperty`
and defaults to `'Subtitle1'`.
"""
theme_text_color = StringProperty("Primary", allownone=True)
"""
Theme text color in ``rgba`` format for primary text.
:attr:`theme_text_color` is a :class:`~kivy.properties.StringProperty`
and defaults to `'Primary'`.
"""
secondary_text = StringProperty()
"""
Text shown in the second line.
:attr:`secondary_text` is a :class:`~kivy.properties.StringProperty`
and defaults to `''`.
"""
tertiary_text = StringProperty()
"""
The text is displayed on the third line.
:attr:`tertiary_text` is a :class:`~kivy.properties.StringProperty`
and defaults to `''`.
"""
secondary_text_color = ColorProperty(None)
"""
Text color in ``rgba`` format used for secondary text
if :attr:`~secondary_theme_text_color` is set to `'Custom'`.
:attr:`secondary_text_color` is a :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
tertiary_text_color = ColorProperty(None)
"""
Text color in ``rgba`` format used for tertiary text
if :attr:`~tertiary_theme_text_color` is set to 'Custom'.
:attr:`tertiary_text_color` is a :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
secondary_theme_text_color = StringProperty("Secondary", allownone=True)
"""
Theme text color for secondary text.
:attr:`secondary_theme_text_color` is a :class:`~kivy.properties.StringProperty`
and defaults to `'Secondary'`.
"""
tertiary_theme_text_color = StringProperty("Secondary", allownone=True)
"""
Theme text color for tertiary text.
:attr:`tertiary_theme_text_color` is a :class:`~kivy.properties.StringProperty`
and defaults to `'Secondary'`.
"""
secondary_font_style = StringProperty("Body1")
"""
Font style for secondary line. See ``kivymd.font_definitions.py``.
:attr:`secondary_font_style` is a :class:`~kivy.properties.StringProperty`
and defaults to `'Body1'`.
"""
tertiary_font_style = StringProperty("Body1")
"""
Font style for tertiary line. See ``kivymd.font_definitions.py``.
:attr:`tertiary_font_style` is a :class:`~kivy.properties.StringProperty`
and defaults to `'Body1'`.
"""
divider = OptionProperty(
"Full", options=["Full", "Inset", None], allownone=True
)
"""
Divider mode. Available options are: `'Full'`, `'Inset'`
and default to `'Full'`.
:attr:`divider` is a :class:`~kivy.properties.OptionProperty`
and defaults to `'Full'`.
"""
bg_color = ColorProperty(None)
"""
Background color for menu item.
:attr:`bg_color` is a :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
_txt_left_pad = NumericProperty("16dp")
_txt_top_pad = NumericProperty()
_txt_bot_pad = NumericProperty()
_txt_right_pad = NumericProperty(m_res.HORIZ_MARGINS)
_num_lines = 3
_no_ripple_effect = BooleanProperty(False)
class ILeftBody:
"""
Pseudo-interface for widgets that go in the left container for
ListItems that support it.
Implements nothing and requires no implementation, for annotation only.
"""
class ILeftBodyTouch:
"""
Same as :class:`~ILeftBody`, but allows the widget to receive touch
events instead of triggering the ListItem's ripple effect.
"""
class IRightBody:
"""
Pseudo-interface for widgets that go in the right container for
ListItems that support it.
Implements nothing and requires no implementation, for annotation only.
"""
class IRightBodyTouch:
"""
Same as :class:`~IRightBody`, but allows the widget to receive touch
events instead of triggering the ``ListItem``'s ripple effect
"""
class ContainerSupport:
"""
Overrides ``add_widget`` in a ``ListItem`` to include support
for ``I*Body`` widgets when the appropiate containers are present.
"""
_touchable_widgets = ListProperty()
def add_widget(self, widget, index=0):
if issubclass(widget.__class__, ILeftBody):
self.ids._left_container.add_widget(widget)
elif issubclass(widget.__class__, ILeftBodyTouch):
self.ids._left_container.add_widget(widget)
self._touchable_widgets.append(widget)
elif issubclass(widget.__class__, IRightBody):
self.ids._right_container.add_widget(widget)
elif issubclass(widget.__class__, IRightBodyTouch):
self.ids._right_container.add_widget(widget)
self._touchable_widgets.append(widget)
else:
return super().add_widget(widget)
def remove_widget(self, widget):
super().remove_widget(widget)
if widget in self._touchable_widgets:
self._touchable_widgets.remove(widget)
def on_touch_down(self, touch):
if self.propagate_touch_to_touchable_widgets(touch, "down"):
return
super().on_touch_down(touch)
def on_touch_move(self, touch, *args):
if self.propagate_touch_to_touchable_widgets(touch, "move", *args):
return
super().on_touch_move(touch, *args)
def on_touch_up(self, touch):
if self.propagate_touch_to_touchable_widgets(touch, "up"):
return
super().on_touch_up(touch)
def propagate_touch_to_touchable_widgets(self, touch, touch_event, *args):
triggered = False
for i in self._touchable_widgets:
if i.collide_point(touch.x, touch.y):
triggered = True
if touch_event == "down":
i.on_touch_down(touch)
elif touch_event == "move":
i.on_touch_move(touch, *args)
elif touch_event == "up":
i.on_touch_up(touch)
return triggered
class OneLineListItem(BaseListItem):
"""A one line list item."""
_txt_top_pad = NumericProperty("16dp")
_txt_bot_pad = NumericProperty("15dp") # dp(20) - dp(5)
_height = NumericProperty()
_num_lines = 1
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.height = dp(48) if not self._height else self._height
class TwoLineListItem(BaseListItem):
"""A two line list item."""
_txt_top_pad = NumericProperty("20dp")
_txt_bot_pad = NumericProperty("15dp") # dp(20) - dp(5)
_height = NumericProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.height = dp(72) if not self._height else self._height
class ThreeLineListItem(BaseListItem):
"""A three line list item."""
_txt_top_pad = NumericProperty("16dp")
_txt_bot_pad = NumericProperty("15dp") # dp(20) - dp(5)
_height = NumericProperty()
_num_lines = 3
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.height = dp(88) if not self._height else self._height
class OneLineAvatarListItem(ContainerSupport, BaseListItem):
_txt_left_pad = NumericProperty("72dp")
_txt_top_pad = NumericProperty("20dp")
_txt_bot_pad = NumericProperty("19dp") # dp(24) - dp(5)
_height = NumericProperty()
_num_lines = 1
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.height = dp(56) if not self._height else self._height
class TwoLineAvatarListItem(OneLineAvatarListItem):
_txt_top_pad = NumericProperty("20dp")
_txt_bot_pad = NumericProperty("15dp") # dp(20) - dp(5)
_height = NumericProperty()
_num_lines = 2
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.height = dp(72) if not self._height else self._height
class ThreeLineAvatarListItem(ContainerSupport, ThreeLineListItem):
_txt_left_pad = NumericProperty("72dp")
class OneLineIconListItem(ContainerSupport, OneLineListItem):
_txt_left_pad = NumericProperty("72dp")
class TwoLineIconListItem(OneLineIconListItem):
_txt_top_pad = NumericProperty("20dp")