-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicker.py
3133 lines (2670 loc) · 105 KB
/
picker.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/Pickers
==================
.. seealso::
`Material Design spec, Time picker <https://material.io/components/time-pickers>`_
`Material Design spec, Date picker <https://material.io/components/date-pickers>`_
.. rubric:: Includes date, time and color picker.
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/picker-previous.png
:align: center
`KivyMD` provides the following classes for use:
- MDTimePicker_
- MDDatePicker_
- MDThemePicker_
.. MDTimePicker:
MDTimePicker
------------
.. rubric:: Usage
.. code-block::
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.picker import MDTimePicker
KV = '''
MDFloatLayout:
MDRaisedButton:
text: "Open time picker"
pos_hint: {'center_x': .5, 'center_y': .5}
on_release: app.show_time_picker()
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def show_time_picker(self):
'''Open time picker dialog.'''
time_dialog = MDTimePicker()
time_dialog.open()
Test().run()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/MDTimePicker.png
:align: center
Binding method returning set time
---------------------------------
.. code-block:: python
def show_time_picker(self):
time_dialog = MDTimePicker()
time_dialog.bind(time=self.get_time)
time_dialog.open()
def get_time(self, instance, time):
'''
The method returns the set time.
:type instance: <kivymd.uix.picker.MDTimePicker object>
:type time: <class 'datetime.time'>
'''
return time
Open time dialog with the specified time
----------------------------------------
Use the :attr:`~MDTimePicker.set_time` method of the
:class:`~MDTimePicker.` class.
.. code-block:: python
def show_time_picker(self):
from datetime import datetime
# Must be a datetime object
previous_time = datetime.strptime("03:20:00", '%H:%M:%S').time()
time_dialog = MDTimePicker()
time_dialog.set_time(previous_time)
time_dialog.open()
.. note:: For customization of the :class:`~MDTimePicker` class, see the
documentation in the :class:`~BaseDialogPicker` class.
.. MDDatePicker:
MDDatePicker
------------
.. warning:: The widget is under testing. Therefore, we would be grateful if
you would let us know about the bugs found.
Usage
-----
.. code-block:: python
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.picker import MDDatePicker
KV = '''
MDFloatLayout:
MDToolbar:
title: "MDDatePicker"
pos_hint: {"top": 1}
elevation: 10
MDRaisedButton:
text: "Open time picker"
pos_hint: {'center_x': .5, 'center_y': .5}
on_release: app.show_date_picker()
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def on_save(self, instance, value, date_range):
'''
Events called when the "OK" dialog box button is clicked.
:type instance: <kivymd.uix.picker.MDDatePicker object>;
:param value: selected date;
:type value: <class 'datetime.date'>;
:param date_range: list of 'datetime.date' objects in the selected range;
:type date_range: <class 'list'>;
'''
print(instance, value, date_range)
def on_cancel(self, instance, value):
'''Events called when the "CANCEL" dialog box button is clicked.'''
def show_date_picker(self):
date_dialog = MDDatePicker()
date_dialog.bind(on_save=self.on_save, on_cancel=self.on_cancel)
date_dialog.open()
Test().run()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/MDDatePicker.gif
:align: center
Open date dialog with the specified date
----------------------------------------
.. code-block:: python
def show_date_picker(self):
date_dialog = MDDatePicker(year=1983, month=4, day=12)
date_dialog.open()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/previous-date.png
:align: center
You can set the time interval from and to the set date. All days of the week
that are not included in this range will have the status `disabled`.
.. code-block:: python
def show_date_picker(self):
date_dialog = MDDatePicker(
min_date=datetime.date(2021, 2, 15),
max_date=datetime.date(2021, 3, 27),
)
date_dialog.open()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/range-date.gif
:align: center
The range of available dates can be changed in the picker dialog:
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/change-range-date.gif
:align: center
Select year
-----------
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/select-year-date.gif
:align: center
.. warning:: The list of years when opening is not automatically set
to the current year.
You can set the range of years using the :attr:`~kivymd.uix.picker.MDDatePicker.min_year` and
:attr:`~kivymd.uix.picker.MDDatePicker.max_year` attributes:
.. code-block:: python
def show_date_picker(self):
date_dialog = MDDatePicker(min_year=2021, max_year=2030)
date_dialog.open()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/min-max-year-date.png
:align: center
Set and select a date range
---------------------------
.. code-block:: python
def show_date_picker(self):
date_dialog = MDDatePicker(mode="range")
date_dialog.open()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/set-select-range-date.gif
:align: center
.. MDThemePicker:
MDThemePicker
-------------
.. code-block:: python
def show_theme_picker(self):
theme_dialog = MDThemePicker()
theme_dialog.open()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/MDThemePicker.gif
:align: center
"""
__all__ = ("MDTimePicker", "MDDatePicker", "MDThemePicker", "BaseDialogPicker")
import calendar
import datetime
import re
from datetime import date
from typing import NoReturn, Union
from kivy import Logger
from kivy.animation import Animation
from kivy.clock import Clock
from kivy.event import EventDispatcher
from kivy.factory import Factory
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.properties import (
BooleanProperty,
ColorProperty,
ListProperty,
NumericProperty,
ObjectProperty,
OptionProperty,
StringProperty,
)
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.behaviors import ButtonBehavior, FocusBehavior
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.utils import get_color_from_hex
from kivy.vector import Vector
from kivymd.color_definitions import colors, palette
from kivymd.theming import ThemableBehavior, ThemeManager
from kivymd.toast import toast
from kivymd.uix.behaviors import (
CircularRippleBehavior,
FakeRectangularElevationBehavior,
SpecificBackgroundColorBehavior,
)
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import MDIconButton
from kivymd.uix.circularlayout import MDCircularLayout
from kivymd.uix.dialog import BaseDialog
from kivymd.uix.label import MDLabel
from kivymd.uix.relativelayout import MDRelativeLayout
from kivymd.uix.textfield import MDTextField
from kivymd.uix.tooltip import MDTooltip
Builder.load_string(
"""
#:import os os
#:import date datetime.date
#:import calendar calendar
#:import platform platform
#:import Clock kivy.clock.Clock
#:import images_path kivymd.images_path
<DatePickerBaseTooltip>
on_enter:
self.tooltip_text = "" if self.owner \
and self.owner._input_date_dialog_open \
or self.owner._select_year_dialog_open \
else self.hint_text
<DatePickerIconTooltipButton>
<MDDatePicker>
_calendar_layout: _calendar_layout
size_hint: None, None
size:
(dp(328), dp(512) - root._shift_dialog_height) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(528), dp(328) - root._shift_dialog_height)
MDRelativeLayout:
id: container
background: os.path.join(images_path, "transparent.png")
canvas:
Color:
rgb:
app.theme_cls.primary_color \
if not root.primary_color else root.primary_color
RoundedRectangle:
size:
(dp(328), dp(120)) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(168), dp(328) - root._shift_dialog_height)
pos:
(0, root.height - dp(120)) \
if root.theme_cls.device_orientation == "portrait" \
else (0, 0)
radius:
(root.radius[0], root.radius[1], dp(0), dp(0)) \
if root.theme_cls.device_orientation == "portrait" \
else (root.radius[0], dp(0), dp(0), root.radius[3])
Color:
rgba:
app.theme_cls.bg_normal \
if not root.accent_color else root.accent_color
RoundedRectangle:
size:
(dp(328), dp(512) - dp(120) - root._shift_dialog_height) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(360), dp(328) - root._shift_dialog_height)
pos:
(0, 0) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(168), 0)
radius:
(dp(0), dp(0), root.radius[2], root.radius[3]) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(0), root.radius[1], root.radius[2], dp(0))
MDLabel:
id: label_title
font_style: "Body2"
bold: True
theme_text_color: "Custom"
size_hint_x: None
width: root.width
adaptive_height: True
text: root.title
font_name: root.font_name
pos:
(dp(24), root.height - self.height - dp(18)) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(24), root.height - self.height - dp(24))
text_color:
root.specific_text_color \
if not root.text_toolbar_color else root.text_toolbar_color
MDLabel:
id: label_full_date
font_style: "H4"
theme_text_color: "Custom"
size_hint_x: None
width: root.width
adaptive_height: True
font_name: root.font_name
markup: True
pos:
(dp(24), root.height - dp(120) + dp(18)) \
if root.theme_cls.device_orientation == "portrait" \
else \
( \
dp(24) if not root._input_date_dialog_open else dp(168) + dp(24), \
root.height - self.height - dp(96) \
)
text:
root.set_text_full_date(root.sel_year, root.sel_month, root.sel_day, \
root.theme_cls.device_orientation)
text_color:
( \
root.specific_text_color \
if not root.text_toolbar_color else root.text_toolbar_color \
) \
if root.theme_cls.device_orientation == "portrait" \
else \
( \
( \
self.theme_cls.primary_color \
if not root.primary_color else root.primary_color \
) \
if root._input_date_dialog_open \
else \
( \
root.specific_text_color \
if not root.text_toolbar_color else root.text_toolbar_color \
) \
)
RecycleView:
id: _year_layout
key_viewclass: "viewclass"
size_hint: None, None
size: _calendar_layout.size
pos: _calendar_layout.pos
disabled: True
canvas.before:
PushMatrix
Scale:
x: root._scale_year_layout
y: root._scale_year_layout
origin: self.center
canvas.after:
PopMatrix
SelectYearList:
cols: 3
default_size: dp(170), dp(36)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
MDIconButton:
id: edit_icon
icon: "pencil"
user_font_size: "24sp"
theme_text_color: "Custom"
on_release:
root.transformation_to_dialog_input_date() \
if not root._input_date_dialog_open else \
Clock.schedule_once(root.transformation_from_dialog_input_date, .15)
x:
(root.width - self.width - dp(12)) \
if root.theme_cls.device_orientation == "portrait" \
else dp(12)
y:
(root.height - dp(120) + dp(12)) \
if root.theme_cls.device_orientation == "portrait" \
else dp(12)
text_color:
root.specific_text_color \
if not root.text_toolbar_color else root.text_toolbar_color
MDLabel:
id: label_month_selector
font_style: "Body2"
-text_size: None, None
theme_text_color: "Custom"
adaptive_size: True
text: calendar.month_name[root.month].capitalize() + " " + str(root.year)
font_name: root.font_name
pos:
(dp(24), root.height - dp(120) - self.height - dp(20)) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(168) + dp(24), label_title.y)
text_color:
app.theme_cls.text_color \
if not root.text_color else root.text_color
DatePickerIconTooltipButton:
id: triangle
owner: root
icon: "menu-down"
ripple_scale: .5
theme_text_color: "Custom"
hint_text: "Choose year"
on_release:
root.transformation_to_dialog_select_year() \
if not root._select_year_dialog_open else \
root.transformation_from_dialog_select_year()
pos:
(label_month_selector.width + dp(14), root.height - dp(123) - self.height) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(180) + label_month_selector.width, label_title.y - dp(14))
text_color:
app.theme_cls.text_color \
if not root.text_color else root.text_color
md_bg_color_disabled: 0, 0, 0, 0
DatePickerIconTooltipButton:
id: chevron_left
owner: root
icon: "chevron-left"
theme_text_color: "Secondary"
on_release: root.change_month("prev")
theme_text_color: "Custom"
hint_text: "Previous month"
x:
dp(228) if root.theme_cls.device_orientation == "portrait" \
else dp(418)
y:
root.height - dp(120) - self.height / 2 - dp(30) \
if root.theme_cls.device_orientation == "portrait" \
else dp(272)
text_color:
app.theme_cls.text_color \
if not root.text_color else root.text_color
DatePickerIconTooltipButton:
id: chevron_right
owner: root
icon: "chevron-right"
theme_text_color: "Secondary"
on_release: root.change_month("next")
theme_text_color: "Custom"
hint_text: "Next month"
x:
dp(272) if root.theme_cls.device_orientation == "portrait" \
else dp(464)
y:
root.height - dp(120) - self.height / 2 - dp(30) \
if root.theme_cls.device_orientation == "portrait" \
else dp(272)
text_color:
app.theme_cls.text_color \
if not root.text_color else root.text_color
# TODO: Replace the GridLayout with a RecycleView
# if it improves performance.
GridLayout:
id: _calendar_layout
cols: 7
size_hint: None, None
size:
(dp(44 * 7), dp(40 * 7)) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(46 * 7), dp(32 * 7))
col_default_width:
dp(42) if root.theme_cls.device_orientation == "portrait" \
else dp(39)
padding:
(dp(2), 0) if root.theme_cls.device_orientation == "portrait" \
else (dp(7), 0)
spacing:
(dp(2), 0) if root.theme_cls.device_orientation == "portrait" \
else (dp(7), 0)
pos:
(dp(10), dp(56)) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(168) + dp(20), dp(44))
canvas.before:
PushMatrix
Scale:
x: root._scale_calendar_layout
y: root._scale_calendar_layout
origin: self.center
canvas.after:
PopMatrix
MDFlatButton:
id: ok_button
width: dp(32)
pos: root.width - self.width, dp(10)
text: "OK"
theme_text_color: "Custom"
font_name: root.font_name
text_color:
root.theme_cls.primary_color \
if not root.text_button_color else root.text_button_color
on_release:
root.dispatch(\
"on_save", \
date(root.sel_year, root.sel_month, root.sel_day), \
root._date_range \
)
MDFlatButton:
id: cancel_button
text: "CANCEL"
on_release: root.dispatch("on_cancel", None)
theme_text_color: "Custom"
pos: root.width - self.width - ok_button.width - dp(10), dp(10)
font_name: root.font_name
text_color:
root.theme_cls.primary_color \
if not root.text_button_color else root.text_button_color
<DatePickerDaySelectableItem>
size_hint: None, None
size:
(dp(42), dp(42)) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(32), dp(32))
disabled: True
canvas:
Color:
rgba:
( \
( \
self.theme_cls.primary_color if not root.owner.selector_color \
else root.owner.selector_color \
) \
if root.is_selected and not self.disabled \
else (0, 0, 0, 0) \
) \
if self.owner.mode != "range" else \
( \
( \
self.theme_cls.primary_color if not root.owner.selector_color \
else root.owner.selector_color \
) \
if root.is_selected and not self.disabled \
and (self.owner.mode == "range" and self.owner._start_range_date) \
else (0, 0, 0, 0) \
)
Ellipse:
size:
(dp(42), dp(42)) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(32), dp(32))
pos: self.pos
# Fill marking the available dates of the range, if using the `range` mode
# or use `min_date/max_date`.
canvas.before:
Color:
rgba:
(\
self.owner.selector_color[:-1] + [.3] \
if self.owner.selector_color \
else self.theme_cls.primary_color[:-1] + [.3] \
) \
if not self.disabled \
and self.text \
and self.check_date(self.owner.year, self.owner.month, int(self.text)) \
else (0, 0, 0, 0)
RoundedRectangle:
size:
(dp(44), dp(32)) \
if root.theme_cls.device_orientation == "portrait" \
else \
(dp(32), dp(28)) \
if self.index in [6, 13, 20, 27, 30] or self.owner._date_range \
and self.text and self.owner._date_range[-1] == date( \
self.current_year, \
self.current_month, \
int(self.text) \
) \
else (dp(46), dp(28))
pos:
(self.x - dp(1.5), self.y + dp(5)) \
if root.theme_cls.device_orientation == "portrait" else \
(self.x, self.y + 1)
radius:
[0, 0, 0, 0] if not self.owner._date_range else \
( \
[self.width / 2, 0, 0, self.width / 2] \
if self.text and self.owner._date_range[0] == date( \
self.current_year, \
self.current_month, \
int(self.text) \
) \
or (self.index in [0, 7, 14, 21, 28] and root.is_selected) \
else \
( \
[0, 0, 0, 0] if self.text \
and self.owner._date_range[-1] != date( \
self.current_year, \
self.current_month, \
int(self.text) \
) \
and self.index not in [6, 13, 20, 27, 30] \
else [0, self.width / 2, self.width, 0] \
if root.is_selected or self.text \
and self.owner._date_range[-1] == date( \
self.current_year, \
self.current_month, \
int(self.text) \
) \
else [0, 0, 0, 0]) \
)
# Circle marking the beginning and end of the date range if the "range"
# mode is used.
Color:
rgba:
[0, 0, 0, 0] if not self.owner._date_range else \
(
( \
self.theme_cls.primary_color if not root.owner.selector_color \
else root.owner.selector_color \
) \
if self.text and self.owner._date_range[0] == date( \
self.current_year, \
self.current_month, \
int(self.text) \
) \
or \
self.text and self.owner._date_range[-1] == date( \
self.current_year, \
self.current_month, \
int(self.text) \
) \
else (0, 0, 0, 0) \
)
Ellipse:
size:
(dp(42), dp(42)) \
if root.theme_cls.device_orientation == "portrait" \
else (dp(32), dp(32))
pos: self.pos
MDLabel:
font_style: "Caption"
size_hint_x: None
halign: "center"
text: root.text
font_name: root.owner.font_name
theme_text_color: "Custom"
text_color:
( \
root.theme_cls.primary_color \
if not root.owner.text_current_color \
else root.owner.text_current_color \
) \
if root.is_today and not root.is_selected \
else ( \
( \
root.theme_cls.text_color \
if not root.is_selected or root.owner.mode == "range" \
else (1, 1, 1, 1) \
) \
if not root.owner.text_color \
else \
( \
root.owner.text_color \
if not root.is_selected else (1, 1, 1, 1)) \
)
<DatePickerWeekdayLabel>
font_style: "Caption"
theme_text_color: "Custom"
size_hint: None, None
text_size: self.size
halign: "center"
valign:
"middle" if root.theme_cls.device_orientation == "portrait" \
else "center"
size:
(dp(40), dp(40)) if root.theme_cls.device_orientation == "portrait" \
else (dp(32), dp(32))
text_color:
app.theme_cls.disabled_hint_text_color \
if not root.owner.text_weekday_color else root.owner.text_weekday_color
<DatePickerYearSelectableItem>
font_style: "Caption"
size_hint_x: None
valign: "middle"
halign: "center"
text: root.text
theme_text_color: "Custom"
on_text: root.font_name = root.owner.font_name
canvas.before:
Color:
rgba:
root.selected_color if root.selected_color \
else self.theme_cls.primary_color
RoundedRectangle:
pos: self.x + dp(12), self.y
size: self.width - dp(24), self.height
radius: [root.height / 2, ]
<DatePickerDatePickerEnterDataFieldContainer>
adaptive_height: True
size_hint_x: None
spacing: dp(8)
width:
self.owner.width - dp(48) \
if root.owner.theme_cls.device_orientation == "portrait" \
else self.owner.width - dp(168) - dp(48)
y:
self.owner.height - dp(123) - self.height - dp(20) \
if root.owner.theme_cls.device_orientation == "portrait" \
else self.owner.height - self.height - dp(24)
x:
dp(24) if root.owner.theme_cls.device_orientation == "portrait" \
else dp(168) + dp(24)
<DatePickerEnterDataField>
mode: "fill"
opacity: 0
hint_text: "dd/mm/yyyy"
input_filter: root.input_filter
do_backspace: root.do_backspace
fill_color:
(0, 0, 0, .15) \
if not self.owner.input_field_background_color \
else root.owner.input_field_background_color
"""
)
class BaseDialogPicker(
BaseDialog,
FakeRectangularElevationBehavior,
SpecificBackgroundColorBehavior,
):
"""
Base class for :attr:`~kivymd.uix.picker.MDDatePicker` and
:attr:`~kivymd.uix.picker.MDTimePicker` classes.
:Events:
`on_save`
Events called when the "OK" dialog box button is clicked.
`on_cancel`
Events called when the "CANCEL" dialog box button is clicked.
"""
title_input = StringProperty("INPUT DATE")
"""
Dialog title fot input date.
:attr:`title_input` is an :class:`~kivy.properties.StringProperty`
and defaults to `INPUT DATE`.
"""
title = StringProperty("SELECT DATE")
"""
Dialog title fot select date.
:attr:`title` is an :class:`~kivy.properties.StringProperty`
and defaults to `SELECT DATE`.
"""
radius = ListProperty([7, 7, 7, 7])
"""
Radius list for the four corners of the dialog.
:attr:`radius` is an :class:`~kivy.properties.ListProperty`
and defaults to `[7, 7, 7, 7]`.
"""
primary_color = ColorProperty(None)
"""
Background color of toolbar.
.. code-block:: python
MDDatePicker(primary_color=get_color_from_hex("#72225b")
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/primary-color-date.png
:align: center
:attr:`primary_color` is an :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
accent_color = ColorProperty(None)
"""
Background color of calendar/clock face.
.. code-block:: python
MDDatePicker(
primary_color=get_color_from_hex("#72225b"),
accent_color=get_color_from_hex("#5d1a4a"),
)
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/accent-color-date.png
:align: center
:attr:`accent_color` is an :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
selector_color = ColorProperty(None)
"""
Background color of the selected day of the month or hour.
.. code-block:: python
MDDatePicker(
primary_color=get_color_from_hex("#72225b"),
accent_color=get_color_from_hex("#5d1a4a"),
selector_color=get_color_from_hex("#e93f39"),
)
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/selector-color-date.png
:align: center
:attr:`selector_color` is an :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
text_toolbar_color = ColorProperty(None)
"""
Color of labels for text on a toolbar.
.. code-block:: python
MDDatePicker(
primary_color=get_color_from_hex("#72225b"),
accent_color=get_color_from_hex("#5d1a4a"),
selector_color=get_color_from_hex("#e93f39"),
text_toolbar_color=get_color_from_hex("#cccccc"),
)
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/text-toolbar-color-date.png
:align: center
:attr:`text_toolbar_color` is an :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
text_color = ColorProperty(None)
"""
Color of text labels in calendar/clock face.
.. code-block:: python
MDDatePicker(
primary_color=get_color_from_hex("#72225b"),
accent_color=get_color_from_hex("#5d1a4a"),
selector_color=get_color_from_hex("#e93f39"),
text_toolbar_color=get_color_from_hex("#cccccc"),
text_color=("#ffffff"),
)
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/text-color-date.png
:align: center
:attr:`text_color` is an :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
text_current_color = ColorProperty(None)
"""
Color of the text of the current day of the month/hour.
.. code-block:: python
MDDatePicker(
primary_color=get_color_from_hex("#72225b"),
accent_color=get_color_from_hex("#5d1a4a"),
selector_color=get_color_from_hex("#e93f39"),
text_toolbar_color=get_color_from_hex("#cccccc"),
text_color=("#ffffff"),
text_current_color=get_color_from_hex("#e93f39"),
)
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/text-current-color-date.png
:align: center
:attr:`text_current_color` is an :class:`~kivy.properties.ColorProperty`
and defaults to `None`.
"""
text_button_color = ColorProperty(None)
"""
Text button color.
.. code-block:: python
MDDatePicker(
primary_color=get_color_from_hex("#72225b"),
accent_color=get_color_from_hex("#5d1a4a"),
selector_color=get_color_from_hex("#e93f39"),
text_toolbar_color=get_color_from_hex("#cccccc"),
text_color=("#ffffff"),
text_current_color=get_color_from_hex("#e93f39"),
text_button_color=(1, 1, 1, .5),
)
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/text-button-color-date.png
:align: center
:attr:`text_button_color` is an :class:`~kivy.properties.ColorProperty`
and defaults to `None`.