adding micropython examples (#2286)
* adding micropython examples * adding micropython examples
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user