forked from tinyprinter/python-paperang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.py
More file actions
executable file
·64 lines (56 loc) · 2.38 KB
/
Copy pathprinter.py
File metadata and controls
executable file
·64 lines (56 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
from tkinter import Image
import hardware
import image_data
import skimage.io
import skimage as ski
import config
from PIL import Image
from ppa6 import Printer,PrinterType
class Paperang_Printer:
def __init__(self):
if hasattr(config, "macaddress"):
self.printer_hardware = hardware.Paperang(config.macaddress)
else:
self.printer_hardware = hardware.Paperang()
def print_self_test(self):
print("attempting test print to MAC address \"% s\""% config.macaddress)
if self.printer_hardware.connected:
self.printer_hardware.sendSelfTestToBt()
def print_image_file(self, path):
if self.printer_hardware.connected:
self.printer_hardware.sendImageToBt(image_data.binimage2bitstream(
image_data.im2binimage(ski.io.imread(path),conversion="threshold")))
def print_dithered_image(self, path):
if self.printer_hardware.connected:
self.printer_hardware.sendImageToBt(image_data.im2binimage2(path))
class Peripage_Printer:
def __init__(self):
self.printer_hardware = Printer(config.macaddress,timeout=10)
self.printer_hardware.connect()
def print_self_test(self):
print("attempting test print to MAC address \"% s\""% config.macaddress)
if self.printer_hardware.isConnected():
self.name = self.printer_hardware.getDeviceName()
self.hardware = self.printer_hardware.getDeviceHardware()
self.firmware = self.printer_hardware.getDeviceFirmware()
self.mac = self.printer_hardware.getDeviceMAC()
self.serial = self.printer_hardware.getDeviceSerialNumber()
self.printer_hardware.printBreak()
self.printer_hardware.printASCII("Woohoo! It works!\n")
self.printer_hardware.printBreak()
def print_image_file(self, path):
if self.printer_hardware.isConnected():
with Image.open(path) as im:
self.printer_hardware.printImage(im)
self.printer_hardware.printBreak()
if __name__=="__main__":
type: str
if hasattr(config, "type"):
type = config.type
if type.casefold() == "peripage":
mmj=Peripage_Printer()
elif type.casefold() == "paperang":
mmj=Paperang_Printer()
mmj.print_self_test()
mmj.print_image_file("C:\\Users\\john\\Pictures\\hype.png")