def set_text(self, text="Text"): if self._text != text: print("QR on screen:", text) self._text = text qr = qrcode.encode_to_string(text) size = int(math.sqrt(len(qr))) # + 4 clear space on every side 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, qr_style) style.text.font = font pad = 4*fontsize style.body.radius = fontsize style.body.padding.top = pad style.body.padding.left = pad style.body.padding.right = pad style.body.padding.bottom = pad-fontsize # there is \n at the end self.set_style(lv.label.STYLE.MAIN, style) self.set_body_draw(True) super().set_text(qr) del qr gc.collect()
def _set_text(self, text): qr = qrcode.encode_to_string(text).strip() size = int(math.sqrt(len(qr))) # + 4 clear space on every side 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, qr_style) style.text.font = font style.body.radius = fontsize self.set_style(style) self.label.set_text(qr) self.label.align(self, lv.ALIGN.CENTER, 0, 0) self.note.align(self, lv.ALIGN.IN_BOTTOM_MID, 0, 0) del qr gc.collect()
def _set_text(self, text): # one bcur frame doesn't require checksum if text.startswith("UR:BYTES/") and text.count("/") == 2: text = "UR:BYTES/"+text.split("/")[-1] qr = qrcode.encode_to_string(text).strip() size = int(math.sqrt(len(qr)))+1 # to make sure round up width = self.label.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, qr_style) style.text.font = font style.body.radius = fontsize self.set_style(style) self.label.set_text(qr) self.label.align(self, lv.ALIGN.CENTER, 0, 0) self.note.align(self, lv.ALIGN.IN_BOTTOM_MID, 0, 0) del qr gc.collect()
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()
def set_text(self, text): if QrA.pending(text): if QrA.isQRplaying: self._text = text else: self._text = "".join(QrA.payload) else: if self.is_qr_big(text): self.isQRbig = True n = QrA.average_chunk_size(len(text), QRCode.MAX_SIZE) QrA.payload = [text[i:i + n] for i in range(0, len(text), n)] QrA.indx = [0, len(QrA.payload) - 1] if QrA.isQRtoobig: self._text = QrA.payload[QrA.indx[0]] QrA.isQRplaying = True else: self._text = text QrA.run() else: self.isQRbig = False self.isQRtoobig = False self._text = text QrA.abort = True if text != self.text_prev: print("QR on screen:", QrA.header() + self._text) self.text_prev = text if QrA.isQRplaying: if self.max_size: self.lbl.set_size(self.max_size, self.max_size) else: self.lbl.set_size(self.size, self.size) else: self.lbl.set_size(self.size, self.size) qr = qrcode.encode_to_string(QrA.header() + self._text) size = int(math.sqrt(len(qr))) # + 4 clear space on every side width = self.lbl.get_width() scale = round(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, qr_style) style.text.font = font pad = 4 * fontsize style.body.radius = fontsize style.body.padding.top = pad style.body.padding.left = pad style.body.padding.right = pad style.body.padding.bottom = pad - fontsize # there is \n at the end self.lbl.set_style(lv.label.STYLE.MAIN, style) self.lbl.set_body_draw(True) self.lbl.set_text(qr) del qr gc.collect() # apply the padding of the qr label to the container, otherwise it gets lost style2 = lv.style_t() style2.body.padding.top = pad style2.body.padding.left = pad style2.body.padding.right = pad style2.body.padding.bottom = pad - fontsize self.set_style(lv.label.STYLE.MAIN, style2) if self.isQRbig: style_tip = lv.style_t() lv.style_copy(style_tip, styles["theme"].style.ta.oneline) style_tip.text.font = lv.font_roboto_mono_16 self.lbl_indx.set_style(lv.label.STYLE.MAIN, style_tip) if QrA.isQRplaying: self.animation_tip = False if self.animation_tip: tip_text = "Tip: tap to animate" else: tip_text = "" self.lbl_indx.set_text(tip_text) self.lbl.set_width(self.lbl.get_height()) if not self.isQRbig: self.cont.set_fit(lv.FIT.TIGHT) self.set_fit(lv.FIT.TIGHT) elif not QrA.isQRplaying: self.max_size = self.lbl.get_height() self.cont.align_origo(self.lbl, lv.ALIGN.OUT_TOP_MID, 0, -35)