示例#1
0
def widget_new(type, parm = None):
    config = sys.modules['llvgl'].config        
    content = config["win"].get_content()
    lv_obj = None
    if type == TYPE.LABEL:    
        lv_obj = lv.label(content)
    elif type == TYPE.BUTTON:    
        lv_obj = lv.btn(content)
        # buttons don't scale with the content by default
        lv_obj.set_fit(lv.FIT.TIGHT)  # MAX, NONE, PARENT, TIGHT
    elif type == TYPE.SWITCH:    
        lv_obj = lv.switch(content)
    elif type == TYPE.SLIDER:    
        lv_obj = lv.slider(content)
        # sliders default width is too wide for the 240x320 screen
        lv_obj.set_width(180)
    elif type == TYPE.CHECKBOX:    
        lv_obj = lv.checkbox(content)
    elif type == TYPE.LED:    
        lv_obj = lv.led(content)
        # leds default size is a little big for the 240x320 screen
        lv_obj.set_size(30,30)
    elif type == TYPE.GAUGE:    
        lv_obj = lv.gauge(content)
    elif type == TYPE.CHART:
        lv_obj = lv.chart(content)
        # leds default size is a little big for the 240x320 screen
        lv_obj.set_size(180,180)
    elif type == TYPE.DROPDOWN:
        lv_obj = lv.dropdown(content)
    else:
        print("Unknown type:", type);
        return None

    # add new object to internal list
    obj =  { "lv_obj": lv_obj, "type": type }    
    config["objects"].append(obj)

    # set optional parameter if widget support
    if type == TYPE.LABEL or type == TYPE.BUTTON or type == TYPE.CHECKBOX:    
        widget_set_text(obj, parm)
    elif type == TYPE.SWITCH or type == TYPE.LED or type == TYPE.SLIDER:    
        widget_set_value(obj, parm)    
    
    # install default event handler
    lv_obj.set_event_cb(lambda o, e: on_event(obj, e))

    return obj
 def led_init(self):
     """
     Initialize the LED on the screen
     """
     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
     led = lv.led(self.main_scr)
     led.set_style(lv.led.STYLE.MAIN, style_led)
     led.align(lv.scr_act(), lv.ALIGN.IN_TOP_RIGHT, -10, 5)
     led.off()
     return led
