Exemple #1
0
    def page_obj_init(self, par):
        self.anim_obj = lv.obj(par)
        self.anim_obj.set_size(30, 30)
        self.anim_obj.set_align(lv.ALIGN.TOP_LEFT)
        self.anim_obj.clear_flag(lv.obj.FLAG.SCROLLABLE)
        self.anim_obj.set_style_bg_color(lv.palette_main(lv.PALETTE.RED),
                                         lv.PART.MAIN)
        self.anim_obj.set_grid_cell(lv.GRID_ALIGN.START, 0, 1,
                                    lv.GRID_ALIGN.START, 0, 1)

        self.p1_label = lv.label(par)
        self.p2_label = lv.label(par)
        self.p1_label.set_text("p1:0")
        self.p2_label.set_text("p2:0")
        self.p1_label.set_grid_cell(lv.GRID_ALIGN.START, 0, 1,
                                    lv.GRID_ALIGN.START, 1, 1)
        self.p2_label.set_grid_cell(lv.GRID_ALIGN.START, 0, 1,
                                    lv.GRID_ALIGN.START, 2, 1)

        self.p1_slider = lv.slider(par)
        self.p2_slider = lv.slider(par)
        self.p1_slider.set_range(0, 1024)
        self.p2_slider.set_range(0, 1024)
        self.p1_slider.set_style_pad_all(2, lv.PART.KNOB)
        self.p2_slider.set_style_pad_all(2, lv.PART.KNOB)
        self.p1_slider.add_event_cb(self.slider_event_cb,
                                    lv.EVENT.VALUE_CHANGED, None)
        self.p2_slider.add_event_cb(self.slider_event_cb,
                                    lv.EVENT.VALUE_CHANGED, None)
        self.p1_slider.set_grid_cell(lv.GRID_ALIGN.STRETCH, 1, 1,
                                     lv.GRID_ALIGN.START, 1, 1)
        self.p2_slider.set_grid_cell(lv.GRID_ALIGN.STRETCH, 1, 1,
                                     lv.GRID_ALIGN.START, 2, 1)

        self.run_btn = lv.btn(par)
        self.run_btn.add_event_cb(self.run_btn_event_handler, lv.EVENT.CLICKED,
                                  None)
        btn_label = lv.label(self.run_btn)
        btn_label.set_text(lv.SYMBOL.PLAY)
        btn_label.center()
        self.run_btn.set_grid_cell(lv.GRID_ALIGN.STRETCH, 2, 1,
                                   lv.GRID_ALIGN.STRETCH, 1, 2)

        self.chart = lv.chart(par)
        self.chart.set_style_pad_all(0, lv.PART.MAIN)
        self.chart.set_style_size(0, lv.PART.INDICATOR)
        self.chart.set_type(lv.chart.TYPE.SCATTER)
        self.ser1 = self.chart.add_series(lv.palette_main(lv.PALETTE.RED),
                                          lv.chart.AXIS.PRIMARY_Y)
        self.chart.set_range(lv.chart.AXIS.PRIMARY_Y, 0, 1024)
        self.chart.set_range(lv.chart.AXIS.PRIMARY_X, 0, 1024)
        self.chart.set_point_count(CHART_POINTS_NUM)
        self.chart.set_grid_cell(lv.GRID_ALIGN.STRETCH, 0, 3,
                                 lv.GRID_ALIGN.STRETCH, 3, 1)
Exemple #2
0
    def __init__(self, app, page):
        self.app = app
        self.page = page

        # slider
        self.slider = lv.slider(page)
        self.slider.align(page, lv.ALIGN.IN_TOP_LEFT, 20, 20)
        self.slider_label = lv.label(page)
        self.slider_label.align(self.slider, lv.ALIGN.OUT_RIGHT_MID, 15, 0)
        self.slider.set_event_cb(self.on_slider_changed)
        self.on_slider_changed(None)

        # style selector
        self.styles = [
            ("Plain", lv.style_plain),
            ("Plain color", lv.style_plain_color),
            ("Pretty", lv.style_pretty),
            ("Pretty color", lv.style_pretty_color),
        ]

        self.style_selector = lv.ddlist(page)
        self.style_selector.align(self.slider, lv.ALIGN.IN_BOTTOM_LEFT, 0, 40)
        self.style_selector.set_options("\n".join(x[0] for x in self.styles))
        self.style_selector.set_event_cb(self.on_style_selector_changed)

        # counter button
        self.counter_btn = lv.btn(page)
        self.counter_btn.set_size(80, 80)
        self.counter_btn.align(self.style_selector, lv.ALIGN.OUT_RIGHT_TOP, 40, 0)
        self.counter_label = lv.label(self.counter_btn)
        self.counter_label.set_text("Count")
        self.counter_btn.set_event_cb(self.on_counter_btn)
        self.counter = 0
    def __init__(self, app, page):
        self.app = app
        self.page = page

        # slider
        self.slider = lv.slider(page)
        self.slider.align(page, lv.ALIGN.IN_TOP_LEFT, 20, 20)
        self.slider_label = lv.label(page)
        self.slider_label.align(self.slider, lv.ALIGN.OUT_RIGHT_MID, 15, 0)
        self.slider.set_event_cb(self.on_slider_changed)
        self.on_slider_changed(None)

        # style selector
        self.styles = [('Plain', lv.style_plain),
                       ('Plain color', lv.style_plain_color),
                       ('Pretty', lv.style_pretty),
                       ('Pretty color', lv.style_pretty_color)]

        self.style_selector = lv.ddlist(page)
        self.style_selector.align(self.slider, lv.ALIGN.IN_BOTTOM_LEFT, 0, 40)
        self.style_selector.set_options('\n'.join(x[0] for x in self.styles))
        self.style_selector.set_event_cb(self.on_style_selector_changed)

        self.counter_btn = lv.btn(page)
        self.counter_btn.set_size(140, 100)
        self.counter_btn.align(self.page, lv.ALIGN.IN_TOP_RIGHT, -20, 20)
        self.counter_label = lv.label(self.counter_btn)
        self.counter_label.set_text('Count')
        self.counter_btn.set_event_cb(self.on_counter_btn)
        self.counter = 0
