Пример #1
0
 def _set_custom_style(self):
     style = lv.style_t()
     lv.style_copy(style, self.lv_obj.get_style(lv.cont.STYLE.MAIN))
     style.body.main_color = lv.color_make(0xC0, 0xC0, 0xC0)
     style.body.grad_color = lv.color_make(0x4F, 0x52, 0x57)
     style.body.radius = 0
     self.lv_obj.set_style(lv.cont.STYLE.MAIN, style)
    def __init__(self):

	scr = lv.obj()

	# Create style for the Arcs - Hour
	styleHour = lv.style_t()
	lv.style_copy(styleHour, lv.style_plain)
	styleHour.line.color = lv.color_make(119,158,203) # Arc color
	styleHour.line.width = 8                      # Arc width

	# Create an Arc - Hour
	arcHour = lv.arc(scr)
	arcHour.set_style(lv.arc.STYLE.MAIN, styleHour)   # Use the new style
	arcHour.set_angles(45, 0)
	arcHour.set_size(300, 300)
	arcHour.align(None, lv.ALIGN.CENTER, 0, 0)

	# Create style for the Arcs - Minute
	styleMin = lv.style_t()
	lv.style_copy(styleMin, lv.style_plain)
	styleMin.line.color = lv.color_make(124,252,0) # Arc color
	styleMin.line.width = 8                      # Arc width

	# Create an Arc - Minute
	arcMin = lv.arc(scr)
	arcMin.set_style(lv.arc.STYLE.MAIN, styleMin)   # Use the new style
	arcMin.set_angles(45, 0)
	arcMin.set_size(380, 380)
	arcMin.align(None, lv.ALIGN.CENTER, 0, 0)

	# Create style for the Arcs - Second
	styleSecond = lv.style_t()
	lv.style_copy(styleSecond, lv.style_plain)
	styleSecond.line.color = lv.color_make(250,128,114) # Arc color
	styleSecond.line.width = 8                      # Arc width

	# Create an Arc - Minute
	arcSecond = lv.arc(scr)
	arcSecond.set_style(lv.arc.STYLE.MAIN, styleSecond)   # Use the new style
	arcSecond.set_angles(45, 0)
	arcSecond.set_size(220, 220)
	arcSecond.align(None, lv.ALIGN.CENTER, 0, 0)

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

	btn1 = lv.btn(scr)
	btn1.set_event_cb(event_handler)
	btn1.align(None, lv.ALIGN.CENTER, 0, 0)
	label = lv.label(btn1)
	label.set_text("Button")

	lv.scr_load(scr)
