mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
feat(calendar) improve MicroPython example (#2366)
Small improvements: - Remove cast from get_pressed_date - Check return value of get_pressed_date - Call set_today_date on clicked date - Compact highlighted_days - Added a switch to show different header type
This commit is contained in:
parent
1b6a39ca61
commit
5f6e07e57f
@ -4,9 +4,9 @@ def event_handler(evt):
|
|||||||
if code == lv.EVENT.VALUE_CHANGED:
|
if code == lv.EVENT.VALUE_CHANGED:
|
||||||
source = evt.get_target()
|
source = evt.get_target()
|
||||||
date = lv.calendar_date_t()
|
date = lv.calendar_date_t()
|
||||||
lv.calendar.get_pressed_date(source,date)
|
if source.get_pressed_date(date) == lv.RES.OK:
|
||||||
if date:
|
calendar.set_today_date(date.year, date.month, date.day)
|
||||||
print("Clicked date: %02d.%02d.%02d"%(date.day, date.month, date.year))
|
print("Clicked date: %02d.%02d.%02d"%(date.day, date.month, date.year))
|
||||||
|
|
||||||
|
|
||||||
calendar = lv.calendar(lv.scr_act())
|
calendar = lv.calendar(lv.scr_act())
|
||||||
@ -18,25 +18,32 @@ calendar.set_today_date(2021, 02, 23)
|
|||||||
calendar.set_showed_date(2021, 02)
|
calendar.set_showed_date(2021, 02)
|
||||||
|
|
||||||
# Highlight a few days
|
# Highlight a few days
|
||||||
highlighted_days=[]
|
highlighted_days=[
|
||||||
for i in range(3):
|
lv.calendar_date_t({'year':2021, 'month':2, 'day':6}),
|
||||||
highlighted_days.append(lv.calendar_date_t())
|
lv.calendar_date_t({'year':2021, 'month':2, 'day':11}),
|
||||||
|
lv.calendar_date_t({'year':2021, 'month':2, 'day':22})
|
||||||
|
]
|
||||||
|
|
||||||
highlighted_days[0].year=2021
|
calendar.set_highlighted_dates(highlighted_days, len(highlighted_days))
|
||||||
highlighted_days[0].month=02
|
|
||||||
highlighted_days[0].day=6
|
|
||||||
|
|
||||||
highlighted_days[1].year=2021
|
# 2 options for header
|
||||||
highlighted_days[1].month=02
|
header1 = lv.calendar_header_dropdown(lv.scr_act(),calendar)
|
||||||
highlighted_days[1].day=11
|
header2 = lv.calendar_header_arrow(lv.scr_act(),calendar,25)
|
||||||
|
|
||||||
highlighted_days[2].year=2022
|
# Switch to switch headeres
|
||||||
highlighted_days[2].month=02
|
header2.add_flag(lv.obj.FLAG.HIDDEN)
|
||||||
highlighted_days[2].day=22
|
header1.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||||
|
|
||||||
calendar.set_highlighted_dates(highlighted_days, 3)
|
sw = lv.switch(lv.scr_act())
|
||||||
|
sw.set_pos(20,20)
|
||||||
header = lv.calendar_header_dropdown(lv.scr_act(),calendar)
|
|
||||||
# header = lv.calendar_header_arrow(lv.scr_act(),calendar,25)
|
|
||||||
|
|
||||||
|
def sw_cb(e):
|
||||||
|
obj = e.get_target()
|
||||||
|
if obj.has_state(lv.STATE.CHECKED):
|
||||||
|
header1.add_flag(lv.obj.FLAG.HIDDEN)
|
||||||
|
header2.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||||
|
else:
|
||||||
|
header2.add_flag(lv.obj.FLAG.HIDDEN)
|
||||||
|
header1.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||||
|
|
||||||
|
sw.add_event_cb(sw_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user