Exemple #4
0
    def __init__(self, app, page):
        self.app = app
        self.page = page

        # slider
        self.slider = lv.slider(page)
        self.slider.set_width(160)
        self.slider.align(page, lv.ALIGN.IN_TOP_LEFT, 20, 20)
        self.slider_label = lv.label(page)
        self.slider_label.align(self.slider, lv.ALIGN.OUT_RIGHT_MID, 15, 0)
        self.slider.set_event_cb(self.on_slider_changed)
        self.on_slider_changed(None)

        # style selector
        self.styles = [('Gray', ColorStyle(0xCCC)), ('Red', ColorStyle(0xF00)),
                       ('Green', ColorStyle(0x0F0)),
                       ('Blue', ColorStyle(0x00F))]

        self.style_selector = lv.dropdown(page)
        self.style_selector.add_style(self.style_selector.PART.MAIN,
                                      ShadowStyle())
        self.style_selector.align(self.slider, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 40)
        self.style_selector.set_options('\n'.join(x[0] for x in self.styles))
        self.style_selector.set_event_cb(self.on_style_selector_changed)

        # counter button
        self.counter_btn = lv.btn(page)
        self.counter_btn.set_size(80, 80)
        self.counter_btn.align(self.page, lv.ALIGN.IN_BOTTOM_MID, 0, -20)
        self.counter_label = lv.label(self.counter_btn)
        self.counter_label.set_text("Count")
        self.counter_btn.set_event_cb(self.on_counter_btn)
        self.counter = 0
Exemple #5
0
    def __init__(self, app, page):
        self.app = app
        self.page = page
        self.chart = AnimatedChart(page, 100, 1000)
        self.chart.set_width(page.get_width() - 100)
        self.chart.align(page, lv.ALIGN.CENTER, 0, 0)
        self.series1 = self.chart.add_series(lv.color_hex(0xFF0000))
        self.chart.set_type(self.chart.TYPE.POINT | self.chart.TYPE.LINE)
        self.chart.set_series_width(3)
        self.chart.set_range(0, 100)
        self.chart.init_points(self.series1, 10)
        self.chart.set_points(self.series1, [10, 20, 30, 20, 10, 40, 50, 90, 95, 90])
        self.chart.set_x_tick_texts("a\nb\nc\nd\ne", 2, lv.chart.AXIS.DRAW_LAST_TICK)
        self.chart.set_x_tick_length(10, 5)
        self.chart.set_y_tick_texts("1\n2\n3\n4\n5", 2, lv.chart.AXIS.DRAW_LAST_TICK)
        self.chart.set_y_tick_length(10, 5)
        self.chart.set_div_line_count(3, 3)
        self.chart.set_margin(30)

        # Create a slider that controls the chart animation speed

        def on_slider_changed(obj=None, event=-1):
            self.chart.factor = self.slider.get_value()

        self.slider = lv.slider(page)
        self.slider.align(self.chart, lv.ALIGN.OUT_RIGHT_TOP, 10, 0)
        self.slider.set_width(30)
        self.slider.set_height(self.chart.get_height())
        self.slider.set_range(10, 200)
        self.slider.set_value(self.chart.factor, 0)
        self.slider.set_event_cb(on_slider_changed)