Пример #3
0
    def popup_confirm_stop(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_stop = lv.mbox(bg)
        popup_stop.set_text(
            'Do you really want to stop the soldering process?')
        btns = ['OK', 'Cancel', '']
        popup_stop.add_btns(btns)
        this = self

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                if popup_stop.get_active_btn() == 0:
                    this.set_reflow_process_on(False)
                else:
                    pass

                bg.del_async()
                popup_stop.start_auto_close(5)

        popup_stop.set_event_cb(event_handler)
        popup_stop.align(None, lv.ALIGN.CENTER, 0, 0)
Пример #4
0
 def create_style(self, colour=(0x00, 0x3b, 0x75), width=3, rounded=1):
     style_line = lv.style_t()
     lv.style_copy(style_line, lv.style_plain)
     style_line.line.color = lv.color_make(colour[0], colour[1], colour[2])
     style_line.line.width = width
     style_line.line.rounded = rounded
     return style_line
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
 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
    def popup_calibration(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_cali = lv.mbox(bg)
        popup_cali.set_text('What would you like to calibrate?')
        btns = ['Temp Sensor', '\n', 'Touch Screen', '\n', 'Cancel', '']
        popup_cali.add_btns(btns)

        lv.cont.set_fit(popup_cali, lv.FIT.NONE)
        mbox_style = popup_cali.get_style(popup_cali.STYLE.BTN_REL)
        popup_cali_style = lv.style_t()
        lv.style_copy(popup_cali_style, mbox_style)
        popup_cali_style.body.padding.bottom = 96
        popup_cali.set_style(popup_cali.STYLE.BTN_REL, popup_cali_style)

        popup_cali.set_height(186)

        this = self

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                active_btn_text = popup_cali.get_active_btn_text()
                tim = machine.Timer(-1)
                if active_btn_text == 'Temp Sensor':
                    this.config['has_calibrated'] = False
                    with open('config.json', 'w') as f:
                        ujson.dump(this.config, f)
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                elif active_btn_text == 'Touch Screen':
                    uos.remove(this.config.get('touch_cali_file'))
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                else:
                    tim.deinit()

                bg.del_async()
                popup_cali.start_auto_close(5)

        popup_cali.set_event_cb(event_handler)
        popup_cali.align(None, lv.ALIGN.CENTER, 0, 0)
        self.popup_cali = popup_cali
        return self.popup_cali
Пример #9
0
    def popup_settings(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_settings = lv.mbox(bg)
        popup_settings.set_text('Settings')
        btns = ['Set PID Params', '\n', 'Calibrate Touch', '\n', 'Close', '']
        popup_settings.add_btns(btns)

        lv.cont.set_fit(popup_settings, lv.FIT.NONE)
        mbox_style = popup_settings.get_style(popup_settings.STYLE.BTN_REL)
        popup_cali_style = lv.style_t()
        lv.style_copy(popup_cali_style, mbox_style)
        popup_cali_style.body.padding.bottom = 115
        popup_settings.set_style(popup_settings.STYLE.BTN_REL,
                                 popup_cali_style)
        popup_settings.set_height(186)

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                active_btn_text = popup_settings.get_active_btn_text()
                tim = machine.Timer(-1)
                # Note: With PID, temp calibration no longer needed
                # if active_btn_text == 'Temp Sensor':
                #     this.config['has_calibrated'] = False
                #     with open('config.json', 'w') as f:
                #         ujson.dump(this.config, f)
                #     tim.init(period=500, mode=machine.Timer.ONE_SHOT, callback=lambda t:machine.reset())
                # elif active_btn_text == 'Touch Screen':
                if active_btn_text == 'Calibrate Touch':
                    uos.remove(self.config.get('touch_cali_file'))
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                elif active_btn_text == 'Set PID Params':
                    tim.init(period=50,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: self.popup_pid_params())
                else:
                    tim.deinit()
                bg.del_async()
                popup_settings.start_auto_close(5)

        popup_settings.set_event_cb(event_handler)
        popup_settings.align(None, lv.ALIGN.CENTER, 0, 0)
Пример #10
0
 def chart_init(self):
     """
     Initialize the temp chart on the screen
     """
     chart = lv.chart(self.main_scr)
     chart.set_size(GUI.CHART_WIDTH, GUI.CHART_HEIGHT)  # width, height pixel of the chart
     chart.align(lv.scr_act(), lv.ALIGN.IN_BOTTOM_MID, 0, 0)
     chart.set_type(lv.chart.TYPE.LINE)
     chart.set_style(lv.chart.STYLE.MAIN, lv.style_plain)
     chart.set_series_opa(lv.OPA.COVER)
     chart.set_series_width(3)
     chart_series = chart.add_series(lv.color_make(0xFF, 0, 0))
     return chart, chart_series
Пример #11
0
 def set_text(self, text="Text"):
     self._text = text
     qr = qrcode.encode_to_string(text)
     size = int(math.sqrt(len(qr)))
     width = self.get_width()
     scale = width // size
     sizes = range(1, 10)
     fontsize = [s for s in sizes if s < scale or s == 1][-1]
     font = getattr(lv, "square%d" % fontsize)
     style = lv.style_t()
     lv.style_copy(style, lv.style_plain)
     style.body.main_color = lv.color_make(0xFF, 0xFF, 0xFF)
     style.body.grad_color = lv.color_make(0xFF, 0xFF, 0xFF)
     style.body.opa = 255
     style.text.font = font
     style.text.line_space = 0
     style.text.letter_space = 0
     self.set_style(0, style)
     # self.set_body_draw(True)
     super().set_text(qr)
     del qr
     gc.collect()
Пример #12
0
 def draw_profile_line(self, points):
     """
     Draw reflow temp profile over the chart per selection
     """
     style_line = lv.style_t()
     lv.style_copy(style_line, lv.style_transp)
     style_line.line.color = lv.color_make(0, 0x80, 0)
     style_line.line.width = 3
     style_line.line.rounded = 1
     style_line.line.opa = lv.OPA._40
     line = lv.line(self.chart)
     line.set_points(points, len(points))  # Set the points
     line.set_style(lv.line.STYLE.MAIN, style_line)
     line.align(self.chart, lv.ALIGN.IN_BOTTOM_MID, 0, 0)
     line.set_y_invert(True)
     return line
Пример #13
0
    def __init__(self, parent, *args, **kwargs):
        # Create a base object for the modal background
        super().__init__(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

        self.set_style(modal_style)
        self.set_pos(0, 0)
        self.set_size(parent.get_width(), parent.get_height())

        self.mbox = lv.mbox(self)
        self.mbox.set_width(400)
        self.mbox.align(None, lv.ALIGN.IN_TOP_MID, 0, 200)
Пример #14
0
    def createItem(self, parent, iconPath, value, unityPath, tips):
        col_dsc = [
            lv.GRID.CONTENT, 5, lv.GRID.CONTENT, lv.GRID.CONTENT,
            lv.GRID_TEMPLATE.LAST
        ]
        row_dsc = [lv.GRID.CONTENT, lv.GRID.CONTENT, lv.GRID_TEMPLATE.LAST]

        cont = lv.obj(parent)
        cont.set_style_bg_opa(0, 0)
        cont.set_style_border_opa(0, 0)
        cont.set_style_pad_all(0, 0)
        cont.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
        cont.set_style_grid_column_dsc_array(col_dsc, 0)
        cont.set_style_grid_row_dsc_array(row_dsc, 0)
        cont.set_layout(lv.LAYOUT_GRID.value)

        img = lv.img(cont)
        img.set_src(iconPath)
        img.set_grid_cell(lv.GRID_ALIGN.START, 0, 1, lv.GRID_ALIGN.CENTER, 0,
                          2)

        label = lv.label(cont)
        label.set_text(value)
        label.set_style_text_color(lv.color_white(), 0)
        label.set_style_text_font(lv.font_montserrat_48, 0)
        label.set_style_pad_all(0, 0)
        label.set_grid_cell(lv.GRID_ALIGN.START, 2, 1, lv.GRID_ALIGN.CENTER, 0,
                            1)

        if (unityPath.strip()):
            iconImg = lv.img(cont)
            iconImg.set_src(unityPath)
            iconImg.set_zoom(205)
            iconImg.set_style_pad_bottom(0, 0)
            iconImg.set_grid_cell(lv.GRID_ALIGN.START, 3, 1,
                                  lv.GRID_ALIGN.CENTER, 0, 1)

        tip = lv.label(cont)
        tip.set_text(tips)
        tip.set_style_text_color(lv.color_make(0xCC, 0xCC, 0xCC), 0)
        tip.set_grid_cell(lv.GRID_ALIGN.START, 2, 2, lv.GRID_ALIGN.START, 1, 1)
Пример #15
0
    def confirm_exit(self):

        mnemonic = self.table.get_mnemonic()
        if len(mnemonic) == 0:
            self.set_value(None)
            return

        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        # Set the background's style
        modal_style.body.main_color = lv.color_make(0, 0, 0)
        modal_style.body.grad_color = modal_style.body.main_color
        modal_style.body.opa = lv.OPA._50

        # Create a base object for the modal background
        bg = lv.obj(self)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.get_width(), self.get_height())
        # Enable opacity scaling for the animation
        bg.set_opa_scale_enable(True)

        btns = ["No, stay here", "Yes, leave", ""]

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                if lv.mbox.get_active_btn_text(obj) == btns[1]:
                    self.set_value(None)
                else:
                    obj.del_async()
                    bg.del_async()

        mbox = lv.mbox(self)
        mbox.set_text(
            "\nAre you sure you want to exit?\n\n"
            "Everything you entered will be forgotten!\n\n"
        )
        mbox.add_btns(btns)
        mbox.set_width(400)
        mbox.set_event_cb(event_handler)
        mbox.align(None, lv.ALIGN.CENTER, 0, 0)
Пример #16
0
 def draw_melting_dash_line(self, y_point, melting_temp):
     """
     Draw melting temp with dashed line over the chart
     """
     # Container for dashed line
     style_cont = lv.style_t()
     lv.style_copy(style_cont, lv.style_transp)
     dashed_segments = 10
     dashed_cont = lv.cont(self.chart)
     dashed_cont.set_style(lv.line.STYLE.MAIN, style_cont)
     dashed_cont.set_width(GUI.CHART_WIDTH)
     # Draw dashed line
     style_dash_line = lv.style_t()
     lv.style_copy(style_dash_line, lv.style_transp)
     style_dash_line.line.color = lv.color_make(0xFF, 0x68, 0x33)
     style_dash_line.line.width = 3
     dash_width = int(GUI.CHART_WIDTH / (dashed_segments * 2 - 1))
     dashed_points = [
         {'x': 0, 'y': 0},
         {'x': dash_width, 'y': 0}
     ]
     dashed_line0 = lv.line(dashed_cont)
     dashed_line0.set_points(dashed_points, len(dashed_points))
     dashed_line0.set_style(lv.line.STYLE.MAIN, style_dash_line)
     dashed_line0.align(None, lv.ALIGN.IN_LEFT_MID, 0, 0)
     for i in range(dashed_segments - 1):
         dl_name = 'dashed_line' + str(i+1)
         parent_name = 'dashed_line' + str(i)
         locals()[dl_name] = lv.line(dashed_cont, dashed_line0)
         locals()[dl_name].align(None, lv.ALIGN.IN_LEFT_MID, dash_width * (i+1) * 2, 0)
     # Melting temp
     melt_label = lv.label(dashed_cont)
     melt_label.set_recolor(True)
     melt_label.set_text('#FF6833 ' + str(melting_temp) + '#')
     # Put above elements in place
     dashed_cont.align_origo(self.chart, lv.ALIGN.IN_BOTTOM_MID, 0, -y_point)
     melt_label.align(dashed_cont, lv.ALIGN.IN_TOP_LEFT, 8, 12)
     return dashed_cont
Пример #17
0
    def next_color(self):
        index = self.color_state[0]
        level = self.color_state[1]
        if index == 0:   color = lv.color_make(255, level, 0)
        elif index == 1: color = lv.color_make(255-level, 255, 0)
        elif index == 2: color = lv.color_make(0, 255, level)
        elif index == 3: color = lv.color_make(0, 255-level, 255)
        elif index == 4: color = lv.color_make(level, 0, 255)
        else:            color = lv.color_make(255, 0, 255-level)
        level = level + 6
        if level >= 256:
            level -= 256
            index = index + 1
            if index == 6:
                index = 0

        self.color_state = (index, level)
        return color
Пример #18
0
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver
import time

# Create a normal cell style
style_cell1 = lv.style_t()
style_cell1.init()
style_cell1.set_border_width(lv.STATE.DEFAULT, 1)
style_cell1.set_border_color(lv.STATE.DEFAULT, lv.color_make(0, 0, 0))

# Create a header cell style
style_cell2 = lv.style_t()
style_cell2.init()
style_cell2.set_border_width(lv.STATE.DEFAULT, 1)
style_cell2.set_border_color(lv.STATE.DEFAULT, lv.color_make(0, 0, 0))
style_cell2.set_bg_color(lv.STATE.DEFAULT, lv.color_make(0xC0, 0xC0, 0xC0))
style_cell2.set_bg_grad_color(lv.STATE.DEFAULT,
                              lv.color_make(0xC0, 0xC0, 0xC0))

table = lv.table(lv.scr_act())
table.add_style(lv.table.PART.CELL1, style_cell1)
table.add_style(lv.table.PART.CELL2, style_cell2)
#table.add_style(lv.table.PART.BG, lv.style.transp_tight)
table.set_col_cnt(2)
table.set_row_cnt(4)
table.align(None, lv.ALIGN.CENTER, 0, 0)

# Make the cells of the first row center aligned
table.set_cell_align(0, 0, lv.label.ALIGN.CENTER)
table.set_cell_align(0, 1, lv.label.ALIGN.CENTER)
Пример #19
0
slider.align(scr2, lv.ALIGN.IN_TOP_MID, 0, 15)

btn1 = lv.btn(scr1)
btn1.align(scr1, lv.ALIGN.IN_TOP_RIGHT, -5, 5)
label = lv.label(btn1)
label.set_text(">")

btn2 = lv.btn(scr2)
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):
Пример #20
0
        cal_x1=touch_x1,
        cal_y0=touch_y0,
        cal_y1=touch_y1,
    )

    TOUCH_READY = 1  #表示已经配置好触摸参数

#############################################
###############      Page    ################
#############################################
if TOUCH_READY:

    # Create a scroll bar style
    style_sb = lv.style_t()
    lv.style_copy(style_sb, lv.style_plain)
    style_sb.body.main_color = lv.color_make(0, 0, 0)
    style_sb.body.grad_color = lv.color_make(0, 0, 0)
    style_sb.body.border.color = lv.color_make(0xff, 0xff, 0xff)
    style_sb.body.border.width = 1
    style_sb.body.border.opa = lv.OPA._70
    style_sb.body.radius = 800  # large enough to make a circle
    style_sb.body.opa = lv.OPA._60
    style_sb.body.padding.right = 3
    style_sb.body.padding.bottom = 3
    style_sb.body.padding.inner = 8  # Scrollbar width

    # Create a page
    page = lv.page(lv.scr_act())
    page.set_size(240, 300)
    page.align(None, lv.ALIGN.CENTER, 0, 0)
    page.set_style(lv.page.STYLE.SB, style_sb)  # Set the scrollbar style
Пример #21
0
def LV_COLOR_MAKE(r,g,b):
#    return lv.color_hex(r<<16| g<<8 |b)
    return lv.color_make(r,g,b)
Пример #22
0
import lvgl as lv

# lvgl must be initialized before any lvgl function is called or object/struct is constructed!

lv.init()

# Create a style based on style_plain but with a symbol font

symbolstyle = lv.style_t(lv.style_plain)
symbolstyle.text.font = lv.font_roboto_28

# The following two lines do the same thing.
# They show how to initialize struct either directly or through a dict

symbolstyle.text.color = lv.color_hex(0xFFFFFF)
symbolstyle.text.color = lv.color_make(0xFF, 0xFF, 0xFF)
if hasattr(symbolstyle.text.color.ch, "alpha"):
    symbolstyle.text.color.ch.alpha = 0xFF  # Only has alpha when color is 32 bit


def get_member_name(obj, value):
    for member in dir(obj):
        if getattr(obj, member) == value:
            return member


class SymbolButton(lv.btn):
    def __init__(self, parent, symbol, text):
        super().__init__(parent)
        self.symbol = lv.label(self)
        self.symbol.set_text(symbol)
Пример #23
0
import lvgl as lv

# lvgl must be initialized before any lvgl function is called or object/struct is constructed!

lv.init()

# Create a style based on style_plain but with a symbol font

symbolstyle = lv.style_t(lv.style_plain)
symbolstyle.text.font = lv.font_roboto_28

# The following two lines do the same thing.
# They show how to initialize struct either directly or through a dict

symbolstyle.text.color = lv.color_hex(0xffffff)
symbolstyle.text.color = lv.color_make(0xff, 0xff, 0xff)
if hasattr(symbolstyle.text.color.ch, 'alpha'):
    symbolstyle.text.color.ch.alpha = 0xff  # Only has alpha when color is 32 bit


def get_member_name(obj, value):
    for member in dir(obj):
        if getattr(obj, member) == value:
            return member


class SymbolButton(lv.btn):
    def __init__(self, parent, symbol, text):
        super().__init__(parent)
        self.symbol = lv.label(self)
        self.symbol.set_text(symbol)
Пример #24
0
import time
import lvgl as lv

lv.init()
import display

display.init()
from lvstm32 import lvstm32
from lvdisplay import lvdisplay

scr = lv.obj()
#color for button
style1 = lv.style_t(lv.style_plain)
style1.text.font = lv.font_roboto_28
style1.body.main_color = lv.color_make(158, 158, 158)
style1.body.grad_color = lv.color_make(158, 158, 158)
style1.body.radius = lv.RADIUS.CIRCLE
style1.text.color = lv.color_make(0, 0, 0)
#color for background
style2 = lv.style_t(style1)
style2.text.font = lv.font_roboto_28
style2.body.main_color = lv.color_make(0, 0, 0)
style2.body.grad_color = lv.color_make(0, 0, 0)
style2.text.color = lv.color_make(158, 158, 158)

#button1
btn1 = lv.btn(scr)
btn1.set_style(lv.btn.STYLE.REL, style1)
btn1.align(None, lv.ALIGN.CENTER, 0, -85)
btn1.set_size(100, 100)
label1 = lv.label(btn1)
Пример #25
0
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver

# Create a scroll bar style
style_sb = lv.style_t()
style_sb.init()
#lv.style_copy(style_sb, lv.style_plain)
style_sb.set_bg_color(lv.STATE.DEFAULT, lv.color_make(0, 0, 0))
style_sb.set_bg_grad_color(lv.STATE.DEFAULT, lv.color_make(0, 0, 0))
style_sb.set_border_color(lv.STATE.DEFAULT, lv.color_make(0xff, 0xff, 0xff))
style_sb.set_border_width(lv.STATE.DEFAULT, 1)
style_sb.set_border_opa(lv.STATE.DEFAULT, lv.OPA._70)
style_sb.set_radius(lv.STATE.DEFAULT, 800)  # large enough to make a circle
style_sb.set_bg_opa(lv.STATE.DEFAULT, lv.OPA._60)
style_sb.set_pad_right(lv.STATE.DEFAULT, 3)
style_sb.set_pad_bottom(lv.STATE.DEFAULT, 3)
style_sb.set_pad_inner(lv.STATE.DEFAULT, 8)  # Scrollbar width

# Create a page
page = lv.page(lv.scr_act())
page.set_size(150, 200)
page.align(None, lv.ALIGN.CENTER, 0, 0)
page.add_style(lv.page.PART.SCROLLABLE, style_sb)  # Set the scrollbar style

# Create a label on the page
label = lv.label(page)
label.set_long_mode(lv.label.LONG.BREAK)  # Automatically break long lines
label.set_width(page.get_fit_width(
))  # Set the label width to max value to not show hor. scroll bars
label.set_text("""Lorem ipsum dolor sit amet, consectetur adipiscing elit,
Пример #26
0
    def createPage(self):
        global value
        global sound_ttf_alive

        print("Enter SoundTTF")

        # 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)
        win.set_style_pad_right(30, 0)

        title = lv.label(win)
        title.set_text("Sound TTF")
        title.set_style_text_color(lv.color_white(), 0)
        title.set_style_text_font(lv.font_montserrat_28, 0)
        title.align(lv.ALIGN.TOP_LEFT, 20, 0)

        decibel = lv.label(win)
        decibel.set_text(str(value) + "dB")
        decibel.set_style_text_color(lv.color_make(0xFF, 0xA8, 0x48), 0)
        decibel.set_style_text_font(lv.font_montserrat_28, 0)
        decibel.align(lv.ALIGN.TOP_RIGHT, 0, 0)

        chart = lv.chart(win)
        chart.set_type(lv.chart.TYPE.BAR)
        chart.set_style_border_opa(0, 0)
        chart.set_style_bg_opa(0, 0)
        chart.set_style_line_opa(0, 0)
        chart.set_width(280)
        chart.set_height(160)
        chart.set_div_line_count(6, 0)
        chart.set_point_count(12)
        chart.align(lv.ALIGN.BOTTOM_MID, 20, -5)
        chart.add_event_cb(chart_event_cb, lv.EVENT.DRAW_PART_END, None)

        ser1 = chart.add_series(lv.color_make(0x56, 0x56, 0x56),
                                lv.chart.AXIS.PRIMARY_Y)
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))
        chart.set_next_value(ser1, lv.rand(30, 100))

        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: sound_ttf_back_click_callback(e, win),
                             lv.EVENT.CLICKED, None)
        backImg.set_ext_click_area(30)
        backImg.add_event_cb(
            lambda e: sound_ttf_back_press_callback(e, backImg),
            lv.EVENT.PRESSED, None)
        backImg.add_event_cb(
            lambda e: sound_ttf_back_release_callback(e, backImg),
            lv.EVENT.RELEASED, None)

        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)

        sound_ttf_alive = True
Пример #27
0
# 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(lv.scr_act())
gauge1.set_style(lv.gauge.STYLE.MAIN, style)
gauge1.set_needle_count(len(needle_colors), needle_colors)
gauge1.set_size(150, 150)
gauge1.align(None, lv.ALIGN.CENTER, 0, 20)

# Set the values
gauge1.set_value(0, 10)
gauge1.set_value(1, 20)
gauge1.set_value(2, 30)
Пример #28
0
#   Start your codes here.
# **********************************

# 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)

# Add two data series
ser1 = chart.add_series(lv.color_make(0xFF, 0, 0))
ser2 = chart.add_series(lv.color_make(0, 0x80, 0))

# Set points on 'dl1'
chart.set_points(ser1, [10, 10, 10, 10, 10, 10, 10, 30, 70, 90])

# Set points on 'dl2'
chart.set_points(ser2, [90, 70, 65, 65, 65, 65, 65, 65, 65, 65])

# **********************************
#   End your codes here.
# **********************************


def on_timer(timer):
    lv.tick_inc(5)
Пример #29
0
#create button in center with callback
btn = lv.btn(scr)
btn.align(scr, lv.ALIGN.CENTER, 0, 0)
btn.set_event_cb(event_handler)
label = lv.label(btn)
label.set_text("Press me")
label.set_size(20,20)

#create semi-transparrent background and set it to hidden
bg = lv.obj(scr)
bg.set_pos(0, 0)
bg.set_size(scr.get_width(), scr.get_height())
modal_style = lv.style_t()
lv.style_copy(modal_style, lv.style_plain_color)
modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(0,0,50)
modal_style.body.opa = 75
bg.set_style(modal_style)
bg.set_hidden(1)

#create message box and set it to hidden
box = lv.mbox(scr)
box.set_text("Congratulations, you pressed the button! Now do it again, here");
box.add_btns(["OK", ""])
box.set_width(200)
box.set_event_cb(event_handler)
box.align(None, lv.ALIGN.CENTER, 0, 0)
box.set_hidden(1)

lv.scr_load(scr)
Пример #30
0
    def popup_pid_params(self):
        """
        The popup window of PID params settings
        """
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        # init mbox and title
        popup_pid = lv.mbox(bg)
        popup_pid.set_text('Set PID Params')
        popup_pid.set_size(220, 300)
        popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)

        input_cont = lv.cont(popup_pid)
        input_cont.set_size(210, 180)

        def input_event_cb(ta, event):
            if event == lv.EVENT.CLICKED:
                self.current_input_placeholder = ta.get_placeholder_text()
                if self.current_input_placeholder == 'Set Offset':
                    popup_pid.align(bg, lv.ALIGN.CENTER, 0, -55)
                else:
                    popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)
                if kb.get_hidden():
                    kb.set_hidden(False)
                # Focus on the clicked text area
                kb.set_ta(ta)

        def keyboard_event_cb(event_kb, event):
            event_kb.def_event_cb(event)
            if event == lv.EVENT.CANCEL or event == lv.EVENT.APPLY:
                kb.set_hidden(True)
                if self.current_input_placeholder == 'Set Offset':
                    popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)

        # init keyboard
        kb = lv.kb(bg)
        kb.set_cursor_manage(True)
        kb.set_event_cb(keyboard_event_cb)
        lv.kb.set_mode(kb, lv.kb.MODE.NUM)
        rel_style = lv.style_t()
        pr_style = lv.style_t()
        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
        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)

        # init text areas
        kp_input = lv.ta(input_cont)
        kp_input.set_text(str(self.pid_params.get('kp')))
        kp_input.set_placeholder_text('Set Kp')
        kp_input.set_accepted_chars('0123456789.+-')
        kp_input.set_one_line(True)
        kp_input.set_width(120)
        kp_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 20)
        kp_input.set_event_cb(input_event_cb)
        kp_label = lv.label(input_cont)
        kp_label.set_text("Kp: ")
        kp_label.align(kp_input, lv.ALIGN.OUT_LEFT_MID, 0, 0)
        pid_title_label = lv.label(input_cont)
        pid_title_label.set_text("PID Params:")
        pid_title_label.align(kp_input, lv.ALIGN.OUT_TOP_LEFT, -65, 0)

        ki_input = lv.ta(input_cont)
        ki_input.set_text(str(self.pid_params.get('ki')))
        ki_input.set_placeholder_text('Set Ki')
        ki_input.set_accepted_chars('0123456789.+-')
        ki_input.set_one_line(True)
        ki_input.set_width(120)
        ki_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 55)
        ki_input.set_event_cb(input_event_cb)
        ki_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN)
        ki_label = lv.label(input_cont)
        ki_label.set_text("Ki: ")
        ki_label.align(ki_input, lv.ALIGN.OUT_LEFT_MID, 0, 0)

        kd_input = lv.ta(input_cont)
        kd_input.set_text(str(self.pid_params.get('kd')))
        kd_input.set_placeholder_text('Set Kd')
        kd_input.set_accepted_chars('0123456789.+-')
        kd_input.set_one_line(True)
        kd_input.set_width(120)
        kd_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 90)
        kd_input.set_event_cb(input_event_cb)
        kd_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN)
        kd_label = lv.label(input_cont)
        kd_label.set_text("Kd: ")
        kd_label.align(kd_input, lv.ALIGN.OUT_LEFT_MID, 0, 0)

        temp_offset_input = lv.ta(input_cont)
        temp_offset_input.set_text(str(self.temp_offset))
        temp_offset_input.set_placeholder_text('Set Offset')
        temp_offset_input.set_accepted_chars('0123456789.+-')
        temp_offset_input.set_one_line(True)
        temp_offset_input.set_width(120)
        temp_offset_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 145)
        temp_offset_input.set_event_cb(input_event_cb)
        temp_offset_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN)
        temp_offset_label = lv.label(input_cont)
        temp_offset_label.set_text("Offset: ")
        temp_offset_label.align(temp_offset_input, lv.ALIGN.OUT_LEFT_MID, 0, 0)
        offset_title_label = lv.label(input_cont)
        offset_title_label.set_text("Temp Correction:")
        offset_title_label.align(temp_offset_input, lv.ALIGN.OUT_TOP_LEFT, -65,
                                 0)

        # set btns to mbox
        btns = ['Save', 'Cancel', '']
        popup_pid.add_btns(btns)

        lv.cont.set_fit(popup_pid, lv.FIT.NONE)
        mbox_style = popup_pid.get_style(popup_pid.STYLE.BTN_REL)
        popup_pid_style = lv.style_t()
        lv.style_copy(popup_pid_style, mbox_style)
        popup_pid_style.body.padding.bottom = 46
        popup_pid.set_style(popup_pid.STYLE.BTN_REL, popup_pid_style)
        popup_pid.set_size(220, 300)

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                active_btn_text = popup_pid.get_active_btn_text()
                if active_btn_text == 'Save':
                    kp_value = float(kp_input.get_text())
                    ki_value = float(ki_input.get_text())
                    kd_value = float(kd_input.get_text())
                    temp_offset_value = float(temp_offset_input.get_text())
                    self.config['pid'] = {
                        'kp': kp_value,
                        'ki': ki_value,
                        'kd': kd_value
                    }
                    self.config['sensor_offset'] = temp_offset_value
                    self.pid_params = self.config.get('pid')
                    self.temp_offset = self.config.get('sensor_offset')
                    # Save settings to config.json
                    with open('config.json', 'w') as f:
                        ujson.dump(self.config, f)
                    # Apply settings immediately
                    self.pid.reset(kp_value, ki_value, kd_value)
                    self.sensor.set_offset(temp_offset_value)
                bg.del_async()
                popup_pid.start_auto_close(5)

        popup_pid.set_event_cb(event_handler)
        popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)
        kb.set_ta(kp_input)
        kb.set_hidden(True)