You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6 KiB
Python

6 years ago
import argparse
6 years ago
import sys
import os
import six
from random import randint
from PIL import Image, ImageOps
import curses
import sys, termios, tty, os, time
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class Printer():
ESC = b'\x1B'
CHANGE_EMULATION = ESC+b'\x7B'+b'\x65'
LINE_FEED = b'\n'
CARIDGE_RET = b'\x0D'
strokes = 0
def printchar(self,char):
with open('/dev/usb/lp0', 'wb') as printer:
printer.write(self.ESC+b"\x7B"+b"\x41")
char=self.strokes*" "+char
printer.write(bytes(str(char), 'utf-8'))
printer.write(self.ESC+b"\x25"+b"\x46"+b"\x0F"+b"\x00"+b"\x04"+b"\x08"+b"\x00")
self.strokes += 1
if(self.strokes>78):
printer.write(self.LINE_FEED)
self.strokes = 0
def newline(self):
global strokes
with open('/dev/usb/lp0', 'wb') as printer:
printer.write(self.LINE_FEED)
self.strokes = 0
def waitforinput():
while True:
char = getch()
if (ord(char) == 27):
print("exited publication :-(")
exit(0)
if (ord(char) == 13):
printer.newline()
else:
printer.printchar(char)
print("POETIC SOFTWARE")
print("Let's boot into this publication together?")
print("cancel [ok]")
printer = Printer()
waitforinput()