def draw_part_event_cb(e): objc = e.get_code() objt = e.get_target() dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) s_row = lv.point_t() s_col = lv.point_t() if objc == lv.EVENT.PRESSING: '''only in effect if cell is pressed''' objt.get_selected_cell(s_row, s_col) print("selected row:{}, col:{}".format(s_row.x, s_col.x)) if objc == lv.EVENT.DRAW_PART_BEGIN: '''only change when draw part begins''' if dsc.part == lv.PART.ITEMS: #print('true!') row = dsc.id // objt.get_col_cnt() col = dsc.id - row * objt.get_col_cnt() #print("row : {}, column : {} ".format(row,col)) if row == 0: #change header style dsc.label_dsc.align = lv.TEXT_ALIGN.CENTER dsc.label_dsc.color = lv.color_hex(0xffffff) dsc.rect_dsc.bg_color = lv.color_hex(0x6b765b) if row > 0 and col > 0: #center colum 1 and 2 dsc.label_dsc.align = lv.TEXT_ALIGN.CENTER
def testfastlines(canvas, color1, color2): # there are no hline and vline calls in the lvgl display driver # replace them by normal lines p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] # style for horizontal lines hline_dsc = lv.draw_line_dsc_t() hline_dsc.init() hline_dsc.color = color1 hline_dsc.opa = lv.OPA.COVER # style for vertical lines vline_dsc = lv.draw_line_dsc_t() vline_dsc.init() vline_dsc.color = color2 vline_dsc.opa = lv.OPA.COVER print("Test horizontal and vertical fast lines") p1.x = 0 p2.x = CANVAS_WIDTH - 1 for y in range(0, CANVAS_HEIGHT - 1, 5): p1.y = y p2.y = y canvas.draw_line(point_array, 2, hline_dsc) p1.y = 0 p2.y = CANVAS_HEIGHT - 1 for x in range(0, CANVAS_WIDTH - 1, 5): p1.x = x p2.x = x canvas.draw_line(point_array, 2, vline_dsc)
def testtriangles(canvas): print("Test triangles") offset = (CANVAS_WIDTH - CANVAS_HEIGHT) // 2 p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] line_dsc = lv.draw_line_dsc_t() line_dsc.init() w = CANVAS_HEIGHT // 2 x = CANVAS_HEIGHT - 1 y = 0 z = CANVAS_HEIGHT - 1 for i in range(0, 15): line_dsc.color = colors[i] p1.x = w + offset p1.y = y p2.x = y + offset p2.y = x canvas.draw_line(point_array, 2, line_dsc) p1.x = y + offset p1.y = x p2.x = z + offset canvas.draw_line(point_array, 2, line_dsc) p1.x = z + offset p2.x = w + offset p2.y = y canvas.draw_line(point_array, 2, line_dsc) x -= 8 y += 8 z -= 8
def __init__(self, i2c_dev=0, sda=21, scl=22, freq=400000, addr=0x38, width=-1, height=-1, inv_x=False, inv_y=False, swap_xy=False): if not lv.is_initialized(): lv.init() self.width, self.height = width, height self.inv_x, self.inv_y, self.swap_xy = inv_x, inv_y, swap_xy self.i2c = I2C(i2c_dev, sda=Pin(sda), scl=Pin(scl), freq=freq) self.addr = addr try: print("FT6X36 touch IC ready (fw id 0x{0:X} rel {1:d}, lib {2:X})".format( \ int.from_bytes(self.i2c.readfrom_mem(self.addr, 0xA6, 1), "big"), \ int.from_bytes(self.i2c.readfrom_mem(self.addr, 0xAF, 1), "big"), \ int.from_bytes(self.i2c.readfrom_mem(self.addr, 0xA1, 2), "big") \ )) except: print("FT6X36 touch IC not responding") return self.point = lv.point_t( {'x': 0, 'y': 0} ) self.points = [lv.point_t( {'x': 0, 'y': 0} ), lv.point_t( {'x': 0, 'y': 0} )] self.state = lv.INDEV_STATE.RELEASED self.indev_drv = lv.indev_drv_t() self.indev_drv.init() self.indev_drv.type = lv.INDEV_TYPE.POINTER self.indev_drv.read_cb = self.callback self.indev_drv.register()
def cb(self, obj, event): # check event if event == lv.EVENT.DELETE: self.task.cancel() elif event == lv.EVENT.PRESSED: # get coords point = lv.point_t() indev = lv.indev_get_act() lv.indev_get_point(indev, point) self._press_start = point elif event == lv.EVENT.RELEASED: if (len(self._text) <= self.MIN_SIZE or len(self._text) > self.MAX_SIZE): self.toggle_fullscreen() return point = lv.point_t() indev = lv.indev_get_act() lv.indev_get_point(indev, point) # if swipe if (abs(self._press_start.x - point.x) + abs(self._press_start.y - point.y) > 100): self.toggle_fullscreen() return if self.idx is None: self.idx = 0 self.set_frame() else: self.idx = None self._set_text(self._text) self.updata_note()
def __init__(self): self.value = 0 canvas_style = lv.style_t() canvas_style.init() canvas_style.set_bg_color(lv.STATE.DEFAULT, lv_colors.WHITE) cbuf = bytearray(SCREEN_WIDTH * 30 * 4) canvas = lv.canvas(lv.scr_act(), None) canvas.set_buffer(cbuf, SCREEN_WIDTH, 30, lv.img.CF.TRUE_COLOR) # canvas.add_style(lv.canvas.PART.MAIN,canvas_style) canvas.align(None, lv.ALIGN.IN_TOP_LEFT, 0, 0) p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] p1.x = 0 p1.y = 0 p2.x = 15 p2.y = p1.y # style for horizontal lines line_dsc = lv.draw_line_dsc_t() line_dsc.init() line_dsc.color = lv_colors.BLUE line_dsc.opa = lv.OPA.COVER line_dsc.width = 5 # draw the horizontal lines canvas.draw_line(point_array, 2, line_dsc) p1.x = 130 p2.x = SCREEN_WIDTH canvas.draw_line(point_array, 2, line_dsc) # draw the vertical lines p1.x = 0 p2.x = p1.x p2.y = 30 canvas.draw_line(point_array, 2, line_dsc) p1.x = SCREEN_WIDTH - 3 p2.x = p1.x canvas.draw_line(point_array, 2, line_dsc) text_style = lv.style_t() text_style.init() text_style.set_text_font(lv.STATE.DEFAULT, lv.font_montserrat_18) text_style.set_bg_color(lv.STATE.DEFAULT, lv_colors.BLACK) text_style.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.label = lv.label(canvas, None) self.label.add_style(lv.label.PART.MAIN, text_style) self.label.set_recolor(True) self.reset() self.label.align(None, lv.ALIGN.OUT_TOP_MID, -60, 25)
def event_cb(self, e): code = e.get_code() chart = lv.chart.__cast__(e.get_target()) if code == lv.EVENT.VALUE_CHANGED: # print("last_id: ",self.last_id) self.last_id = chart.get_pressed_point() if self.last_id != lv.CHART_POINT.NONE: p = lv.point_t() chart.get_point_pos_by_id(self.ser, self.last_id, p) chart.set_cursor_point(self.cursor, None, self.last_id) elif code == lv.EVENT.DRAW_PART_END: # print("EVENT.DRAW_PART_END") dsc = lv.obj_draw_part_dsc_t.cast(e.get_param()) # if dsc.p1 and dsc.p2: # print("p1, p2", dsc.p1,dsc.p2) # print("p1.y, p2.y", dsc.p1.y, dsc.p2.y) # print("last_id: ",self.last_id) if dsc.part == lv.PART.CURSOR and dsc.p1 and dsc.p2 and dsc.p1.y == dsc.p2.y and self.last_id >= 0: v = self.ser_p[self.last_id] # print("value: ",v) value_txt = str(v) size = lv.point_t() lv.txt_get_size(size, value_txt, lv.font_default(), 0, 0, lv.COORD.MAX, lv.TEXT_FLAG.NONE) a = lv.area_t() a.y2 = dsc.p1.y - 5 a.y1 = a.y2 - size.y - 10 a.x1 = dsc.p1.x + 10 a.x2 = a.x1 + size.x + 10 draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE) draw_rect_dsc.radius = 3 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc) draw_label_dsc = lv.draw_label_dsc_t() draw_label_dsc.init() draw_label_dsc.color = lv.color_white() a.x1 += 5 a.x2 -= 5 a.y1 += 5 a.y2 -= 5 lv.draw_label(a, dsc.clip_area, draw_label_dsc, value_txt, None)
def set_value(self, value): # print("set value: ",value) if self.value == value: return p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.border_width = 0 # draw the new bar if value > self.value: self.value = value value_y = round((self.height - 4) / (self.max_value - self.min_value) * self.value) rect_dsc.bg_color = self.bar_color self.canvas.draw_rect(self.width // 5 + 5, self.base - value_y, 2 * self.width // 5, value_y, rect_dsc) else: # remove the difference from the old value from the bar old_value_y = round((self.height - 4) / (self.max_value - self.min_value) * self.value) self.value = value value_y = round((self.height - 4) / (self.max_value - self.min_value) * self.value) rect_dsc.bg_color = self.bg_color self.canvas.draw_rect(self.width // 5 + 5, self.base - old_value_y, 2 * self.width // 5, old_value_y - value_y, rect_dsc) if self.divisions > 0: dy = (self.height - 4) / self.divisions # Tick marks # print("dy: ",dy) for tick in range(self.divisions + 1): ypos = int(dy * tick) p1.x = self.width // 5 p1.y = ypos + 2 p2.x = p1.x + self.width - 2 * self.width // 5 p2.y = p1.y if p1.y >= self.base - old_value_y and p1.y < self.base - value_y: self.canvas.draw_line(point_array, 2, self.hline_dsc) break if self.value_text_format: value_text = self.value_text_format.format(self.value) self.value_label.set_text(value_text)
def draw_filledCircle(canvas, x0, y0, r, color): """Draw a filled circle. Args: x0 (int): X coordinate of center point. y0 (int): Y coordinate of center point. r (int): Radius. color (int): RGB565 color value. """ p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] line_dsc = lv.draw_line_dsc_t() line_dsc.init() line_dsc.color = color line_dsc.opa = lv.OPA.COVER f = 1 - r dx = 1 dy = -r - r x = 0 y = r p1.x = x0 p1.y = y0 - r p2.x = p1.x p2.y = p1.y + 2 * r + 1 canvas.draw_line(point_array, 2, line_dsc) while x < y: if f >= 0: y -= 1 dy += 2 f += dy x += 1 dx += 2 f += dx p1.x = x0 + x p1.y = y0 - y p2.x = p1.x p2.y = p1.y + 2 * y + 1 canvas.draw_line(point_array, 2, line_dsc) p1.x = x0 - x p2.x = p1.x canvas.draw_line(point_array, 2, line_dsc) p1.x = x0 - y p1.y = y0 - x p2.x = p1.x p2.y = p1.y + 2 * x + 1 canvas.draw_line(point_array, 2, line_dsc) p1.x = x0 + y p2.x = p1.x canvas.draw_line(point_array, 2, line_dsc)
def lv_line(screen): line_points = [[5,5], [70,70]] valid_pos = [lv.point_t(), lv.point_t(), lv.point_t(), lv.point_t(), lv.point_t(), lv.point_t(), lv.point_t()] valid_pos[0].x = 0 valid_pos[0].y = 0 valid_pos[1].x = 10 valid_pos[1].y = 0 valid_pos[2].x = 10 valid_pos[2].y = 10 valid_pos[3].x = 0 valid_pos[3].y = 10 valid_pos[4].x = 10 valid_pos[4].y = 10 valid_pos[5].x = 10 valid_pos[5].y = 20 valid_pos[6].x = 0 valid_pos[6].y = 20 line_style2 = lv.style_t() line_style2.init() line_style2.set_line_width(lv.STATE.DEFAULT, 8) line_style2.set_line_color(lv.STATE.DEFAULT, styles.LV_COLOR_BLUE) line_style2.set_line_rounded(lv.STATE.DEFAULT, True) cont_style = lv.style_t() cont_style.init() cont_style.set_border_opa(lv.STATE.DEFAULT, lv.OPA.TRANSP) cont_style.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.TRANSP) # cont_style.set_bg_color(lv.STATE.DEFAULT, styles.LV_COLOR_WATCH) cont = lv.cont(screen) #cont.add_style(cont.PART.MAIN, cont_style) cont.set_auto_realign(True) cont.set_size(200,65) cont.set_pos(20,85) #cont.align_origo(None, lv.ALIGN.CENTER, 0, 0) cont.set_fit(lv.FIT.NONE) # cont.set_layout(lv.LAYOUT.PRETTY_MID) cont.set_layout(lv.LAYOUT.ROW_MID) line = lv.line(cont) points = styles.get_line_pts_from_num(1, size=40) line.set_points(points, len(points)) line.add_style(line.PART.MAIN, line_style2) line.align(None, lv.ALIGN.CENTER, 0, 0) line2 = lv.line(cont) points = styles.get_line_pts_from_num(2, size=40) line2.set_points(points, len(points)) line2.add_style(line2.PART.MAIN, line_style2) line2.align(None, lv.ALIGN.CENTER, 0, 0)
def slider_event_cb(e): code = e.get_code() obj = e.get_target() # Provide some extra space for the value if code == lv.EVENT.REFR_EXT_DRAW_SIZE: e.set_ext_draw_size(50) elif code == lv.EVENT.DRAW_PART_END: # print("DRAW_PART_END") dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) # print(dsc) if dsc.part == lv.PART.INDICATOR: label_text = "{:d} - {:d}".format(obj.get_left_value(),slider.get_value()) label_size = lv.point_t() lv.txt_get_size(label_size, label_text, lv.font_default(), 0, 0, lv.COORD.MAX, 0) # print(label_size.x,label_size.y) label_area = lv.area_t() label_area.x1 = dsc.draw_area.x1 + dsc.draw_area.get_width() // 2 - label_size.x // 2 label_area.x2 = label_area.x1 + label_size.x label_area.y2 = dsc.draw_area.y1 - 10 label_area.y1 = label_area.y2 - label_size.y label_draw_dsc = lv.draw_label_dsc_t() label_draw_dsc.init() lv.draw_label(label_area, dsc.clip_area, label_draw_dsc, label_text, None)
def calibrate_clicked(self): point = self.points[self.cur_point] indev = lv.indev_get_act() indev.get_point(self.med[self.cur_touch]) # print("calibrate_clicked: x: %d, y: %d"%(self.med[self.cur_touch].x,self.med[self.cur_touch].y)) self.cur_touch += 1 if self.cur_touch == self.touch_count: med_x = sorted([med.x for med in self.med]) med_y = sorted([med.y for med in self.med]) x = med_x[len(med_x) // 2] y = med_y[len(med_y) // 2] point.touch_coordinate = lv.point_t({'x': x, 'y': y}) self.cur_point += 1 self.cur_touch = 0 if self.cur_point == len(self.points): self.calibrate(self.points) self.cur_point = 0 self.show_text("Click/drag on screen\n" + \ "to check calibration") self.big_btn.set_event_cb(lambda event, self=self: self.check(), lv.EVENT.PRESSING, None) else: self.show_circle()
def check(self): point = lv.point_t() indev = lv.indev_get_act() indev.get_point(point) # print("click position: x: %d, y: %d"%(point.x,point.y)) self.circ_area.set_pos(point.x - CIRCLE_SIZE // 2, point.y - CIRCLE_SIZE // 2)
def __init__(self, parent): super().__init__(parent, 20) self.vect = lv.point_t() self.set_size(100, 80) self.add_title("Pop") msg_box_close_btn = self.add_btn(lv.SYMBOL.CLOSE, 20) msg_box_close_btn.add_event_cb(lambda e: self.close_msg_box(), lv.EVENT.RELEASED, None) header = self.get_header() header.set_style_bg_color(lv.color_hex3(0xFEE), lv.PART.MAIN) content = self.get_content() content.set_style_bg_color(lv.color_hex3(0xFFF), lv.PART.MAIN) self.set_style_border_width(4, lv.PART.MAIN) self.set_style_border_color(lv.color_hex3(0xF88), lv.PART.MAIN) self.set_style_shadow_color(lv.color_hex3(0x000), lv.PART.MAIN) self.set_style_shadow_opa(50, lv.PART.MAIN) self.set_style_shadow_width(20, lv.PART.MAIN) self.set_style_shadow_ofs_x(10, lv.PART.MAIN) self.set_style_shadow_ofs_y(10, lv.PART.MAIN) self.set_style_shadow_spread(0, lv.PART.MAIN) self.set_style_radius(10, lv.PART.MAIN) self.label = lv.label(content) for element in [content, header]: element.add_event_cb(self.drag_event_handler, lv.EVENT.PRESSING, None) self.opened = True
def polar(canvas, origin, line, width, color): line_dsc = lv.draw_line_dsc_t() line_dsc.init() line_dsc.color = color line_dsc.width = width p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] xs, ys = origin.real, origin.imag p1.x = round(xs) p1.y = round(ys) p2.x = round(xs + line.real) p2.y = round(ys - line.imag) # print("x0: %d, y0: %d, x1: %d, y1: %d"%(round(xs), round(ys), round(xs + line.real), round(ys - line.imag))) canvas.draw_line(point_array, 2, line_dsc)
def getCenter(obj): ar = lv.area_t() obj.get_coords(ar) pt = lv.point_t() pt.x = (ar.x1+ar.x2)//2 pt.y = (ar.y1+ar.y2)//2 return pt
def event_cb(e): dsc = lv.obj_draw_part_dsc_t.cast(e.get_param()) if dsc.part != lv.PART.INDICATOR: return obj = lv.bar.__cast__(e.get_target()) label_dsc = lv.draw_label_dsc_t() label_dsc.init() # label_dsc.font = LV_FONT_DEFAULT; value_txt = str(obj.get_value()) txt_size = lv.point_t() lv.txt_get_size(txt_size, value_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, lv.COORD.MAX, label_dsc.flag) txt_area = lv.area_t() # If the indicator is long enough put the text inside on the right if dsc.draw_area.get_width() > txt_size.x + 20: txt_area.x2 = dsc.draw_area.x2 - 5 txt_area.x1 = txt_area.x2 - txt_size.x + 1 label_dsc.color = lv.color_white() # If the indicator is still short put the text out of it on the right*/ else: txt_area.x1 = dsc.draw_area.x2 + 5 txt_area.x2 = txt_area.x1 + txt_size.x - 1 label_dsc.color = lv.color_black() txt_area.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - txt_size.y) // 2 txt_area.y2 = txt_area.y1 + txt_size.y - 1 lv.draw_label(txt_area, dsc.clip_area, label_dsc, value_txt, None)
def add_tile(self, x, y, id): self.log.debug("add tile no %d: x: %d y: %d, id= %s" % (self.tile_entries, x, y, id)) self.tile_entries += 1 new_tile = Tile() new_tile.tile = lv.cont(self.mainbar, None) hor_res = lv.scr_act().get_disp().driver.hor_res ver_res = lv.scr_act().get_disp().driver.ver_res new_tile.tile.set_width(hor_res) new_tile.tile.set_height(ver_res) new_tile.tile.set_pos(hor_res * x, ver_res * y) new_tile.tile.add_style(lv.obj.PART.MAIN, self.mainbar_style) new_tile.x = x new_tile.y = y new_tile.id = id self.tile_table.append(new_tile) self.mainbar.add_element(new_tile.tile) new_pos = lv.point_t() new_pos.x = x new_pos.y = y self.tile_pos_table.append(new_pos) self.tile_table[self.tile_entries - 1].tile.add_style( lv.obj.PART.MAIN, self.mainbar_style) self.tile_table[self.tile_entries - 1].tile.set_pos( self.tile_pos_table[self.tile_entries - 1].x * lv.scr_act().get_disp().driver.hor_res, self.tile_pos_table[self.tile_entries - 1].y * lv.scr_act().get_disp().driver.ver_res) self.mainbar.set_valid_positions(self.tile_pos_table, self.tile_entries) return (self.tile_entries - 1)
def read_cb(drv, ptr): # print(ptr, b) data = lv.indev_data_t.cast(ptr) TOUCH.event() # print(TOUCH.state, TOUCH.points) data.point = lv.point_t({'x': TOUCH.points[1][0], 'y': TOUCH.points[1][1]}) data.state = lv.INDEV_STATE.PR if TOUCH.state == 1 else lv.INDEV_STATE.REL return False
def drag_event_handler(e): self = e.get_target() indev = lv.indev_get_act() vect = lv.point_t() indev.get_vect(vect) x = self.get_x() + vect.x y = self.get_y() + vect.y self.set_pos(x, y)
def drag_event_handler(e): obj = e.get_target() indev = lv.indev_get_act() vect = lv.point_t() indev.get_vect(vect) x = obj.get_x() + vect.x y = obj.get_y() + vect.y obj.set_pos(x, y)
def feed_touch(): point = lv.point_t() indev = lv.indev_get_act() lv.indev_get_point(indev, point) # now we can take bytes([point.x % 256, point.y % 256]) # and feed it into hash digest t = time.ticks_cpu() random_data = t.to_bytes(4,'big') + bytes([point.x % 256, point.y % 256]) rng.feed(random_data)
def table_event_cb(e): row = lv.point_t() col = lv.point_t() lv.table.get_selected_cell(table, row, col) print("row :" + str(row.x)) print("col :" + str(col.x)) print("value :" + table.get_cell_value(row.x, col.x)) key = str(table.get_cell_value(row.x, col.x)) '''only show msgbox when column 0 is selected''' if col.x == 0: msb_edit_table(key) global tabledata tabledata = e return tabledata
def __init__(self, sda=21, scl=22, freq=400000, width=-1, height=-1, inv_x=False, inv_y=False, swap_xy=False): if not lv.is_initialized(): lv.init() self.width, self.height = width, height self.inv_x, self.inv_y, self.swap_xy = inv_x, inv_y, swap_xy self.touch = ft6336u(sda=Pin(sda), scl=Pin(scl), freq=freq) try: status = self.touch.check() print("FT6X36 touch IC ready (fw id 0x{0:X} rel {1:d}, lib {2:X})".format( \ status[0], \ status[1], \ status[2] \ )) except: print("FT6X36 touch IC not responding") return self.point = lv.point_t({'x': 0, 'y': 0}) self.points = [ lv.point_t({ 'x': 0, 'y': 0 }), lv.point_t({ 'x': 0, 'y': 0 }) ] self.state = lv.INDEV_STATE.RELEASED self.indev_drv = lv.indev_drv_t() self.indev_drv.init() self.indev_drv.type = lv.INDEV_TYPE.POINTER self.indev_drv.read_cb = self.callback self.indev_drv.register()
def test(): """Test code.""" cbuf = bytearray(CANVAS_WIDTH * CANVAS_HEIGHT * 4) # create a canvas canvas = lv.canvas(lv.scr_act(), None) canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) canvas.align(None, lv.ALIGN.CENTER, 0, 0) p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] p2.x = CENTER_X p2.y = CENTER_Y line_dsc = lv.draw_line_dsc_t() line_dsc.init() line_dsc.opa = lv.OPA.COVER x, y = 0, 0 angle = 0.0 # Loop all angles from 0 to 2 * PI radians while angle < PI2: # Calculate x, y from a vector with known length and angle x = int(CENTER_Y * sin(angle) + HALF_WIDTH) y = int(CENTER_Y * cos(angle) + HALF_HEIGHT) color = LV_COLOR_MAKE(*hsv_to_rgb(angle / PI2, 1, 1)) line_dsc.color = color p1.x = x p1.y = y canvas.draw_line(point_array, 2, line_dsc) angle += ANGLE_STEP_SIZE sleep(5) clear(canvas) line_dsc.width = 3 for r in range(CENTER_Y, 0, -1): line_dsc.color = LV_COLOR_MAKE(*hsv_to_rgb(r / HALF_HEIGHT, 1, 1)) canvas.draw_arc(CENTER_X, CENTER_Y, r, 0, 360, line_dsc) sleep(5)
def on_word_click(self, obj, evt): if evt != lv.EVENT.RELEASED: return # get coordinates point = lv.point_t() indev = lv.indev_get_act() lv.indev_get_point(indev, point) # get offsets dx = point.x - obj.get_x() dy = point.y - obj.get_y() # get index idx = 12*int(dx > obj.get_width()//2) + int(12*dy/obj.get_height()) self.change_word(idx)
def feed_touch(): """ Gets a point from the touchscreen and feeds it to random number pool """ point = lv.point_t() indev = lv.indev_get_act() lv.indev_get_point(indev, point) # now we can take bytes([point.x % 256, point.y % 256]) # and feed it into hash digest t = time.ticks_cpu() random_data = t.to_bytes(4, 'big') + bytes([point.x % 256, point.y % 256]) rng.feed(random_data)
def cb(self, obj, event): if event == lv.EVENT.PRESSING: feed_touch() c = obj.get_active_btn_text() if c is not None and len(c)<=2: self.hint.set_hidden(False) self.hint_lbl.set_text(c) point = lv.point_t() indev = lv.indev_get_act() lv.indev_get_point(indev, point) self.hint.set_pos(point.x-25, point.y-130) elif event == lv.EVENT.RELEASED: self.hint.set_hidden(True) if self.callback is not None: self.callback(obj, event)
def cb(obj, event): if event == lv.EVENT.PRESSING: c = obj.get_active_btn_text() if c is None: return if len(c)>2: key_hint.set_hidden(True) return key_hint.set_hidden(False) key_lbl.set_text(c) point = lv.point_t() indev = lv.indev_get_act() lv.indev_get_point(indev, point) key_hint.set_pos(point.x-25, point.y-130) elif event == lv.EVENT.RELEASED: key_hint.set_hidden(True) c = obj.get_active_btn_text() if c is None: return if c[0] == lv.SYMBOL.LEFT: ta.del_char() elif c == lv.SYMBOL.UP or c == lv.SYMBOL.DOWN: for i,ch in enumerate(CHARSET): if ch.isalpha(): if c == lv.SYMBOL.UP: CHARSET[i] = CHARSET[i].upper() else: CHARSET[i] = CHARSET[i].lower() elif ch == lv.SYMBOL.UP: CHARSET[i] = lv.SYMBOL.DOWN elif ch == lv.SYMBOL.DOWN: CHARSET[i] = lv.SYMBOL.UP btnm.set_map(CHARSET) elif c == "#@": btnm.set_map(CHARSET_EXTRA) elif c == "aA": btnm.set_map(CHARSET) elif c[0] == lv.SYMBOL.CLOSE: ta.set_text("") elif c[0] == lv.SYMBOL.OK: cb_continue(ta.get_text()) ta.set_text("") else: ta.add_text(c)
def __init__(self, points, calibrate, touch_count=5): self.points = points self.calibrate = calibrate self.touch_count = touch_count self.med = [lv.point_t() for i in range(0, self.touch_count) ] # Storage point to calculate median self.cur_point = 0 self.cur_touch = 0 self.scr = lv.obj(None) self.scr.set_size(TP_MAX_VALUE, TP_MAX_VALUE) lv.scr_load(self.scr) # Create a big transparent button screen to receive clicks style_transp = lv.style_t() style_transp.init() style_transp.set_bg_opa(lv.OPA.TRANSP) self.big_btn = lv.btn(lv.scr_act()) self.big_btn.set_size(TP_MAX_VALUE, TP_MAX_VALUE) self.big_btn.add_style(style_transp, lv.PART.MAIN) self.big_btn.add_style(style_transp, lv.PART.MAIN) #self.big_btn.set_layout(lv.LAYOUT.OFF) self.big_btn.add_event_cb( lambda event, self=self: self.calibrate_clicked(), lv.EVENT.CLICKED, None) # Create the screen, circle and label self.label_main = lv.label(lv.scr_act()) style_circ = lv.style_t() style_circ.init() style_circ.set_radius(LV_RADIUS_CIRCLE) self.circ_area = lv.obj(lv.scr_act()) self.circ_area.set_size(CIRCLE_SIZE, CIRCLE_SIZE) self.circ_area.add_style(style_circ, lv.STATE.DEFAULT) self.circ_area.clear_flag( lv.obj.FLAG.CLICKABLE) # self.circ_area.set_click(False) self.show_circle()