def new_mnemonic(mnemonic, 
                 cb_continue, cb_back, cb_update=None, 
                 title="Your new recovery phrase:"):
    """Makes the new mnemonic screen with a slider to change number of words"""
    scr = switch_to_new_screen()
    add_label(title, style="title")
    table = add_mnemonic_table(mnemonic, y=100)

    if cb_update is not None:
        wordcount = len(mnemonic.split())
        slider = lv.slider(scr)
        slider.set_width(HOR_RES-2*PADDING)
        slider.set_range(0, 4)
        slider.set_pos(PADDING, 600)
        slider.set_value((wordcount-12)//3, lv.ANIM.OFF)
        lbl = add_label("Number of words: %d" % wordcount, y=550)
        @feed_rng
        def cb_upd(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                wordcount = slider.get_value()*3+12
                lbl.set_text("Number of words: %d" % wordcount)
                mnemonic = cb_update(wordcount)
                table_set_mnemonic(table, mnemonic)
        slider.set_event_cb(cb_upd)
    @feed_rng
    def cb_prev(obj, event):
        if event == lv.EVENT.RELEASED:
            cb_back()
    @feed_rng
    def cb_next(obj, event):
        if event == lv.EVENT.RELEASED:
            cb_continue()
    add_button_pair("Back", cb_prev, "Continue", cb_next)
Exemple #7
0
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 interface():
    def update_task(task):
        set_usb_voltage(power.getVbusVoltage())
        set_usb_pwr(power.getVbusCurrent())
        if power.isBatteryConnect():
            set_batt_voltage(power.getBattVoltage())
            if power.isChargeing():
                set_batt_pwr("Charging", power.getBattChargeCurrent())
                batt_percent.set_hidden(True)
            else:
                set_batt_pwr("Discharging", power.getBattDischargeCurrent())
                set_batt_per(power.getBattPercentage())
                batt_percent.set_hidden(False)

    def event_cb(obj, event):
        if event == lv.EVENT.VALUE_CHANGED:
            tft.set_backlight_level(obj.get_value())

    def set_usb_pwr(pwr):
        usb_pwr.set_text("USB current: {} mA".format(pwr))

    def set_usb_voltage(volts):
        usb_voltage.set_text("USB voltage: {} mV".format(volts))

    def set_batt_voltage(volts):
        batt_voltage.set_text("Battery voltage: {} mV".format(volts))

    def set_batt_pwr(mode, pwr):
        batt_pwr.set_text("{} battery \ncurrent: {} mA".format(mode, pwr))

    def set_batt_per(per):
        batt_percent.set_text("Battery percent: {}%".format(per))

    scr = lv.obj()
    tabview = lv.tabview(scr)
    vbus_tab = tabview.add_tab("USB")
    usb_voltage = lv.label(vbus_tab)
    usb_pwr = lv.label(vbus_tab)
    usb_pwr.set_y(usb_voltage.get_y() + 20)
    la = lv.switch(vbus_tab)
    batt_tab = tabview.add_tab("Battery")
    batt_voltage = lv.label(batt_tab)
    batt_pwr = lv.label(batt_tab)
    batt_pwr.set_y(batt_voltage.get_y() + 20)
    batt_percent = lv.label(batt_tab)
    batt_percent.set_y(batt_pwr.get_y() + 40)
    brightness_slider = lv.slider(batt_tab)
    brightness_slider.align(None, lv.ALIGN.IN_BOTTOM_MID, 0, 0)
    brightness_slider.set_range(0, 100)
    brightness_slider.set_value(100, 1)
    brightness_slider.set_event_cb(event_cb)
    update_task(None)
    lv.scr_load(scr)
    watch.tft.backlight_fade(100)
    lv.task_create(update_task, 1000, 5, None)
Exemple #9
0
    def __init__(self):
        self.obj_width = 120
        self.obj_height = 150
        #
        # Create an animation timeline
        #

        self.par = lv.scr_act()
        self.par.set_flex_flow(lv.FLEX_FLOW.ROW)
        self.par.set_flex_align(lv.FLEX_ALIGN.SPACE_AROUND,
                                lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)

        self.btn_run = lv.btn(self.par)
        self.btn_run.add_event_cb(self.btn_run_event_handler,
                                  lv.EVENT.VALUE_CHANGED, None)
        self.btn_run.add_flag(lv.obj.FLAG.IGNORE_LAYOUT)
        self.btn_run.add_flag(lv.obj.FLAG.CHECKABLE)
        self.btn_run.align(lv.ALIGN.TOP_MID, -50, 20)

        self.label_run = lv.label(self.btn_run)
        self.label_run.set_text("Run")
        self.label_run.center()

        self.btn_del = lv.btn(self.par)
        self.btn_del.add_event_cb(self.btn_del_event_handler, lv.EVENT.CLICKED,
                                  None)
        self.btn_del.add_flag(lv.obj.FLAG.IGNORE_LAYOUT)
        self.btn_del.align(lv.ALIGN.TOP_MID, 50, 20)

        self.label_del = lv.label(self.btn_del)
        self.label_del.set_text("Stop")
        self.label_del.center()

        self.slider = lv.slider(self.par)
        self.slider.add_event_cb(self.slider_prg_event_handler,
                                 lv.EVENT.VALUE_CHANGED, None)
        self.slider.add_flag(lv.obj.FLAG.IGNORE_LAYOUT)
        self.slider.align(lv.ALIGN.BOTTOM_RIGHT, -20, -20)
        self.slider.set_range(0, 65535)

        self.obj1 = lv.obj(self.par)
        self.obj1.set_size(self.obj_width, self.obj_height)

        self.obj2 = lv.obj(self.par)
        self.obj2.set_size(self.obj_width, self.obj_height)

        self.obj3 = lv.obj(self.par)
        self.obj3.set_size(self.obj_width, self.obj_height)

        self.anim_timeline = None
Exemple #10
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
Exemple #11
0
 def __init__(self, app, page):
     self.app = app
     self.page = page
     
     # slider 
     self.slider = lv.slider(page)
     self.slider.align(page, lv.ALIGN.IN_TOP_LEFT, 20, 0)
     self.slider_label = lv.label(page)
     self.slider_label.align(self.slider, lv.ALIGN.OUT_RIGHT_MID, 15, 0)
     self.slider.set_action(self.on_slider_changed)
     self.on_slider_changed(0)
     
     # style selector
     self.styles = [('Plain', lv.style_plain), ('Plain color', lv.style_plain_color), ('Pretty', lv.style_pretty), ('Pretty color', lv.style_pretty_color)]
 
     self.style_selector = lv.ddlist(page)
     self.style_selector.align(self.slider, lv.ALIGN.IN_BOTTOM_LEFT, 0, 40)
     self.style_selector.set_options('\n'.join(x[0] for x in self.styles))
     self.style_selector.set_action(self.on_style_selector_changed)
    def __init__(self, app, page):
        self.app = app
        self.page = page
        self.test_events = []

        self.page.set_flex_flow(lv.FLEX_FLOW.COLUMN)
        self.page.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY,
                                 lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)

        # slider
        self.slider = lv.slider(page)
        self.slider.set_width(lv.pct(80))
        self.slider_label = lv.label(page)
        self.slider.add_event_cb(self.on_slider_changed,
                                 lv.EVENT.VALUE_CHANGED, None)
        self.on_slider_changed(None)

        # style selector
        self.styles = [('Gray', ColorStyle(0xCCC)), ('Red', ColorStyle(0xF00)),
                       ('Green', ColorStyle(0x0F0)),
                       ('Blue', ColorStyle(0x00F))]

        self.style_selector = lv.dropdown(page)
        self.style_selector.add_style(ShadowStyle(), lv.PART.MAIN)
        self.style_selector.align(lv.ALIGN.OUT_BOTTOM_LEFT, 0, 40)
        self.style_selector.set_options('\n'.join(x[0] for x in self.styles))
        self.style_selector.add_event_cb(self.on_style_selector_changed,
                                         lv.EVENT.VALUE_CHANGED, None)

        # counter button
        self.counter_btn = lv.btn(page)
        self.counter_btn.set_size(80, 80)
        self.counter_label = lv.label(self.counter_btn)
        self.counter_label.set_text("Count")
        self.counter_label.align(lv.ALIGN.CENTER, 0, 0)
        self.counter_btn.add_event_cb(self.on_counter_btn, lv.EVENT.CLICKED,
                                      None)
        self.counter = 0
    def __init__(self, app, page):
        self.app = app
        self.page = page
        self.page.set_flex_flow(lv.FLEX_FLOW.ROW)
        self.page.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY,
                                 lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
        self.page.set_style_pad_all(10, lv.PART.MAIN)
        self.page.set_style_pad_gap(10, lv.PART.MAIN)
        self.chart = AnimatedChart(page, 100, 1000)
        self.chart.set_flex_grow(1)
        self.chart.set_height(lv.pct(100))
        self.series1 = self.chart.add_series(lv.color_hex(0xFF0000),
                                             self.chart.AXIS.PRIMARY_Y)
        self.chart.set_type(self.chart.TYPE.LINE)
        self.chart.set_style_line_width(3, lv.PART.ITEMS)
        self.chart.add_style(ColorStyle(0x055), lv.PART.ITEMS)
        self.chart.set_range(self.chart.AXIS.PRIMARY_Y, 0, 100)
        self.chart.set_point_count(10)
        self.chart.set_ext_y_array(self.series1,
                                   [10, 20, 30, 20, 10, 40, 50, 90, 95, 90])
        # self.chart.set_x_tick_texts("a\nb\nc\nd\ne", 2, lv.chart.AXIS.DRAW_LAST_TICK)
        # self.chart.set_x_tick_length(10, 5)
        # self.chart.set_y_tick_texts("1\n2\n3\n4\n5", 2, lv.chart.AXIS.DRAW_LAST_TICK)
        # self.chart.set_y_tick_length(10, 5)
        self.chart.set_div_line_count(5, 5)

        # Create a slider that controls the chart animation speed

        def on_slider_changed(event):
            self.chart.factor = self.slider.get_value()

        self.slider = lv.slider(page)
        self.slider.set_size(10, lv.pct(100))
        self.slider.set_range(10, 200)
        self.slider.set_value(self.chart.factor, 0)
        self.slider.add_event_cb(on_slider_changed, lv.EVENT.VALUE_CHANGED,
                                 None)
Exemple #14
0
    def __init__(self, page):
        self.page = page
        self.chart = AnimatedChart(page, 100, 1000)
        self.chart.set_width(page.get_width() - 80)
        self.series1 = self.chart.add_series(lv.color_hex(0xFF0000))
        self.chart.set_type(self.chart.TYPE.LINE)
        self.chart.set_style_local_line_width(self.chart.PART.SERIES,
                                              lv.STATE.DEFAULT, 3)
        self.chart.add_style(self.chart.PART.SERIES, ColorStyle(0x055))
        self.chart.add_style(self.chart.PART.BG, ChartPaddingStyle())
        self.chart.set_y_range(self.chart.AXIS.PRIMARY_Y, 0, 100)
        self.chart.init_points(self.series1, 10)
        self.chart.set_points(self.series1,
                              [10, 20, 30, 20, 10, 40, 50, 90, 95, 90])
        self.chart.set_x_tick_texts("a\nb\nc\nd\ne", 2,
                                    lv.chart.AXIS.DRAW_LAST_TICK)
        self.chart.set_x_tick_length(10, 5)
        self.chart.set_y_tick_texts("1\n2\n3\n4\n5", 2,
                                    lv.chart.AXIS.DRAW_LAST_TICK)
        self.chart.set_y_tick_length(10, 5)
        self.chart.set_div_line_count(3, 3)
        self.chart.set_height(page.get_height() - 60)
        self.chart.align(page, lv.ALIGN.CENTER, 0, 0)

        # Create a slider that controls the chart animation speed

        def on_slider_changed(obj=None, event=-1):
            self.chart.factor = self.slider.get_value()

        self.slider = lv.slider(page)
        self.slider.align(self.chart, lv.ALIGN.OUT_RIGHT_TOP, 10, 0)
        self.slider.set_width(10)
        self.slider.set_height(self.chart.get_height())
        self.slider.set_range(10, 200)
        self.slider.set_value(self.chart.factor, 0)
        self.slider.set_event_cb(on_slider_changed)
#!/opt/bin/lv_micropython -i
import time
import lvgl as lv
import display_driver


#
# A default slider with a label displaying the current value
#
def slider_event_cb(e):

    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)