示例#3
0
def visuals_create(parent):
    page = lv.page.__cast__(parent)
    lv.page.set_scrl_layout(page, lv.LAYOUT.PRETTY_TOP)

    disp_size = display.get_size_category()

    grid_h_chart = lv.page.get_height_grid(page, 1, 1)
    if disp_size <= lv.DISP_SIZE.LARGE:
        grid_w_chart = lv.page.get_width_grid(page, 1, 1)
    else:
        grid_w_chart = lv.page.get_width_grid(page, 1, 2)

    chart = lv.chart(parent, None)
    chart.add_style(lv.chart.PART.BG, style_box)
    if disp_size <= lv.DISP_SIZE.SMALL:
        chart.set_style_local_text_font(lv.chart.PART.SERIES_BG,
                                        lv.STATE.DEFAULT,
                                        lv.theme_get_font_small())

    chart.set_drag_parent(True)
    chart.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                    "Line chart")
    chart.set_width_margin(grid_w_chart)
    chart.set_height_margin(grid_h_chart)
    chart.set_div_line_count(3, 0)
    chart.set_point_count(8)
    chart.set_type(lv.chart.TYPE.LINE)

    if disp_size > lv.DISP_SIZE.SMALL:
        chart.set_style_local_pad_left(lv.chart.PART.BG, lv.STATE.DEFAULT,
                                       4 * (LV_DPI // 10))
        chart.set_style_local_pad_bottom(lv.chart.PART.BG, lv.STATE.DEFAULT,
                                         3 * (LV_DPI // 10))
        chart.set_style_local_pad_right(lv.chart.PART.BG, lv.STATE.DEFAULT,
                                        2 * (LV_DPI // 10))
        chart.set_style_local_pad_top(lv.chart.PART.BG, lv.STATE.DEFAULT,
                                      2 * (LV_DPI // 10))
        chart.set_y_tick_length(0, 0)
        chart.set_x_tick_length(0, 0)
        chart.set_y_tick_texts("600\n500\n400\n300\n200", 0,
                               lv.chart.AXIS.DRAW_LAST_TICK)
        chart.set_x_tick_texts("Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug", 0,
                               lv.chart.AXIS.DRAW_LAST_TICK)

    s1 = chart.add_series(LV_THEME_DEFAULT_COLOR_PRIMARY)
    s2 = chart.add_series(LV_THEME_DEFAULT_COLOR_SECONDARY)

    chart.set_next(s1, 10)
    chart.set_next(s1, 90)
    chart.set_next(s1, 30)
    chart.set_next(s1, 60)
    chart.set_next(s1, 10)
    chart.set_next(s1, 90)
    chart.set_next(s1, 30)
    chart.set_next(s1, 60)
    chart.set_next(s1, 10)
    chart.set_next(s1, 90)

    chart.set_next(s2, 32)
    chart.set_next(s2, 66)
    chart.set_next(s2, 5)
    chart.set_next(s2, 47)
    chart.set_next(s2, 32)
    chart.set_next(s2, 32)
    chart.set_next(s2, 66)
    chart.set_next(s2, 5)
    chart.set_next(s2, 47)
    chart.set_next(s2, 66)
    chart.set_next(s2, 5)
    chart.set_next(s2, 47)

    chart2 = lv.chart(parent, chart)
    chart2.set_type(lv.chart.TYPE.COLUMN)
    chart2.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                     "Column chart")

    s1 = chart2.add_series(LV_THEME_DEFAULT_COLOR_PRIMARY)
    s2 = chart2.add_series(LV_THEME_DEFAULT_COLOR_SECONDARY)

    chart2.set_next(s1, 10)
    chart2.set_next(s1, 90)
    chart2.set_next(s1, 30)
    chart2.set_next(s1, 60)
    chart2.set_next(s1, 10)
    chart2.set_next(s1, 90)
    chart2.set_next(s1, 30)
    chart2.set_next(s1, 60)
    chart2.set_next(s1, 10)
    chart2.set_next(s1, 90)

    chart2.set_next(s2, 32)
    chart2.set_next(s2, 66)
    chart2.set_next(s2, 5)
    chart2.set_next(s2, 47)
    chart2.set_next(s2, 32)
    chart2.set_next(s2, 32)
    chart2.set_next(s2, 66)
    chart2.set_next(s2, 5)
    chart2.set_next(s2, 47)
    chart2.set_next(s2, 66)
    chart2.set_next(s2, 5)
    chart2.set_next(s2, 47)

    if disp_size <= lv.DISP_SIZE.SMALL:
        grid_w_meter = lv.page.get_width_grid(page, 1, 1)
    elif disp_size <= lv.DISP_SIZE.MEDIUM:
        grid_w_meter = lv.page.get_width_grid(page, 2, 1)
    else:
        grid_w_meter = lv.page.get_width_grid(page, 3, 1)

    meter_h = lv.page.get_height_fit(page)
    if grid_w_meter < meter_h:
        meter_size = grid_w_meter
    else:
        meter_size = meter_h

    lmeter = lv.linemeter(parent, None)
    lmeter.set_drag_parent(True)
    lmeter.set_value(50)
    lmeter.set_size(meter_size, meter_size)
    lmeter.add_style(lv.linemeter.PART.MAIN, style_box)
    lmeter.set_style_local_value_str(lv.linemeter.PART.MAIN, lv.STATE.DEFAULT,
                                     "Line meter")

    label = lv.label(lmeter, None)
    label.align(lmeter, lv.ALIGN.CENTER, 0, 0)
    label.set_style_local_text_font(lv.label.PART.MAIN, lv.STATE.DEFAULT,
                                    lv.theme_get_font_title())

    a_lm = lv.anim_t()
    a_lm.init()
    a_lm.set_custom_exec_cb(lambda a, val: linemeter_anim(a, lmeter, val))
    a_lm.set_values(0, 100)
    a_lm.set_time(4000)
    a_lm.set_playback_time(1000)
    a_lm.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    lv.anim_t.start(a_lm)

    gauge = lv.gauge(parent, None)
    gauge.set_drag_parent(True)
    gauge.set_size(meter_size, meter_size)
    gauge.add_style(lv.gauge.PART.MAIN, style_box)
    gauge.set_style_local_value_str(lv.gauge.PART.MAIN, lv.STATE.DEFAULT,
                                    "Gauge")

    label = lv.label(gauge, label)
    label.align(gauge, lv.ALIGN.CENTER, 0, grid_w_meter // 3)

    a_ga = lv.anim_t()
    a_ga.init()
    a_ga.set_custom_exec_cb(lambda a, val: linemeter_anim(a, lmeter, val))
    a_ga.set_values(0, 100)
    a_ga.set_time(4000)
    a_ga.set_playback_time(1000)
    a_ga.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    a_ga.set_custom_exec_cb(lambda a, val: gauge_anim(a, gauge, val))
    lv.anim_t.start(a_ga)

    arc = lv.arc(parent, None)
    arc.set_drag_parent(True)
    arc.set_bg_angles(0, 360)
    arc.set_rotation(270)
    arc.set_angles(0, 0)
    arc.set_size(meter_size, meter_size)
    arc.add_style(lv.arc.PART.BG, style_box)
    arc.set_style_local_value_str(lv.arc.PART.BG, lv.STATE.DEFAULT, "Arc")

    label = lv.label(arc)
    label.align(arc, lv.ALIGN.CENTER, 0, 0)

    a_arc = lv.anim_t()
    a_arc.init()
    a_arc.set_custom_exec_cb(lambda a_arc, val: anim_phase1(a_arc, arc, val))
    a_arc.set_values(0, 360)
    a_arc.set_ready_cb(lambda a: arc_phase1_ready_cb(a, arc))
    # a_arc.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    a_arc.set_time(1000)
    lv.anim_t.start(a_arc)

    # Create a bar and use the backgrounds value style property to display the current value
    bar_h = lv.cont(parent, None)
    bar_h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
    bar_h.add_style(lv.cont.PART.MAIN, style_box)
    bar_h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Bar")

    if disp_size <= lv.DISP_SIZE.SMALL:
        bar_h.set_width(lv.page_get_width_grid(page, 1, 1))
    elif disp_size <= lv.DISP_SIZE.MEDIUM:
        bar_h.set_width(lv.page.get_width_grid(page, 2, 1))
    else:
        bar_h.set_width(lv.page.get_width_grid(parent, 3, 2))

    bar = lv.bar(bar_h, None)
    bar.set_width(lv.cont.get_width_fit(bar_h))
    bar.set_style_local_value_font(lv.bar.PART.BG, lv.STATE.DEFAULT,
                                   lv.theme_get_font_small())
    bar.set_style_local_value_align(lv.bar.PART.BG, lv.STATE.DEFAULT,
                                    lv.ALIGN.OUT_BOTTOM_MID)
    bar.set_style_local_value_ofs_y(lv.bar.PART.BG, lv.STATE.DEFAULT,
                                    LV_DPI // 20)
    bar.set_style_local_margin_bottom(lv.bar.PART.BG, lv.STATE.DEFAULT,
                                      LV_DPI // 7)
    bar.align(None, lv.ALIGN.CENTER, 0, 0)
    bar.set_value(30, lv.ANIM.OFF)

    led_h = lv.cont(parent, None)
    led_h.set_layout(lv.LAYOUT.PRETTY_MID)
    if disp_size <= lv.DISP_SIZE.SMALL:
        led_h.set_width(lv.page.get_width_grid(page, 1, 1))
    elif disp_size <= lv.DISP_SIZE.MEDIUM:
        led_h.set_width(lv.page.get_width_grid(page, 2, 1))
    else:
        led_h.set_width(lv.page.get_width_grid(page, 3, 1))

    led_h.set_height(lv.obj.get_height(lv.obj.__cast__(bar_h)))
    led_h.add_style(lv.cont.PART.MAIN, style_box)
    led_h.set_drag_parent(True)
    led_h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                    "LEDs")

    led = lv.led(led_h, None)
    led_size = lv.obj.get_height_fit(lv.obj.__cast__(led_h))
    led.set_size(led_size, led_size)
    led.off()

    led = lv.led(led_h, led)
    led.set_bright((LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN) // 2 +
                   LV_LED_BRIGHT_MIN)

    led = lv.led(led_h, led)
    led.on()

    if disp_size == lv.DISP_SIZE.MEDIUM:
        led_h.add_protect(lv.PROTECT.POS)
        led_h.align(
            bar_h, lv.ALIGN.OUT_BOTTOM_MID, 0,
            lv.obj.get_style_margin_top(lv.obj.__cast__(led_h),
                                        lv.obj.PART.MAIN) +
            lv.obj.get_style_pad_inner(parent, lv.page.PART.SCROLLABLE))

    task = lv.task_create_basic()
    task.set_cb(lambda task: bar_anim(task, bar))
    task.set_period(100)
    task.set_prio(lv.TASK_PRIO.LOWEST)
示例#4
0
#!//opt/bin/lv_micropython -i
import time
import lvgl as lv
import display_driver

#
# Create LED's with different brightness and color
#

# Create a LED and switch it OFF
led1 = lv.led(lv.scr_act())
led1.align(lv.ALIGN.CENTER, -80, 0)
led1.off()

# Copy the previous LED and set a brightness
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())
led3.align(lv.ALIGN.CENTER, 80, 0)
led3.on()
示例#5
0
btn2.align(scr2, lv.ALIGN.IN_TOP_LEFT, 5, 5)
label2 = lv.label(btn2)
label2.set_text("<")

style_led = lv.style_t()
lv.style_copy(style_led, lv.style_pretty_color)
style_led.body.radius = 800
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

led1 = lv.led(scr2)
# led1.set_style(lv.led.STYLE.MAIN, style_led)
led1.align(slider, lv.ALIGN.OUT_RIGHT_MID, 10, 0)
led1.set_bright(slider.get_value() * 2)
led1.set_drag(True)


def slider_event_cb(slider, event):
    if event == lv.EVENT.VALUE_CHANGED:
        led1.set_bright(slider.get_value() * 2)


def btn1_event_cb(btn1, event):
    if event == lv.EVENT.CLICKED:
        lv.scr_load(scr2)
示例#6
0
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver

# Create a LED and switch it OFF
led1 = lv.led(lv.scr_act(), None)
led1.align(None, 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)

# 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()
    def __init__(self):
        scr = lv.obj()

        #############################create a gauge#################################
        # Create a style
        style = lv.style_t()
        lv.style_copy(style, lv.style_pretty_color)
        style.body.main_color = lv.color_hex3(
            0x666)  # Line color at the beginning
        style.body.grad_color = lv.color_hex3(0x666)  # Line color at the end
        style.body.padding.left = 10  # Scale line length
        style.body.padding.inner = 8  # Scale label padding
        style.body.border.color = lv.color_hex3(
            0x333)  # Needle middle circle color
        style.line.width = 3
        style.text.color = lv.color_hex3(0x333)
        style.line.color = lv.color_hex3(
            0xF00)  # Line color after the critical value

        # Describe the color for the needles
        needle_colors = [
            lv.color_make(0x00, 0x00, 0xFF),
            lv.color_make(0xFF, 0xA5, 0x00),
            lv.color_make(0x80, 0x00, 0x80)
        ]

        # Create a gauge
        gauge1 = lv.gauge(scr)
        gauge1.set_style(lv.gauge.STYLE.MAIN, style)
        gauge1.set_needle_count(len(needle_colors), needle_colors)
        gauge1.set_size(200, 200)
        gauge1.align(None, lv.ALIGN.CENTER, 0, -50)

        # Set the values
        gauge1.set_value(0, 10)
        gauge1.set_value(1, 20)
        gauge1.set_value(2, 30)

        #################################explanation of needle############################
        # Create a style for the LED

        #color for LED 1
        style_led1 = lv.style_t()
        lv.style_copy(style_led1, lv.style_pretty_color)
        style_led1.body.radius = 800  # large enough to draw a circle
        style_led1.body.main_color = lv.color_make(0x00, 0x00, 0xFF)
        style_led1.body.border.width = 3
        style_led1.body.border.opa = lv.OPA._30
        style_led1.body.shadow.width = 5

        # Create a LED 1
        led1 = lv.led(scr)
        led1.set_style(lv.led.STYLE.MAIN, style_led1)
        led1.align(None, lv.ALIGN.CENTER, -40, 40)
        led1.on()

        btnLED1 = lv.btn(scr)
        btnLED1.align(lv.scr_act(), lv.ALIGN.CENTER, 30, 60)
        btnLED1.set_size(70, 30)
        labelLED1 = lv.label(btnLED1)
        labelLED1.set_text("Battery")

        #color for LED 2
        style_led2 = lv.style_t()
        lv.style_copy(style_led2, lv.style_pretty_color)
        style_led2.body.radius = 800  # large enough to draw a circle
        style_led2.body.main_color = lv.color_make(0xFF, 0xA5, 0x00)
        style_led2.body.border.width = 3
        style_led2.body.border.opa = lv.OPA._30
        style_led2.body.shadow.width = 5

        # Create a LED 2
        led2 = lv.led(scr)
        led2.set_style(lv.led.STYLE.MAIN, style_led2)
        led2.align(None, lv.ALIGN.CENTER, -40, 85)
        led2.on()

        def event_handler(obj, event):
            lv.obj_del(scr)
            from thirdScreen import thirdScreen

        btnLED2 = lv.btn(scr)
        btnLED2.align(lv.scr_act(), lv.ALIGN.CENTER, 30, 105)
        btnLED2.set_size(70, 30)
        labelLED2 = lv.label(btnLED2)
        labelLED2.set_text("Memory")
        btnLED2.set_event_cb(event_handler)
        #color for LED 3
        style_led3 = lv.style_t()
        lv.style_copy(style_led3, lv.style_pretty_color)
        style_led3.body.radius = 800  # large enough to draw a circle
        style_led3.body.main_color = lv.color_make(0x80, 0x00, 0x80)
        style_led3.body.border.width = 3
        style_led3.body.border.opa = lv.OPA._30
        style_led3.body.shadow.width = 5

        # Create a LED 3
        led3 = lv.led(scr)
        led3.set_style(lv.led.STYLE.MAIN, style_led3)
        led3.align(None, lv.ALIGN.CENTER, -40, 130)
        led3.on()

        btnLED3 = lv.btn(scr)
        btnLED3.align(lv.scr_act(), lv.ALIGN.CENTER, 30, 150)
        btnLED3.set_size(70, 30)
        labelLED3 = lv.label(btnLED3)
        labelLED3.set_text("RAM")

        lv.scr_load(scr)