mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-23 01:33:59 +08:00
adding micropython examples (#2286)
* adding micropython examples * adding micropython examples
This commit is contained in:
parent
ac8f4534a5
commit
c60ed68e94
41
examples/anim/lv_example_anim_1.py
Normal file
41
examples/anim/lv_example_anim_1.py
Normal file
@ -0,0 +1,41 @@
|
||||
def anim_x_cb(label, v):
|
||||
label.set_x(v)
|
||||
|
||||
def sw_event_cb(e,label):
|
||||
sw = e.get_target()
|
||||
|
||||
if sw.has_state(lv.STATE.CHECKED):
|
||||
a = lv.anim_t()
|
||||
a.init()
|
||||
a.set_var(label)
|
||||
a.set_values(label.get_x(), 100)
|
||||
a.set_time(500)
|
||||
a.set_path_cb(lv.anim_t.path_overshoot)
|
||||
a.set_custom_exec_cb(lambda a,val: anim_x_cb(label,val))
|
||||
lv.anim_t.start(a)
|
||||
else:
|
||||
a = lv.anim_t()
|
||||
a.init()
|
||||
a.set_var(label)
|
||||
a.set_values(label.get_x(), -label.get_width())
|
||||
a.set_time(500)
|
||||
a.set_path_cb(lv.anim_t.path_ease_in)
|
||||
a.set_custom_exec_cb(lambda a,val: anim_x_cb(label,val))
|
||||
lv.anim_t.start(a)
|
||||
|
||||
#
|
||||
# Start animation on an event
|
||||
#
|
||||
|
||||
label = lv.label(lv.scr_act())
|
||||
label.set_text("Hello animations!")
|
||||
label.set_pos(100, 10)
|
||||
|
||||
|
||||
sw = lv.switch(lv.scr_act())
|
||||
sw.center()
|
||||
sw.add_state(lv.STATE.CHECKED)
|
||||
sw.add_event_cb(lambda e: sw_event_cb(e,label), lv.EVENT.VALUE_CHANGED, None)
|
||||
|
||||
|
||||
|
41
examples/anim/lv_example_anim_2.py
Normal file
41
examples/anim/lv_example_anim_2.py
Normal file
@ -0,0 +1,41 @@
|
||||
def anim_x_cb(obj, v):
|
||||
obj.set_x(v)
|
||||
|
||||
def anim_size_cb(obj, v):
|
||||
obj.set_size(v, v)
|
||||
|
||||
|
||||
#
|
||||
# Create a playback animation
|
||||
#
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.set_style_bg_color(lv.palette_main(lv.PALETTE.RED), 0)
|
||||
obj.set_style_radius(lv.RADIUS.CIRCLE, 0)
|
||||
|
||||
obj.align(lv.ALIGN.LEFT_MID, 10, 0)
|
||||
|
||||
a1 = lv.anim_t()
|
||||
a1.init()
|
||||
a1.set_var(obj)
|
||||
a1.set_values(10, 50)
|
||||
a1.set_time(1000)
|
||||
a1.set_playback_delay(100)
|
||||
a1.set_playback_time(300)
|
||||
a1.set_repeat_delay(500)
|
||||
a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a1.set_path_cb(lv.anim_t.path_ease_in_out)
|
||||
a1.set_custom_exec_cb(lambda a1,val: anim_size_cb(obj,val))
|
||||
lv.anim_t.start(a1)
|
||||
|
||||
a2 = lv.anim_t()
|
||||
a2.init()
|
||||
a2.set_var(obj)
|
||||
a2.set_values(10, 240)
|
||||
a2.set_time(1000)
|
||||
a2.set_playback_delay(100)
|
||||
a2.set_playback_time(300)
|
||||
a2.set_repeat_delay(500)
|
||||
a2.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a2.set_path_cb(lv.anim_t.path_ease_in_out)
|
||||
a2.set_custom_exec_cb(lambda a1,val: anim_x_cb(obj,val))
|
||||
lv.anim_t.start(a2)
|
1
examples/assets/img_star.png
Symbolic link
1
examples/assets/img_star.png
Symbolic link
@ -0,0 +1 @@
|
||||
star.png
|
1
examples/assets/img_strip.png
Symbolic link
1
examples/assets/img_strip.png
Symbolic link
@ -0,0 +1 @@
|
||||
skew_strip.png
|
25
examples/event/lv_example_event_1.py
Normal file
25
examples/event/lv_example_event_1.py
Normal file
@ -0,0 +1,25 @@
|
||||
class Event_1():
|
||||
def __init__(self):
|
||||
self.cnt = 1
|
||||
#
|
||||
# Add click event to a button
|
||||
#
|
||||
|
||||
btn = lv.btn(lv.scr_act())
|
||||
btn.set_size(100, 50)
|
||||
btn.center()
|
||||
btn.add_event_cb(self.event_cb, lv.EVENT.CLICKED, None)
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text("Click me!");
|
||||
label.center()
|
||||
|
||||
def event_cb(self,e):
|
||||
print("Clicked");
|
||||
|
||||
btn = lv.btn.__cast__(e.get_target())
|
||||
label = btn.get_child(0)
|
||||
label.set_text(str(self.cnt))
|
||||
self.cnt += 1
|
||||
|
||||
evt1 = Event_1()
|
22
examples/event/lv_example_event_2.py
Normal file
22
examples/event/lv_example_event_2.py
Normal file
@ -0,0 +1,22 @@
|
||||
def event_cb(e,label):
|
||||
code = e.get_code()
|
||||
if code == lv.EVENT.PRESSED:
|
||||
label.set_text("The last button event:\nLV_EVENT_PRESSED")
|
||||
elif code == lv.EVENT.CLICKED:
|
||||
label.set_text("The last button event:\nLV_EVENT_CLICKED")
|
||||
elif code == lv.EVENT.LONG_PRESSED:
|
||||
label.set_text("The last button event:\nLV_EVENT_LONG_PRESSED")
|
||||
elif code == lv.EVENT.LONG_PRESSED_REPEAT:
|
||||
label.set_text("The last button event:\nLV_EVENT_LONG_PRESSED_REPEAT")
|
||||
btn = lv.btn(lv.scr_act())
|
||||
btn.set_size(100, 50)
|
||||
btn.center()
|
||||
|
||||
btn_label = lv.label(btn)
|
||||
btn_label.set_text("Click me!")
|
||||
btn_label.center()
|
||||
|
||||
info_label = lv.label(lv.scr_act())
|
||||
info_label.set_text("The last button event:\nNone");
|
||||
|
||||
btn.add_event_cb(lambda e: event_cb(e,info_label), lv.EVENT.ALL, None)
|
31
examples/event/lv_example_event_3.py
Normal file
31
examples/event/lv_example_event_3.py
Normal file
@ -0,0 +1,31 @@
|
||||
def event_cb(e):
|
||||
|
||||
# The original target of the event. Can be the buttons or the container
|
||||
target = e.get_target()
|
||||
# print(type(target))
|
||||
|
||||
# If container was clicked do nothing
|
||||
if type(target) != type(lv.btn()):
|
||||
return
|
||||
|
||||
# Make the clicked buttons red
|
||||
target.set_style_bg_color(lv.palette_main(lv.PALETTE.RED), 0)
|
||||
|
||||
#
|
||||
# Demonstrate event bubbling
|
||||
#
|
||||
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(320, 200)
|
||||
cont.center()
|
||||
cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
|
||||
|
||||
for i in range(30):
|
||||
btn = lv.btn(cont)
|
||||
btn.set_size(80, 50)
|
||||
btn.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text(str(i))
|
||||
label.center()
|
||||
cont.add_event_cb(event_cb, lv.EVENT.CLICKED, None)
|
29
examples/get_started/lv_example_get_started_1.py
Normal file
29
examples/get_started/lv_example_get_started_1.py
Normal file
@ -0,0 +1,29 @@
|
||||
class CounterBtn():
|
||||
def __init__(self):
|
||||
self.cnt = 0
|
||||
#
|
||||
# Create a button with a label and react on click event.
|
||||
#
|
||||
|
||||
btn = lv.btn(lv.scr_act()) # Add a button the current screen
|
||||
btn.set_pos(10, 10) # Set its position
|
||||
btn.set_size(120, 50) # Set its size
|
||||
btn.align(lv.ALIGN.CENTER,0,0)
|
||||
btn.add_event_cb(self.btn_event_cb, lv.EVENT.ALL, None) # Assign a callback to the button
|
||||
label = lv.label(btn) # Add a label to the button
|
||||
label.set_text("Button") # Set the labels text
|
||||
label.center()
|
||||
|
||||
def btn_event_cb(self,evt):
|
||||
code = evt.get_code()
|
||||
btn = evt.get_target()
|
||||
if code == lv.EVENT.CLICKED:
|
||||
self.cnt += 1
|
||||
|
||||
# Get the first child of the button which is the label and change its text
|
||||
label = lv.label.__cast__(btn.get_child(0))
|
||||
label.set_text("Button: " + str(self.cnt))
|
||||
|
||||
|
||||
counterBtn = CounterBtn()
|
||||
|
62
examples/get_started/lv_example_get_started_2.py
Normal file
62
examples/get_started/lv_example_get_started_2.py
Normal file
@ -0,0 +1,62 @@
|
||||
#
|
||||
# Create styles from scratch for buttons.
|
||||
#
|
||||
style_btn = lv.style_t()
|
||||
style_btn_red = lv.style_t()
|
||||
style_btn_pressed = lv.style_t()
|
||||
|
||||
# Create a simple button style
|
||||
style_btn.init()
|
||||
style_btn.set_radius(10)
|
||||
style_btn.set_bg_opa(lv.OPA.COVER)
|
||||
style_btn.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
|
||||
style_btn.set_bg_grad_color(lv.palette_main(lv.PALETTE.GREY))
|
||||
style_btn.set_bg_grad_dir(lv.GRAD_DIR.VER)
|
||||
|
||||
# Add a border
|
||||
style_btn.set_border_color(lv.color_white())
|
||||
style_btn.set_border_opa(lv.OPA._70)
|
||||
style_btn.set_border_width(2)
|
||||
|
||||
# Set the text style
|
||||
style_btn.set_text_color(lv.color_white())
|
||||
|
||||
# Create a red style. Change only some colors.
|
||||
style_btn_red.init()
|
||||
style_btn_red.set_bg_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style_btn_red.set_bg_grad_color(lv.palette_lighten(lv.PALETTE.RED, 2))
|
||||
|
||||
# Create a style for the pressed state.
|
||||
style_btn_pressed.init()
|
||||
style_btn_pressed.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style_btn_pressed.set_bg_grad_color(lv.palette_darken(lv.PALETTE.RED, 3))
|
||||
|
||||
# Create a button and use the new styles
|
||||
btn = lv.btn(lv.scr_act()) # Add a button the current screen
|
||||
# Remove the styles coming from the theme
|
||||
# Note that size and position are also stored as style properties
|
||||
# so lv_obj_remove_style_all will remove the set size and position too
|
||||
btn.remove_style_all() # Remove the styles coming from the theme
|
||||
btn.set_pos(10, 10) # Set its position
|
||||
btn.set_size(120, 50) # Set its size
|
||||
btn.add_style(style_btn, 0)
|
||||
btn.add_style(style_btn_pressed, lv.STATE.PRESSED)
|
||||
|
||||
label = lv.label(btn) # Add a label to the button
|
||||
label.set_text("Button") # Set the labels text
|
||||
label.center()
|
||||
|
||||
# Create an other button and use the red style too
|
||||
btn2 = lv.btn(lv.scr_act())
|
||||
btn2.remove_style_all() # Remove the styles coming from the theme
|
||||
btn2.set_pos(10, 80) # Set its position
|
||||
btn2.set_size(120, 50) # Set its size
|
||||
btn2.add_style(style_btn, 0)
|
||||
btn2.add_style(style_btn_red, 0)
|
||||
btn2.add_style(style_btn_pressed, lv.STATE.PRESSED)
|
||||
btn2.set_style_radius(lv.RADIUS.CIRCLE, 0); # Add a local style
|
||||
|
||||
label = lv.label(btn2) # Add a label to the button
|
||||
label.set_text("Button 2"); # Set the labels text
|
||||
label.center()
|
||||
|
22
examples/get_started/lv_example_get_started_3.py
Normal file
22
examples/get_started/lv_example_get_started_3.py
Normal file
@ -0,0 +1,22 @@
|
||||
def slider_event_cb(evt):
|
||||
slider = evt.get_target()
|
||||
|
||||
# Refresh the text
|
||||
label.set_text(str(slider.get_value()))
|
||||
|
||||
#
|
||||
# Create a slider and write its value on a label.
|
||||
#
|
||||
|
||||
# Create a slider in the center of the display
|
||||
slider = lv.slider(lv.scr_act())
|
||||
slider.set_width(200) # Set the width
|
||||
slider.center() # Align to the center of the parent (screen)
|
||||
slider.add_event_cb(slider_event_cb, lv.EVENT.VALUE_CHANGED, None) # Assign an event function
|
||||
|
||||
# Create a label below the slider
|
||||
label = lv.label(lv.scr_act());
|
||||
label.set_text("0")
|
||||
label.align_to(slider, lv.ALIGN.OUT_TOP_MID, 0, -15) # Align below the slider
|
||||
|
||||
|
3
examples/header.py
Normal file
3
examples/header.py
Normal file
@ -0,0 +1,3 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import lvgl as lv
|
||||
import display_driver
|
33
examples/layouts/flex/lv_example_flex_1.py
Normal file
33
examples/layouts/flex/lv_example_flex_1.py
Normal file
@ -0,0 +1,33 @@
|
||||
#
|
||||
# A simple row and a column layout with flexbox
|
||||
#
|
||||
|
||||
# Create a container with ROW flex direction
|
||||
cont_row = lv.obj(lv.scr_act())
|
||||
cont_row.set_size(300, 75)
|
||||
cont_row.align(lv.ALIGN.TOP_MID, 0, 5)
|
||||
cont_row.set_flex_flow(lv.FLEX_FLOW.ROW)
|
||||
|
||||
# Create a container with COLUMN flex direction
|
||||
cont_col = lv.obj(lv.scr_act())
|
||||
cont_col.set_size(200, 150)
|
||||
cont_col.align_to(cont_row, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
|
||||
cont_col.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
|
||||
for i in range(10):
|
||||
# Add items to the row
|
||||
obj = lv.btn(cont_row)
|
||||
obj.set_size(100, lv.pct(100))
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("Item: {:d}".format(i))
|
||||
label.center()
|
||||
|
||||
# Add items to the column
|
||||
obj = lv.btn(cont_col)
|
||||
obj.set_size(lv.pct(100), lv.SIZE.CONTENT)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("Item: {:d}".format(i))
|
||||
label.center()
|
||||
|
22
examples/layouts/flex/lv_example_flex_2.py
Normal file
22
examples/layouts/flex/lv_example_flex_2.py
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# Arrange items in rows with wrap and place the items to get even space around them.
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
|
||||
style.set_flex_main_place(lv.FLEX_ALIGN.SPACE_EVENLY)
|
||||
style.set_layout(lv.LAYOUT_FLEX.value)
|
||||
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.add_style(style, 0)
|
||||
|
||||
for i in range(8):
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(70, lv.SIZE.CONTENT)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("{:d}".format(i))
|
||||
label.center()
|
||||
|
23
examples/layouts/flex/lv_example_flex_3.py
Normal file
23
examples/layouts/flex/lv_example_flex_3.py
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# Demonstrate flex grow.
|
||||
#
|
||||
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.set_flex_flow(lv.FLEX_FLOW.ROW)
|
||||
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(40, 40) # Fix size
|
||||
|
||||
obj = lv.obj(cont)
|
||||
obj.set_height(40)
|
||||
obj.set_flex_grow(1) # 1 portion from the free space
|
||||
|
||||
obj = lv.obj(cont)
|
||||
obj.set_height(40)
|
||||
obj.set_flex_grow(2) # 2 portion from the free space
|
||||
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(40, 40) # Fix size. It is flushed to the right by the "grow" items
|
||||
|
16
examples/layouts/flex/lv_example_flex_4.py
Normal file
16
examples/layouts/flex/lv_example_flex_4.py
Normal file
@ -0,0 +1,16 @@
|
||||
#
|
||||
# Reverse the order of flex items
|
||||
#
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.set_flex_flow(lv.FLEX_FLOW.COLUMN_REVERSE)
|
||||
|
||||
for i in range(6):
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(100, 50)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("Item: " + str(i))
|
||||
label.center()
|
||||
|
47
examples/layouts/flex/lv_example_flex_5.py
Normal file
47
examples/layouts/flex/lv_example_flex_5.py
Normal file
@ -0,0 +1,47 @@
|
||||
def row_gap_anim(obj, v):
|
||||
obj.set_style_pad_row(v, 0)
|
||||
|
||||
|
||||
def column_gap_anim(obj, v):
|
||||
obj.set_style_pad_column(v, 0)
|
||||
|
||||
#
|
||||
# Demonstrate the effect of column and row gap style properties
|
||||
#
|
||||
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
|
||||
|
||||
for i in range(9):
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(70, lv.SIZE.CONTENT)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text(str(i))
|
||||
label.center()
|
||||
|
||||
a_row = lv.anim_t()
|
||||
a_row.init()
|
||||
a_row.set_var(cont)
|
||||
a_row.set_values(0, 10)
|
||||
a_row.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
|
||||
a_row.set_time(500)
|
||||
a_row.set_playback_time(500)
|
||||
a_row.set_custom_exec_cb(lambda a,val: row_gap_anim(cont,val))
|
||||
lv.anim_t.start(a_row)
|
||||
|
||||
a_col = lv.anim_t()
|
||||
a_col.init()
|
||||
a_col.set_var(cont)
|
||||
a_col.set_values(0, 10)
|
||||
a_col.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
|
||||
a_col.set_time(3000)
|
||||
a_col.set_playback_time(3000)
|
||||
a_col.set_custom_exec_cb(lambda a,val: column_gap_anim(cont,val))
|
||||
|
||||
lv.anim_t.start(a_col)
|
||||
|
19
examples/layouts/flex/lv_example_flex_6.py
Normal file
19
examples/layouts/flex/lv_example_flex_6.py
Normal file
@ -0,0 +1,19 @@
|
||||
#
|
||||
# RTL base direction changes order of the items.
|
||||
# Also demonstrate how horizontal scrolling works with RTL.
|
||||
#
|
||||
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_style_base_dir(lv.BASE_DIR.RTL,0)
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
|
||||
|
||||
for i in range(20):
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(70, lv.SIZE.CONTENT)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text(str(i))
|
||||
label.center()
|
||||
|
29
examples/layouts/grid/lv_example_grid_1.py
Normal file
29
examples/layouts/grid/lv_example_grid_1.py
Normal file
@ -0,0 +1,29 @@
|
||||
#
|
||||
# A simple grid
|
||||
#
|
||||
|
||||
col_dsc = [70, 70, 70, lv.COORD.MAX]
|
||||
row_dsc = [50, 50, 50, lv.COORD.MAX]
|
||||
|
||||
# Create a container with grid
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_style_grid_column_dsc_array(col_dsc, 0)
|
||||
cont.set_style_grid_row_dsc_array(row_dsc, 0)
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.set_layout(lv.LAYOUT_GRID.value)
|
||||
|
||||
for i in range(9):
|
||||
col = i % 3
|
||||
row = i // 3
|
||||
|
||||
obj = lv.btn(cont)
|
||||
# Stretch the cell horizontally and vertically too
|
||||
# Set span to 1 to make the cell 1 column/row sized
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, col, 1,
|
||||
lv.GRID_ALIGN.STRETCH, row, 1)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("c" +str(col) + "r" +str(row))
|
||||
label.center()
|
||||
|
53
examples/layouts/grid/lv_example_grid_2.py
Normal file
53
examples/layouts/grid/lv_example_grid_2.py
Normal file
@ -0,0 +1,53 @@
|
||||
#
|
||||
# Demonstrate cell placement and span
|
||||
#
|
||||
|
||||
col_dsc = [70, 70, 70, lv.GRID_TEMPLATE.LAST]
|
||||
row_dsc = [50, 50, 50, lv.GRID_TEMPLATE.LAST]
|
||||
|
||||
# Create a container with grid
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_grid_dsc_array(col_dsc, row_dsc)
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
|
||||
# Cell to 0;0 and align to to the start (left/top) horizontally and vertically too
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.START, 0, 1,
|
||||
lv.GRID_ALIGN.START, 0, 1)
|
||||
label = lv.label(obj);
|
||||
label.set_text("c0, r0")
|
||||
|
||||
# Cell to 1;0 and align to to the start (left) horizontally and center vertically too
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.START, 1, 1,
|
||||
lv.GRID_ALIGN.CENTER, 0, 1)
|
||||
label = lv.label(obj)
|
||||
label.set_text("c1, r0")
|
||||
|
||||
# Cell to 2;0 and align to to the start (left) horizontally and end (bottom) vertically too
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.START, 2, 1,
|
||||
lv.GRID_ALIGN.END, 0, 1)
|
||||
label = lv.label(obj)
|
||||
label.set_text("c2, r0");
|
||||
|
||||
# Cell to 1;1 but 2 column wide (span = 2).Set width and height to stretched.
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, 1, 2,
|
||||
lv.GRID_ALIGN.STRETCH, 1, 1)
|
||||
label = lv.label(obj)
|
||||
label.set_text("c1-2, r1")
|
||||
|
||||
# Cell to 0;1 but 2 rows tall (span = 2).Set width and height to stretched.
|
||||
obj = lv.obj(cont)
|
||||
obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, 0, 1,
|
||||
lv.GRID_ALIGN.STRETCH, 1, 2)
|
||||
label = lv.label(obj)
|
||||
label.set_text("c0\nr1-2")
|
||||
|
38
examples/layouts/grid/lv_example_grid_3.py
Normal file
38
examples/layouts/grid/lv_example_grid_3.py
Normal file
@ -0,0 +1,38 @@
|
||||
def LV_GRID_FR(x):
|
||||
return lv.COORD.MAX - 100 + x
|
||||
#
|
||||
# Demonstrate grid's "free unit"
|
||||
#
|
||||
|
||||
# Column 1: fix width 60 px
|
||||
# Column 2: 1 unit from the remaining free space
|
||||
# Column 3: 2 unit from the remaining free space
|
||||
|
||||
col_dsc = [60, LV_GRID_FR(1), LV_GRID_FR(2), lv.COORD.MAX]
|
||||
|
||||
# Row 1: fix width 60 px
|
||||
# Row 2: 1 unit from the remaining free space
|
||||
# Row 3: fix width 60 px
|
||||
|
||||
row_dsc = [40, LV_GRID_FR(1), 40, lv.COORD.MAX]
|
||||
|
||||
# Create a container with grid
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.set_grid_dsc_array(col_dsc, row_dsc)
|
||||
|
||||
for i in range(9):
|
||||
col = i % 3
|
||||
row = i // 3
|
||||
|
||||
obj = lv.obj(cont)
|
||||
# Stretch the cell horizontally and vertically too
|
||||
# Set span to 1 to make the cell 1 column/row sized
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, col, 1,
|
||||
lv.GRID_ALIGN.STRETCH, row, 1)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("%d,%d"%(col, row))
|
||||
label.center()
|
||||
|
32
examples/layouts/grid/lv_example_grid_4.py
Normal file
32
examples/layouts/grid/lv_example_grid_4.py
Normal file
@ -0,0 +1,32 @@
|
||||
#
|
||||
# Demonstrate track placement
|
||||
#
|
||||
|
||||
col_dsc = [60, 60, 60, lv.GRID_TEMPLATE.LAST]
|
||||
row_dsc = [40, 40, 40, lv.GRID_TEMPLATE.LAST]
|
||||
|
||||
|
||||
# Add space between the columns and move the rows to the bottom (end)
|
||||
|
||||
# Create a container with grid
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN, lv.GRID_ALIGN.END)
|
||||
cont.set_grid_dsc_array(col_dsc, row_dsc)
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
|
||||
|
||||
for i in range(9):
|
||||
col = i % 3
|
||||
row = i // 3
|
||||
|
||||
obj = lv.obj(cont)
|
||||
# Stretch the cell horizontally and vertically too
|
||||
# Set span to 1 to make the cell 1 column/row sized
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, col, 1,
|
||||
lv.GRID_ALIGN.STRETCH, row, 1)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("{:d}{:d}".format(col, row))
|
||||
label.center()
|
||||
|
52
examples/layouts/grid/lv_example_grid_5.py
Normal file
52
examples/layouts/grid/lv_example_grid_5.py
Normal file
@ -0,0 +1,52 @@
|
||||
def row_gap_anim(obj, v):
|
||||
obj.set_style_pad_row(v, 0)
|
||||
|
||||
def column_gap_anim(obj, v):
|
||||
obj.set_style_pad_column(v, 0)
|
||||
|
||||
#
|
||||
# Demonstrate column and row gap
|
||||
#
|
||||
|
||||
# 60x60 cells
|
||||
col_dsc = [60, 60, 60, lv.GRID_TEMPLATE.LAST]
|
||||
row_dsc = [40, 40, 40, lv.GRID_TEMPLATE.LAST]
|
||||
|
||||
# Create a container with grid
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.set_grid_dsc_array(col_dsc, row_dsc)
|
||||
|
||||
for i in range(9):
|
||||
col = i % 3
|
||||
row = i // 3
|
||||
|
||||
obj = lv.obj(cont)
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, col, 1,
|
||||
lv.GRID_ALIGN.STRETCH, row, 1)
|
||||
label = lv.label(obj)
|
||||
label.set_text("{:d},{:d}".format(col, row))
|
||||
label.center()
|
||||
|
||||
a_row = lv.anim_t()
|
||||
a_row.init()
|
||||
a_row.set_var(cont)
|
||||
a_row.set_values(0, 10)
|
||||
a_row.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a_row.set_time(500)
|
||||
a_row.set_playback_time(500)
|
||||
a_row. set_custom_exec_cb(lambda a,val: row_gap_anim(cont,val))
|
||||
lv.anim_t.start(a_row)
|
||||
|
||||
a_col = lv.anim_t()
|
||||
a_col.init()
|
||||
a_col.set_var(cont)
|
||||
a_col.set_values(0, 10)
|
||||
a_col.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a_col.set_time(500)
|
||||
a_col.set_playback_time(500)
|
||||
a_col. set_custom_exec_cb(lambda a,val: column_gap_anim(cont,val))
|
||||
lv.anim_t.start(a_col)
|
||||
|
||||
|
27
examples/layouts/grid/lv_example_grid_6.py
Normal file
27
examples/layouts/grid/lv_example_grid_6.py
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
# Demonstrate RTL direction on grid
|
||||
#
|
||||
col_dsc = [60, 60, 60, lv.GRID_TEMPLATE.LAST]
|
||||
row_dsc = [40, 40, 40, lv.GRID_TEMPLATE.LAST]
|
||||
|
||||
# Create a container with grid
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(300, 220)
|
||||
cont.center()
|
||||
cont.set_style_base_dir(lv.BASE_DIR.RTL,0)
|
||||
cont.set_grid_dsc_array(col_dsc, row_dsc)
|
||||
|
||||
for i in range(9):
|
||||
col = i % 3
|
||||
row = i // 3
|
||||
|
||||
obj = lv.obj(cont)
|
||||
# Stretch the cell horizontally and vertically too
|
||||
# Set span to 1 to make the cell 1 column/row sized
|
||||
obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, col, 1,
|
||||
lv.GRID_ALIGN.STRETCH, row, 1);
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("{:d},{:d}".format(col, row))
|
||||
label.center()
|
||||
|
38
examples/scroll/lv_example_scroll_1.py
Normal file
38
examples/scroll/lv_example_scroll_1.py
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# Demonstrate how scrolling appears automatically
|
||||
#
|
||||
# Create an object with the new style
|
||||
panel = lv.obj(lv.scr_act())
|
||||
panel.set_size(200, 200)
|
||||
panel.center()
|
||||
|
||||
child = lv.obj(panel)
|
||||
child.set_pos(0, 0)
|
||||
label = lv.label(child)
|
||||
label.set_text("Zero")
|
||||
label.center()
|
||||
|
||||
child = lv.obj(panel)
|
||||
child.set_pos(-40, 100)
|
||||
label = lv.label(child)
|
||||
label.set_text("Left")
|
||||
label.center()
|
||||
|
||||
child = lv.obj(panel)
|
||||
child.set_pos(90, -30)
|
||||
label = lv.label(child)
|
||||
label.set_text("Top")
|
||||
label.center()
|
||||
|
||||
child = lv.obj(panel)
|
||||
child.set_pos(150, 80)
|
||||
label = lv.label(child)
|
||||
label.set_text("Right")
|
||||
label.center()
|
||||
|
||||
child = lv.obj(panel)
|
||||
child.set_pos(60, 170)
|
||||
label = lv.label(child)
|
||||
label.set_text("Bottom")
|
||||
label.center()
|
||||
|
47
examples/scroll/lv_example_scroll_2.py
Normal file
47
examples/scroll/lv_example_scroll_2.py
Normal file
@ -0,0 +1,47 @@
|
||||
def sw_event_cb(e,panel):
|
||||
|
||||
code = e.get_code()
|
||||
sw = e.get_target()
|
||||
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
|
||||
if sw.has_state(lv.STATE.CHECKED):
|
||||
panel.add_flag(lv.obj.FLAG.SCROLL_ONE)
|
||||
else:
|
||||
panel.clear_flag(lv.obj.FLAG.SCROLL_ONE)
|
||||
|
||||
|
||||
#
|
||||
# Show an example to scroll snap
|
||||
#
|
||||
|
||||
panel = lv.obj(lv.scr_act())
|
||||
panel.set_size(280, 150)
|
||||
panel.set_scroll_snap_x(lv.SCROLL_SNAP.CENTER)
|
||||
panel.set_flex_flow(lv.FLEX_FLOW.ROW)
|
||||
panel.center()
|
||||
|
||||
for i in range(10):
|
||||
btn = lv.btn(panel)
|
||||
btn.set_size(150, 100)
|
||||
|
||||
label = lv.label(btn)
|
||||
if i == 3:
|
||||
label.set_text("Panel {:d}\nno snap".format(i))
|
||||
btn.clear_flag(lv.obj.FLAG.SNAPABLE)
|
||||
else:
|
||||
label.set_text("Panel {:d}".format(i))
|
||||
label.center()
|
||||
|
||||
panel.update_snap(lv.ANIM.ON)
|
||||
|
||||
|
||||
# Switch between "One scroll" and "Normal scroll" mode
|
||||
sw = lv.switch(lv.scr_act());
|
||||
sw.align(lv.ALIGN.TOP_RIGHT, -20, 10)
|
||||
sw.add_event_cb(lambda evt: sw_event_cb(evt,panel), lv.EVENT.ALL, None)
|
||||
label = lv.label(lv.scr_act())
|
||||
label.set_text("One scroll")
|
||||
label.align_to(sw, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
|
||||
|
||||
|
38
examples/scroll/lv_example_scroll_3.py
Normal file
38
examples/scroll/lv_example_scroll_3.py
Normal file
@ -0,0 +1,38 @@
|
||||
class ScrollExample_3():
|
||||
def __init__(self):
|
||||
self.btn_cnt = 1
|
||||
#
|
||||
# Create a list a with a floating button
|
||||
#
|
||||
|
||||
list = lv.list(lv.scr_act())
|
||||
list.set_size(280, 220)
|
||||
list.center()
|
||||
|
||||
for btn_cnt in range(2):
|
||||
list.add_btn(lv.SYMBOL.AUDIO,"Track {:d}".format(btn_cnt))
|
||||
|
||||
float_btn = lv.btn(list)
|
||||
float_btn.set_size(50, 50)
|
||||
float_btn.add_flag(lv.obj.FLAG.FLOATING)
|
||||
float_btn.align(lv.ALIGN.BOTTOM_RIGHT, 0, -list.get_style_pad_right(lv.PART.MAIN))
|
||||
float_btn.add_event_cb(lambda evt: self.float_btn_event_cb(evt,list), lv.EVENT.ALL, None)
|
||||
float_btn.set_style_radius(lv.RADIUS.CIRCLE, 0)
|
||||
float_btn.set_style_bg_img_src(lv.SYMBOL.PLUS, 0)
|
||||
float_btn.set_style_text_font(lv.theme_get_font_large(float_btn), 0)
|
||||
|
||||
def float_btn_event_cb(self,e,list):
|
||||
code = e.get_code()
|
||||
float_btn = e.get_target()
|
||||
|
||||
if code == lv.EVENT.CLICKED:
|
||||
list_btn = list.add_btn(lv.SYMBOL.AUDIO, "Track {:d}".format(self.btn_cnt))
|
||||
self.btn_cnt += 1
|
||||
|
||||
float_btn.move_foreground()
|
||||
|
||||
list_btn.scroll_to_view(lv.ANIM.ON)
|
||||
|
||||
scroll_example_3 = ScrollExample_3()
|
||||
|
||||
|
62
examples/scroll/lv_example_scroll_4.py
Normal file
62
examples/scroll/lv_example_scroll_4.py
Normal file
@ -0,0 +1,62 @@
|
||||
#
|
||||
# Styling the scrollbars
|
||||
#
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.set_size(200, 100)
|
||||
obj.center()
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text(
|
||||
"""
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
Etiam dictum, tortor vestibulum lacinia laoreet, mi neque consectetur neque, vel mattis odio dolor egestas ligula.
|
||||
Sed vestibulum sapien nulla, id convallis ex porttitor nec.
|
||||
Duis et massa eu libero accumsan faucibus a in arcu.
|
||||
Ut pulvinar odio lorem, vel tempus turpis condimentum quis. Nam consectetur condimentum sem in auctor.
|
||||
Sed nisl augue, venenatis in blandit et, gravida ac tortor.
|
||||
Etiam dapibus elementum suscipit.
|
||||
Proin mollis sollicitudin convallis.
|
||||
Integer dapibus tempus arcu nec viverra.
|
||||
Donec molestie nulla enim, eu interdum velit placerat quis.
|
||||
Donec id efficitur risus, at molestie turpis.
|
||||
Suspendisse vestibulum consectetur nunc ut commodo.
|
||||
Fusce molestie rhoncus nisi sit amet tincidunt.
|
||||
Suspendisse a nunc ut magna ornare volutpat.
|
||||
""")
|
||||
|
||||
|
||||
# Remove the style of scrollbar to have clean start
|
||||
obj.remove_style(None, lv.PART.SCROLLBAR | lv.STATE.ANY)
|
||||
|
||||
# Create a transition the animate the some properties on state change
|
||||
props = [lv.STYLE.BG_OPA, lv.STYLE.WIDTH, 0]
|
||||
trans = lv.style_transition_dsc_t()
|
||||
trans.init(props, lv.anim_t.path_linear, 200, 0, None)
|
||||
|
||||
# Create a style for the scrollbars
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_width(4) # Width of the scrollbar
|
||||
style.set_pad_right(5) # Space from the parallel side
|
||||
style.set_pad_top(5) # Space from the perpendicular side
|
||||
|
||||
style.set_radius(2)
|
||||
style.set_bg_opa(lv.OPA._70)
|
||||
style.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_border_color(lv.palette_darken(lv.PALETTE.BLUE, 3))
|
||||
style.set_border_width(2)
|
||||
style.set_shadow_width(8)
|
||||
style.set_shadow_spread(2)
|
||||
style.set_shadow_color(lv.palette_darken(lv.PALETTE.BLUE, 1))
|
||||
|
||||
style.set_transition(trans)
|
||||
|
||||
# Make the scrollbars wider and use 100% opacity when scrolled
|
||||
style_scrolled = lv.style_t()
|
||||
style_scrolled.init()
|
||||
style_scrolled.set_width(8)
|
||||
style_scrolled.set_bg_opa(lv.OPA.COVER)
|
||||
|
||||
obj.add_style(style, lv.PART.SCROLLBAR)
|
||||
obj.add_style(style_scrolled, lv.PART.SCROLLBAR | lv.STATE.SCROLLED)
|
||||
|
13
examples/scroll/lv_example_scroll_5.py
Normal file
13
examples/scroll/lv_example_scroll_5.py
Normal file
@ -0,0 +1,13 @@
|
||||
#
|
||||
# Scrolling with Right To Left base direction
|
||||
#
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.set_style_base_dir(lv.BASE_DIR.RTL, 0)
|
||||
obj.set_size(200, 100)
|
||||
obj.center()
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("میکروکُنترولر (به انگلیسی: Microcontroller) گونهای ریزپردازنده است که دارای حافظهٔ دسترسی تصادفی (RAM) و حافظهٔ فقطخواندنی (ROM)، تایمر، پورتهای ورودی و خروجی (I/O) و درگاه ترتیبی (Serial Port پورت سریال)، درون خود تراشه است، و میتواند به تنهایی ابزارهای دیگر را کنترل کند. به عبارت دیگر یک میکروکنترلر، مدار مجتمع کوچکی است که از یک CPU کوچک و اجزای دیگری مانند تایمر، درگاههای ورودی و خروجی آنالوگ و دیجیتال و حافظه تشکیل شدهاست.")
|
||||
label.set_width(400)
|
||||
label.set_style_text_font(lv.font_dejavu_16_persian_hebrew, 0)
|
||||
|
68
examples/scroll/lv_example_scroll_6.py
Normal file
68
examples/scroll/lv_example_scroll_6.py
Normal file
@ -0,0 +1,68 @@
|
||||
def scroll_event_cb(e):
|
||||
|
||||
cont = e.get_target()
|
||||
|
||||
cont_a = lv.area_t()
|
||||
cont.get_coords(cont_a)
|
||||
cont_y_center = cont_a.y1 + cont_a.get_height() // 2
|
||||
|
||||
r = cont.get_height() * 7 // 10
|
||||
|
||||
child_cnt = cont.get_child_cnt()
|
||||
for i in range(child_cnt):
|
||||
child = cont.get_child(i)
|
||||
child_a = lv.area_t()
|
||||
child.get_coords(child_a)
|
||||
|
||||
child_y_center = child_a.y1 + child_a.get_height() // 2
|
||||
|
||||
diff_y = child_y_center - cont_y_center;
|
||||
diff_y = abs(diff_y)
|
||||
|
||||
# Get the x of diff_y on a circle.
|
||||
|
||||
# If diff_y is out of the circle use the last point of the circle (the radius)
|
||||
if diff_y >= r:
|
||||
x = r
|
||||
else:
|
||||
# Use Pythagoras theorem to get x from radius and y
|
||||
x_sqr = r * r - diff_y * diff_y;
|
||||
res = lv.sqrt_res_t()
|
||||
lv.sqrt(x_sqr, res, 0x8000) # Use lvgl's built in sqrt root function
|
||||
x = r - res.i
|
||||
|
||||
# Translate the item by the calculated X coordinate
|
||||
child.set_style_translate_x(x, 0)
|
||||
|
||||
# Use some opacity with larger translations
|
||||
opa = lv.map(x, 0, r, lv.OPA.TRANSP, lv.OPA.COVER)
|
||||
child.set_style_opa(lv.OPA.COVER - opa, 0)
|
||||
|
||||
#
|
||||
# Translate the object as they scroll
|
||||
#
|
||||
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(200, 200)
|
||||
cont.center()
|
||||
cont.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
cont.add_event_cb(scroll_event_cb, lv.EVENT.SCROLL, None)
|
||||
cont.set_style_radius(lv.RADIUS.CIRCLE, 0)
|
||||
cont.set_style_clip_corner(True, 0)
|
||||
cont.set_scroll_dir(lv.DIR.VER)
|
||||
cont.set_scroll_snap_y(lv.SCROLL_SNAP.CENTER)
|
||||
cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
|
||||
|
||||
for i in range(20):
|
||||
btn = lv.btn(cont)
|
||||
btn.set_width(lv.pct(100))
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text("Button " + str(i))
|
||||
|
||||
# Update the buttons position manually for first*
|
||||
lv.event_send(cont, lv.EVENT.SCROLL, None)
|
||||
|
||||
# Be sure the fist button is in the middle
|
||||
#lv.obj.scroll_to_view(cont.get_child(0), lv.ANIM.OFF)
|
||||
cont.get_child(0).scroll_to_view(lv.ANIM.OFF)
|
24
examples/styles/lv_example_style_1.py
Normal file
24
examples/styles/lv_example_style_1.py
Normal file
@ -0,0 +1,24 @@
|
||||
#
|
||||
# Using the Size, Position and Padding style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_radius(5)
|
||||
|
||||
# Make a gradient
|
||||
style.set_width(150)
|
||||
style.set_height(lv.SIZE.CONTENT)
|
||||
|
||||
style.set_pad_ver(20)
|
||||
style.set_pad_left(5)
|
||||
|
||||
style.set_x(lv.pct(50))
|
||||
style.set_y(80)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("Hello");
|
||||
|
36
examples/styles/lv_example_style_10.py
Normal file
36
examples/styles/lv_example_style_10.py
Normal file
@ -0,0 +1,36 @@
|
||||
#
|
||||
# Creating a transition
|
||||
#
|
||||
|
||||
props = [lv.STYLE.BG_COLOR, lv.STYLE.BORDER_COLOR, lv.STYLE.BORDER_WIDTH, 0]
|
||||
|
||||
# A default transition
|
||||
# Make it fast (100ms) and start with some delay (200 ms)
|
||||
|
||||
trans_def = lv.style_transition_dsc_t()
|
||||
trans_def.init(props, lv.anim_t.path_linear, 100, 200, None)
|
||||
|
||||
# A special transition when going to pressed state
|
||||
# Make it slow (500 ms) but start without delay
|
||||
|
||||
trans_pr = lv.style_transition_dsc_t()
|
||||
trans_pr.init(props, lv.anim_t.path_linear, 500, 0, None)
|
||||
|
||||
style_def = lv.style_t()
|
||||
style_def.init()
|
||||
style_def.set_transition(trans_def)
|
||||
|
||||
style_pr = lv.style_t()
|
||||
style_pr.init()
|
||||
style_pr.set_bg_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style_pr.set_border_width(6)
|
||||
style_pr.set_border_color(lv.palette_darken(lv.PALETTE.RED, 3))
|
||||
style_pr.set_transition(trans_pr)
|
||||
|
||||
# Create an object with the new style_pr
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style_def, 0)
|
||||
obj.add_style(style_pr, lv.STATE.PRESSED)
|
||||
|
||||
obj.center()
|
||||
|
44
examples/styles/lv_example_style_11.py
Normal file
44
examples/styles/lv_example_style_11.py
Normal file
@ -0,0 +1,44 @@
|
||||
#
|
||||
# Using multiple styles
|
||||
#
|
||||
# A base style
|
||||
|
||||
style_base = lv.style_t()
|
||||
style_base.init()
|
||||
style_base.set_bg_color(lv.palette_main(lv.PALETTE.LIGHT_BLUE))
|
||||
style_base.set_border_color(lv.palette_darken(lv.PALETTE.LIGHT_BLUE, 3))
|
||||
style_base.set_border_width(2)
|
||||
style_base.set_radius(10)
|
||||
style_base.set_shadow_width(10)
|
||||
style_base.set_shadow_ofs_y(5)
|
||||
style_base.set_shadow_opa(lv.OPA._50)
|
||||
style_base.set_text_color(lv.color_white())
|
||||
style_base.set_width(100)
|
||||
style_base.set_height(lv.SIZE.CONTENT)
|
||||
|
||||
# Set only the properties that should be different
|
||||
style_warning = lv.style_t()
|
||||
style_warning.init()
|
||||
style_warning.set_bg_color(lv.palette_main(lv.PALETTE.YELLOW))
|
||||
style_warning.set_border_color(lv.palette_darken(lv.PALETTE.YELLOW, 3))
|
||||
style_warning.set_text_color(lv.palette_darken(lv.PALETTE.YELLOW, 4))
|
||||
|
||||
# Create an object with the base style only
|
||||
obj_base = lv.obj(lv.scr_act())
|
||||
obj_base.add_style(style_base, 0)
|
||||
obj_base.align(lv.ALIGN.LEFT_MID, 20, 0)
|
||||
|
||||
label = lv.label(obj_base)
|
||||
label.set_text("Base")
|
||||
label.center()
|
||||
|
||||
# Create an other object with the base style and earnings style too
|
||||
obj_warning = lv.obj(lv.scr_act())
|
||||
obj_warning.add_style(style_base, 0)
|
||||
obj_warning.add_style(style_warning, 0)
|
||||
obj_warning.align(lv.ALIGN.RIGHT_MID, -20, 0)
|
||||
|
||||
label = lv.label(obj_warning)
|
||||
label.set_text("Warning")
|
||||
label.center()
|
||||
|
18
examples/styles/lv_example_style_12.py
Normal file
18
examples/styles/lv_example_style_12.py
Normal file
@ -0,0 +1,18 @@
|
||||
#
|
||||
# Local styles
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_bg_color(lv.palette_main(lv.PALETTE.GREEN))
|
||||
style.set_border_color(lv.palette_lighten(lv.PALETTE.GREEN, 3))
|
||||
style.set_border_width(3)
|
||||
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
|
||||
# Overwrite the background color locally
|
||||
obj.set_style_bg_color(lv.palette_main(lv.PALETTE.ORANGE), lv.PART.MAIN)
|
||||
|
||||
obj.center()
|
||||
|
23
examples/styles/lv_example_style_13.py
Normal file
23
examples/styles/lv_example_style_13.py
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# Add styles to parts and states
|
||||
#
|
||||
|
||||
style_indic = lv.style_t()
|
||||
style_indic.init()
|
||||
style_indic.set_bg_color(lv.palette_lighten(lv.PALETTE.RED, 3))
|
||||
style_indic.set_bg_grad_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style_indic.set_bg_grad_dir(lv.GRAD_DIR.HOR)
|
||||
|
||||
style_indic_pr = lv.style_t()
|
||||
style_indic_pr.init()
|
||||
style_indic_pr.set_shadow_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style_indic_pr.set_shadow_width(10)
|
||||
style_indic_pr.set_shadow_spread(3)
|
||||
|
||||
# Create an object with the new style_pr
|
||||
obj = lv.slider(lv.scr_act())
|
||||
obj.add_style(style_indic, lv.PART.INDICATOR)
|
||||
obj.add_style(style_indic_pr, lv.PART.INDICATOR | lv.STATE.PRESSED)
|
||||
obj.set_value(70, lv.ANIM.OFF)
|
||||
obj.center()
|
||||
|
53
examples/styles/lv_example_style_14.py
Normal file
53
examples/styles/lv_example_style_14.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Will be called when the styles of the base theme are already added
|
||||
# to add new styles
|
||||
|
||||
|
||||
class NewTheme(lv.theme_t):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# Initialize the styles
|
||||
self.style_btn = lv.style_t()
|
||||
self.style_btn.init()
|
||||
self.style_btn.set_bg_color(lv.palette_main(lv.PALETTE.GREEN))
|
||||
self.style_btn.set_border_color(lv.palette_darken(lv.PALETTE.GREEN, 3))
|
||||
self.style_btn.set_border_width(3)
|
||||
|
||||
# This theme is based on active theme
|
||||
th_act = lv.theme_get_from_obj(lv.scr_act())
|
||||
# This theme will be applied only after base theme is applied
|
||||
self.set_parent(th_act)
|
||||
|
||||
class ExampleStyle_14():
|
||||
|
||||
def __init__(self):
|
||||
#
|
||||
# Extending the current theme
|
||||
#
|
||||
|
||||
btn = lv.btn(lv.scr_act())
|
||||
btn.align(lv.ALIGN.TOP_MID, 0, 20)
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text("Original theme")
|
||||
|
||||
self.new_theme_init_and_set()
|
||||
|
||||
btn = lv.btn(lv.scr_act())
|
||||
btn.align(lv.ALIGN.BOTTOM_MID, 0, -20)
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text("New theme")
|
||||
|
||||
def new_theme_apply_cb(self,th, obj):
|
||||
print(th,obj)
|
||||
if obj.get_class() == lv.btn_class:
|
||||
obj.add_style(self.th_new.style_btn, 0)
|
||||
|
||||
def new_theme_init_and_set(self):
|
||||
print("new_theme_init_and_set")
|
||||
# Initialize the new theme from the current theme
|
||||
self.th_new = NewTheme()
|
||||
self.th_new.set_apply_cb(self.new_theme_apply_cb)
|
||||
lv.disp_get_default().set_theme(self.th_new)
|
||||
|
||||
exampleStyle_14 = ExampleStyle_14()
|
22
examples/styles/lv_example_style_2.py
Normal file
22
examples/styles/lv_example_style_2.py
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# Using the background style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_radius(5)
|
||||
|
||||
# Make a gradient
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 1))
|
||||
style.set_bg_grad_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_bg_grad_dir(lv.GRAD_DIR.VER)
|
||||
|
||||
# Shift the gradient to the bottom
|
||||
style.set_bg_main_stop(128)
|
||||
style.set_bg_grad_stop(192)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
22
examples/styles/lv_example_style_3.py
Normal file
22
examples/styles/lv_example_style_3.py
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# Using the border style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
# Set a background color and a radius
|
||||
style.set_radius(10)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 1))
|
||||
|
||||
# Add border to the bottom+right
|
||||
style.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_border_width(5)
|
||||
style.set_border_opa(lv.OPA._50)
|
||||
style.set_border_side(lv.BORDER_SIDE.BOTTOM | lv.BORDER_SIDE.RIGHT)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
23
examples/styles/lv_example_style_4.py
Normal file
23
examples/styles/lv_example_style_4.py
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# Using the outline style properties
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
# Set a background color and a radius
|
||||
style.set_radius(5)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 1))
|
||||
|
||||
# Add outline
|
||||
style.set_outline_width(2)
|
||||
style.set_outline_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_outline_pad(8)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
||||
|
23
examples/styles/lv_example_style_5.py
Normal file
23
examples/styles/lv_example_style_5.py
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# Using the Shadow style properties
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
# Set a background color and a radius
|
||||
style.set_radius(5)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 1))
|
||||
|
||||
# Add a shadow
|
||||
style.set_shadow_width(8)
|
||||
style.set_shadow_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_shadow_ofs_x(10)
|
||||
style.set_shadow_ofs_y(20)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
44
examples/styles/lv_example_style_6.py
Normal file
44
examples/styles/lv_example_style_6.py
Normal file
@ -0,0 +1,44 @@
|
||||
from imagetools import get_png_info, open_png
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../assets/img_cogwheel_argb.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_cogwheel_argb.png")
|
||||
sys.exit()
|
||||
|
||||
img_cogwheel_argb = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
#
|
||||
# Using the Image style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
# Set a background color and a radius
|
||||
style.set_radius(5)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
|
||||
style.set_border_width(2)
|
||||
style.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
|
||||
style.set_img_recolor(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_img_recolor_opa(lv.OPA._50)
|
||||
# style.set_transform_angle(300)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.img(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
|
||||
obj.set_src(img_cogwheel_argb)
|
||||
|
||||
obj.center()
|
||||
|
15
examples/styles/lv_example_style_7.py
Normal file
15
examples/styles/lv_example_style_7.py
Normal file
@ -0,0 +1,15 @@
|
||||
#
|
||||
# Using the Arc style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
style.set_arc_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style.set_arc_width(4)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.arc(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
||||
|
27
examples/styles/lv_example_style_8.py
Normal file
27
examples/styles/lv_example_style_8.py
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
# Using the text style properties
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
style.set_radius(5)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
|
||||
style.set_border_width(2)
|
||||
style.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_pad_all(10)
|
||||
|
||||
style.set_text_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_text_letter_space(5)
|
||||
style.set_text_line_space(20)
|
||||
style.set_text_decor(lv.TEXT_DECOR.UNDERLINE)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.label(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.set_text("Text of\n"
|
||||
"a label");
|
||||
|
||||
obj.center()
|
||||
|
22
examples/styles/lv_example_style_9.py
Normal file
22
examples/styles/lv_example_style_9.py
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# Using the line style properties
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
style.set_line_color(lv.palette_main(lv.PALETTE.GREY))
|
||||
style.set_line_width(6)
|
||||
style.set_line_rounded(True)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.line(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
p = [ {"x":10, "y":30},
|
||||
{"x":30, "y":50},
|
||||
{"x":100, "y":0}]
|
||||
|
||||
obj.set_points(p, 3)
|
||||
|
||||
obj.center()
|
||||
|
4
examples/test_ex.sh
Executable file
4
examples/test_ex.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
cat ../../header.py $1 > test.py
|
||||
chmod +x test.py
|
||||
./test.py
|
54
examples/widgets/animimg/lv_example_animimg_1.py
Normal file
54
examples/widgets/animimg/lv_example_animimg_1.py
Normal file
@ -0,0 +1,54 @@
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
anim_imgs = [None]*3
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/animimg001.png','rb') as f:
|
||||
anim001_data = f.read()
|
||||
except:
|
||||
print("Could not find animimg001.png")
|
||||
sys.exit()
|
||||
|
||||
anim_imgs[0] = lv.img_dsc_t({
|
||||
'data_size': len(anim001_data),
|
||||
'data': anim001_data
|
||||
})
|
||||
|
||||
try:
|
||||
with open('../../assets/animimg002.png','rb') as f:
|
||||
anim002_data = f.read()
|
||||
except:
|
||||
print("Could not find animimg002.png")
|
||||
sys.exit()
|
||||
|
||||
anim_imgs[1] = lv.img_dsc_t({
|
||||
'data_size': len(anim002_data),
|
||||
'data': anim002_data
|
||||
})
|
||||
|
||||
try:
|
||||
with open('../../assets/animimg003.png','rb') as f:
|
||||
anim003_data = f.read()
|
||||
except:
|
||||
print("Could not find animimg003.png")
|
||||
sys.exit()
|
||||
|
||||
anim_imgs[2] = lv.img_dsc_t({
|
||||
'data_size': len(anim003_data),
|
||||
'data': anim003_data
|
||||
})
|
||||
|
||||
animimg0 = lv.animimg(lv.scr_act())
|
||||
animimg0.center()
|
||||
animimg0.set_src(anim_imgs, 3)
|
||||
animimg0.set_duration(1000)
|
||||
animimg0.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
animimg0.start()
|
||||
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
# Create style for the Arcs
|
||||
style = lv.style_t()
|
||||
lv.style_copy(style, lv.style_plain)
|
||||
style.line.color = lv.color_make(0,0,255) # Arc color
|
||||
style.line.width = 8 # Arc width
|
||||
|
||||
# Create an Arc
|
||||
arc = lv.arc(lv.scr_act())
|
||||
arc.set_style(lv.arc.STYLE.MAIN, style) # Use the new style
|
||||
arc.set_angles(90, 60)
|
||||
arc.set_end_angle(200)
|
||||
arc.set_size(150, 150)
|
||||
arc.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
arc.center()
|
||||
|
||||
|
||||
|
||||
|
@ -1,43 +1,37 @@
|
||||
# Create an arc which acts as a loader.
|
||||
class loader_arc(lv.arc):
|
||||
|
||||
def __init__(self, parent, color=lv.color_hex(0x000080),
|
||||
width=8, style=lv.style_plain, rate=20):
|
||||
super().__init__(parent)
|
||||
#
|
||||
# An `lv_timer` to call periodically to set the angles of the arc
|
||||
#
|
||||
class ArcLoader():
|
||||
def __init__(self):
|
||||
self.a = 270
|
||||
|
||||
self.a = 0
|
||||
self.rate = rate
|
||||
def arc_loader_cb(self,tim,arc):
|
||||
# print(tim,arc)
|
||||
self.a += 5
|
||||
|
||||
# Create style for the Arcs
|
||||
self.style = lv.style_t()
|
||||
lv.style_copy(self.style, style)
|
||||
self.style.line.color = color
|
||||
self.style.line.width = width
|
||||
arc.set_end_angle(self.a)
|
||||
|
||||
# Create an Arc
|
||||
self.set_angles(180, 180);
|
||||
self.set_style(self.STYLE.MAIN, self.style);
|
||||
if self.a >= 270 + 360:
|
||||
tim._del()
|
||||
|
||||
# Spin the Arc
|
||||
self.spin()
|
||||
|
||||
def spin(self):
|
||||
# Create an `lv_task` to update the arc.
|
||||
lv.task_create(self.task_cb, self.rate, lv.TASK_PRIO.LOWEST, {})
|
||||
#
|
||||
# Create an arc which acts as a loader.
|
||||
#
|
||||
|
||||
|
||||
# An `lv_task` to call periodically to set the angles of the arc
|
||||
def task_cb(self, task):
|
||||
self.a+=5;
|
||||
if self.a >= 359: self.a = 359
|
||||
# Create an Arc
|
||||
arc = lv.arc(lv.scr_act())
|
||||
arc.set_bg_angles(0, 360)
|
||||
arc.set_angles(270, 270)
|
||||
arc.center()
|
||||
|
||||
if self.a < 180: self.set_angles(180-self.a, 180)
|
||||
else: self.set_angles(540-self.a, 180)
|
||||
# create the loader
|
||||
arc_loader = ArcLoader()
|
||||
|
||||
if self.a == 359:
|
||||
self.a = 0
|
||||
lv.task_del(task)
|
||||
# Create an `lv_timer` to update the arc.
|
||||
|
||||
timer = lv.timer_create_basic()
|
||||
timer.set_period(20)
|
||||
timer.set_cb(lambda src: arc_loader.arc_loader_cb(timer,arc))
|
||||
|
||||
|
||||
# Create a loader arc
|
||||
loader_arc = loader_arc(lv.scr_act())
|
||||
loader_arc.align(None, lv.ALIGN.CENTER, 0, 0)
|
@ -1,5 +1,5 @@
|
||||
bar1 = lv.bar(lv.scr_act())
|
||||
bar1.set_size(200, 30)
|
||||
bar1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
bar1.set_anim_time(1000)
|
||||
bar1.set_value(100, lv.ANIM.ON)
|
||||
bar1.set_size(200, 20)
|
||||
bar1.center()
|
||||
bar1.set_value(70, lv.ANIM.OFF)
|
||||
|
||||
|
27
examples/widgets/bar/lv_example_bar_2.py
Normal file
27
examples/widgets/bar/lv_example_bar_2.py
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
# Example of styling the bar
|
||||
#
|
||||
style_bg = lv.style_t()
|
||||
style_indic = lv.style_t()
|
||||
|
||||
style_bg.init()
|
||||
style_bg.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style_bg.set_border_width(2)
|
||||
style_bg.set_pad_all(6) # To make the indicator smaller
|
||||
style_bg.set_radius(6)
|
||||
style_bg.set_anim_time(1000)
|
||||
|
||||
style_indic.init()
|
||||
style_indic.set_bg_opa(lv.OPA.COVER)
|
||||
style_indic.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style_indic.set_radius(3)
|
||||
|
||||
bar = lv.bar(lv.scr_act())
|
||||
bar.remove_style_all() # To have a clean start
|
||||
bar.add_style(style_bg, 0)
|
||||
bar.add_style(style_indic, lv.PART.INDICATOR)
|
||||
|
||||
bar.set_size(200, 20)
|
||||
bar.center()
|
||||
bar.set_value(100, lv.ANIM.ON)
|
||||
|
32
examples/widgets/bar/lv_example_bar_3.py
Normal file
32
examples/widgets/bar/lv_example_bar_3.py
Normal file
@ -0,0 +1,32 @@
|
||||
def set_temp(bar, temp):
|
||||
bar.set_value(temp, lv.ANIM.ON)
|
||||
|
||||
#
|
||||
# A temperature meter example
|
||||
#
|
||||
|
||||
|
||||
style_indic = lv.style_t()
|
||||
|
||||
style_indic.init()
|
||||
style_indic.set_bg_opa(lv.OPA.COVER)
|
||||
style_indic.set_bg_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style_indic.set_bg_grad_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style_indic.set_bg_grad_dir(lv.GRAD_DIR.VER)
|
||||
|
||||
bar = lv.bar(lv.scr_act())
|
||||
bar.add_style(style_indic, lv.PART.INDICATOR)
|
||||
bar.set_size(20, 200)
|
||||
bar.center()
|
||||
bar.set_range(-20, 40)
|
||||
|
||||
a = lv.anim_t()
|
||||
a.init()
|
||||
a.set_time(3000)
|
||||
a.set_playback_time(3000)
|
||||
a.set_var(bar)
|
||||
a.set_values(-20, 40)
|
||||
a.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a.set_custom_exec_cb(lambda a, val: set_temp(bar,val))
|
||||
lv.anim_t.start(a)
|
||||
|
45
examples/widgets/bar/lv_example_bar_4.py
Normal file
45
examples/widgets/bar/lv_example_bar_4.py
Normal file
@ -0,0 +1,45 @@
|
||||
#
|
||||
# get an icon
|
||||
#
|
||||
def get_icon(filename,xres,yres):
|
||||
try:
|
||||
sdl_filename = "../../assets/" + filename + "_" + str(xres) + "x" + str(yres) + "_argb8888.bin"
|
||||
print("file name: ", sdl_filename)
|
||||
with open(sdl_filename,'rb') as f:
|
||||
icon_data = f.read()
|
||||
except:
|
||||
print("Could not find image file: " + filename)
|
||||
return None
|
||||
|
||||
icon_dsc = lv.img_dsc_t(
|
||||
{
|
||||
"header": {"always_zero": 0, "w": xres, "h": yres, "cf": lv.img.CF.TRUE_COLOR_ALPHA},
|
||||
"data": icon_data,
|
||||
"data_size": len(icon_data),
|
||||
}
|
||||
)
|
||||
return icon_dsc
|
||||
|
||||
#
|
||||
# Bar with stripe pattern and ranged value
|
||||
#
|
||||
|
||||
img_skew_strip_dsc = get_icon("img_skew_strip",80,20)
|
||||
style_indic = lv.style_t()
|
||||
|
||||
style_indic.init()
|
||||
style_indic.set_bg_img_src(img_skew_strip_dsc)
|
||||
style_indic.set_bg_img_tiled(True);
|
||||
style_indic.set_bg_img_opa(lv.OPA._30)
|
||||
|
||||
bar = lv.bar(lv.scr_act())
|
||||
bar.add_style(style_indic, lv.PART.INDICATOR)
|
||||
|
||||
bar.set_size(260, 20)
|
||||
bar.center()
|
||||
bar.set_mode(lv.bar.MODE.RANGE)
|
||||
bar.set_value(90, lv.ANIM.OFF)
|
||||
bar.set_start_value(20, lv.ANIM.OFF)
|
||||
|
||||
|
||||
|
22
examples/widgets/bar/lv_example_bar_5.py
Normal file
22
examples/widgets/bar/lv_example_bar_5.py
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# Bar with LTR and RTL base direction
|
||||
#
|
||||
|
||||
bar_ltr = lv.bar(lv.scr_act())
|
||||
bar_ltr.set_size(200, 20)
|
||||
bar_ltr.set_value(70, lv.ANIM.OFF)
|
||||
bar_ltr.align(lv.ALIGN.CENTER, 0, -30)
|
||||
|
||||
label = lv.label(lv.scr_act())
|
||||
label.set_text("Left to Right base direction")
|
||||
label.align_to(bar_ltr, lv.ALIGN.OUT_TOP_MID, 0, -5)
|
||||
|
||||
bar_rtl = lv.bar(lv.scr_act())
|
||||
bar_rtl.set_style_base_dir(lv.BASE_DIR.RTL,0)
|
||||
bar_rtl.set_size(200, 20)
|
||||
bar_rtl.set_value(70, lv.ANIM.OFF)
|
||||
bar_rtl.align(lv.ALIGN.CENTER, 0, 30)
|
||||
|
||||
label = lv.label(lv.scr_act())
|
||||
label.set_text("Right to Left base direction")
|
||||
label.align_to(bar_rtl, lv.ALIGN.OUT_TOP_MID, 0, -5)
|
54
examples/widgets/bar/lv_example_bar_6.py
Normal file
54
examples/widgets/bar/lv_example_bar_6.py
Normal file
@ -0,0 +1,54 @@
|
||||
def set_value(bar, v):
|
||||
bar.set_value(v, lv.ANIM.OFF)
|
||||
|
||||
def event_cb(e):
|
||||
dsc = lv.obj_draw_part_dsc_t.cast(e.get_param())
|
||||
if dsc.part != lv.PART.INDICATOR:
|
||||
return
|
||||
|
||||
obj= lv.bar.__cast__(e.get_target())
|
||||
|
||||
label_dsc = lv.draw_label_dsc_t()
|
||||
label_dsc.init()
|
||||
# label_dsc.font = LV_FONT_DEFAULT;
|
||||
|
||||
value_txt = str(obj.get_value())
|
||||
txt_size = lv.point_t()
|
||||
lv.txt_get_size(txt_size, value_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, lv.COORD.MAX, label_dsc.flag)
|
||||
|
||||
txt_area = lv.area_t()
|
||||
# If the indicator is long enough put the text inside on the right
|
||||
if dsc.draw_area.get_width() > txt_size.x + 20:
|
||||
txt_area.x2 = dsc.draw_area.x2 - 5
|
||||
txt_area.x1 = txt_area.x2 - txt_size.x + 1
|
||||
label_dsc.color = lv.color_white()
|
||||
# If the indicator is still short put the text out of it on the right*/
|
||||
else:
|
||||
txt_area.x1 = dsc.draw_area.x2 + 5
|
||||
txt_area.x2 = txt_area.x1 + txt_size.x - 1
|
||||
label_dsc.color = lv.color_black()
|
||||
|
||||
txt_area.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - txt_size.y) // 2
|
||||
txt_area.y2 = txt_area.y1 + txt_size.y - 1
|
||||
|
||||
lv.draw_label(txt_area, dsc.clip_area, label_dsc, value_txt, None)
|
||||
|
||||
#
|
||||
# Custom drawer on the bar to display the current value
|
||||
#
|
||||
|
||||
bar = lv.bar(lv.scr_act())
|
||||
bar.add_event_cb(event_cb, lv.EVENT.DRAW_PART_END, None)
|
||||
bar.set_size(200, 20)
|
||||
bar.center()
|
||||
|
||||
a = lv.anim_t()
|
||||
a.init()
|
||||
a.set_var(bar)
|
||||
a.set_values(0, 100)
|
||||
a.set_custom_exec_cb(lambda a,val: set_value(bar,val))
|
||||
a.set_time(2000)
|
||||
a.set_playback_time(2000)
|
||||
a.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
lv.anim_t.start(a)
|
||||
|
57
examples/widgets/bar/test.py
Normal file
57
examples/widgets/bar/test.py
Normal file
@ -0,0 +1,57 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
def set_value(bar, v):
|
||||
bar.set_value(v, lv.ANIM.OFF)
|
||||
|
||||
def event_cb(e):
|
||||
dsc = lv.obj_draw_part_dsc_t.cast(e.get_param())
|
||||
if dsc.part != lv.PART.INDICATOR:
|
||||
return
|
||||
|
||||
obj= lv.bar.__cast__(e.get_target())
|
||||
|
||||
label_dsc = lv.draw_label_dsc_t()
|
||||
label_dsc.init()
|
||||
# label_dsc.font = LV_FONT_DEFAULT;
|
||||
|
||||
value_txt = str(obj.get_value())
|
||||
txt_size = lv.point_t()
|
||||
lv.txt_get_size(txt_size, value_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, lv.COORD.MAX, label_dsc.flag)
|
||||
|
||||
txt_area = lv.area_t()
|
||||
# If the indicator is long enough put the text inside on the right
|
||||
if dsc.draw_area.get_width() > txt_size.x + 20:
|
||||
txt_area.x2 = dsc.draw_area.x2 - 5
|
||||
txt_area.x1 = txt_area.x2 - txt_size.x + 1
|
||||
label_dsc.color = lv.color_white()
|
||||
# If the indicator is still short put the text out of it on the right*/
|
||||
else:
|
||||
txt_area.x1 = dsc.draw_area.x2 + 5
|
||||
txt_area.x2 = txt_area.x1 + txt_size.x - 1
|
||||
label_dsc.color = lv.color_black()
|
||||
|
||||
txt_area.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - txt_size.y) // 2
|
||||
txt_area.y2 = txt_area.y1 + txt_size.y - 1
|
||||
|
||||
lv.draw_label(txt_area, dsc.clip_area, label_dsc, value_txt, None)
|
||||
|
||||
#
|
||||
# Custom drawer on the bar to display the current value
|
||||
#
|
||||
|
||||
bar = lv.bar(lv.scr_act())
|
||||
bar.add_event_cb(event_cb, lv.EVENT.DRAW_PART_END, None)
|
||||
bar.set_size(200, 20)
|
||||
bar.center()
|
||||
|
||||
a = lv.anim_t()
|
||||
a.init()
|
||||
a.set_var(bar)
|
||||
a.set_values(0, 100)
|
||||
a.set_custom_exec_cb(lambda a,val: set_value(bar,val))
|
||||
a.set_time(2000)
|
||||
a.set_playback_time(2000)
|
||||
a.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
lv.anim_t.start(a)
|
||||
|
@ -1,21 +1,32 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.CLICKED:
|
||||
print("Clicked")
|
||||
def event_handler(evt):
|
||||
code = evt.get_code()
|
||||
|
||||
if code == lv.EVENT.CLICKED:
|
||||
print("Clicked event seen")
|
||||
elif code == lv.EVENT.VALUE_CHANGED:
|
||||
print("Value changed seen")
|
||||
|
||||
# create a simple button
|
||||
btn1 = lv.btn(lv.scr_act())
|
||||
btn1.set_event_cb(event_handler)
|
||||
btn1.align(None, lv.ALIGN.CENTER, 0, -40)
|
||||
|
||||
label = lv.label(btn1)
|
||||
# attach the callback
|
||||
btn1.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
||||
btn1.align(lv.ALIGN.CENTER,0,-40)
|
||||
label=lv.label(btn1)
|
||||
label.set_text("Button")
|
||||
|
||||
# create a toggle button
|
||||
btn2 = lv.btn(lv.scr_act())
|
||||
# callback can be lambda:
|
||||
btn2.set_event_cb(lambda obj, event: print("Toggled") if event == lv.EVENT.VALUE_CHANGED else None)
|
||||
btn2.align(None, lv.ALIGN.CENTER, 0, 40)
|
||||
btn2.set_toggle(True)
|
||||
btn2.toggle()
|
||||
btn2.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
|
||||
|
||||
label = lv.label(btn2)
|
||||
label.set_text("Toggled")
|
||||
# attach the callback
|
||||
#btn2.add_event_cb(event_handler,lv.EVENT.VALUE_CHANGED,None)
|
||||
btn2.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
||||
btn2.align(lv.ALIGN.CENTER,0,40)
|
||||
btn2.add_flag(lv.obj.FLAG.CHECKABLE)
|
||||
btn2.set_height(lv.SIZE.CONTENT)
|
||||
|
||||
label=lv.label(btn2)
|
||||
label.set_text("Toggle")
|
||||
label.center()
|
||||
|
60
examples/widgets/btn/lv_example_btn_2.py
Normal file
60
examples/widgets/btn/lv_example_btn_2.py
Normal file
@ -0,0 +1,60 @@
|
||||
#
|
||||
# Style a button from scratch
|
||||
#
|
||||
|
||||
# Init the style for the default state
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
style.set_radius(3)
|
||||
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_bg_grad_color(lv.palette_darken(lv.PALETTE.BLUE, 2))
|
||||
style.set_bg_grad_dir(lv.GRAD_DIR.VER)
|
||||
|
||||
style.set_border_opa(lv.OPA._40)
|
||||
style.set_border_width(2)
|
||||
style.set_border_color(lv.palette_main(lv.PALETTE.GREY))
|
||||
|
||||
style.set_shadow_width(8)
|
||||
style.set_shadow_color(lv.palette_main(lv.PALETTE.GREY))
|
||||
style.set_shadow_ofs_y(8)
|
||||
|
||||
style.set_outline_opa(lv.OPA.COVER)
|
||||
style.set_outline_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
|
||||
style.set_text_color(lv.color_white())
|
||||
style.set_pad_all(10)
|
||||
|
||||
# Init the pressed style
|
||||
style_pr = lv.style_t()
|
||||
style_pr.init()
|
||||
|
||||
# Add a large outline when pressed
|
||||
style_pr.set_outline_width(30)
|
||||
style_pr.set_outline_opa(lv.OPA.TRANSP)
|
||||
|
||||
style_pr.set_translate_y(5)
|
||||
style_pr.set_shadow_ofs_y(3)
|
||||
style_pr.set_bg_color(lv.palette_darken(lv.PALETTE.BLUE, 2))
|
||||
style_pr.set_bg_grad_color(lv.palette_darken(lv.PALETTE.BLUE, 4))
|
||||
|
||||
# Add a transition to the the outline
|
||||
trans = lv.style_transition_dsc_t()
|
||||
props = [lv.STYLE.OUTLINE_WIDTH, lv.STYLE.OUTLINE_OPA, 0]
|
||||
trans.init(props, lv.anim_t.path_linear, 300, 0, None)
|
||||
|
||||
style_pr.set_transition(trans)
|
||||
|
||||
btn1 = lv.btn(lv.scr_act())
|
||||
btn1.remove_style_all() # Remove the style coming from the theme
|
||||
btn1.add_style(style, 0)
|
||||
btn1.add_style(style_pr, lv.STATE.PRESSED)
|
||||
btn1.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
|
||||
btn1.center()
|
||||
|
||||
label = lv.label(btn1)
|
||||
label.set_text("Button")
|
||||
label.center()
|
||||
|
38
examples/widgets/btn/lv_example_btn_3.py
Normal file
38
examples/widgets/btn/lv_example_btn_3.py
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# Create a style transition on a button to act like a gum when clicked
|
||||
#
|
||||
|
||||
# Properties to transition
|
||||
props = [lv.STYLE.TRANSFORM_WIDTH, lv.STYLE.TRANSFORM_HEIGHT, lv.STYLE.TEXT_LETTER_SPACE, 0]
|
||||
|
||||
# Transition descriptor when going back to the default state.
|
||||
# Add some delay to be sure the press transition is visible even if the press was very short*/
|
||||
transition_dsc_def = lv.style_transition_dsc_t()
|
||||
transition_dsc_def.init(props, lv.anim_t.path_overshoot, 250, 100, None)
|
||||
|
||||
# Transition descriptor when going to pressed state.
|
||||
# No delay, go to pressed state immediately
|
||||
transition_dsc_pr = lv.style_transition_dsc_t()
|
||||
transition_dsc_pr.init(props, lv.anim_t.path_ease_in_out, 250, 0, None)
|
||||
|
||||
# Add only the new transition to the default state
|
||||
style_def = lv.style_t()
|
||||
style_def.init()
|
||||
style_def.set_transition(transition_dsc_def)
|
||||
|
||||
# Add the transition and some transformation to the presses state.
|
||||
style_pr = lv.style_t()
|
||||
style_pr.init()
|
||||
style_pr.set_transform_width(10)
|
||||
style_pr.set_transform_height(-10)
|
||||
style_pr.set_text_letter_space(10)
|
||||
style_pr.set_transition(transition_dsc_pr)
|
||||
|
||||
btn1 = lv.btn(lv.scr_act())
|
||||
btn1.align(lv.ALIGN.CENTER, 0, -80)
|
||||
btn1.add_style(style_pr, lv.STATE.PRESSED)
|
||||
btn1.add_style(style_def, 0)
|
||||
|
||||
label = lv.label(btn1)
|
||||
label.set_text("Gum");
|
||||
|
@ -1,14 +1,24 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
txt = obj.get_active_btn_text()
|
||||
print("%s was pressed" % txt)
|
||||
def event_handler(evt):
|
||||
code = evt.get_code()
|
||||
obj = evt.get_target()
|
||||
|
||||
if code == lv.EVENT.VALUE_CHANGED :
|
||||
id = obj.get_selected_btn()
|
||||
txt = obj.get_btn_text(id)
|
||||
|
||||
print("%s was pressed"%txt)
|
||||
|
||||
btnm_map = ["1", "2", "3", "4", "5", "\n",
|
||||
"6", "7", "8", "9", "0", "\n",
|
||||
"Action1", "Action2", ""]
|
||||
|
||||
btnm1 = lv.btnm(lv.scr_act())
|
||||
btnm1 = lv.btnmatrix(lv.scr_act())
|
||||
btnm1.set_map(btnm_map)
|
||||
btnm1.set_btn_width(10, 2) # Make "Action1" twice as wide as "Action2"
|
||||
btnm1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
btnm1.set_event_cb(event_handler)
|
||||
btnm1.set_btn_ctrl(10, lv.btnmatrix.CTRL.CHECKABLE)
|
||||
btnm1.set_btn_ctrl(11, lv.btnmatrix.CTRL.CHECKED)
|
||||
btnm1.align(lv.ALIGN.CENTER, 0, 0)
|
||||
btnm1.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
|
||||
#endif
|
||||
|
83
examples/widgets/btnmatrix/lv_example_btnmatrix_2.py
Normal file
83
examples/widgets/btnmatrix/lv_example_btnmatrix_2.py
Normal file
@ -0,0 +1,83 @@
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_star.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_star.png")
|
||||
sys.exit()
|
||||
|
||||
img_star_argb = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
def event_cb(e):
|
||||
code = e.get_code()
|
||||
obj = e.get_target()
|
||||
if code == lv.EVENT.DRAW_PART_BEGIN:
|
||||
dsc = lv.obj_draw_part_dsc_t.cast(e.get_param())
|
||||
# Change the draw descriptor the 2nd button
|
||||
if dsc.id == 1:
|
||||
dsc.rect_dsc.radius = 0;
|
||||
if obj.get_selected_btn() == dsc.id:
|
||||
dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.GREY, 3)
|
||||
else:
|
||||
dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE)
|
||||
|
||||
dsc.rect_dsc.shadow_width = 6
|
||||
dsc.rect_dsc.shadow_ofs_x = 3
|
||||
dsc.rect_dsc.shadow_ofs_y = 3
|
||||
dsc.label_dsc.color = lv.color_white()
|
||||
|
||||
# Change the draw descriptor the 3rd button
|
||||
|
||||
elif dsc.id == 2:
|
||||
dsc.rect_dsc.radius = lv.RADIUS.CIRCLE
|
||||
if obj.get_selected_btn() == dsc.id:
|
||||
dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.RED, 3)
|
||||
else:
|
||||
dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.RED)
|
||||
|
||||
dsc.label_dsc.color = lv.color_white()
|
||||
elif dsc.id == 3:
|
||||
dsc.label_dsc.opa = lv.OPA.TRANSP # Hide the text if any
|
||||
|
||||
if code == lv.EVENT.DRAW_PART_END:
|
||||
dsc = lv.obj_draw_part_dsc_t.cast(e.get_param())
|
||||
|
||||
# Add custom content to the 4th button when the button itself was drawn
|
||||
if dsc.id == 3:
|
||||
# LV_IMG_DECLARE(img_star);
|
||||
header = lv.img_header_t()
|
||||
res = lv.img.decoder_get_info(img_star_argb, header)
|
||||
if res != lv.RES.OK:
|
||||
print("error when getting image header")
|
||||
return
|
||||
else:
|
||||
a = lv.area_t()
|
||||
a.x1 = dsc.draw_area.x1 + (dsc.draw_area.get_width() - header.w) // 2
|
||||
a.x2 = a.x1 + header.w - 1;
|
||||
a.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - header.h) // 2
|
||||
a.y2 = a.y1 + header.h - 1;
|
||||
img_draw_dsc = lv.draw_img_dsc_t()
|
||||
img_draw_dsc.init()
|
||||
img_draw_dsc.recolor = lv.color_black()
|
||||
if obj.get_selected_btn() == dsc.id:
|
||||
img_draw_dsc.recolor_opa = lv.OPA._30
|
||||
|
||||
lv.draw_img(a, dsc.clip_area, img_star_argb, img_draw_dsc)
|
||||
|
||||
#
|
||||
# Add custom drawer to the button matrix to c
|
||||
#
|
||||
btnm = lv.btnmatrix(lv.scr_act())
|
||||
btnm.add_event_cb(event_cb, lv.EVENT.ALL, None)
|
||||
btnm.center()
|
||||
|
64
examples/widgets/btnmatrix/lv_example_btnmatrix_3.py
Normal file
64
examples/widgets/btnmatrix/lv_example_btnmatrix_3.py
Normal file
@ -0,0 +1,64 @@
|
||||
def event_cb(e):
|
||||
obj = lv.btnmatrix.__cast__(e.get_target())
|
||||
id = obj.get_selected_btn()
|
||||
if id == 0:
|
||||
prev = True
|
||||
else:
|
||||
prev = False
|
||||
if id == 6:
|
||||
next = True
|
||||
else:
|
||||
next = False
|
||||
if prev or next:
|
||||
# Find the checked butto
|
||||
for i in range(7):
|
||||
if obj.has_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED):
|
||||
break
|
||||
if prev and i > 1:
|
||||
i-=1
|
||||
elif next and i < 5:
|
||||
i+=1
|
||||
|
||||
obj.set_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED)
|
||||
|
||||
#
|
||||
# Make a button group
|
||||
#
|
||||
|
||||
style_bg = lv.style_t()
|
||||
style_bg.init()
|
||||
style_bg.set_pad_all(0)
|
||||
style_bg.set_pad_gap(0)
|
||||
style_bg.set_clip_corner(True)
|
||||
style_bg.set_radius(lv.RADIUS.CIRCLE)
|
||||
style_bg.set_border_width(0)
|
||||
|
||||
|
||||
style_btn = lv.style_t()
|
||||
style_btn.init()
|
||||
style_btn.set_radius(0)
|
||||
style_btn.set_border_width(1)
|
||||
style_btn.set_border_opa(lv.OPA._50)
|
||||
style_btn.set_border_color(lv.palette_main(lv.PALETTE.GREY))
|
||||
style_btn.set_border_side(lv.BORDER_SIDE.INTERNAL)
|
||||
style_btn.set_radius(0)
|
||||
|
||||
map = [lv.SYMBOL.LEFT,"1","2", "3", "4", "5",lv.SYMBOL.RIGHT, ""]
|
||||
|
||||
btnm = lv.btnmatrix(lv.scr_act())
|
||||
btnm.set_map(map)
|
||||
btnm.add_style(style_bg, 0);
|
||||
btnm.add_style(style_btn, lv.PART.ITEMS)
|
||||
btnm.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
btnm.set_size(225, 35)
|
||||
|
||||
# Allow selecting on one number at time
|
||||
btnm.set_btn_ctrl_all(lv.btnmatrix.CTRL.CHECKABLE)
|
||||
btnm.clear_btn_ctrl(0, lv.btnmatrix.CTRL.CHECKABLE)
|
||||
btnm.clear_btn_ctrl(6, lv.btnmatrix.CTRL.CHECKABLE)
|
||||
|
||||
btnm.set_one_checked(True);
|
||||
btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECKED)
|
||||
|
||||
btnm.center()
|
||||
|
42
examples/widgets/calendar/lv_example_calendar_1.py
Normal file
42
examples/widgets/calendar/lv_example_calendar_1.py
Normal file
@ -0,0 +1,42 @@
|
||||
def event_handler(evt):
|
||||
code = evt.get_code()
|
||||
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
source = lv.calendar.__cast__(evt.get_target())
|
||||
date = lv.calendar_date_t()
|
||||
lv.calendar.get_pressed_date(source,date)
|
||||
if date:
|
||||
print("Clicked date: %02d.%02d.%02d"%(date.day, date.month, date.year))
|
||||
|
||||
|
||||
calendar = lv.calendar(lv.scr_act())
|
||||
calendar.set_size(200, 200)
|
||||
calendar.align(lv.ALIGN.CENTER, 0, 20)
|
||||
calendar.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
calendar.set_today_date(2021, 02, 23)
|
||||
calendar.set_showed_date(2021, 02)
|
||||
|
||||
# Highlight a few days
|
||||
highlighted_days=[]
|
||||
for i in range(3):
|
||||
highlighted_days.append(lv.calendar_date_t())
|
||||
|
||||
highlighted_days[0].year=2021
|
||||
highlighted_days[0].month=02
|
||||
highlighted_days[0].day=6
|
||||
|
||||
highlighted_days[1].year=2021
|
||||
highlighted_days[1].month=02
|
||||
highlighted_days[1].day=11
|
||||
|
||||
highlighted_days[2].year=2022
|
||||
highlighted_days[2].month=02
|
||||
highlighted_days[2].day=22
|
||||
|
||||
calendar.set_highlighted_dates(highlighted_days, 3)
|
||||
|
||||
header = lv.calendar_header_dropdown(lv.scr_act(),calendar)
|
||||
# header = lv.calendar_header_arrow(lv.scr_act(),calendar,25)
|
||||
|
||||
|
@ -1,38 +1,43 @@
|
||||
CANVAS_WIDTH = 200
|
||||
CANVAS_HEIGHT = 150
|
||||
_CANVAS_WIDTH = 200
|
||||
_CANVAS_HEIGHT = 150
|
||||
LV_IMG_ZOOM_NONE = 256
|
||||
|
||||
style = lv.style_t()
|
||||
lv.style_copy(style, lv.style_plain)
|
||||
style.body.main_color = lv.color_make(0xFF,0,0)
|
||||
style.body.grad_color = lv.color_make(0x80,0,0)
|
||||
style.body.radius = 4
|
||||
style.body.border.width = 2
|
||||
style.body.border.color = lv.color_make(0xFF,0xFF,0xFF)
|
||||
style.body.shadow.color = lv.color_make(0xFF,0xFF,0xFF)
|
||||
style.body.shadow.width = 4
|
||||
style.line.width = 2
|
||||
style.line.color = lv.color_make(0,0,0)
|
||||
style.text.color = lv.color_make(0,0,0xFF)
|
||||
rect_dsc = lv.draw_rect_dsc_t()
|
||||
rect_dsc.init()
|
||||
rect_dsc.radius = 10
|
||||
rect_dsc.bg_opa = lv.OPA.COVER
|
||||
rect_dsc.bg_grad_dir = lv.GRAD_DIR.HOR
|
||||
rect_dsc.bg_color = lv.palette_main(lv.PALETTE.RED)
|
||||
rect_dsc.bg_grad_color = lv.palette_main(lv.PALETTE.BLUE)
|
||||
rect_dsc.border_width = 2
|
||||
rect_dsc.border_opa = lv.OPA._90
|
||||
rect_dsc.border_color = lv.color_white()
|
||||
rect_dsc.shadow_width = 5
|
||||
rect_dsc.shadow_ofs_x = 5
|
||||
rect_dsc.shadow_ofs_y = 5
|
||||
|
||||
# CF.TRUE_COLOR requires 4 bytes per pixel
|
||||
cbuf = bytearray(CANVAS_WIDTH * CANVAS_HEIGHT * 4)
|
||||
label_dsc = lv.draw_label_dsc_t()
|
||||
label_dsc.init()
|
||||
label_dsc.color = lv.palette_main(lv.PALETTE.YELLOW)
|
||||
|
||||
cbuf = bytearray(_CANVAS_WIDTH * _CANVAS_HEIGHT * 4)
|
||||
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
canvas.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
canvas.fill_bg(lv.color_make(0xC0, 0xC0, 0xC0))
|
||||
canvas.set_buffer(cbuf, _CANVAS_WIDTH, _CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
canvas.center()
|
||||
canvas.fill_bg(lv.palette_lighten(lv.PALETTE.GREY, 3), lv.OPA.COVER)
|
||||
|
||||
canvas.draw_rect(70, 60, 100, 70, style)
|
||||
|
||||
canvas.draw_text(40, 20, 100, style, "Some text on text canvas", lv.label.ALIGN.LEFT)
|
||||
canvas.draw_rect(70, 60, 100, 70, rect_dsc)
|
||||
canvas.draw_text(40, 20, 100, label_dsc, "Some text on text canvas")
|
||||
|
||||
# Test the rotation. It requires an other buffer where the orignal image is stored.
|
||||
# So copy the current image to buffer and rotate it to the canvas
|
||||
|
||||
img = lv.img_dsc_t()
|
||||
img.data = cbuf[:]
|
||||
img.header.cf = lv.img.CF.TRUE_COLOR
|
||||
img.header.w = CANVAS_WIDTH
|
||||
img.header.h = CANVAS_HEIGHT
|
||||
img.header.w = _CANVAS_WIDTH
|
||||
img.header.h = _CANVAS_HEIGHT
|
||||
|
||||
canvas.fill_bg(lv.color_make(0xC0, 0xC0, 0xC0))
|
||||
canvas.rotate(img, 30, 0, 0, CANVAS_WIDTH // 2, CANVAS_HEIGHT // 2)
|
||||
canvas.fill_bg(lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER)
|
||||
canvas.transform(img, 30, LV_IMG_ZOOM_NONE, 0, 0, _CANVAS_WIDTH // 2, _CANVAS_HEIGHT // 2, True);
|
||||
|
@ -1,29 +1,31 @@
|
||||
CANVAS_WIDTH = 50
|
||||
CANVAS_HEIGHT = 50
|
||||
LV_COLOR_CHROMA_KEY = lv.color_hex(0x00ff00)
|
||||
|
||||
def LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h):
|
||||
return int(((w / 8) + 1) * h)
|
||||
|
||||
def LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h):
|
||||
return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2
|
||||
|
||||
def LV_CANVAS_BUF_SIZE_INDEXED_1BIT(w, h):
|
||||
return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h)
|
||||
|
||||
#
|
||||
# Create a transparent canvas with Chroma keying and indexed color format (palette).
|
||||
|
||||
CANVAS_WIDTH = 50
|
||||
CANVAS_HEIGHT = 50
|
||||
|
||||
def bufsize(w, h, bits, indexed=False):
|
||||
"""this function determines required buffer size
|
||||
depending on the color depth"""
|
||||
size = (w * bits // 8 + 1) * h
|
||||
if indexed:
|
||||
# + 4 bytes per palette color
|
||||
size += 4 * (2**bits)
|
||||
return size
|
||||
#
|
||||
|
||||
# Create a button to better see the transparency
|
||||
lv.btn(lv.scr_act())
|
||||
btn=lv.btn(lv.scr_act())
|
||||
|
||||
# Create a buffer for the canvas
|
||||
cbuf = bytearray(bufsize(CANVAS_WIDTH, CANVAS_HEIGHT, 1, indexed=True))
|
||||
cbuf= bytearray(LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT))
|
||||
|
||||
# Create a canvas and initialize its the palette
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.INDEXED_1BIT)
|
||||
# transparent color can be defined in lv_conf.h and set to pure green by default
|
||||
canvas.set_palette(0, lv.color_make(0x00, 0xFF, 0x00))
|
||||
canvas.set_palette(1, lv.color_make(0xFF, 0x00, 0x00))
|
||||
canvas.set_palette(0, LV_COLOR_CHROMA_KEY)
|
||||
canvas.set_palette(1, lv.palette_main(lv.PALETTE.RED))
|
||||
|
||||
# Create colors with the indices of the palette
|
||||
c0 = lv.color_t()
|
||||
@ -32,10 +34,10 @@ c1 = lv.color_t()
|
||||
c0.full = 0
|
||||
c1.full = 1
|
||||
|
||||
# Transparent background
|
||||
canvas.fill_bg(c1)
|
||||
# Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)
|
||||
canvas.fill_bg(c1, lv.OPA.COVER)
|
||||
|
||||
# Create hole on the canvas
|
||||
for y in range(10,30):
|
||||
for x in range(5, 20):
|
||||
for x in range(5,20):
|
||||
canvas.set_px(x, y, c0)
|
||||
|
@ -1,19 +1,26 @@
|
||||
# Create a chart
|
||||
chart = lv.chart(lv.scr_act())
|
||||
chart.set_size(200, 150)
|
||||
chart.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
chart.set_type(lv.chart.TYPE.POINT | lv.chart.TYPE.LINE) # Show lines and points too
|
||||
chart.set_series_opa(lv.OPA._70) # Opacity of the data series
|
||||
chart.set_series_width(4) # Line width and point radious
|
||||
|
||||
chart.set_range(0, 100)
|
||||
chart.center()
|
||||
chart.set_type(lv.chart.TYPE.LINE) # Show lines and points too
|
||||
|
||||
# Add two data series
|
||||
ser1 = chart.add_series(lv.color_make(0xFF,0,0))
|
||||
ser2 = chart.add_series(lv.color_make(0,0x80,0))
|
||||
ser1 = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y);
|
||||
ser2 = chart.add_series(lv.palette_main(lv.PALETTE.GREEN), lv.chart.AXIS.SECONDARY_Y)
|
||||
print(ser2)
|
||||
# Set next points on ser1
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,10)
|
||||
chart.set_next_value(ser1,30)
|
||||
chart.set_next_value(ser1,70)
|
||||
chart.set_next_value(ser1,90)
|
||||
|
||||
# Set points on 'dl1'
|
||||
chart.set_points(ser1, [10, 10, 10, 10, 10, 10, 10, 30, 70, 90])
|
||||
# Directly set points on 'ser2'
|
||||
ser2.y_points = [90, 70, 65, 65, 65, 65, 65, 65, 65, 65]
|
||||
chart.refresh() # Required after direct set
|
||||
|
||||
# Set points on 'dl2'
|
||||
chart.set_points(ser2, [90, 70, 65, 65, 65, 65, 65, 65, 65, 65])
|
77
examples/widgets/chart/lv_example_chart_2.py
Normal file
77
examples/widgets/chart/lv_example_chart_2.py
Normal file
@ -0,0 +1,77 @@
|
||||
def draw_event_cb(e):
|
||||
|
||||
obj = lv.obj.__cast__(e.get_target())
|
||||
|
||||
# Add the faded area before the lines are drawn
|
||||
dsc = lv.obj_draw_part_dsc_t.cast(e.get_param())
|
||||
if dsc.part != lv.PART.ITEMS:
|
||||
return
|
||||
if not dsc.p1 or not dsc.p2:
|
||||
return
|
||||
|
||||
# Add a line mask that keeps the area below the line
|
||||
line_mask_param = lv.draw_mask_line_param_t()
|
||||
line_mask_param.points_init(dsc.p1.x, dsc.p1.y, dsc.p2.x, dsc.p2.y, lv.DRAW_MASK_LINE_SIDE.BOTTOM)
|
||||
# line_mask_id = line_mask_param.draw_mask_add(None)
|
||||
line_mask_id = lv.draw_mask_add(line_mask_param, None)
|
||||
# Add a fade effect: transparent bottom covering top
|
||||
h = obj.get_height()
|
||||
fade_mask_param = lv.draw_mask_fade_param_t()
|
||||
coords = lv.area_t()
|
||||
obj.get_coords(coords)
|
||||
fade_mask_param.init(coords, lv.OPA.COVER, coords.y1 + h // 8, lv.OPA.TRANSP,coords.y2)
|
||||
fade_mask_id = lv.draw_mask_add(fade_mask_param,None)
|
||||
|
||||
# Draw a rectangle that will be affected by the mask
|
||||
draw_rect_dsc = lv.draw_rect_dsc_t()
|
||||
draw_rect_dsc.init()
|
||||
draw_rect_dsc.bg_opa = lv.OPA._20
|
||||
draw_rect_dsc.bg_color = dsc.line_dsc.color
|
||||
|
||||
a = lv.area_t()
|
||||
a.x1 = dsc.p1.x
|
||||
a.x2 = dsc.p2.x - 1
|
||||
a.y1 = min(dsc.p1.y, dsc.p2.y)
|
||||
coords = lv.area_t()
|
||||
obj.get_coords(coords)
|
||||
a.y2 = coords.y2
|
||||
lv.draw_rect(a, dsc.clip_area, draw_rect_dsc)
|
||||
|
||||
# Remove the masks
|
||||
lv.draw_mask_remove_id(line_mask_id)
|
||||
lv.draw_mask_remove_id(fade_mask_id)
|
||||
|
||||
|
||||
def add_data(timer):
|
||||
# LV_UNUSED(timer);
|
||||
cnt = 0;
|
||||
char1.set_next_value(ser1, lv.rand(20, 90))
|
||||
|
||||
if cnt % 4 == 0:
|
||||
chart1.set_next_value(ser2, lv_rand(40, 60))
|
||||
|
||||
cnt +=1
|
||||
|
||||
#
|
||||
# Add a faded area effect to the line chart
|
||||
#
|
||||
|
||||
# Create a chart1
|
||||
chart1 = lv.chart(lv.scr_act())
|
||||
chart1.set_size(200, 150)
|
||||
chart1.center()
|
||||
chart1.set_type(lv.chart.TYPE.LINE) # Show lines and points too
|
||||
|
||||
chart1.add_event_cb(draw_event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
|
||||
chart1.set_update_mode(lv.chart.UPDATE_MODE.CIRCULAR)
|
||||
|
||||
# Add two data series
|
||||
ser1 = chart1.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
||||
ser2 = chart1.add_series(lv.palette_main(lv.PALETTE.BLUE), lv.chart.AXIS.SECONDARY_Y)
|
||||
|
||||
for i in range(10):
|
||||
chart1.set_next_value(ser1, lv.rand(20, 90))
|
||||
chart1.set_next_value(ser2, lv.rand(30, 70))
|
||||
|
||||
# timer = lv.timer_t(add_data, 200, None)
|
||||
|
52
examples/widgets/chart/lv_example_chart_3.py
Normal file
52
examples/widgets/chart/lv_example_chart_3.py
Normal file
@ -0,0 +1,52 @@
|
||||
def draw_event_cb(e):
|
||||
|
||||
dsc = lv.obj_draw_part_dsc_t.cast(e.get_param())
|
||||
if dsc.part == lv.PART.TICKS and dsc.id == lv.chart.AXIS.PRIMARY_X:
|
||||
month = ["Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"]
|
||||
# dsc.text is defined char text[16], I must therefore convert the Python string to a byte_array
|
||||
dsc.text = bytes(month[dsc.value],"ascii")
|
||||
#
|
||||
# Add ticks and labels to the axis and demonstrate scrolling
|
||||
#
|
||||
|
||||
# Create a chart
|
||||
chart = lv.chart(lv.scr_act())
|
||||
chart.set_size(200, 150)
|
||||
chart.center()
|
||||
chart.set_type(lv.chart.TYPE.BAR)
|
||||
chart.set_range(lv.chart.AXIS.PRIMARY_Y, 0, 100)
|
||||
chart.set_range(lv.chart.AXIS.SECONDARY_Y, 0, 400)
|
||||
chart.set_point_count(12)
|
||||
chart.add_event_cb(draw_event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
|
||||
|
||||
# Add ticks and label to every axis
|
||||
chart.set_axis_tick(lv.chart.AXIS.PRIMARY_X, 10, 5, 12, 3, True, 40)
|
||||
chart.set_axis_tick(lv.chart.AXIS.PRIMARY_Y, 10, 5, 6, 2, True, 50)
|
||||
chart.set_axis_tick(lv.chart.AXIS.SECONDARY_Y, 10, 5, 3, 4,True, 50)
|
||||
|
||||
# Zoom in a little in X
|
||||
chart.set_zoom_x(800)
|
||||
|
||||
# Add two data series
|
||||
ser1 = lv.chart.add_series(chart, lv.palette_lighten(lv.PALETTE.GREEN, 2), lv.chart.AXIS.PRIMARY_Y);
|
||||
ser2 = lv.chart.add_series(chart, lv.palette_darken(lv.PALETTE.GREEN, 2), lv.chart.AXIS.SECONDARY_Y);
|
||||
|
||||
# Set the next points on 'ser1'
|
||||
chart.set_next_value(ser1, 31)
|
||||
chart.set_next_value(ser1, 66)
|
||||
chart.set_next_value(ser1, 10)
|
||||
chart.set_next_value(ser1, 89)
|
||||
chart.set_next_value(ser1, 63)
|
||||
chart.set_next_value(ser1, 56)
|
||||
chart.set_next_value(ser1, 32)
|
||||
chart.set_next_value(ser1, 35)
|
||||
chart.set_next_value(ser1, 57)
|
||||
chart.set_next_value(ser1, 85)
|
||||
chart.set_next_value(ser1, 22)
|
||||
chart.set_next_value(ser1, 58)
|
||||
|
||||
# Directly set points on 'ser2'
|
||||
ser2.y_points = [92,71,61,15,21,35,35,58,31,53,33,73]
|
||||
|
||||
chart.refresh() #Required after direct set
|
||||
|
73
examples/widgets/chart/lv_example_chart_4.py
Normal file
73
examples/widgets/chart/lv_example_chart_4.py
Normal file
@ -0,0 +1,73 @@
|
||||
def event_cb(e):
|
||||
code = e.get_code()
|
||||
chart = e.get_target()
|
||||
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
chart.invalidate()
|
||||
|
||||
if code == lv.EVENT.REFR_EXT_DRAW_SIZE:
|
||||
e.set_ext_draw_size(20)
|
||||
|
||||
elif code == lv.EVENT.DRAW_POST_END:
|
||||
id = lv.chart.get_pressed_point(chart)
|
||||
if id == lv.CHART_POINT.NONE:
|
||||
return
|
||||
# print("Selected point ", id)
|
||||
for i in range(len(series)):
|
||||
p = lv.point_t()
|
||||
chart.get_point_pos_by_id(series[i], id, p)
|
||||
value = series_points[i][id]
|
||||
buf = lv.SYMBOL.DUMMY + "$" + str(value)
|
||||
|
||||
draw_rect_dsc = lv.draw_rect_dsc_t()
|
||||
draw_rect_dsc.init()
|
||||
draw_rect_dsc.bg_color = lv.color_black()
|
||||
draw_rect_dsc.bg_opa = lv.OPA._50
|
||||
draw_rect_dsc.radius = 3
|
||||
draw_rect_dsc.bg_img_src = buf;
|
||||
draw_rect_dsc.bg_img_recolor = lv.color_white()
|
||||
|
||||
a = lv.area_t()
|
||||
coords = lv.area_t()
|
||||
chart.get_coords(coords)
|
||||
a.x1 = coords.x1 + p.x - 20
|
||||
a.x2 = coords.x1 + p.x + 20
|
||||
a.y1 = coords.y1 + p.y - 30
|
||||
a.y2 = coords.y1 + p.y - 10
|
||||
|
||||
clip_area = lv.area_t.cast(e.get_param())
|
||||
lv.draw_rect(a, clip_area, draw_rect_dsc)
|
||||
|
||||
elif code == lv.EVENT.RELEASED:
|
||||
chart.invalidate()
|
||||
|
||||
#
|
||||
# Add ticks and labels to the axis and demonstrate scrolling
|
||||
#
|
||||
|
||||
# Create a chart
|
||||
chart = lv.chart(lv.scr_act())
|
||||
chart.set_size(200, 150)
|
||||
chart.center()
|
||||
|
||||
chart.add_event_cb(event_cb, lv.EVENT.ALL, None)
|
||||
chart.refresh_ext_draw_size()
|
||||
|
||||
# Zoom in a little in X
|
||||
chart.set_zoom_x(800)
|
||||
|
||||
# Add two data series
|
||||
ser1 = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
||||
ser2 = chart.add_series(lv.palette_main(lv.PALETTE.GREEN), lv.chart.AXIS.PRIMARY_Y)
|
||||
|
||||
ser1_p = []
|
||||
ser2_p = []
|
||||
for i in range(10):
|
||||
ser1_p.append(lv.rand(60,90))
|
||||
ser2_p.append(lv.rand(10,40))
|
||||
ser1.y_points = ser1_p
|
||||
ser2.y_points = ser2_p
|
||||
|
||||
series = [ser1,ser2]
|
||||
series_points=[ser1_p,ser2_p]
|
||||
|
89
examples/widgets/chart/lv_example_chart_5.py
Normal file
89
examples/widgets/chart/lv_example_chart_5.py
Normal file
@ -0,0 +1,89 @@
|
||||
# Source: https://github.com/ankur219/ECG-Arrhythmia-classification/blob/642230149583adfae1e4bd26c6f0e1fd8af2be0e/sample.csv
|
||||
ecg_sample = [
|
||||
-2, 2, 0, -15, -39, -63, -71, -68, -67, -69, -84, -95, -104, -107, -108, -107, -107, -107, -107, -114, -118, -117,
|
||||
-112, -100, -89, -83, -71, -64, -58, -58, -62, -62, -58, -51, -46, -39, -27, -10, 4, 7, 1, -3, 0, 14, 24, 30, 25, 19,
|
||||
13, 7, 12, 15, 18, 21, 13, 6, 9, 8, 17, 19, 13, 11, 11, 11, 23, 30, 37, 34, 25, 14, 15, 19, 28, 31, 26, 23, 25, 31,
|
||||
39, 37, 37, 34, 30, 32, 22, 29, 31, 33, 37, 23, 13, 7, 2, 4, -2, 2, 11, 22, 33, 19, -1, -27, -55, -67, -72, -71, -63,
|
||||
-49, -18, 35, 113, 230, 369, 525, 651, 722, 730, 667, 563, 454, 357, 305, 288, 274, 255, 212, 173, 143, 117, 82, 39,
|
||||
-13, -53, -78, -91, -101, -113, -124, -131, -131, -131, -129, -128, -129, -125, -123, -123, -129, -139, -148, -153,
|
||||
-159, -166, -183, -205, -227, -243, -248, -246, -254, -280, -327, -381, -429, -473, -517, -556, -592, -612, -620,
|
||||
-620, -614, -604, -591, -574, -540, -497, -441, -389, -358, -336, -313, -284, -222, -167, -114, -70, -47, -28, -4, 12,
|
||||
38, 52, 58, 56, 56, 57, 68, 77, 86, 86, 80, 69, 67, 70, 82, 85, 89, 90, 89, 89, 88, 91, 96, 97, 91, 83, 78, 82, 88, 95,
|
||||
96, 105, 106, 110, 102, 100, 96, 98, 97, 101, 98, 99, 100, 107, 113, 119, 115, 110, 96, 85, 73, 64, 69, 76, 79,
|
||||
78, 75, 85, 100, 114, 113, 105, 96, 84, 74, 66, 60, 75, 85, 89, 83, 67, 61, 67, 73, 79, 74, 63, 57, 56, 58, 61, 55,
|
||||
48, 45, 46, 55, 62, 55, 49, 43, 50, 59, 63, 57, 40, 31, 23, 25, 27, 31, 35, 34, 30, 36, 34, 42, 38, 36, 40, 46, 50,
|
||||
47, 32, 30, 32, 52, 67, 73, 71, 63, 54, 53, 45, 41, 28, 13, 3, 1, 4, 4, -8, -23, -32, -31, -19, -5, 3, 9, 13, 19,
|
||||
24, 27, 29, 25, 22, 26, 32, 42, 51, 56, 60, 57, 55, 53, 53, 54, 59, 54, 49, 26, -3, -11, -20, -47, -100, -194, -236,
|
||||
-212, -123, 8, 103, 142, 147, 120, 105, 98, 93, 81, 61, 40, 26, 28, 30, 30, 27, 19, 17, 21, 20, 19, 19, 22, 36, 40,
|
||||
35, 20, 7, 1, 10, 18, 27, 22, 6, -4, -2, 3, 6, -2, -13, -14, -10, -2, 3, 2, -1, -5, -10, -19, -32, -42, -55, -60,
|
||||
-68, -77, -86, -101, -110, -117, -115, -104, -92, -84, -85, -84, -73, -65, -52, -50, -45, -35, -20, -3, 12, 20, 25,
|
||||
26, 28, 28, 30, 28, 25, 28, 33, 42, 42, 36, 23, 9, 0, 1, -4, 1, -4, -4, 1, 5, 9, 9, -3, -1, -18, -50, -108, -190,
|
||||
-272, -340, -408, -446, -537, -643, -777, -894, -920, -853, -697, -461, -251, -60, 58, 103, 129, 139, 155, 170, 173,
|
||||
178, 185, 190, 193, 200, 208, 215, 225, 224, 232, 234, 240, 240, 236, 229, 226, 224, 232, 233, 232, 224, 219, 219,
|
||||
223, 231, 226, 223, 219, 218, 223, 223, 223, 233, 245, 268, 286, 296, 295, 283, 271, 263, 252, 243, 226, 210, 197,
|
||||
186, 171, 152, 133, 117, 114, 110, 107, 96, 80, 63, 48, 40, 38, 34, 28, 15, 2, -7, -11, -14, -18, -29, -37, -44, -50,
|
||||
-58, -63, -61, -52, -50, -48, -61, -59, -58, -54, -47, -52, -62, -61, -64, -54, -52, -59, -69, -76, -76, -69, -67,
|
||||
-74, -78, -81, -80, -73, -65, -57, -53, -51, -47, -35, -27, -22, -22, -24, -21, -17, -13, -10, -11, -13, -20, -20,
|
||||
-12, -2, 7, -1, -12, -16, -13, -2, 2, -4, -5, -2, 9, 19, 19, 14, 11, 13, 19, 21, 20, 18, 19, 19, 19, 16, 15, 13, 14,
|
||||
9, 3, -5, -9, -5, -3, -2, -3, -3, 2, 8, 9, 9, 5, 6, 8, 8, 7, 4, 3, 4, 5, 3, 5, 5, 13, 13, 12, 10, 10, 15, 22, 17,
|
||||
14, 7, 10, 15, 16, 11, 12, 10, 13, 9, -2, -4, -2, 7, 16, 16, 17, 16, 7, -1, -16, -18, -16, -9, -4, -5, -10, -9, -8,
|
||||
-3, -4, -10, -19, -20, -16, -9, -9, -23, -40, -48, -43, -33, -19, -21, -26, -31, -33, -19, 0, 17, 24, 9, -17, -47,
|
||||
-63, -67, -59, -52, -51, -50, -49, -42, -26, -21, -15, -20, -23, -22, -19, -12, -8, 5, 18, 27, 32, 26, 25, 26, 22,
|
||||
23, 17, 14, 17, 21, 25, 2, -45, -121, -196, -226, -200, -118, -9, 73, 126, 131, 114, 87, 60, 42, 29, 26, 34, 35, 34,
|
||||
25, 12, 9, 7, 3, 2, -8, -11, 2, 23, 38, 41, 23, 9, 10, 13, 16, 8, -8, -17, -23, -26, -25, -21, -15, -10, -13, -13,
|
||||
-19, -22, -29, -40, -48, -48, -54, -55, -66, -82, -85, -90, -92, -98, -114, -119, -124, -129, -132, -146, -146, -138,
|
||||
-124, -99, -85, -72, -65, -65, -65, -66, -63, -64, -64, -58, -46, -26, -9, 2, 2, 4, 0, 1, 4, 3, 10, 11, 10, 2, -4,
|
||||
0, 10, 18, 20, 6, 2, -9, -7, -3, -3, -2, -7, -12, -5, 5, 24, 36, 31, 25, 6, 3, 7, 12, 17, 11, 0, -6, -9, -8, -7, -5,
|
||||
-6, -2, -2, -6, -2, 2, 14, 24, 22, 15, 8, 4, 6, 7, 12, 16, 25, 20, 7, -16, -41, -60, -67, -65, -54, -35, -11, 30,
|
||||
84, 175, 302, 455, 603, 707, 743, 714, 625, 519, 414, 337, 300, 281, 263, 239, 197, 163, 136, 109, 77, 34, -18, -50,
|
||||
-66, -74, -79, -92, -107, -117, -127, -129, -135, -139, -141, -155, -159, -167, -171, -169, -174, -175, -178, -191,
|
||||
-202, -223, -235, -243, -237, -240, -256, -298, -345, -393, -432, -475, -518, -565, -596, -619, -623, -623, -614,
|
||||
-599, -583, -559, -524, -477, -425, -383, -357, -331, -301, -252, -198, -143, -96, -57, -29, -8, 10, 31, 45, 60, 65,
|
||||
70, 74, 76, 79, 82, 79, 75, 62,
|
||||
]
|
||||
|
||||
def slider_x_event_cb(e):
|
||||
|
||||
slider = lv.slider.__cast__(e.get_target())
|
||||
v = slider.get_value()
|
||||
chart.set_zoom_x(v)
|
||||
|
||||
def slider_y_event_cb(e):
|
||||
|
||||
slider = lv.slider.__cast__(e.get_target())
|
||||
v = slider.get_value()
|
||||
chart.set_zoom_y(v)
|
||||
|
||||
|
||||
#
|
||||
# Display 1000 data points with zooming and scrolling.
|
||||
# See how the chart changes drawing mode (draw only vertical lines) when
|
||||
# the points get too crowded.
|
||||
|
||||
# Create a chart
|
||||
chart = lv.chart(lv.scr_act())
|
||||
chart.set_size(200, 150)
|
||||
chart.align(lv.ALIGN.CENTER, -30, -30)
|
||||
chart.set_range(lv.chart.AXIS.PRIMARY_Y, -1000, 1000)
|
||||
|
||||
# Do not display points on the data
|
||||
chart.set_style_size(0, lv.PART.INDICATOR)
|
||||
|
||||
ser = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
||||
|
||||
pcnt = len(ecg_sample)
|
||||
chart.set_point_count(pcnt)
|
||||
chart.set_ext_y_array(ser, ecg_sample)
|
||||
|
||||
slider = lv.slider(lv.scr_act())
|
||||
slider.set_range(lv.IMG_ZOOM.NONE, lv.IMG_ZOOM.NONE * 10)
|
||||
slider.add_event_cb(slider_x_event_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
slider.set_size(200,10)
|
||||
slider.align_to(chart, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
|
||||
|
||||
slider = lv.slider(lv.scr_act())
|
||||
slider.set_range(lv.IMG_ZOOM.NONE, lv.IMG_ZOOM.NONE * 10)
|
||||
slider.add_event_cb(slider_y_event_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
slider.set_size(10, 150)
|
||||
slider.align_to(chart, lv.ALIGN.OUT_RIGHT_MID, 20, 0)
|
||||
|
88
examples/widgets/chart/lv_example_chart_6.py
Normal file
88
examples/widgets/chart/lv_example_chart_6.py
Normal file
@ -0,0 +1,88 @@
|
||||
class ExampleChart_6():
|
||||
|
||||
def __init__(self):
|
||||
self.last_id = -1
|
||||
#
|
||||
# Show cursor on the clicked point
|
||||
#
|
||||
|
||||
chart = lv.chart(lv.scr_act())
|
||||
chart.set_size(200, 150)
|
||||
chart.align(lv.ALIGN.CENTER, 0, -10)
|
||||
|
||||
chart.set_axis_tick(lv.chart.AXIS.PRIMARY_Y, 10, 5, 6, 5, True, 40)
|
||||
chart.set_axis_tick(lv.chart.AXIS.PRIMARY_X, 10, 5, 10, 1, True, 30)
|
||||
|
||||
chart.add_event_cb(self.event_cb, lv.EVENT.ALL, None)
|
||||
chart.refresh_ext_draw_size()
|
||||
|
||||
self.cursor = chart.add_cursor(lv.palette_main(lv.PALETTE.BLUE), lv.DIR.LEFT | lv.DIR.BOTTOM)
|
||||
|
||||
self.ser = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
||||
|
||||
self.ser_p = []
|
||||
for i in range(10):
|
||||
self.ser_p.append(lv.rand(10,90))
|
||||
self.ser.y_points = self.ser_p
|
||||
|
||||
newser = chart.get_series_next(None)
|
||||
# print("length of data points: ",len(newser.points))
|
||||
chart.set_zoom_x(500)
|
||||
|
||||
label = lv.label(lv.scr_act())
|
||||
label.set_text("Click on a point")
|
||||
label.align_to(chart, lv.ALIGN.OUT_TOP_MID, 0, -5)
|
||||
|
||||
|
||||
def event_cb(self,e):
|
||||
|
||||
code = e.get_code()
|
||||
chart = lv.chart.__cast__(e.get_target())
|
||||
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
# print("last_id: ",self.last_id)
|
||||
self.last_id = chart.get_pressed_point()
|
||||
if self.last_id != lv.CHART_POINT.NONE:
|
||||
p = lv.point_t()
|
||||
chart.get_point_pos_by_id(self.ser, self.last_id, p)
|
||||
chart.set_cursor_point(self.cursor, None, self.last_id)
|
||||
|
||||
elif code == lv.EVENT.DRAW_PART_END:
|
||||
# print("EVENT.DRAW_PART_END")
|
||||
dsc = lv.obj_draw_part_dsc_t.cast(e.get_param())
|
||||
# if dsc.p1 and dsc.p2:
|
||||
# print("p1, p2", dsc.p1,dsc.p2)
|
||||
# print("p1.y, p2.y", dsc.p1.y, dsc.p2.y)
|
||||
# print("last_id: ",self.last_id)
|
||||
if dsc.part == lv.PART.CURSOR and dsc.p1 and dsc.p2 and dsc.p1.y == dsc.p2.y and self.last_id >= 0:
|
||||
|
||||
v = self.ser_p[self.last_id];
|
||||
|
||||
# print("value: ",v)
|
||||
value_txt = str(v)
|
||||
size = lv.point_t()
|
||||
lv.txt_get_size(size, value_txt, lv.font_default(), 0, 0, lv.COORD.MAX, lv.TEXT_FLAG.NONE)
|
||||
|
||||
a = lv.area_t()
|
||||
a.y2 = dsc.p1.y - 5
|
||||
a.y1 = a.y2 - size.y - 10
|
||||
a.x1 = dsc.p1.x + 10;
|
||||
a.x2 = a.x1 + size.x + 10;
|
||||
|
||||
draw_rect_dsc = lv.draw_rect_dsc_t()
|
||||
draw_rect_dsc.init()
|
||||
draw_rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE)
|
||||
draw_rect_dsc.radius = 3;
|
||||
|
||||
lv.draw_rect(a, dsc.clip_area, draw_rect_dsc)
|
||||
|
||||
draw_label_dsc = lv.draw_label_dsc_t()
|
||||
draw_label_dsc.init()
|
||||
draw_label_dsc.color = lv.color_white()
|
||||
a.x1 += 5
|
||||
a.x2 -= 5
|
||||
a.y1 += 5
|
||||
a.y2 -= 5
|
||||
lv.draw_label(a, dsc.clip_area, draw_label_dsc, value_txt, None)
|
||||
|
||||
example_chart_6 = ExampleChart_6()
|
77
examples/widgets/chart/lv_example_chart_7.py
Normal file
77
examples/widgets/chart/lv_example_chart_7.py
Normal file
@ -0,0 +1,77 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import time
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
|
||||
def draw_event_cb(e):
|
||||
dsc = e.get_draw_part_dsc()
|
||||
if dsc.part == lv.PART.ITEMS:
|
||||
obj = e.get_target()
|
||||
ser = obj.get_series_next(None)
|
||||
cnt = obj.get_point_count()
|
||||
# print("cnt: ",cnt)
|
||||
# Make older value more transparent
|
||||
dsc.rect_dsc.bg_opa = (lv.OPA.COVER * dsc.id) // (cnt - 1)
|
||||
|
||||
# Make smaller values blue, higher values red
|
||||
# x_array = chart.get_x_array(ser)
|
||||
# y_array = chart.get_y_array(ser)
|
||||
# dsc->id is the tells drawing order, but we need the ID of the point being drawn.
|
||||
start_point = chart.get_x_start_point(ser)
|
||||
# print("start point: ",start_point)
|
||||
p_act = (start_point + dsc.id) % cnt # Consider start point to get the index of the array
|
||||
# print("p_act", p_act)
|
||||
x_opa = (x_array[p_act] * lv.OPA._50) // 200
|
||||
y_opa = (y_array[p_act] * lv.OPA._50) // 1000
|
||||
|
||||
dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.RED).color_mix(
|
||||
lv.palette_main(lv.PALETTE.BLUE),
|
||||
x_opa + y_opa)
|
||||
|
||||
def add_data(timer,chart):
|
||||
# print("add_data")
|
||||
x = lv.rand(0,200)
|
||||
y = lv.rand(0,1000)
|
||||
chart.set_next_value2(ser, x, y)
|
||||
# chart.set_next_value2(chart.gx, y)
|
||||
x_array.pop(0)
|
||||
x_array.append(x)
|
||||
y_array.pop(0)
|
||||
y_array.append(y)
|
||||
|
||||
#
|
||||
# A scatter chart
|
||||
#
|
||||
|
||||
chart = lv.chart(lv.scr_act())
|
||||
chart.set_size(200, 150)
|
||||
chart.align(lv.ALIGN.CENTER, 0, 0)
|
||||
chart.add_event_cb(draw_event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
|
||||
chart.set_style_line_width(0, lv.PART.ITEMS) # Remove the lines
|
||||
|
||||
chart.set_type(lv.chart.TYPE.SCATTER)
|
||||
|
||||
chart.set_axis_tick(lv.chart.AXIS.PRIMARY_X, 5, 5, 5, 1, True, 30)
|
||||
chart.set_axis_tick(lv.chart.AXIS.PRIMARY_Y, 10, 5, 6, 5, True, 50)
|
||||
|
||||
chart.set_range(lv.chart.AXIS.PRIMARY_X, 0, 200)
|
||||
chart.set_range(lv.chart.AXIS.PRIMARY_Y, 0, 1000)
|
||||
|
||||
chart.set_point_count(50)
|
||||
|
||||
ser = chart.add_series(lv.palette_main(lv.PALETTE.RED), lv.chart.AXIS.PRIMARY_Y)
|
||||
|
||||
x_array = []
|
||||
y_array = []
|
||||
for i in range(50):
|
||||
x_array.append(lv.rand(0, 200))
|
||||
y_array.append(lv.rand(0, 1000))
|
||||
|
||||
ser.x_points = x_array
|
||||
ser.y_points = y_array
|
||||
|
||||
# Create an `lv_timer` to update the chart.
|
||||
|
||||
timer = lv.timer_create_basic()
|
||||
timer.set_period(100)
|
||||
timer.set_cb(lambda src: add_data(timer,chart))
|
@ -1,8 +1,36 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
print("State: %s" % ("Checked" if obj.is_checked() else "Unchecked"))
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = lv.checkbox.__cast__(e.get_target())
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
txt = obj.get_text()
|
||||
if obj.get_state() & lv.STATE.CHECKED:
|
||||
state = "Checked"
|
||||
else:
|
||||
state = "Unchecked";
|
||||
print(txt + ":" + state)
|
||||
|
||||
|
||||
lv.scr_act().set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
lv.scr_act().set_flex_align(lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER)
|
||||
|
||||
cb = lv.checkbox(lv.scr_act())
|
||||
cb.set_text("Apple")
|
||||
cb.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
cb = lv.checkbox(lv.scr_act())
|
||||
cb.set_text("Banana")
|
||||
cb.add_state(lv.STATE.CHECKED)
|
||||
cb.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
cb = lv.checkbox(lv.scr_act())
|
||||
cb.set_text("Lemon")
|
||||
cb.add_state(lv.STATE.DISABLED)
|
||||
cb.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
cb = lv.checkbox(lv.scr_act())
|
||||
cb.add_state(lv.STATE.CHECKED | lv.STATE.DISABLED)
|
||||
cb.set_text("Melon")
|
||||
cb.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
cb.update_layout()
|
||||
|
||||
cb = lv.cb(lv.scr_act())
|
||||
cb.set_text("I agree to terms and conditions.")
|
||||
cb.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
cb.set_event_cb(event_handler)
|
4
examples/widgets/colorwheel/lv_example_colorwheel_1.py
Normal file
4
examples/widgets/colorwheel/lv_example_colorwheel_1.py
Normal file
@ -0,0 +1,4 @@
|
||||
cw = lv.colorwheel(lv.scr_act(), True)
|
||||
cw.set_size(200, 200)
|
||||
cw.center()
|
||||
|
@ -1,21 +1,26 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = lv.dropdown.__cast__(e.get_target())
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
option = " "*10 # should be large enough to store the option
|
||||
obj.get_selected_str(option, len(option))
|
||||
# .strip() removes trailing spaces
|
||||
print("Option: \"%s\"" % option.strip())
|
||||
|
||||
# Create a drop down list
|
||||
ddlist = lv.ddlist(lv.scr_act())
|
||||
ddlist.set_options("\n".join([
|
||||
"Apple",
|
||||
"Banana",
|
||||
"Orange",
|
||||
"Melon",
|
||||
"Grape",
|
||||
"Raspberry"]))
|
||||
# Create a normal drop down list
|
||||
dd = lv.dropdown(lv.scr_act())
|
||||
dd.set_options("\n".join([
|
||||
"Apple\n"
|
||||
"Banana\n"
|
||||
"Orange\n"
|
||||
"Cherry\n"
|
||||
"Grape\n"
|
||||
"Raspberry\n"
|
||||
"Melon\n"
|
||||
"Orange\n"
|
||||
"Lemon\n"
|
||||
"Nuts\n"]))
|
||||
|
||||
dd.align(lv.ALIGN.TOP_MID, 0, 20)
|
||||
dd.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
ddlist.set_fix_width(150)
|
||||
ddlist.set_draw_arrow(True)
|
||||
ddlist.align(None, lv.ALIGN.IN_TOP_MID, 0, 20)
|
||||
ddlist.set_event_cb(event_handler)
|
@ -1,23 +1,34 @@
|
||||
# Create a drop UP list by applying auto realign
|
||||
#
|
||||
# Create a drop down, up, left and right menus
|
||||
#
|
||||
|
||||
# Create a drop down list
|
||||
ddlist = lv.ddlist(lv.scr_act())
|
||||
ddlist.set_options("\n".join([
|
||||
"Apple",
|
||||
"Banana",
|
||||
"Orange",
|
||||
"Melon",
|
||||
"Grape",
|
||||
"Raspberry"]))
|
||||
opts = "\n".join([
|
||||
"Apple\n"
|
||||
"Banana\n"
|
||||
"Orange\n"
|
||||
"Melon\n"
|
||||
"Grape\n"
|
||||
"Raspberry"])
|
||||
|
||||
dd = lv.dropdown(lv.scr_act())
|
||||
dd.set_options_static(opts)
|
||||
dd.align(lv.ALIGN.TOP_MID, 0, 10)
|
||||
dd = lv.dropdown(lv.scr_act())
|
||||
dd.set_options_static(opts)
|
||||
dd.set_dir(lv.DIR.BOTTOM)
|
||||
dd.set_symbol(lv.SYMBOL.UP)
|
||||
dd.align(lv.ALIGN.BOTTOM_MID, 0, -10)
|
||||
|
||||
dd = lv.dropdown(lv.scr_act())
|
||||
dd.set_options_static(opts)
|
||||
dd.set_dir(lv.DIR.RIGHT)
|
||||
dd.set_symbol(lv.SYMBOL.RIGHT)
|
||||
dd.align(lv.ALIGN.LEFT_MID, 10, 0)
|
||||
|
||||
dd = lv.dropdown(lv.scr_act())
|
||||
dd.set_options_static(opts)
|
||||
dd.set_dir(lv.DIR.LEFT)
|
||||
dd.set_symbol(lv.SYMBOL.LEFT)
|
||||
dd.align(lv.ALIGN.RIGHT_MID, -10, 0)
|
||||
|
||||
|
||||
ddlist.set_fix_width(150)
|
||||
ddlist.set_fix_height(150)
|
||||
ddlist.set_draw_arrow(True)
|
||||
|
||||
# Enable auto-realign when the size changes.
|
||||
# It will keep the bottom of the ddlist fixed
|
||||
ddlist.set_auto_realign(True)
|
||||
|
||||
# It will be called automatically when the size changes
|
||||
ddlist.align(None, lv.ALIGN.IN_BOTTOM_MID, 0, -20)
|
||||
|
53
examples/widgets/dropdown/lv_example_dropdown_3.py
Normal file
53
examples/widgets/dropdown/lv_example_dropdown_3.py
Normal file
@ -0,0 +1,53 @@
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_caret_down.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_caret_down.png")
|
||||
sys.exit()
|
||||
|
||||
img_caret_down_argb = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
def event_cb(e):
|
||||
dropdown = lv.dropdown.__cast__(e.get_target())
|
||||
option = " "*64 # should be large enough to store the option
|
||||
dropdown.get_selected_str(option, len(option))
|
||||
print(option.strip() +" is selected")
|
||||
#
|
||||
# Create a menu from a drop-down list and show some drop-down list features and styling
|
||||
#
|
||||
|
||||
# Create a drop down list
|
||||
dropdown = lv.dropdown(lv.scr_act())
|
||||
dropdown.align(lv.ALIGN.TOP_LEFT, 10, 10)
|
||||
dropdown.set_options("".join([
|
||||
"New project\n",
|
||||
"New file\n",
|
||||
"Open project\n",
|
||||
"Recent projects\n",
|
||||
"Preferences\n",
|
||||
"Exit"]))
|
||||
|
||||
# Set a fixed text to display on the button of the drop-down list
|
||||
dropdown.set_text("Menu")
|
||||
|
||||
# Use a custom image as down icon and flip it when the list is opened
|
||||
# LV_IMG_DECLARE(img_caret_down)
|
||||
dropdown.set_symbol(img_caret_down_argb)
|
||||
dropdown.set_style_transform_angle(1800, lv.STATE.CHECKED)
|
||||
|
||||
# In a menu we don't need to show the last clicked item
|
||||
dropdown.set_selected_highlight(False)
|
||||
|
||||
dropdown.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
|
@ -1,3 +1,7 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import sys
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
@ -5,25 +9,24 @@ decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create a screen with a draggable image
|
||||
|
||||
with open('cogwheel.png','rb') as f:
|
||||
png_data = f.read()
|
||||
|
||||
png_img_dsc = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_cogwheel_argb.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_cogwheel_argb.png")
|
||||
sys.exit()
|
||||
|
||||
img_cogwheel_argb = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
scr = lv.scr_act()
|
||||
img1 = lv.img(lv.scr_act())
|
||||
img1.set_src(img_cogwheel_argb)
|
||||
img1.align(lv.ALIGN.CENTER, 0, -20)
|
||||
img1.set_size(200, 200)
|
||||
|
||||
# Create an image on the left using the decoder
|
||||
|
||||
# lv.img.cache_set_size(2)
|
||||
img1 = lv.img(scr)
|
||||
img1.align(scr, lv.ALIGN.CENTER, 0, -20)
|
||||
img1.set_src(png_img_dsc)
|
||||
|
||||
img2 = lv.img(scr)
|
||||
img2 = lv.img(lv.scr_act())
|
||||
img2.set_src(lv.SYMBOL.OK + "Accept")
|
||||
img2.align(img1, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
|
||||
img2.align_to(img1, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
|
||||
|
70
examples/widgets/img/lv_example_img_2.py
Normal file
70
examples/widgets/img/lv_example_img_2.py
Normal file
@ -0,0 +1,70 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import sys
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_cogwheel_argb.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_cogwheel_argb.png")
|
||||
sys.exit()
|
||||
|
||||
img_cogwheel_argb = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
def create_slider(color):
|
||||
slider = lv.slider(lv.scr_act())
|
||||
slider.set_range(0, 255)
|
||||
slider.set_size(10, 200);
|
||||
slider.set_style_bg_color(color, lv.PART.KNOB);
|
||||
slider.set_style_bg_color(color.color_darken(lv.OPA._40), lv.PART.INDICATOR)
|
||||
slider.add_event_cb(slider_event_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
return slider
|
||||
|
||||
def slider_event_cb(e):
|
||||
# Recolor the image based on the sliders' values
|
||||
color = lv.color_make(red_slider.get_value(), green_slider.get_value(), blue_slider.get_value())
|
||||
intense = intense_slider.get_value()
|
||||
img1.set_style_img_recolor_opa(intense, 0)
|
||||
img1.set_style_img_recolor(color, 0)
|
||||
|
||||
#
|
||||
# Demonstrate runtime image re-coloring
|
||||
#
|
||||
# Create 4 sliders to adjust RGB color and re-color intensity
|
||||
red_slider = create_slider(lv.palette_main(lv.PALETTE.RED))
|
||||
green_slider = create_slider(lv.palette_main(lv.PALETTE.GREEN))
|
||||
blue_slider = create_slider(lv.palette_main(lv.PALETTE.BLUE))
|
||||
intense_slider = create_slider(lv.palette_main(lv.PALETTE.GREY))
|
||||
|
||||
red_slider.set_value(lv.OPA._20, lv.ANIM.OFF)
|
||||
green_slider.set_value(lv.OPA._90, lv.ANIM.OFF)
|
||||
blue_slider.set_value(lv.OPA._60, lv.ANIM.OFF)
|
||||
intense_slider.set_value(lv.OPA._50, lv.ANIM.OFF)
|
||||
|
||||
red_slider.align(lv.ALIGN.LEFT_MID, 25, 0)
|
||||
green_slider.align_to(red_slider, lv.ALIGN.OUT_RIGHT_MID, 25, 0)
|
||||
blue_slider.align_to(green_slider, lv.ALIGN.OUT_RIGHT_MID, 25, 0)
|
||||
intense_slider.align_to(blue_slider, lv.ALIGN.OUT_RIGHT_MID, 25, 0)
|
||||
|
||||
# Now create the actual image
|
||||
img1 = lv.img(lv.scr_act())
|
||||
img1.set_src(img_cogwheel_argb)
|
||||
img1.align(lv.ALIGN.RIGHT_MID, -20, 0)
|
||||
|
||||
lv.event_send(intense_slider, lv.EVENT.VALUE_CHANGED, None)
|
||||
|
||||
|
||||
|
||||
|
||||
|
61
examples/widgets/img/lv_example_img_3.py
Normal file
61
examples/widgets/img/lv_example_img_3.py
Normal file
@ -0,0 +1,61 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import sys
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_cogwheel_argb.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_cogwheel_argb.png")
|
||||
sys.exit()
|
||||
|
||||
img_cogwheel_argb = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
def set_angle(img, v):
|
||||
img.set_angle(v)
|
||||
|
||||
def set_zoom(img, v):
|
||||
img.set_zoom(v)
|
||||
|
||||
|
||||
#
|
||||
# Show transformations (zoom and rotation) using a pivot point.
|
||||
#
|
||||
|
||||
# Now create the actual image
|
||||
img = lv.img(lv.scr_act())
|
||||
img.set_src(img_cogwheel_argb)
|
||||
img.align(lv.ALIGN.CENTER, 50, 50)
|
||||
img.set_pivot(0, 0) # Rotate around the top left corner
|
||||
|
||||
a1 = lv.anim_t()
|
||||
a1.init()
|
||||
a1.set_var(img)
|
||||
a1.set_custom_exec_cb(lambda a,val: set_angle(img,val))
|
||||
a1.set_values(0, 3600)
|
||||
a1.set_time(5000)
|
||||
a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
lv.anim_t.start(a1)
|
||||
|
||||
a2 = lv.anim_t()
|
||||
a2.init()
|
||||
a2.set_var(img)
|
||||
a2.set_custom_exec_cb(lambda a,val: set_zoom(img,val))
|
||||
a2.set_values(128, 256)
|
||||
a2.set_time(5000)
|
||||
a2.set_playback_time(3000)
|
||||
a2.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
|
||||
lv.anim_t.start(a2)
|
||||
|
||||
|
51
examples/widgets/img/lv_example_img_4.py
Normal file
51
examples/widgets/img/lv_example_img_4.py
Normal file
@ -0,0 +1,51 @@
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
def ofs_y_anim(img, v):
|
||||
img.set_offset_y(v)
|
||||
# print(img,v)
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_skew_strip.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_skew_strip.png")
|
||||
sys.exit()
|
||||
|
||||
img_skew_strip = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
#
|
||||
# Image styling and offset
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_bg_color(lv.palette_main(lv.PALETTE.YELLOW))
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_img_recolor_opa(lv.OPA.COVER)
|
||||
style.set_img_recolor(lv.color_black())
|
||||
|
||||
img = lv.img(lv.scr_act())
|
||||
img.add_style(style, 0)
|
||||
img.set_src(img_skew_strip)
|
||||
img.set_size(150, 100)
|
||||
img.center()
|
||||
|
||||
a = lv.anim_t()
|
||||
a.init()
|
||||
a.set_var(img)
|
||||
a.set_values(0, 100)
|
||||
a.set_time(3000)
|
||||
a.set_playback_time(500)
|
||||
a.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a.set_custom_exec_cb(lambda a,val: ofs_y_anim(img,val))
|
||||
lv.anim_t.start(a)
|
||||
|
74
examples/widgets/imgbtn/lv_example_imgbtn_1.py
Normal file
74
examples/widgets/imgbtn/lv_example_imgbtn_1.py
Normal file
@ -0,0 +1,74 @@
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/imgbtn_left.png','rb') as f:
|
||||
imgbtn_left_data = f.read()
|
||||
except:
|
||||
print("Could not find imgbtn_left.png")
|
||||
sys.exit()
|
||||
|
||||
imgbtn_left_dsc = lv.img_dsc_t({
|
||||
'data_size': len(imgbtn_left_data),
|
||||
'data': imgbtn_left_data
|
||||
})
|
||||
|
||||
try:
|
||||
with open('../../assets/imgbtn_mid.png','rb') as f:
|
||||
imgbtn_mid_data = f.read()
|
||||
except:
|
||||
print("Could not find imgbtn_mid.png")
|
||||
sys.exit()
|
||||
|
||||
imgbtn_mid_dsc = lv.img_dsc_t({
|
||||
'data_size': len(imgbtn_mid_data),
|
||||
'data': imgbtn_mid_data
|
||||
})
|
||||
|
||||
try:
|
||||
with open('../../assets/imgbtn_right.png','rb') as f:
|
||||
imgbtn_right_data = f.read()
|
||||
except:
|
||||
print("Could not find imgbtn_right.png")
|
||||
sys.exit()
|
||||
|
||||
imgbtn_right_dsc = lv.img_dsc_t({
|
||||
'data_size': len(imgbtn_right_data),
|
||||
'data': imgbtn_right_data
|
||||
})
|
||||
|
||||
# Create a transition animation on width transformation and recolor.
|
||||
tr_prop = [lv.STYLE.TRANSFORM_WIDTH, lv.STYLE.IMG_RECOLOR_OPA, 0]
|
||||
tr = lv.style_transition_dsc_t()
|
||||
tr.init(tr_prop, lv.anim_t.path_linear, 200, 0, None)
|
||||
|
||||
style_def = lv.style_t()
|
||||
style_def.init()
|
||||
style_def.set_text_color(lv.color_white())
|
||||
style_def.set_transition(tr)
|
||||
|
||||
# Darken the button when pressed and make it wider
|
||||
style_pr = lv.style_t()
|
||||
style_pr.init()
|
||||
style_pr.set_img_recolor_opa(lv.OPA._30)
|
||||
style_pr.set_img_recolor(lv.color_black())
|
||||
style_pr.set_transform_width(20)
|
||||
|
||||
# Create an image button
|
||||
imgbtn1 = lv.imgbtn(lv.scr_act())
|
||||
imgbtn1.set_src(lv.imgbtn.STATE.RELEASED, imgbtn_left_dsc, imgbtn_mid_dsc, imgbtn_right_dsc)
|
||||
imgbtn1.add_style(style_def, 0)
|
||||
imgbtn1.add_style(style_pr, lv.STATE.PRESSED)
|
||||
|
||||
imgbtn1.align(lv.ALIGN.CENTER, 0, 0)
|
||||
|
||||
# Create a label on the image button
|
||||
label = lv.label(imgbtn1)
|
||||
label.set_text("Button");
|
||||
label.align(lv.ALIGN.CENTER, 0, -4)
|
||||
|
@ -1,26 +1,28 @@
|
||||
# Create styles for the keyboard
|
||||
rel_style = lv.style_t()
|
||||
pr_style = lv.style_t()
|
||||
def ta_event_cb(e,kb):
|
||||
code = e.get_code()
|
||||
ta = e.get_target()
|
||||
if code == lv.EVENT.FOCUSED:
|
||||
kb.set_textarea(ta)
|
||||
kb.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||
|
||||
lv.style_copy(rel_style, lv.style_btn_rel)
|
||||
rel_style.body.radius = 0
|
||||
rel_style.body.border.width = 1
|
||||
|
||||
lv.style_copy(pr_style, lv.style_btn_pr)
|
||||
pr_style.body.radius = 0
|
||||
pr_style.body.border.width = 1
|
||||
|
||||
# Create a keyboard and apply the styles
|
||||
kb = lv.kb(lv.scr_act())
|
||||
kb.set_cursor_manage(True)
|
||||
kb.set_style(lv.kb.STYLE.BG, lv.style_transp_tight)
|
||||
kb.set_style(lv.kb.STYLE.BTN_REL, rel_style)
|
||||
kb.set_style(lv.kb.STYLE.BTN_PR, pr_style)
|
||||
if code == lv.EVENT.DEFOCUSED:
|
||||
kb.set_textarea(None)
|
||||
kb.add_flag(lv.obj.FLAG.HIDDEN)
|
||||
|
||||
# Create a keyboard to use it with an of the text areas
|
||||
kb = lv.keyboard(lv.scr_act())
|
||||
|
||||
# Create a text area. The keyboard will write here
|
||||
ta = lv.ta(lv.scr_act())
|
||||
ta.align(None, lv.ALIGN.IN_TOP_MID, 0, 10)
|
||||
ta.set_text("")
|
||||
ta = lv.textarea(lv.scr_act())
|
||||
ta.set_width(200)
|
||||
ta.align(lv.ALIGN.TOP_LEFT, 10, 10)
|
||||
ta.add_event_cb(lambda e: ta_event_cb(e,kb), lv.EVENT.ALL, None)
|
||||
ta.set_placeholder_text("Hello")
|
||||
|
||||
ta = lv.textarea(lv.scr_act())
|
||||
ta.set_width(200)
|
||||
ta.align(lv.ALIGN.TOP_RIGHT, -10, 10)
|
||||
ta.add_event_cb(lambda e: ta_event_cb(e,kb), lv.EVENT.ALL, None)
|
||||
|
||||
kb.set_textarea(ta)
|
||||
|
||||
# Assign the text area to the keyboard
|
||||
kb.set_ta(ta)
|
@ -1,14 +1,19 @@
|
||||
#
|
||||
# Show line wrap, re-color, line align and text scrolling.
|
||||
#
|
||||
label1 = lv.label(lv.scr_act())
|
||||
label1.set_long_mode(lv.label.LONG.BREAK) # Break the long lines
|
||||
label1.set_long_mode(lv.label.LONG.WRAP); # Break the long lines*/
|
||||
label1.set_recolor(True) # Enable re-coloring by commands in the text
|
||||
label1.set_align(lv.label.ALIGN.CENTER) # Center aligned lines
|
||||
label1.set_text("#000080 Re-color# #0000ff words# #6666ff of a# label " +
|
||||
"and wrap long text automatically.")
|
||||
label1.set_width(150)
|
||||
label1.align(None, lv.ALIGN.CENTER, 0, -30)
|
||||
label1.set_text("#0000ff Re-color# #ff00ff words# #ff0000 of a# label, align the lines to the center"
|
||||
"and wrap long text automatically.")
|
||||
label1.set_width(150) # Set smaller width to make the lines wrap
|
||||
label1.set_style_text_align(lv.ALIGN.CENTER, 0)
|
||||
label1.align(lv.ALIGN.CENTER, 0, -40)
|
||||
|
||||
|
||||
label2 = lv.label(lv.scr_act())
|
||||
label2.set_long_mode(lv.label.LONG.SROLL_CIRC) # Circular scroll
|
||||
label2.set_long_mode(lv.label.LONG.SCROLL_CIRCULAR) # Circular scroll
|
||||
label2.set_width(150)
|
||||
label2.set_text("It is a circularly scrolling text. ")
|
||||
label2.align(None, lv.ALIGN.CENTER, 0, 30)
|
||||
label2.align(lv.ALIGN.CENTER, 0, 40)
|
||||
|
||||
|
@ -1,24 +1,30 @@
|
||||
#
|
||||
# Create a fake text shadow
|
||||
#
|
||||
|
||||
# Create a style for the shadow
|
||||
label_style = lv.style_t()
|
||||
lv.style_copy(label_style, lv.style_plain)
|
||||
label_style.text.opa = lv.OPA._50
|
||||
style_shadow = lv.style_t()
|
||||
style_shadow.init()
|
||||
style_shadow.set_text_opa(lv.OPA._30)
|
||||
style_shadow.set_text_color(lv.color_black())
|
||||
|
||||
# Create a label for the shadow first (it's in the background)
|
||||
shadow_label = lv.label(lv.scr_act())
|
||||
shadow_label.set_style(lv.label.STYLE.MAIN, label_style)
|
||||
shadow_label.add_style(style_shadow, 0)
|
||||
|
||||
# Create the main label
|
||||
main_label = lv.label(lv.scr_act())
|
||||
main_label.set_text("A simple method to create\n" +
|
||||
"shadows on text\n" +
|
||||
"It even works with\n\n" +
|
||||
"newlines and spaces.")
|
||||
main_label.set_text("A simple method to create\n"
|
||||
"shadows on a text.\n"
|
||||
"It even works with\n\n"
|
||||
"newlines and spaces.")
|
||||
|
||||
# Set the same text for the shadow label
|
||||
shadow_label.set_text(main_label.get_text())
|
||||
shadow_label.set_text(lv.label.get_text(main_label))
|
||||
|
||||
# Position the main label
|
||||
main_label.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
main_label.align(lv.ALIGN.CENTER, 0, 0)
|
||||
|
||||
# Shift the second label down and to the right by 2 pixel
|
||||
shadow_label.align_to(main_label, lv.ALIGN.TOP_LEFT, 2, 2)
|
||||
|
||||
# Shift the second label down and to the right by 1 pixel
|
||||
shadow_label.align(main_label, lv.ALIGN.IN_TOP_LEFT, 1, 1)
|
36
examples/widgets/label/lv_example_label_3.py
Normal file
36
examples/widgets/label/lv_example_label_3.py
Normal file
@ -0,0 +1,36 @@
|
||||
import fs_driver
|
||||
#
|
||||
# Show mixed LTR, RTL and Chinese label
|
||||
#
|
||||
|
||||
ltr_label = lv.label(lv.scr_act())
|
||||
ltr_label.set_text("In modern terminology, a microcontroller is similar to a system on a chip (SoC).");
|
||||
# ltr_label.set_style_text_font(ltr_label, &lv_font_montserrat_16, 0);
|
||||
|
||||
fs_drv = lv.fs_drv_t()
|
||||
fs_driver.fs_register(fs_drv, 'S')
|
||||
|
||||
try:
|
||||
ltr_label.set_style_text_font(ltr_label, lv.font_montserrat_16, 0)
|
||||
except:
|
||||
font_montserrat_16 = lv.font_load("S:../../assets/font/montserrat-16.bin")
|
||||
ltr_label.set_style_text_font(font_montserrat_16, 0)
|
||||
|
||||
ltr_label.set_width(310)
|
||||
ltr_label.align(lv.ALIGN.TOP_LEFT, 5, 5)
|
||||
|
||||
rtl_label = lv.label(lv.scr_act())
|
||||
rtl_label.set_text("מעבד, או בשמו המלא יחידת עיבוד מרכזית (באנגלית: CPU - Central Processing Unit).")
|
||||
rtl_label.set_style_base_dir(lv.BASE_DIR.RTL, 0)
|
||||
rtl_label.set_style_text_font(lv.font_dejavu_16_persian_hebrew, 0)
|
||||
rtl_label.set_width(310)
|
||||
rtl_label.align(lv.ALIGN.LEFT_MID, 5, 0)
|
||||
|
||||
font_simsun_16_cjk = lv.font_load("S:../../assets/font/lv_font_simsun_16_cjk.bin")
|
||||
|
||||
cz_label = lv.label(lv.scr_act())
|
||||
cz_label.set_style_text_font(font_simsun_16_cjk, 0)
|
||||
cz_label.set_text("嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。")
|
||||
cz_label.set_width(310)
|
||||
cz_label.align(lv.ALIGN.BOTTOM_LEFT, 5, -5)
|
||||
|
@ -1,27 +1,20 @@
|
||||
# Create a style for the LED
|
||||
style_led = lv.style_t()
|
||||
lv.style_copy(style_led, lv.style_pretty_color)
|
||||
style_led.body.radius = 800 # large enough to draw a circle
|
||||
style_led.body.main_color = lv.color_make(0xb5, 0x0f, 0x04)
|
||||
style_led.body.grad_color = lv.color_make(0x50, 0x07, 0x02)
|
||||
style_led.body.border.color = lv.color_make(0xfa, 0x0f, 0x00)
|
||||
style_led.body.border.width = 3
|
||||
style_led.body.border.opa = lv.OPA._30
|
||||
style_led.body.shadow.color = lv.color_make(0xb5, 0x0f, 0x04)
|
||||
style_led.body.shadow.width = 5
|
||||
#
|
||||
# Create LED's with different brightness and color
|
||||
#
|
||||
|
||||
# Create a LED and switch it OFF
|
||||
led1 = lv.led(lv.scr_act())
|
||||
led1.set_style(lv.led.STYLE.MAIN, style_led)
|
||||
led1.align(None, lv.ALIGN.CENTER, -80, 0)
|
||||
led1.align(lv.ALIGN.CENTER, -80, 0)
|
||||
led1.off()
|
||||
|
||||
# Copy the previous LED and set a brightness
|
||||
led2 = lv.led(lv.scr_act(), led1)
|
||||
led2.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
led2.set_bright(190)
|
||||
led2 = lv.led(lv.scr_act())
|
||||
led2.align(lv.ALIGN.CENTER, 0, 0)
|
||||
led2.set_brightness(150)
|
||||
led2.set_color(lv.palette_main(lv.PALETTE.RED))
|
||||
|
||||
# Copy the previous LED and switch it ON
|
||||
led3 = lv.led(lv.scr_act(), led1)
|
||||
led3.align(None, lv.ALIGN.CENTER, 80, 0)
|
||||
led3.on()
|
||||
led3 = lv.led(lv.scr_act())
|
||||
led3.align(lv.ALIGN.CENTER, 80, 0)
|
||||
led3.on()
|
||||
|
||||
|
@ -5,15 +5,16 @@ line_points = [ {"x":5, "y":5},
|
||||
{"x":180, "y":60},
|
||||
{"x":240, "y":10}]
|
||||
|
||||
# Create new style (thick dark blue)
|
||||
# Create style
|
||||
style_line = lv.style_t()
|
||||
lv.style_copy(style_line, lv.style_plain)
|
||||
style_line.line.color = lv.color_make(0x00, 0x3b, 0x75)
|
||||
style_line.line.width = 3
|
||||
style_line.line.rounded = 1
|
||||
style_line.init()
|
||||
style_line.set_line_width(8)
|
||||
style_line.set_line_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style_line.set_line_rounded(True)
|
||||
|
||||
# Copy the previous line and apply the new style
|
||||
# Create a line and apply the new style
|
||||
line1 = lv.line(lv.scr_act())
|
||||
line1.set_points(line_points, len(line_points)) # Set the points
|
||||
line1.set_style(lv.line.STYLE.MAIN, style_line)
|
||||
line1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
line1.set_points(line_points, 5) # Set the points
|
||||
line1.add_style(style_line, 0)
|
||||
line1.center()
|
||||
|
||||
|
@ -1,25 +1,40 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.CLICKED:
|
||||
print("Clicked: %s" % lv.list.get_btn_text(obj))
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = lv.btn.__cast__(e.get_target())
|
||||
if code == lv.EVENT.CLICKED:
|
||||
print("Clicked: list1." + list1.get_btn_text(obj))
|
||||
|
||||
# Create a list
|
||||
list1 = lv.list(lv.scr_act())
|
||||
list1.set_size(160, 200)
|
||||
list1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
list1.set_size(180, 220)
|
||||
list1.center()
|
||||
|
||||
# Add buttons to the list
|
||||
list1.add_text("File")
|
||||
btn_new = list1.add_btn(lv.SYMBOL.FILE, "New")
|
||||
btn_new.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_open = list1.add_btn(lv.SYMBOL.DIRECTORY, "Open")
|
||||
btn_open.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_save = list1.add_btn(lv.SYMBOL.SAVE, "Save")
|
||||
btn_save.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_delete = list1.add_btn(lv.SYMBOL.CLOSE, "Delete")
|
||||
btn_delete.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_edit = list1.add_btn(lv.SYMBOL.EDIT, "Edit")
|
||||
btn_edit.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
||||
list_btn = list1.add_btn(lv.SYMBOL.FILE, "New")
|
||||
list_btn.set_event_cb(event_handler)
|
||||
list1.add_text("Connectivity")
|
||||
btn_bluetooth = list1.add_btn(lv.SYMBOL.BLUETOOTH, "Bluetooth")
|
||||
btn_bluetooth.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_navig = list1.add_btn(lv.SYMBOL.GPS, "Navigation")
|
||||
btn_navig.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_USB = list1.add_btn(lv.SYMBOL.USB, "USB")
|
||||
btn_USB.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_battery = list1.add_btn(lv.SYMBOL.BATTERY_FULL, "Battery")
|
||||
btn_battery.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
||||
list_btn = list1.add_btn(lv.SYMBOL.DIRECTORY, "Open")
|
||||
list_btn.set_event_cb(event_handler)
|
||||
list1.add_text("Exit")
|
||||
btn_apply = list1.add_btn(lv.SYMBOL.OK, "Apply")
|
||||
btn_apply.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_close = list1.add_btn(LV_SYMBOL.CLOSE, "Close")
|
||||
btn_close.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
||||
list_btn = list1.add_btn(lv.SYMBOL.CLOSE, "Delete")
|
||||
list_btn.set_event_cb(event_handler)
|
||||
|
||||
list_btn = list1.add_btn(lv.SYMBOL.EDIT, "Edit")
|
||||
list_btn.set_event_cb(event_handler)
|
||||
|
||||
list_btn = list1.add_btn(lv.SYMBOL.SAVE, "Save")
|
||||
list_btn.set_event_cb(event_handler)
|
43
examples/widgets/list/test.py
Executable file
43
examples/widgets/list/test.py
Executable file
@ -0,0 +1,43 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = lv.btn.__cast__(e.get_target())
|
||||
if code == lv.EVENT.CLICKED:
|
||||
print("Clicked: list1." + list1.get_btn_text(obj))
|
||||
|
||||
# Create a list
|
||||
list1 = lv.list(lv.scr_act())
|
||||
list1.set_size(180, 220)
|
||||
list1.center()
|
||||
|
||||
# Add buttons to the list
|
||||
list1.add_text("File")
|
||||
btn_new = list1.add_btn(lv.SYMBOL.FILE, "New")
|
||||
btn_new.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_open = list1.add_btn(lv.SYMBOL.DIRECTORY, "Open")
|
||||
btn_open.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_save = list1.add_btn(lv.SYMBOL.SAVE, "Save")
|
||||
btn_save.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_delete = list1.add_btn(lv.SYMBOL.CLOSE, "Delete")
|
||||
btn_delete.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_edit = list1.add_btn(lv.SYMBOL.EDIT, "Edit")
|
||||
btn_edit.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
||||
list1.add_text("Connectivity")
|
||||
btn_bluetooth = list1.add_btn(lv.SYMBOL.BLUETOOTH, "Bluetooth")
|
||||
btn_bluetooth.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_navig = list1.add_btn(lv.SYMBOL.GPS, "Navigation")
|
||||
btn_navig.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_USB = list1.add_btn(lv.SYMBOL.USB, "USB")
|
||||
btn_USB.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_battery = list1.add_btn(lv.SYMBOL.BATTERY_FULL, "Battery")
|
||||
btn_battery.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
||||
list1.add_text("Exit")
|
||||
btn_apply = list1.add_btn(lv.SYMBOL.OK, "Apply")
|
||||
btn_apply.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
btn_close = list1.add_btn(LV_SYMBOL.CLOSE, "Close")
|
||||
btn_close.add_event_cb(event_handler,lv.EVENT.ALL, None)
|
||||
|
58
examples/widgets/meter/lv_example_meter_1.py
Normal file
58
examples/widgets/meter/lv_example_meter_1.py
Normal file
@ -0,0 +1,58 @@
|
||||
#!//opt/bin/lv_micropython -i
|
||||
import time
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
|
||||
def set_value(indic, v):
|
||||
meter.set_indicator_value(indic, v)
|
||||
|
||||
#
|
||||
# A simple meter
|
||||
#
|
||||
meter = lv.meter(lv.scr_act())
|
||||
meter.center()
|
||||
meter.set_size(200, 200)
|
||||
|
||||
# Add a scale first
|
||||
scale = meter.add_scale()
|
||||
meter.set_scale_ticks(scale, 51, 2, 10, lv.palette_main(lv.PALETTE.GREY))
|
||||
meter.set_scale_major_ticks(scale, 10, 4, 15, lv.color_black(), 10)
|
||||
|
||||
indic = lv.meter_indicator_t()
|
||||
|
||||
# Add a blue arc to the start
|
||||
indic = meter.add_arc(scale, 3, lv.palette_main(lv.PALETTE.BLUE), 0)
|
||||
meter.set_indicator_start_value(indic, 0)
|
||||
meter.set_indicator_end_value(indic, 20)
|
||||
|
||||
# Make the tick lines blue at the start of the scale
|
||||
indic = meter.add_scale_lines(scale, lv.palette_main(lv.PALETTE.BLUE), lv.palette_main(lv.PALETTE.BLUE), False, 0)
|
||||
meter.set_indicator_start_value(indic, 0)
|
||||
meter.set_indicator_end_value(indic, 20)
|
||||
|
||||
# Add a red arc to the end
|
||||
indic = meter.add_arc(scale, 3, lv.palette_main(lv.PALETTE.RED), 0)
|
||||
meter.set_indicator_start_value(indic, 80)
|
||||
meter.set_indicator_end_value(indic, 100)
|
||||
|
||||
# Make the tick lines red at the end of the scale
|
||||
indic = meter.add_scale_lines(scale, lv.palette_main(lv.PALETTE.RED), lv.palette_main(lv.PALETTE.RED), False, 0)
|
||||
meter.set_indicator_start_value(indic, 80)
|
||||
meter.set_indicator_end_value(indic, 100)
|
||||
|
||||
# Add a needle line indicator
|
||||
indic = meter.add_needle_line(scale, 4, lv.palette_main(lv.PALETTE.GREY), -10)
|
||||
|
||||
# Create an animation to set the value
|
||||
a = lv.anim_t()
|
||||
a.init()
|
||||
a.set_var(indic)
|
||||
a.set_values(0, 100)
|
||||
a.set_time(2000)
|
||||
a.set_repeat_delay(100)
|
||||
a.set_playback_time(500)
|
||||
a.set_playback_delay(100)
|
||||
a.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a.set_custom_exec_cb(lambda a,val: set_value(indic,val))
|
||||
lv.anim_t.start(a)
|
||||
|
69
examples/widgets/meter/lv_example_meter_2.py
Normal file
69
examples/widgets/meter/lv_example_meter_2.py
Normal file
@ -0,0 +1,69 @@
|
||||
#!//opt/bin/lv_micropython -i
|
||||
import time
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
|
||||
def set_value(indic,v):
|
||||
meter.set_indicator_end_value(indic, v)
|
||||
|
||||
#
|
||||
# A meter with multiple arcs
|
||||
#
|
||||
|
||||
meter = lv.meter(lv.scr_act())
|
||||
meter.center()
|
||||
meter.set_size(200, 200)
|
||||
|
||||
# Remove the circle from the middle
|
||||
meter.remove_style(None, lv.PART.INDICATOR)
|
||||
|
||||
# Add a scale first
|
||||
scale = meter.add_scale()
|
||||
meter.set_scale_ticks(scale, 11, 2, 10, lv.palette_main(lv.PALETTE.GREY))
|
||||
meter.set_scale_major_ticks(scale, 1, 2, 30, lv.color_hex3(0xeee), 10)
|
||||
meter.set_scale_range(scale, 0, 100, 270, 90)
|
||||
|
||||
# Add a three arc indicator
|
||||
indic1 = meter.add_arc(scale, 10, lv.palette_main(lv.PALETTE.RED), 0)
|
||||
indic2 = meter.add_arc(scale, 10, lv.palette_main(lv.PALETTE.GREEN), -10)
|
||||
indic3 = meter.add_arc(scale, 10, lv.palette_main(lv.PALETTE.BLUE), -20)
|
||||
|
||||
# Create an animation to set the value
|
||||
a1 = lv.anim_t()
|
||||
a1.init()
|
||||
a1.set_values(0, 100)
|
||||
a1.set_time(2000)
|
||||
a1.set_repeat_delay(100)
|
||||
a1.set_playback_delay(100)
|
||||
a1.set_playback_time(500)
|
||||
a1.set_var(indic1)
|
||||
a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a1.set_custom_exec_cb(lambda a,val: set_value(indic1,val))
|
||||
lv.anim_t.start(a1)
|
||||
|
||||
a2 = lv.anim_t()
|
||||
a2.init()
|
||||
a2.set_values(0, 100)
|
||||
a2.set_time(1000)
|
||||
a2.set_repeat_delay(100)
|
||||
a2.set_playback_delay(100)
|
||||
a2.set_playback_time(1000)
|
||||
a2.set_var(indic2)
|
||||
a2.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a2.set_custom_exec_cb(lambda a,val: set_value(indic2,val))
|
||||
lv.anim_t.start(a2)
|
||||
|
||||
a3 = lv.anim_t()
|
||||
a3.init()
|
||||
a3.set_values(0, 100)
|
||||
a3.set_time(1000)
|
||||
a3.set_repeat_delay(100)
|
||||
a3.set_playback_delay(100)
|
||||
a3.set_playback_time(2000)
|
||||
a3.set_var(indic3)
|
||||
a3.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
|
||||
a3.set_custom_exec_cb(lambda a,val: set_value(indic3,val))
|
||||
lv.anim_t.start(a3)
|
||||
|
||||
|
||||
|
83
examples/widgets/meter/lv_example_meter_3.py
Normal file
83
examples/widgets/meter/lv_example_meter_3.py
Normal file
@ -0,0 +1,83 @@
|
||||
#!//opt/bin/lv_micropython -i
|
||||
import time
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_hand_min.png','rb') as f:
|
||||
img_hand_min_data = f.read()
|
||||
except:
|
||||
print("Could not find img_hand_min.png")
|
||||
sys.exit()
|
||||
|
||||
img_hand_min_dsc = lv.img_dsc_t({
|
||||
'data_size': len(img_hand_min_data),
|
||||
'data': img_hand_min_data
|
||||
})
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_hand_hour.png','rb') as f:
|
||||
img_hand_hour_data = f.read()
|
||||
except:
|
||||
print("Could not find img_hand_hour.png")
|
||||
sys.exit()
|
||||
|
||||
img_hand_hour_dsc = lv.img_dsc_t({
|
||||
'data_size': len(img_hand_hour_data),
|
||||
'data': img_hand_hour_data
|
||||
})
|
||||
|
||||
def set_value(indic, v):
|
||||
meter.set_indicator_value(indic, v)
|
||||
#
|
||||
# A clock from a meter
|
||||
#
|
||||
|
||||
meter = lv.meter(lv.scr_act())
|
||||
meter.set_size(220, 220)
|
||||
meter.center()
|
||||
|
||||
# Create a scale for the minutes
|
||||
# 61 ticks in a 360 degrees range (the last and the first line overlaps)
|
||||
scale_min = meter.add_scale()
|
||||
meter.set_scale_ticks(scale_min, 61, 1, 10, lv.palette_main(lv.PALETTE.GREY))
|
||||
meter.set_scale_range(scale_min, 0, 60, 360, 270)
|
||||
|
||||
# Create an other scale for the hours. It's only visual and contains only major ticks
|
||||
scale_hour = meter.add_scale()
|
||||
meter.set_scale_ticks(scale_hour, 12, 0, 0, lv.palette_main(lv.PALETTE.GREY)) # 12 ticks
|
||||
meter.set_scale_major_ticks(scale_hour, 1, 2, 20, lv.color_black(), 10) # Every tick is major
|
||||
meter.set_scale_range(scale_hour, 1, 12, 330, 300) # [1..12] values in an almost full circle
|
||||
|
||||
# LV_IMG_DECLARE(img_hand)
|
||||
|
||||
# Add a the hands from images
|
||||
indic_min = meter.add_needle_img(scale_min, img_hand_min_dsc, 5, 5)
|
||||
indic_hour = meter.add_needle_img(scale_min, img_hand_hour_dsc, 5, 5)
|
||||
|
||||
# Create an animation to set the value
|
||||
a1 = lv.anim_t()
|
||||
a1.init()
|
||||
a1.set_values(0, 60)
|
||||
a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
|
||||
a1.set_time(2000) # 2 sec for 1 turn of the minute hand (1 hour)
|
||||
a1.set_var(indic_min)
|
||||
a1.set_custom_exec_cb(lambda a1,val: set_value(indic_min,val))
|
||||
lv.anim_t.start(a1)
|
||||
|
||||
a2 = lv.anim_t()
|
||||
a2.init()
|
||||
a2.set_var(indic_hour)
|
||||
a2.set_time(24000) # 24 sec for 1 turn of the hour hand
|
||||
a2.set_values(0, 60)
|
||||
a2.set_custom_exec_cb(lambda a2,val: set_value(indic_hour,val))
|
||||
lv.anim_t.start(a2)
|
||||
|
32
examples/widgets/meter/lv_example_meter_4.py
Normal file
32
examples/widgets/meter/lv_example_meter_4.py
Normal file
@ -0,0 +1,32 @@
|
||||
#
|
||||
# Create a pie chart
|
||||
#
|
||||
|
||||
meter = lv.meter(lv.scr_act())
|
||||
|
||||
# Remove the background and the circle from the middle
|
||||
meter.remove_style(None, lv.PART.MAIN)
|
||||
meter.remove_style(None, lv.PART.INDICATOR)
|
||||
|
||||
meter.set_size(200, 200)
|
||||
meter.center()
|
||||
|
||||
# Add a scale first with no ticks.
|
||||
scale = meter.add_scale()
|
||||
meter.set_scale_ticks(scale, 0, 0, 0, lv.color_black())
|
||||
meter.set_scale_range(scale, 0, 100, 360, 0)
|
||||
|
||||
# Add a three arc indicator*
|
||||
indic_w = 100
|
||||
indic1 = meter.add_arc(scale, indic_w,lv.palette_main(lv.PALETTE.ORANGE), 0)
|
||||
meter.set_indicator_start_value(indic1, 0)
|
||||
meter.set_indicator_end_value(indic1, 40)
|
||||
|
||||
indic2 = meter.add_arc(scale, indic_w, lv.palette_main(lv.PALETTE.YELLOW), 0)
|
||||
meter.set_indicator_start_value(indic2, 40) # Start from the previous
|
||||
meter.set_indicator_end_value(indic2, 80)
|
||||
|
||||
indic3 = meter.add_arc(scale, indic_w, lv.palette_main(lv.PALETTE.DEEP_ORANGE), 0)
|
||||
meter_set_indicator_start_value(indic3, 80) # Start from the previous
|
||||
meter_set_indicator_end_value(indic3, 100)
|
||||
|
@ -1,12 +1,10 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
print("Button: %s" % lv.mbox.get_active_btn_text(obj))
|
||||
def event_cb(e):
|
||||
mbox = lv.msgbox.__cast__(e.get_current_target())
|
||||
print("Button " + mbox.get_active_btn_text() + " clicked")
|
||||
|
||||
btns = ["Apply", "Close", ""]
|
||||
|
||||
mbox1 = lv.mbox(lv.scr_act())
|
||||
mbox1.set_text("A message box with two buttons.");
|
||||
mbox1.add_btns(btns)
|
||||
mbox1.set_width(200)
|
||||
mbox1.set_event_cb(event_handler)
|
||||
mbox1.align(None, lv.ALIGN.CENTER, 0, 0) # Align to the corner
|
||||
mbox1 = lv.msgbox(lv.scr_act(), "Hello", "This is a message box with two buttons.", btns, True)
|
||||
mbox1.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
mbox1.center()
|
||||
|
||||
|
@ -1,86 +0,0 @@
|
||||
welcome_info = "Welcome to the modal message box demo!\nPress the button to display a message box."
|
||||
in_msg_info = "Notice that you cannot touch the button again while the message box is open."
|
||||
|
||||
class Modal(lv.mbox):
|
||||
"""mbox with semi-transparent background"""
|
||||
def __init__(self, parent, *args, **kwargs):
|
||||
# Create a full-screen background
|
||||
modal_style = lv.style_t()
|
||||
lv.style_copy(modal_style, lv.style_plain_color)
|
||||
# Set the background's style
|
||||
modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(0,0,0)
|
||||
modal_style.body.opa = lv.OPA._50
|
||||
|
||||
# Create a base object for the modal background
|
||||
self.bg = lv.obj(parent)
|
||||
self.bg.set_style(modal_style)
|
||||
self.bg.set_pos(0, 0)
|
||||
self.bg.set_size(parent.get_width(), parent.get_height())
|
||||
self.bg.set_opa_scale_enable(True) # Enable opacity scaling for the animation
|
||||
|
||||
super().__init__(self.bg, *args, **kwargs)
|
||||
self.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
|
||||
# Fade the message box in with an animation
|
||||
a = lv.anim_t()
|
||||
lv.anim_init(a)
|
||||
lv.anim_set_time(a, 500, 0)
|
||||
lv.anim_set_values(a, lv.OPA.TRANSP, lv.OPA.COVER)
|
||||
lv.anim_set_exec_cb(a, self.bg, lv.obj.set_opa_scale)
|
||||
lv.anim_create(a)
|
||||
super().set_event_cb(self.default_callback)
|
||||
|
||||
def set_event_cb(self, callback):
|
||||
self.callback = callback
|
||||
|
||||
def get_event_cb(self):
|
||||
return self.callback
|
||||
|
||||
def default_callback(self, obj, evt):
|
||||
if evt == lv.EVENT.DELETE:# and obj == self:
|
||||
# Delete the parent modal background
|
||||
self.get_parent().del_async()
|
||||
elif evt == lv.EVENT.VALUE_CHANGED:
|
||||
# A button was clicked
|
||||
self.start_auto_close(0)
|
||||
# Call user-defined callback
|
||||
if self.callback is not None:
|
||||
self.callback(obj, evt)
|
||||
|
||||
def mbox_event_cb(obj, evt):
|
||||
if evt == lv.EVENT.DELETE:
|
||||
info.set_text(welcome_info)
|
||||
|
||||
def btn_event_cb(btn, evt):
|
||||
if evt == lv.EVENT.CLICKED:
|
||||
|
||||
btns2 = ["Ok", "Cancel", ""]
|
||||
|
||||
# Create the message box as a child of the modal background
|
||||
mbox = Modal(lv.scr_act())
|
||||
mbox.add_btns(btns2)
|
||||
mbox.set_text("Hello world!")
|
||||
mbox.set_event_cb(mbox_event_cb)
|
||||
|
||||
info.set_text(in_msg_info)
|
||||
info.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 5, -5)
|
||||
|
||||
# Get active screen
|
||||
scr = lv.scr_act()
|
||||
|
||||
# Create a button, then set its position and event callback
|
||||
btn = lv.btn(scr)
|
||||
btn.set_size(200, 60)
|
||||
btn.set_event_cb(btn_event_cb)
|
||||
btn.align(None, lv.ALIGN.IN_TOP_LEFT, 20, 20)
|
||||
|
||||
# Create a label on the button
|
||||
label = lv.label(btn)
|
||||
label.set_text("Display a message box!")
|
||||
|
||||
# Create an informative label on the screen
|
||||
info = lv.label(scr)
|
||||
info.set_text(welcome_info)
|
||||
info.set_long_mode(lv.label.LONG.BREAK) # Make sure text will wrap
|
||||
info.set_width(scr.get_width() - 10)
|
||||
info.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 5, -5)
|
@ -1,20 +1,14 @@
|
||||
obj1 = lv.obj(lv.scr_act())
|
||||
obj1.set_size(100, 50)
|
||||
obj1.set_style(lv.style_plain_color)
|
||||
obj1.align(None, lv.ALIGN.CENTER, -60, -30)
|
||||
|
||||
# Copy the previous object and enable drag
|
||||
obj2 = lv.obj(lv.scr_act(), obj1)
|
||||
obj2.set_style(lv.style_pretty_color)
|
||||
obj2.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
obj2.set_drag(True)
|
||||
obj1.align(lv.ALIGN.CENTER, -60, -30)
|
||||
|
||||
style_shadow = lv.style_t()
|
||||
lv.style_copy(style_shadow, lv.style_pretty)
|
||||
style_shadow.body.shadow.width = 6
|
||||
style_shadow.body.radius = 800 # large enough to make it round
|
||||
style_shadow.init()
|
||||
style_shadow.set_shadow_width(10)
|
||||
style_shadow.set_shadow_spread(5)
|
||||
style_shadow.set_shadow_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
|
||||
obj2 = lv.obj(lv.scr_act())
|
||||
obj2.add_style(style_shadow, 0)
|
||||
obj2.align(lv.ALIGN.CENTER, 60, 30)
|
||||
|
||||
# Copy the previous object (drag is already enabled)
|
||||
obj3 = lv.obj(lv.scr_act(), obj2)
|
||||
obj3.set_style(style_shadow)
|
||||
obj3.align(None, lv.ALIGN.CENTER, 60, 30)
|
25
examples/widgets/obj/lv_example_obj_2.py
Normal file
25
examples/widgets/obj/lv_example_obj_2.py
Normal file
@ -0,0 +1,25 @@
|
||||
def drag_event_handler(e):
|
||||
|
||||
obj = e.get_target()
|
||||
|
||||
indev = lv.indev_get_act()
|
||||
|
||||
vect = lv.point_t()
|
||||
indev.get_vect(vect)
|
||||
x = obj.get_x() + vect.x
|
||||
y = obj.get_y() + vect.y
|
||||
obj.set_pos(x, y)
|
||||
|
||||
|
||||
#
|
||||
# Make an object dragable.
|
||||
#
|
||||
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.set_size(150, 100)
|
||||
obj.add_event_cb(drag_event_handler, lv.EVENT.PRESSING, None)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("Drag me")
|
||||
label.center()
|
||||
|
@ -1,24 +1,31 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = lv.roller.__cast__(e.get_target())
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
option = " "*10
|
||||
obj.get_selected_str(option, len(option))
|
||||
print("Selected month: %s" % option.strip())
|
||||
print("Selected month: " + option.strip())
|
||||
|
||||
#
|
||||
# An infinite roller with the name of the months
|
||||
#
|
||||
|
||||
roller1 = lv.roller(lv.scr_act())
|
||||
roller1.set_options("\n".join([
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"]), lv.roller.MODE.INIFINITE)
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"]),lv.roller.MODE.INFINITE)
|
||||
|
||||
roller1.set_visible_row_count(4)
|
||||
roller1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
roller1.set_event_cb(event_handler)
|
||||
roller1.center()
|
||||
roller1.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
|
60
examples/widgets/roller/lv_example_roller_2.py
Normal file
60
examples/widgets/roller/lv_example_roller_2.py
Normal file
@ -0,0 +1,60 @@
|
||||
import fs_driver
|
||||
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = lv.roller.__cast__(e.get_target())
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
option = " "*10
|
||||
obj.get_selected_str(option, len(option))
|
||||
print("Selected value: %s\n" + option.strip())
|
||||
|
||||
#
|
||||
# Roller with various alignments and larger text in the selected area
|
||||
#
|
||||
|
||||
# A style to make the selected option larger
|
||||
style_sel = lv.style_t()
|
||||
style_sel.init()
|
||||
|
||||
try:
|
||||
style_sel.set_text_font(lv.font_montserrat_22)
|
||||
except:
|
||||
fs_drv = lv.fs_drv_t()
|
||||
fs_driver.fs_register(fs_drv, 'S')
|
||||
print("montserrat-22 not enabled in lv_conf.h, dynamically loading the font")
|
||||
font_montserrat_22 = lv.font_load("S:" + "../../assets/font/montserrat-22.bin")
|
||||
style_sel.set_text_font(font_montserrat_22)
|
||||
|
||||
opts = "\n".join(["1","2","3","4","5","6","7","8","9","10"])
|
||||
|
||||
# A roller on the left with left aligned text, and custom width
|
||||
roller = lv.roller(lv.scr_act())
|
||||
roller.set_options(opts, lv.roller.MODE.NORMAL)
|
||||
roller.set_visible_row_count(2)
|
||||
roller.set_width(100)
|
||||
roller.add_style(style_sel, lv.PART.SELECTED)
|
||||
roller.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
|
||||
roller.align(lv.ALIGN.LEFT_MID, 10, 0)
|
||||
roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
roller.set_selected(2, lv.ANIM.OFF)
|
||||
|
||||
# A roller on the middle with center aligned text, and auto (default) width
|
||||
roller = lv.roller(lv.scr_act());
|
||||
roller.set_options(opts, lv.roller.MODE.NORMAL)
|
||||
roller.set_visible_row_count(3)
|
||||
roller.add_style(style_sel, lv.PART.SELECTED)
|
||||
roller.align(lv.ALIGN.CENTER, 0, 0)
|
||||
roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
roller.set_selected(5, lv.ANIM.OFF)
|
||||
|
||||
# A roller on the right with right aligned text, and custom width
|
||||
roller = lv.roller(lv.scr_act());
|
||||
roller.set_options(opts, lv.roller.MODE.NORMAL)
|
||||
roller.set_visible_row_count(4)
|
||||
roller.set_width(80)
|
||||
roller.add_style(style_sel, lv.PART.SELECTED)
|
||||
roller.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
|
||||
roller.align(lv.ALIGN.RIGHT_MID, -10, 0)
|
||||
roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
roller.set_selected(8, lv.ANIM.OFF)
|
||||
|
93
examples/widgets/roller/lv_example_roller_3.py
Normal file
93
examples/widgets/roller/lv_example_roller_3.py
Normal file
@ -0,0 +1,93 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import time
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
import sys
|
||||
|
||||
class Lv_Roller_3():
|
||||
|
||||
def __init__(self):
|
||||
self.mask_top_id = -1
|
||||
self.mask_bottom_id = -1
|
||||
|
||||
#
|
||||
# Add an fade mask to roller.
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_bg_color(lv.color_black())
|
||||
style.set_text_color(lv.color_white())
|
||||
|
||||
lv.scr_act().add_style(style, 0)
|
||||
|
||||
roller1 = lv.roller(lv.scr_act())
|
||||
roller1.add_style(style, 0)
|
||||
roller1.set_style_border_width(0, 0)
|
||||
roller1.set_style_pad_all(0, 0)
|
||||
roller1.set_style_bg_opa(lv.OPA.TRANSP, lv.PART.SELECTED)
|
||||
|
||||
#if LV_FONT_MONTSERRAT_22
|
||||
# lv_obj_set_style_text_font(roller1, &lv_font_montserrat_22, LV_PART_SELECTED);
|
||||
#endif
|
||||
roller1.set_options("\n".join([
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"]),lv.roller.MODE.NORMAL)
|
||||
|
||||
roller1.center()
|
||||
roller1.set_visible_row_count(3)
|
||||
roller1.add_event_cb(self.mask_event_cb, lv.EVENT.ALL, None)
|
||||
|
||||
def mask_event_cb(self,e):
|
||||
|
||||
code = e.get_code()
|
||||
obj = e.get_target()
|
||||
|
||||
if code == lv.EVENT.COVER_CHECK:
|
||||
e.set_cover_res(lv.COVER_RES.MASKED)
|
||||
|
||||
elif code == lv.EVENT.DRAW_MAIN_BEGIN:
|
||||
# add mask
|
||||
font = obj.get_style_text_font(lv.PART.MAIN)
|
||||
line_space = obj.get_style_text_line_space(lv.PART.MAIN)
|
||||
font_h = font.get_line_height()
|
||||
|
||||
roller_coords = lv.area_t()
|
||||
obj.get_coords(roller_coords)
|
||||
|
||||
rect_area = lv.area_t()
|
||||
rect_area.x1 = roller_coords.x1
|
||||
rect_area.x2 = roller_coords.x2
|
||||
rect_area.y1 = roller_coords.y1
|
||||
rect_area.y2 = roller_coords.y1 + (obj.get_height() - font_h - line_space) // 2
|
||||
|
||||
fade_mask_top = lv.draw_mask_fade_param_t()
|
||||
fade_mask_top.init(rect_area, lv.OPA.TRANSP, rect_area.y1, lv.OPA.COVER, rect_area.y2)
|
||||
self.mask_top_id = lv.draw_mask_add(fade_mask_top,None)
|
||||
|
||||
rect_area.y1 = rect_area.y2 + font_h + line_space - 1
|
||||
rect_area.y2 = roller_coords.y2
|
||||
|
||||
fade_mask_bottom = lv.draw_mask_fade_param_t()
|
||||
fade_mask_bottom.init(rect_area, lv.OPA.COVER, rect_area.y1, lv.OPA.TRANSP, rect_area.y2)
|
||||
self.mask_bottom_id = lv.draw_mask_add(fade_mask_bottom, None)
|
||||
|
||||
elif code == lv.EVENT.DRAW_POST_END:
|
||||
fade_mask_top = lv.draw_mask_remove_id(self.mask_top_id)
|
||||
fade_mask_bottom = lv.draw_mask_remove_id(self.mask_bottom_id)
|
||||
# Remove the masks
|
||||
lv.draw_mask_remove_id(self.mask_top_id)
|
||||
lv.draw_mask_remove_id(self.mask_bottom_id)
|
||||
self.mask_top_id = -1;
|
||||
self.mask_bottom_id = -1;
|
||||
|
||||
roller3 = Lv_Roller_3()
|
@ -1,37 +1,20 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
print("Value: %d" % obj.get_value())
|
||||
#
|
||||
# A default slider with a label displaying the current value
|
||||
#
|
||||
def slider_event_cb(e):
|
||||
|
||||
# Create styles
|
||||
style_bg = lv.style_t()
|
||||
style_indic = lv.style_t()
|
||||
style_knob = lv.style_t()
|
||||
slider = lv.slider.__cast__(e.get_target())
|
||||
slider_label.set_text("{:d}%".format(slider.get_value()))
|
||||
slider_label.align_to(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10)
|
||||
|
||||
lv.style_copy(style_bg, lv.style_pretty)
|
||||
style_bg.body.main_color = lv.color_make(0,0,0)
|
||||
style_bg.body.grad_color = lv.color_make(0x80, 0x80, 0x80)
|
||||
style_bg.body.radius = 800 # large enough to make a circle
|
||||
style_bg.body.border.color = lv.color_make(0xff,0xff,0xff)
|
||||
|
||||
lv.style_copy(style_indic, lv.style_pretty_color)
|
||||
style_indic.body.radius = 800
|
||||
style_indic.body.shadow.width = 8
|
||||
style_indic.body.shadow.color = style_indic.body.main_color
|
||||
style_indic.body.padding.left = 3
|
||||
style_indic.body.padding.right = 3
|
||||
style_indic.body.padding.top = 3
|
||||
style_indic.body.padding.bottom = 3
|
||||
|
||||
lv.style_copy(style_knob, lv.style_pretty)
|
||||
style_knob.body.radius = 800
|
||||
style_knob.body.opa = lv.OPA._70
|
||||
style_knob.body.padding.top = 10
|
||||
style_knob.body.padding.bottom = 10
|
||||
|
||||
# Create a slider
|
||||
# Create a slider in the center of the display
|
||||
slider = lv.slider(lv.scr_act())
|
||||
slider.set_style(lv.slider.STYLE.BG, style_bg)
|
||||
slider.set_style(lv.slider.STYLE.INDIC, style_indic)
|
||||
slider.set_style(lv.slider.STYLE.KNOB, style_knob)
|
||||
slider.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
slider.set_event_cb(event_handler)
|
||||
slider.center()
|
||||
slider.add_event_cb(slider_event_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
|
||||
# Create a label below the slider
|
||||
slider_label = lv.label(lv.scr_act())
|
||||
slider_label.set_text("0%")
|
||||
|
||||
slider_label.align_to(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10)
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user