# Create a slider in the center of the display
slider = lv.slider(lv.scr_act())
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)
Exemple #16
0
#!/opt/bin/lv_micropython -i

import time
import lvgl as lv
import display_driver


def event_handler(source, evt):
    if evt == lv.EVENT.VALUE_CHANGED:
        # print(slider.get_value())
        slider_label.set_text(str(slider.get_value()))


# Create a slider in the center of the display
slider = lv.slider(lv.scr_act(), None)
slider.set_width(200)
slider.align(None, lv.ALIGN.CENTER, 0, 0)
slider.set_event_cb(event_handler)
slider.set_range(0, 100)

# Create a label below the slider
slider_label = lv.label(lv.scr_act(), None)
slider_label.set_text("0")
slider_label.set_auto_realign(True)
slider_label.align(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10)

# Create an informative label
info_label = lv.label(lv.scr_act(), None)
info_label.set_text("""Welcome to the slider +
label demo!
Move the slider 
Exemple #17
0
    def createPage(self):
        global anim
        global playedTime
        global durationTime
        global slider
        global audio_src
        global player
        global image
        global music_alive
        global currentMusic
        global albumCover
        global songTitle
        global albumTitle
        global totalTime
        global anim_timeline
        global scr

        print("Enter Music")

        # init scr
        scr = lv.obj()

        win = lv.obj(scr)
        win.set_size(scr.get_width(), scr.get_height())
        win.set_style_border_opa(0, 0)
        win.set_style_radius(0, 0)
        win.set_style_bg_color(lv.color_black(), 0)
        win.clear_flag(lv.obj.FLAG.SCROLLABLE)

        backImg = lv.img(win)
        backImg.set_src(RESOURCES_ROOT + "images/back.png")
        backImg.set_style_align(lv.ALIGN.LEFT_MID, 0)
        backImg.add_flag(lv.obj.FLAG.CLICKABLE)
        backImg.add_event_cb(lambda e: music_back_click_callback(e, win),
                             lv.EVENT.CLICKED, None)
        backImg.add_event_cb(lambda e: music_back_press_callback(e, backImg),
                             lv.EVENT.PRESSED, None)
        backImg.add_event_cb(lambda e: music_back_release_callback(e, backImg),
                             lv.EVENT.RELEASED, None)
        backImg.set_ext_click_area(30)

        albumCover = lv.img(win)
        albumCover.set_style_pad_left(12, 0)
        albumCover.set_style_pad_top(10, 0)

        songTitle = lv.label(win)
        songTitle.set_style_text_font(lv.font_montserrat_20, 0)
        songTitle.set_style_text_color(lv.color_white(), 0)
        songTitle.align_to(albumCover, lv.ALIGN.TOP_LEFT, 130, 3)

        albumTitle = lv.label(win)
        albumTitle.set_style_text_font(lv.font_montserrat_16, 0)
        albumTitle.set_style_text_color(lv.color_make(0xCC, 0xCC, 0xCC), 0)
        albumTitle.align_to(songTitle, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 12)

        props = [lv.STYLE.BG_COLOR, 0]
        transition_dsc = lv.style_transition_dsc_t()
        transition_dsc.init(props, lv.anim_t.path_linear, 300, 0, None)

        style_main = lv.style_t()
        style_indicator = lv.style_t()
        style_pressed_color = lv.style_t()
        style_main.init()
        style_main.set_bg_opa(lv.OPA.COVER)
        style_main.set_bg_color(lv.color_make(0x66, 0x66, 0x66))
        style_main.set_radius(lv.RADIUS.CIRCLE)
        style_main.set_line_dash_width(1)

        style_indicator.init()
        style_indicator.set_bg_opa(lv.OPA.COVER)
        style_indicator.set_bg_color(lv.color_white())
        style_indicator.set_radius(lv.RADIUS.CIRCLE)
        style_indicator.set_transition(transition_dsc)

        style_pressed_color.init()
        style_pressed_color.set_bg_color(lv.color_white())

        # Create a slider and add the style
        slider = lv.slider(win)
        slider.remove_style_all()  # Remove the styles coming from the theme

        slider.add_style(style_main, lv.PART.MAIN)
        slider.add_style(style_indicator, lv.PART.INDICATOR)
        slider.add_style(style_pressed_color,
                         lv.PART.INDICATOR | lv.STATE.PRESSED)
        slider.align_to(albumTitle, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 25)
        slider.set_size(140, 1)

        anim = lv.anim_t()
        anim.init()
        anim.set_var(slider)

        playedTime = lv.label(win)
        setLabelValue(playedTime, 0)
        playedTime.set_style_text_font(lv.font_montserrat_16, 0)
        playedTime.set_style_text_color(lv.color_white(), 0)
        playedTime.align_to(slider, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 15)

        totalTime = lv.label(win)
        totalTime.set_style_text_font(lv.font_montserrat_16, 0)
        totalTime.set_style_text_color(lv.color_white(), 0)
        totalTime.align_to(slider, lv.ALIGN.OUT_BOTTOM_RIGHT, 0, 15)

        func_col_dsc = [80, 80, 80, 80, lv.GRID_TEMPLATE.LAST]
        func_row_dsc = [40, lv.GRID_TEMPLATE.LAST]

        funcContainer = lv.obj(win)
        funcContainer.set_style_bg_opa(0x00, 0)
        funcContainer.set_style_border_opa(0x00, 0)
        funcContainer.set_layout(lv.LAYOUT_GRID.value)
        funcContainer.set_grid_dsc_array(func_col_dsc, func_row_dsc)
        funcContainer.set_grid_align(lv.GRID_ALIGN.SPACE_BETWEEN,
                                     lv.GRID_ALIGN.SPACE_BETWEEN)
        funcContainer.set_align(lv.ALIGN.BOTTOM_MID)
        funcContainer.set_size(320, 70)

        for i in range(4):
            image[i] = lv.img(funcContainer)
            image[i].set_src(functionImage[i])
            image[i].add_flag(lv.obj.FLAG.CLICKABLE)
            image[i].set_ext_click_area(20)
            image[i].set_grid_cell(lv.GRID_ALIGN.CENTER, i, 1,
                                   lv.GRID_ALIGN.CENTER, 0, 1)

            if (i == 0):
                image[i].add_event_cb(lambda e: controller_click_cb(e, "prev"),
                                      lv.EVENT.CLICKED, None)
            elif (i == 1):
                image[i].add_event_cb(lambda e: controller_click_cb(e, "play"),
                                      lv.EVENT.CLICKED, None)
            elif (i == 2):
                image[i].add_event_cb(lambda e: controller_click_cb(e, "next"),
                                      lv.EVENT.CLICKED, None)
            elif (i == 3):
                image[i].add_event_cb(lambda e: controller_click_cb(e, "fav"),
                                      lv.EVENT.CLICKED, None)

        anim.set_custom_exec_cb(lambda a1, val: setSpentTime(slider, val))
        reset_music()

        from smart_panel import needAnimation
        if (needAnimation):
            lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.MOVE_LEFT, 500, 0, True)
        else:
            lv.scr_load_anim(scr, lv.SCR_LOAD_ANIM.NONE, 0, 0, True)

        music_alive = True
Exemple #18
0
def controls_create(parent):
    lv.page.set_scrl_layout(lv.page.__cast__(parent), lv.LAYOUT.PRETTY_TOP)
    if LV_DEMO_WIDGETS_SLIDESHOW == 0:
        btns = ["Cancel", "Ok", ""]
        m = lv.msgbox(lv.scr_act(), None)
        m.add_btns(btns)
        btnm = lv.btnmatrix.__cast__(m.get_btnmatrix())
        # print("type(btnm): ",type(btnm))
        btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECK_STATE)

    h = lv.cont(parent, None)
    h.set_layout(lv.LAYOUT.PRETTY_MID)
    h.add_style(lv.cont.PART.MAIN, style_box)
    h.set_drag_parent(True)

    h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Basics")

    disp_size = display.get_size_category()
    if disp_size <= lv.DISP_SIZE.SMALL:
        grid_w = lv.page.get_width_grid(lv.page.__cast__(parent), 1, 1)
        # print("grid_w: ",grid_w)
    else:
        grid_w = lv.page.get_width_grid(lv.page.__cast__(parent), 2, 1)
        # print("grid_w: ",grid_w)

    h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
    h.set_width(grid_w)
    btn = lv.btn(h, None)
    btn.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
    if disp_size <= lv.DISP_SIZE.SMALL:
        button_width = h.get_width_grid(1, 1)
    else:
        button_width = h.get_width_grid(2, 1)
    # print("button_width: %d"%button_width)

    btn.set_width(button_width)
    label = lv.label(btn, None)
    label.set_text("Button")

    btn = lv.btn(h, btn)
    btn.toggle()
    label = lv.label(btn, None)
    label.set_text("Button")

    lv.switch(h, None)

    lv.checkbox(h, None)

    fit_w = h.get_width_fit()

    slider = lv.slider(h, None)
    slider.set_value(40, lv.ANIM.OFF)
    slider.set_event_cb(slider_event_cb)
    slider.set_width_margin(fit_w)

    # Use the knobs style value the display the current value in focused state
    slider.set_style_local_margin_top(lv.slider.PART.BG, lv.STATE.DEFAULT,
                                      LV_DPX(25))
    slider.set_style_local_value_font(lv.slider.PART.KNOB, lv.STATE.DEFAULT,
                                      lv.theme_get_font_small())
    slider.set_style_local_value_ofs_y(lv.slider.PART.KNOB, lv.STATE.FOCUSED,
                                       -LV_DPX(25))
    slider.set_style_local_value_opa(lv.slider.PART.KNOB, lv.STATE.DEFAULT,
                                     lv.OPA.TRANSP)
    slider.set_style_local_value_opa(lv.slider.PART.KNOB, lv.STATE.FOCUSED,
                                     lv.OPA.COVER)
    slider.set_style_local_transition_time(lv.slider.PART.KNOB,
                                           lv.STATE.DEFAULT, 300)
    slider.set_style_local_transition_prop_5(lv.slider.PART.KNOB,
                                             lv.STATE.DEFAULT,
                                             lv.STYLE.VALUE_OFS_Y)
    slider.set_style_local_transition_prop_6(lv.slider.PART.KNOB,
                                             lv.STATE.DEFAULT,
                                             lv.STYLE.VALUE_OPA)

    slider = lv.slider(h, None)
    slider.set_type(lv.slider.TYPE.RANGE)
    slider.set_value(70, lv.ANIM.OFF)
    slider.set_left_value(30, lv.ANIM.OFF)
    slider.set_style_local_value_ofs_y(lv.slider.PART.INDIC, lv.STATE.DEFAULT,
                                       -LV_DPX(25))
    slider.set_style_local_value_font(lv.slider.PART.INDIC, lv.STATE.DEFAULT,
                                      lv.theme_get_font_small())
    slider.set_style_local_value_opa(lv.slider.PART.INDIC, lv.STATE.DEFAULT,
                                     lv.OPA.COVER)
    slider.set_event_cb(slider_event_cb)
    lv.event_send(slider, lv.EVENT.VALUE_CHANGED, None)  # To refresh the text
    if slider.get_width() > fit_w:
        slider.set_width(fit_w)

    h = lv.cont(parent, h)
    h.set_fit(lv.FIT.NONE)
    h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT,
                                "Text input")

    ta = lv.textarea(h, None)
    lv.cont.set_fit2(h, lv.FIT.PARENT, lv.FIT.NONE)
    ta.set_text("")
    ta.set_placeholder_text("E-mail address")
    ta.set_one_line(True)
    ta.set_cursor_hidden(True)
    #lv_obj_set_event_cb(ta, ta_event_cb);

    ta = lv.textarea(h, ta)
    ta.set_pwd_mode(True)
    ta.set_placeholder_text("Password")

    ta = lv.textarea(h, None)
    lv.cont.set_fit2(h, lv.FIT.PARENT, lv.FIT.NONE)
    ta.set_text("")
    ta.set_placeholder_text("Message")
    ta.set_cursor_hidden(True)
    #lv_obj_set_event_cb(ta, ta_event_cb);
    lv.cont.set_fit4(h, lv.FIT.PARENT, lv.FIT.PARENT, lv.FIT.NONE,
                     lv.FIT.PARENT)
Exemple #19
0
label.set_text("Button 1")

# Create a second button
btn2 = lv.btn(scr) # Create a button on the currently loaded screen
btn2.set_event_cb(btn_event_cb) # Set function to be called when the button is released
btn2.set_size(btn2.get_width(), 30) # Set the size
btn2.align(btn1, lv.ALIGN.OUT_RIGHT_MID, 50, 0) # Align next to the prev. button.

# Create a label on the button
label = lv.label(btn2)
label.set_text("Button 2")

"""
ADD A SLIDER
"""
slider = lv.slider(scr) # Create a slider
slider.set_size(round(scr.get_width() / 3), slider.get_height()) # Set the size
slider.align(btn1, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 20) # Align below the first button
slider.set_value(30, False) # Set the current value

"""
ADD A DROP DOWN LIST
"""
ddlist = lv.ddlist(scr) # Create a drop down list
ddlist.align(slider, lv.ALIGN.OUT_RIGHT_TOP, 50, 0) # Align next to the slider
ddlist.set_top(True) # Enable to be on the top when clicked
ddlist.set_options("None\nLittle\nHalf\nA lot\nAll")# Set the options
ddlist.set_event_cb(ddlist_event_cb) # Set function to call on new option is chosen

"""
CREATE A CHART
Exemple #20
0
    
png_img_dsc = lv.img_dsc_t({
    'data_size': len(png_data),
    'data': png_data 
})
def slider_event_cb(slider,event):
    if event == lv.EVENT.VALUE_CHANGED:
      # 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_local_image_recolor_opa(lv.img.PART.MAIN, lv.STATE.DEFAULT, intense)
      img1.set_style_local_image_recolor(lv.img.PART.MAIN, lv.STATE.DEFAULT, color)

# Create a set of RGB sliders 
# Use the red one as a base for all the settings 
red_slider = lv.slider(lv.scr_act(), None)
red_slider.set_range(0, 255)
red_slider.set_size(SLIDER_WIDTH, 200)   # Be sure it's a vertical slider
red_slider.set_style_local_bg_color(lv.slider.PART.INDIC, lv.STATE.DEFAULT, lv_colors.RED)
red_slider.set_event_cb(slider_event_cb)

# Copy it for the other three sliders 
green_slider = lv.slider(lv.scr_act(), red_slider)
green_slider.set_style_local_bg_color(lv.slider.PART.INDIC, lv.STATE.DEFAULT, lv_colors.LIME)
green_slider.set_event_cb(slider_event_cb)

blue_slider = lv.slider(lv.scr_act(), red_slider)
blue_slider.set_style_local_bg_color(lv.slider.PART.INDIC, lv.STATE.DEFAULT, lv_colors.BLUE)
blue_slider.set_event_cb(slider_event_cb)

intense_slider = lv.slider(lv.scr_act(), red_slider)
chart.set_type(chart.TYPE.POINT | chart.TYPE.LINE)
chart.set_series_width(3)
chart.set_range(0, 100)
chart.init_points(series1, 10)
chart.set_points(series1, [10, 20, 30, 20, 10, 40, 50, 90, 95, 90])
chart.set_x_tick_texts("a\nb\nc\nd\ne", 2, lv.chart.AXIS.DRAW_LAST_TICK)
chart.set_x_tick_length(10, 5)
chart.set_y_tick_texts("1\n2\n3\n4\n5", 2, lv.chart.AXIS.DRAW_LAST_TICK)
chart.set_y_tick_length(10, 5)
chart.set_div_line_count(3, 3)
chart.set_margin(30)

# Create a slider that controls the chart animation speed


def on_slider_changed(self, obj=None, event=-1):
    chart.factor = slider.get_value()


slider = lv.slider(scr)
slider.align(chart, lv.ALIGN.OUT_RIGHT_TOP, 10, 0)
slider.set_width(30)
slider.set_height(chart.get_height())
slider.set_range(10, 200)
slider.set_value(chart.factor, 0)
slider.set_event_cb(on_slider_changed)

# Load the screen

lv.scr_load(scr)
Exemple #22
0
    def scan1_open(self, btn_txt):
        self.log.debug("scan1_open " + btn_txt)
        self.anim_out_all(lv.scr_act(), 0)

        self.anim_bg(0, LV_DEMO_PRINTER_BLUE, self.LV_DEMO_PRINTER_BG_NORMAL)
        delay = 200
        back = self.add_back(self.back_to_home_event_cb)
        title = self.add_title("ADJUST IMAGE")

        self.scan_img = lv.img(lv.scr_act(), None)
        self.scan_img.set_src(self.scan_example_dsc)
        self.scan_img.align(None, lv.ALIGN.IN_TOP_LEFT, 40, 100)
        self.scan_img.set_style_local_radius(lv.img.PART.MAIN,
                                             lv.STATE.DEFAULT, 10)
        self.scan_img.set_style_local_clip_corner(lv.img.PART.MAIN,
                                                  lv.STATE.DEFAULT, True)
        self.scan_img.set_style_local_image_recolor_opa(
            lv.img.PART.MAIN, lv.STATE.DEFAULT, 80)

        box_w = 160
        settings_box = lv.obj(lv.scr_act(), None)
        settings_box.set_size(box_w, 245)
        settings_box.align(self.scan_img, lv.ALIGN.OUT_RIGHT_TOP, 40, 0)

        self.lightness_act = 0
        self.hue_act = 180

        slider = lv.slider(settings_box, None)
        slider.set_size(8, 160)
        slider.align(None, lv.ALIGN.IN_TOP_MID, -35, 65)
        slider.set_event_cb(self.lightness_slider_event_cb)
        slider.set_range(-80, 80)
        slider.set_value(0, lv.ANIM.OFF)
        slider.set_ext_click_area(30, 30, 30, 30)
        self.theme.apply(slider, lv.THEME.SLIDER)

        icon = lv.img(settings_box, None)
        icon.set_src(self.icon_bright_dsc)
        icon.align(slider, lv.ALIGN.OUT_TOP_MID, 0, -30)

        slider = lv.slider(settings_box, slider)
        slider.align(None, lv.ALIGN.IN_TOP_MID, 35, 65)
        slider.set_event_cb(self.hue_slider_event_cb)
        slider.set_range(0, 359)
        slider.set_value(180, lv.ANIM.OFF)
        self.theme.apply(slider, lv.THEME.SLIDER)

        icon = lv.img(settings_box, None)
        icon.set_src(self.icon_hue_dsc)
        icon.align(slider, lv.ALIGN.OUT_TOP_MID, 0, -30)

        self.scan_img_color_refr()

        next_btn = lv.btn(lv.scr_act(), None)
        self.theme.apply(next_btn, LV_DEMO_PRINTER_THEME_BTN_CIRCLE)
        next_btn.set_size(box_w, 60)
        next_btn.align(self.scan_img, lv.ALIGN.OUT_RIGHT_BOTTOM, 40, 0)
        if btn_txt == "NEXT":
            next_btn.set_event_cb(self.scan_next_event_cb)
            next_btn.set_style_local_value_str(lv.obj.PART.MAIN,
                                               lv.STATE.DEFAULT, "NEXT")
            next_btn.set_style_local_value_font(lv.obj.PART.MAIN,
                                                lv.STATE.DEFAULT,
                                                self.theme.get_font_subtitle())
        elif btn_txt == "SAVE":
            next_btn.set_event_cb(self.scan_save_event_cb)
            next_btn.set_style_local_value_str(lv.obj.PART.MAIN,
                                               lv.STATE.DEFAULT, "SAVE")
            next_btn.set_style_local_value_font(lv.obj.PART.MAIN,
                                                lv.STATE.DEFAULT,
                                                self.theme.get_font_subtitle())
            next_btn.set_style_local_bg_color(lv.obj.PART.MAIN,
                                              lv.STATE.DEFAULT,
                                              LV_DEMO_PRINTER_GREEN)
            next_btn.set_style_local_bg_color(
                lv.obj.PART.MAIN, lv.STATE.PRESSED,
                LV_DEMO_PRINTER_GREEN.color_darken(lv.OPA._20))