def test_auto_flush(mock_escpos, mock_open, mock_device, txt): """test auto_flush in file-printer""" p = printer.File(auto_flush=False) # inject the mocked device-object p.device = mock_device p._raw(txt) assert not mock_device.flush.called mock_device.reset_mock() p = printer.File(auto_flush=True) # inject the mocked device-object p.device = mock_device p._raw(txt) assert mock_device.flush.called
def test_function_panel_button_off(): """test the panel button function (disabling) by comparing output""" instance = printer.File(devfile=devfile) instance.panel_buttons(False) instance.flush() with open(devfile, "rb") as f: assert(f.read() == b'\x1B\x63\x35\x01')
def test_load_file_printer(mocker, path): """test the loading of the file-printer""" mock_escpos = mocker.patch('escpos.escpos.Escpos.__init__') mock_open = mocker.patch(mock_open_call) printer.File(devfile=path) assert mock_escpos.called mock_open.assert_called_with(path, "wb")
def __init__(self, url): og = OpenGraph(url) file_name, headers = urllib.request.urlretrieve(og.image) # call image magick to update file in place # cmd = 'mogrify -colorspace Gray -ordered-dither h4x4a -resize 512 %s' % file_name cmd = 'mogrify -colorspace Gray -resize 512 -unsharp 0x1 %s' % file_name os.system(cmd) # make an attempt to shorten the title and make it printable title = ascii( fix_text( og.title.split('Instagram post by ').pop().split( 'Instagram: ').pop())).replace('\\u2022', '-').replace('\'', '') p = printer.File("/dev/usb/lp0") p.text(title) p.text("\n") time.sleep(2) p.image(file_name) time.sleep(2) p.text("\n") p.text(og.url) p.cut() print(title) print(file_name) urllib.request.urlcleanup()
def test_auto_flush(mocker, txt): """test auto_flush in file-printer""" mock_escpos = mocker.patch('escpos.escpos.Escpos.__init__') mock_open = mocker.patch(mock_open_call) mock_device = mocker.patch.object(printer.File, 'device') p = printer.File(auto_flush=False) # inject the mocked device-object p.device = mock_device p._raw(txt) assert not mock_device.flush.called mock_device.reset_mock() p = printer.File(auto_flush=True) # inject the mocked device-object p.device = mock_device p._raw(txt) assert mock_device.flush.called
def printPhoto(image): Thermal = printer.File("/dev/usb/lp0") Thermal.image(image) Thermal.control('LF') Thermal.control('LF') Thermal.control('LF') Thermal.control('LF') Thermal.control('LF') Thermal.close()
def test_flush_on_close(mock_open, mock_device, txt): """test flush on close in file-printer""" p = printer.File(auto_flush=False) # inject the mocked device-object p.device = mock_device p._raw(txt) assert not mock_device.flush.called p.close() assert mock_device.flush.called assert mock_device.close.called
def test_flush_on_close(mocker, txt): """test flush on close in file-printer""" mock_open = mocker.patch(mock_open_call) mock_device = mocker.patch.object(printer.File, 'device') p = printer.File(auto_flush=False) # inject the mocked device-object p.device = mock_device p._raw(txt) assert not mock_device.flush.called p.close() assert mock_device.flush.called assert mock_device.close.called
def print_bill(): print("asdad") receipt_from_tailpos = loads(request.get_data(as_text=True)) for_printing = receipt_from_tailpos['data'] print(for_printing) #print(loads(for_receipt['data']['mop'])[0]['translation_text']) #reshaped_text = arabic_reshaper.reshape(loads(for_receipt['data']['mop'])[0]['translation_text']) #rev_text = reshaped_text[::-1] # slice backwards # Some variable port_serial = "/dev/rfcomm4" bluetoothSerial = serial.Serial(port_serial, baudrate=115200, timeout=1) print(bluetoothSerial) fontPath = "/usr/share/fonts/opentype/fonts-hosny-thabit/Thabit.ttf" tmpImage = 'test1.png' printWidth = 250 # Get the characters in order textReshaped = arabic_reshaper.reshape(for_printing['company']) textDisplay = get_display(textReshaped) # PIL can't do this correctly, need to use 'wand'. # Based on # https://stackoverflow.com/questions/5732408/printing-bidi-text-to-an-image im = wImage(width=printWidth, height=36, background=wColor('#ffffff')) draw = wDrawing() draw.text_alignment = 'center'; draw.text_antialias = False draw.text_encoding = 'utf-8' draw.text_kerning = 0.0 draw.font = fontPath draw.font_size = 36 draw.text(printWidth, 22, textDisplay) draw(im) im.save(filename=tmpImage) # Print an image with your printer library printertest = printer.File(port_serial) printertest.set(align="right") printertest.image(tmpImage) printertest.cut() print("SAMOKA GYUD Oi") bluetoothSerial.close() return {}
def test_function_text_dies_ist_ein_test_lf(): """test the text printing function with simple string and compare output""" instance = printer.File(devfile=devfile) instance.text('Dies ist ein Test.\n') instance.flush() assert(filecmp.cmp('test/Dies ist ein Test.LF.txt', devfile))
def print_report(): receipt_from_tailpos = loads(request.get_data(as_text=True)) for_printing = receipt_from_tailpos['data'] type_of_printing = receipt_from_tailpos['type'] print(for_printing) port_serial = "/dev/rfcomm0" home = str(Path.home()) bluetoothSerial = serial.Serial(port_serial, baudrate=115200, timeout=1) company_name = for_printing['company'].lower().replace(" ", "_") print(company_name) fontPath = home + "/tailorder-server/fonts/" + company_name + ".ttf" print(fontPath) tmpImage = 'print_images/report.png' printWidth = 570 height = 600 draw = wDrawing() draw.font = fontPath #COMPANY ============== draw.font_size = 34 y_value = 30 draw.text(x=180, y=y_value, body=for_printing['company']) draw.font_size = 26 y_value = y_value + 35 draw.text(x=5, y=y_value, body="=====================================") y_value = y_value + 35 draw.text_alignment = "center" draw.text(x=300, y=y_value, body=for_printing['reportType']) draw.text_alignment = "undefined" y_value = y_value + 35 draw.text(x=5, y=y_value, body="=====================================") y_value = y_value + 35 draw.text(x=5, y=y_value, body="Opened: " + for_printing['opened']) y_value = y_value + 35 draw.text(x=5, y=y_value, body="Opened: " + for_printing['closed']) y_value = y_value + 35 draw.text(x=5, y=y_value, body="=====================================") y_value = y_value + 35 labels = [ "Opening Amount", "Expected Drawer", "Actual Money", ] for i in labels: draw.text(x=5, y=y_value, body=i) draw.gravity = "north_east" draw.text(x=5, y=y_value - 35, body=for_printing[i.lower().replace(" ", "_")]) draw.gravity = "forget" y_value = y_value + 35 draw.text(x=5, y=y_value, body=for_printing['short_or_overage']) draw.gravity = "north_east" draw.text(x=5, y=y_value - 35, body=for_printing["short_or_overage_amount"]) draw.gravity = "forget" y_value = y_value + 35 draw.text(x=5, y=y_value, body="=====================================") y_value = y_value + 35 labels = [ "Cash Sales", "Total Net Sales", "Total Net Sales with Vat", "Payouts", "Payins", ] for i in labels: draw.text(x=5, y=y_value, body=i) draw.gravity = "north_east" draw.text(x=5, y=y_value - 35, body=for_printing[i.lower().replace(" ", "_")]) draw.gravity = "forget" y_value = y_value + 35 if len(for_printing['total_taxes']) > 0: for i in for_printing['total_taxes']: height += 35 draw.text(x=5, y=y_value, body=i['name']) draw.gravity = "north_east" draw.text(x=5, y=y_value - 35, body=str(i['totalAmount'])) draw.gravity = "forget" y_value = y_value + 35 labels = ["Discount", "Cancelled", "Voided", "Transactions", "Loyalty"] for i in labels: height += 35 draw.text(x=5, y=y_value, body=i) draw.gravity = "north_east" draw.text(x=5, y=y_value - 35, body=str(for_printing[i.lower().replace(" ", "_")])) draw.gravity = "forget" y_value = y_value + 35 height += 35 draw.text(x=5, y=y_value, body="=====================================") y_value = y_value + 35 labels = [ "Dine in", "Takeaway", "Delivery", "Online", "Family", ] for i in labels: if float(for_printing[i.lower().replace(" ", "_")]) > 0: height += 35 draw.text(x=5, y=y_value, body=i) draw.gravity = "north_east" draw.text(x=5, y=y_value - 35, body=for_printing[i.lower().replace(" ", "_")]) draw.gravity = "forget" y_value = y_value + 35 if len(for_printing['categories_total_amounts']) > 0: for i in for_printing['categories_total_amounts']: height += 35 draw.text(x=5, y=y_value, body=i['name']) draw.gravity = "north_east" draw.text(x=5, y=y_value - 35, body=str(format(float(i['total_amount']), '.2f'))) draw.gravity = "forget" y_value = y_value + 35 else: y_value = y_value + 35 height += 35 draw.text(x=5, y=y_value, body="=====================================") y_value = y_value + 35 if len(for_printing['mop_total_amounts']) > 0: for i in for_printing['mop_total_amounts']: height += 35 draw.text(x=5, y=y_value, body=i['name']) draw.gravity = "north_east" draw.text(x=5, y=y_value - 35, body=str(format(float(i['total_amount']), '.2f'))) draw.gravity = "forget" y_value = y_value + 35 if len(for_printing['mop_total_amounts']) > 0: height += 35 draw.text(x=5, y=y_value, body="=====================================") im = wImage(width=printWidth, height=height, background=wColor('#ffffff')) draw(im) im.save(filename=tmpImage) basewidth = 230 baseheight = 221 logo = "logos/logo.png" img = Image.open(logo) wpercent = (basewidth / float(img.size[0])) img = img.resize((basewidth, baseheight), PIL.Image.ANTIALIAS) img.save(logo) # Print an image with your printer library printertest = printer.File(port_serial) printertest.set(align="center") printertest.image(logo) printertest.image(tmpImage) printertest.cut() bluetoothSerial.close() return {}
"model": "Seagate STXXXXXXX", "size": "2 TiB" }, { "type": "ssd", "model": "Samsung 850 EVO", "size": "1 TiB" } ], "psu": "Corsair AX850i", "gpu": "EVGA Geforce GTX Titan X 12GB" }""" j = json.loads(jsonStr) p = printer.File('/dev/usb/lp0') #p = printer.Network("192.168.1.172", 4242) p.set('center') p.image("fgarlogo.png", False, False, "bitImageRaster", 960) p.set('left', 'a', True) p.text("CPU: ") p.set('left', 'a', False) p.textln(j['cpu']) p.set('left', 'a', True) p.text("Motherboard: ") p.set('left', 'a', False) p.textln(j['motherboard']) p.set('left', 'a', True)
def test_load_file_printer(mock_escpos, mock_open, path): """test the loading of the file-printer""" printer.File(devfile=path) assert mock_escpos.called mock_open.assert_called_with(path, "wb")
def print_receipt(): receipt_from_tailpos = loads(request.get_data(as_text=True)) for_printing = receipt_from_tailpos['data'] print(for_printing) port_serial = "/dev/rfcomm0" bluetoothSerial = serial.Serial(port_serial, baudrate=115200, timeout=1) #fontPath = "/home/jiloysss/Documents/spiceco/aljazeera-font/FontAljazeeraColor-lzzD.ttf" fontPath = "/home/pi/FontAljazeeraColor-lzzD.ttf" tmpImage = 'receipt.png' #printWidth = 375 printWidth = 570 height = 600 draw = wDrawing() draw.font = fontPath #COMPANY ============== draw.font_size = 34 draw.text(x=180,y=75,body=for_printing['company']) #DATE ================== split_date = for_printing['date'].split() draw.font_size = 26 draw.text(x=5,y=110,body=split_date[0]) draw.text(x=260,y=110,body=split_date[1]) #ORDER TYPE ============== draw.font_size = 26 draw.text(x=5,y=145,body="Order Type: " + for_printing['ordertype']) y_value = 145 #HEADER ========== if for_printing['header']: header_value = 160 for x in for_printing['header'].split("\n"): y_value = y_value + 35 header_value = header_value + 25 draw.text_alignment = "center" draw.text(x=180,y=header_value,body=x) draw.text_alignment = "undefined" draw.text(x=5,y=y_value + 35 ,body="=====================================") #ITEM PURCHASES y_value = y_value + 30 for idx,i in enumerate(for_printing['lines']): if idx != 0: height += 35 draw.gravity = "north_east" draw.text(x=5,y=y_value + 10,body=format(float(i['qty'] * i['price']), '.2f')) draw.gravity = "forget" if len(i['item_name']) > 22: quotient = len(i['item_name']) / 22 for xxx in range(0,int(quotient)): if idx != 0: height += 35 y_value = y_value + 35 draw.text(x=5,y=y_value,body=i['item_name'][xxx * 22: (xxx+1) * 22]) translation_text = "" if i['translation_text']: textReshaped = arabic_reshaper.reshape(i['translation_text']) textDisplay = get_display(textReshaped) translation_text = "(" + textReshaped + ")" y_value = y_value + 35 draw.text(x=5,y=y_value,body=i['item_name'][(int(quotient)*22): len(i['item_name'])] + translation_text ) else: translation_text = "" if i['translation_text']: textReshaped = arabic_reshaper.reshape(i['translation_text']) textDisplay = get_display(textReshaped) translation_text = "(" + textReshaped + ")" y_value = y_value + 35 draw.text(x=5,y=y_value,body=i['item_name'] ) y_value = y_value + 35 draw.text(x=5,y=y_value,body= translation_text) draw.text(x=5,y=y_value+35,body="=====================================") y_value = y_value + 35 #SUBTOTAL draw.text(x=5,y=y_value + 35,body="Subtotal") draw.gravity = "north_east" draw.text(x=5,y=y_value + 5,body=for_printing['subtotal']) draw.gravity = "forget" y_value = y_value + 35 #DISCOUNT draw.text(x=5,y=y_value + 35,body="Discount") draw.gravity = "north_east" draw.text(x=5,y=y_value + 5,body=for_printing['discount']) draw.gravity = "forget" #TAXES VALUES if len(for_printing['taxesvalues']) > 0: y_value = y_value + 35 for idx,iii in enumerate(for_printing['taxesvalues']): if idx != 0: height += 35 y_value = y_value + 35 draw.text(x=5,y=y_value,body=iii['name']) draw.gravity = "north_east" draw.text(x=5,y=y_value - 25,body=str(format(round(float(iii['totalAmount']),2), '.2f'))) draw.gravity = "forget" #MODE OF PAYMENT for idx, ii in enumerate(loads(for_printing['mop'])): if idx != 0: height += 35 y_value = y_value + 70 type = ii['type'] if ii['translation_text']: textReshaped = arabic_reshaper.reshape(ii['translation_text']) textDisplay = get_display(textReshaped) type += "(" + textReshaped + ")" draw.text(x=5,y=y_value,body=type) draw.gravity = "north_east" draw.text(x=5,y=y_value - 25,body=str(format(float(ii['amount']), '.2f'))) draw.gravity = "forget" #TOTAL AMOUNT draw.text(x=5,y=y_value + 35,body="Total Amount") draw.gravity = "north_east" draw.text(x=5,y=y_value + 5,body=str(format(float(for_printing['total_amount']), '.2f'))) draw.gravity = "forget" #CHANGE draw.text(x=5,y=y_value + 70,body="Change") draw.gravity = "north_east" draw.text(x=5,y=y_value + 43,body=str(format(float(for_printing['change']), '.2f'))) draw.gravity = "forget" draw.text(x=5,y=y_value+105,body="=====================================") #FOOTER ========== if for_printing['footer']: header_value = y_value+105 for x in for_printing['footer'].split("\n"): y_value = y_value + 35 header_value = header_value + 25 draw.text_alignment = "center" draw.text(x=180,y=header_value,body=x) im = wImage(width=printWidth, height=height, background=wColor('#ffffff')) draw(im) im.save(filename=tmpImage) # Print an image with your printer library printertest = printer.File(port_serial) printertest.set(align="left") printertest.image(tmpImage) printertest.cut() print("SAMOKA GYUD Oi") bluetoothSerial.close() return {}
def write_order(order, usb_printer=None, print_item_code=True): port_serial = "/dev/rfcomm1" home = str(Path.home()) bluetoothSerial = serial.Serial(port_serial, baudrate=115200, timeout=1) company_name = "house_of_spices" fontPath = home + "/tailorder-server/fonts/" + company_name + ".ttf" tmpImage = 'print_images/kitchen.png' printWidth = 570 height = 500 draw = wDrawing() draw.font = fontPath draw.font_size = 30 y_value = 30 draw.text(x=5, y=y_value, body="Order Id: ") draw.text(x=160, y=y_value, body=str(order.id)) y_value = y_value + 35 draw.text(x=5, y=y_value, body="Table Number: ") draw.text(x=230, y=y_value, body=str(order.table_no)) y_value = y_value + 35 draw.text(x=5, y=y_value, body="Type: ") draw.text(x=100, y=y_value, body=str(order.type)) lines = [] for i in order.items: lines.append(i.__dict__) # Headers header_line = line_block([ { 'text': 'Qty', 'align': '<', 'width': QTY_WIDTH }, { 'text': 'Item', 'align': '<', 'width': ITEM_WIDTH }, ]) y_value = y_value + 45 draw.text(x=5, y=y_value, body=str(header_line)) # Lines for line in lines: line_text = line_block([ { 'text': line['qty'], 'align': '<', 'width': QTY_WIDTH }, { 'text': line['item_name'], 'align': '<', 'width': ITEM_WIDTH }, ]) y_value = y_value + 35 draw.text(x=5, y=y_value, body=str(line_text)) if print_item_code: item_code = line_block([{ 'text': '-', 'align': '<', 'width': QTY_WIDTH }, { 'text': line['item_code'], 'align': '<', 'width': ITEM_WIDTH }]) y_value = y_value + 35 draw.text(x=5, y=y_value, body=str(item_code)) if order.remarks: y_value = y_value + 70 draw.text(x=5, y=y_value, body="Remarks: ") draw.text(x=180, y=y_value, body=str(order.remarks)) y_value = y_value + 70 draw.text(x=5, y=y_value, body="Printed on: ") draw.text(x=180, y=y_value, body=str(time.ctime())) im = wImage(width=printWidth, height=height, background=wColor('#ffffff')) draw(im) im.save(filename=tmpImage) #basewidth = 230 #baseheight = 221 #logo = "logos/logo.png" #img = Image.open(logo) #wpercent = (basewidth / float(img.size[0])) #img = img.resize((basewidth, baseheight), PIL.Image.ANTIALIAS) #img.save(logo) # Print an image with your printer library printertest = printer.File(port_serial) printertest.set(align="center") #printertest.image(logo) printertest.image(tmpImage) printertest.cut() bluetoothSerial.close()
def print_receipt(): receipt_from_tailpos = loads(request.get_data(as_text=True)) for_printing = receipt_from_tailpos['data'] type_of_printing = receipt_from_tailpos['type'] port_serial = "/dev/rfcomm0" home = str(Path.home()) bluetoothSerial = serial.Serial(port_serial, baudrate=115200, timeout=1) company_name = for_printing['company'].lower().replace(" ", "_") fontPath = home + "/tailorder-server/fonts/" + company_name + ".ttf" tmpImage = 'print_images/receipt.png' #printWidth = 375 printWidth = 570 height = 500 draw = wDrawing() draw.font = fontPath #COMPANY ============== company_translation = "" if for_printing['companyTranslation']: textReshaped = arabic_reshaper.reshape( for_printing['companyTranslation']) company_translation = get_display(textReshaped) draw.font_size = 34 y_value = 30 draw.text(x=180, y=y_value, body=for_printing['company']) draw.text(x=180, y=y_value + 35, body=company_translation) y_value = y_value + 45 draw.font_size = 26 #HEADER ========== if for_printing['header']: draw.text_alignment = "center" header_value = y_value header_array = for_printing['header'].split("\n") header_array_translation = for_printing['headerTranslation'].split( "\n") for x in range(0, len(header_array)): if header_array[x]: translation = "" if x < len(header_array_translation ) and header_array_translation[x]: textReshaped = arabic_reshaper.reshape( header_array_translation[x]) translation = get_display(textReshaped) y_value = y_value + 40 header_value = header_value + 25 draw.text(x=300, y=header_value, body=header_array[x] + translation) draw.text_alignment = "undefined" if for_printing['vat_number']: y_value = y_value + 35 header_value = header_value + 25 draw.text(x=5, y=y_value, body="VAT No.: " + for_printing['vat_number']) if for_printing['ticket_number']: header_value = header_value + 25 draw.text(x=330, y=y_value, body="Ticket Number: " + for_printing['ticket_number']) y_value = y_value + 35 #DATE ================== split_date = for_printing['date'].split() draw.font_size = 26 draw.text(x=5, y=y_value, body=split_date[0]) draw.gravity = "north_east" draw.text(x=5, y=y_value - 20, body=split_date[1]) draw.gravity = "forget" y_value = y_value + 35 #ORDER TYPE ============== draw.font_size = 26 draw.text(x=5, y=y_value, body="Order Type: " + for_printing['ordertype']) draw.text(x=5, y=y_value + 35, body="=====================================") #ITEM PURCHASES y_value = y_value + 30 for idx, i in enumerate(for_printing['lines']): if idx != 0: height += 35 draw.gravity = "north_east" draw.text(x=5, y=y_value + 10, body=format(float(i['qty'] * i['price']), '.2f')) draw.gravity = "forget" draw.text(x=340, y=y_value + 35, body=str(i['qty'])) if len(i['item_name']) > 25: quotient = len(i['item_name']) / 25 for xxx in range(0, int(quotient)): if idx != 0: height += 35 y_value = y_value + 35 draw.text(x=5, y=y_value, body=i['item_name'][xxx * 25:(xxx + 1) * 25]) y_value = y_value + 35 draw.text(x=5, y=y_value, body=i['item_name'][(int(quotient) * 25):len(i['item_name'])]) if i['translation_text']: y_value = y_value + 35 textReshaped = arabic_reshaper.reshape(i['translation_text']) textDisplay = get_display(textReshaped) translation_text = textDisplay draw.text(x=5, y=y_value, body=translation_text) else: y_value = y_value + 35 if idx != 0: height += 35 draw.text(x=5, y=y_value, body=i['item_name']) if i['translation_text']: height += 35 y_value = y_value + 35 textReshaped = arabic_reshaper.reshape(i['translation_text']) textDisplay = get_display(textReshaped) translation_text = textDisplay draw.text(x=5, y=y_value, body=translation_text) draw.text(x=5, y=y_value + 35, body="=====================================") y_value = y_value + 35 #SUBTOTAL textReshaped = arabic_reshaper.reshape("المبلغ الاجمالي") textDisplaySubtotal = get_display(textReshaped) draw.text(x=5, y=y_value + 35, body="Subtotal" + textDisplaySubtotal) draw.gravity = "north_east" draw.text(x=5, y=y_value + 5, body=for_printing['subtotal']) draw.gravity = "forget" y_value = y_value + 35 #DISCOUNT textReshaped = arabic_reshaper.reshape("الخصم") textDisplayDiscount = get_display(textReshaped) draw.text(x=5, y=y_value + 35, body="Discount" + textDisplayDiscount) draw.gravity = "north_east" draw.text(x=5, y=y_value + 5, body=for_printing['discount']) draw.gravity = "forget" if for_printing['loyalty'] > 0: y_value = y_value + 35 #LOYALTY textReshaped = arabic_reshaper.reshape("وفاء") textDisplayDiscount = get_display(textReshaped) draw.text(x=5, y=y_value + 35, body="Loyalty" + textDisplayDiscount) draw.gravity = "north_east" draw.text(x=5, y=y_value + 5, body=str( format(round(float(for_printing['loyalty']), 2), '.2f'))) draw.gravity = "forget" height += 35 #TAXES VALUES if len(for_printing['taxesvalues']) > 0: y_value = y_value + 35 for idx, iii in enumerate(for_printing['taxesvalues']): if idx != 0: height += 35 y_value = y_value + 35 tax_translation = "" if iii['translation']: height += 35 textReshaped = arabic_reshaper.reshape(iii['translation']) tax_translation = get_display(textReshaped) draw.text(x=5, y=y_value, body=iii['name'] + tax_translation) draw.gravity = "north_east" draw.text(x=5, y=y_value - 25, body=str( format(round(float(iii['totalAmount']), 2), '.2f'))) draw.gravity = "forget" if len(for_printing['taxesvalues']) == 0: y_value = y_value + 35 #MODE OF PAYMENT if type_of_printing != "Bill": for idx, ii in enumerate(loads(for_printing['mop'])): if idx != 0: height += 35 y_value = y_value + 35 type = ii['type'] if ii['translation_text']: textReshaped = arabic_reshaper.reshape(ii['translation_text']) textDisplay = get_display(textReshaped) type += textDisplay draw.text(x=5, y=y_value, body=type) draw.gravity = "north_east" draw.text(x=5, y=y_value - 25, body=str(format(float(ii['amount']), '.2f'))) draw.gravity = "forget" #TOTAL AMOUNT height += 35 textReshaped = arabic_reshaper.reshape("المبلغ الاجمالي") textDisplayTA = get_display(textReshaped) draw.text(x=5, y=y_value + 35, body="Total Amount" + textDisplayTA) draw.gravity = "north_east" draw.text(x=5, y=y_value + 5, body=str(format(float(for_printing['total_amount']), '.2f'))) draw.gravity = "forget" #CHANGE if type_of_printing != "Bill": height += 35 textReshaped = arabic_reshaper.reshape("الباقي") textDisplayChange = get_display(textReshaped) draw.text(x=5, y=y_value + 70, body="Change" + textDisplayChange) draw.gravity = "north_east" draw.text(x=5, y=y_value + 45, body=str(format(float(for_printing['change']), '.2f'))) draw.gravity = "forget" height += 40 draw.text(x=5, y=y_value + 105, body="=====================================") #FOOTER ========== if for_printing['footer']: draw.text_alignment = "center" footer_value = y_value + 105 footer_array = for_printing['footer'].split("\n") footer_array_translation = for_printing['footerTranslation'].split( "\n") for xx in range(0, len(footer_array)): if footer_array[xx]: height += 40 translation = "" if xx < len(footer_array_translation ) and footer_array_translation[xx]: textReshaped = arabic_reshaper.reshape( footer_array_translation[xx]) translation = get_display(textReshaped) footer_value = footer_value + 25 draw.text(x=300, y=footer_value, body=footer_array[xx] + translation) im = wImage(width=printWidth, height=height, background=wColor('#ffffff')) draw(im) im.save(filename=tmpImage) basewidth = 230 baseheight = 221 logo = "logos/logo.png" img = Image.open(logo) wpercent = (basewidth / float(img.size[0])) img = img.resize((basewidth, baseheight), PIL.Image.ANTIALIAS) img.save(logo) # Print an image with your printer library printertest = printer.File(port_serial) printertest.set(align="center") printertest.image(logo) printertest.image(tmpImage) printertest.cut() bluetoothSerial.close() return {}
computer = curs.fetchone() computer_id = computer['id'] print("Printing id:" + str(computer_id)) motherboard = computer['motherboard_model'] memory = computer['memory_model'] + " " + str( computer['memory_size']) #gpu = computer['gpu'] cpu = computer['cpu_model'] driveString = "select * from drives where computer_id = " + str( computer_id) + ";" curs.execute(driveString) hddrows = curs.fetchall() try: p = printer.File("/dev/usb/lp1") p.set('center') p.image("fgarlogo.png", False, False, "bitImageRaster", 960) p.set('left', 'a', True) p.text("CPU: ") p.set('left', 'a', False) p.textln(cpu) p.set('left', 'a', True) p.set('left', 'a', True) p.text("Motherboard: ") p.set('left', 'a', False) p.textln(motherboard)
def test_instantiation(): """test the instantiation of a escpos-printer class and basic printing""" instance = printer.File(devfile=devfile) instance.text('This is a test\n')
#!/usr/bin/env python import sys sys.path.append('../../drivers/python-escpos') from escpos import printer device = printer.File("/dev/stdout") if len(sys.argv) > 1: filename = sys.argv[1] else: filename = u"../tulips.png" device.image(filename)