class ThermalPrinter(): def __init__(self): self.p = Usb(0x0fe6, 0x811e, 98, 0x82, 0x02) def insert_imagen(self, img_surce): self.p.image(img_surce) def insert_qr(self, content, size): self.p.qr(content, size=size) #size 1 - 16 default 3 def insert_barcode(self, code, bc, height, width): self.p.barcode(code, bc, height=height, width=width) def insert_text(self, txt): self.p.text(txt) def insert_raw_txt(self, txt): self.p._raw(txt) # harware action, may be: INIT, SELECT, RESET def hardware_operation(self, hw): self.p.hw(hw) #string for the following control sequences: # LF for Line Feed # FF for Form Feed # CR for Carriage Return # HT for Horizontal Tab # VT for Vertical Tab #pos = horizontal tab position 1 - 16 def feed_control(self, ctl, pos): self.p.control() self.p.charcode() # #def insert_textln(self, txt): # align = CENTER LEFT RIGHT default left # font_type = A or B default A # textt_type = B(bold), U(underline), U2(underline, version2), BU(for bold and underlined, NORMAL(normal text) defaul tnormal # width = width multiplier decimal 1 - 8 defaul 1 # heigh = height multiplier decimal 1 - 8 defaul 1 # density = density 0 - 8 # def set_txt(self, align, font, text_type, density, height, width): def set_txt(self, *args, **Kwargs): print(Kwargs) self.p.set(Kwargs) def cut_paper(self): self.p.cut()
from datetime import datetime # sys.argv # [1] Código do movimento de portaria # [2] Nome do motorista # [3] OC ou SCM # [4] Código da OC ou da SCM # [5] Nome do usuário do protheus # [6] tipo da refeição [1]café [2]almoço [3]janta agora = datetime.now().strftime("%d/%m/%Y | %H:%M") p = Usb(0x04B8, 0x0E27, 0, 0x81, 0x02) # Específico para impressora Epson TM-T20X p.set(double_width=True, double_height=True) p.control('HT') p.text(" TICKET REFEICAO") p.set(double_width=True, double_height=False) p.ln() p.ln() p.text(' ' + sys.argv[1]) p.ln() p.ln() p.text(' ' + sys.argv[2].replace('_', ' ')) p.ln() p.ln() p.text(' ' + sys.argv[3] + ' ' + sys.argv[4]) p.ln() p.ln() if sys.argv[6] == '1': p.text(' ' + "Cafe")
def icon(): icon = data['currently']['icon'] image = GRAPHICS_PATH + icon + ".png" return image deg = ' C' # Degree symbol on thermal printer, need to find a better way to use a proper degree symbol # if you want Fahrenheit change units= to 'us' url = "https://api.darksky.net/forecast/" + API_KEY + "/" + LAT + "," + LONG + \ "?exclude=[alerts,minutely,hourly,flags]&units=si" # change last bit to 'us' for Fahrenheit response = urllib.urlopen(url) data = json.loads(response.read()) printer.print_and_feed(n=1) printer.control("LF") printer.set(font='a', height=2, align='center', bold=True, double_height=True) printer.text("Weather Forecast") printer.text("\n") printer.set(align='center') # Print current conditions printer.set(font='a', height=2, align='center', bold=True, double_height=False) printer.text('Current conditions: \n') printer.image(icon()) printer.text("\n") printer.set(font='a', height=2, align='left', bold=False, double_height=False) temp = data['currently']['temperature'] cond = data['currently']['summary']