本文整理汇总了Python中Adafruit_Thermal.justify方法的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_Thermal.justify方法的具体用法?Python Adafruit_Thermal.justify怎么用?Python Adafruit_Thermal.justify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_Thermal
的用法示例。
在下文中一共展示了Adafruit_Thermal.justify方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_post
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
def generate_post():
with open('/home/yuri/mashbotv2/cleaned.txt') as f:
text = f.read()
text_model = markovify.Text(text, state_size=2)
mash_text = text_model.make_short_sentence(129) # was 140
wrapped_text = textwrap.fill(mash_text, 32)
output_text = "@acoluthon " + mash_text
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.setDefault()
printer.justify('L')
printer.feed(3)
printer.boldOn()
printer.setSize('M')
printer.println("Mash Note")
printer.setSize('S')
printer.boldOff()
printer.println(wrapped_text)
printer.feed(2)
# Write the status to a file, for debugging
with open('/home/yuri/mashbotv2/history.txt', 'a') as f:
f.write('mashed: ' + mash_text + ' | tweeted: ' + output_text + '\n')
return output_text
示例2: __init__
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
class thermal_printer:
def __init__(self):
self.printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
def printImg(self, img, priv_key):
self.printer.feed(3)
self.printer.printImage(img)
# I have some reservation about how to deal with encrypted private key, but need to wait for thermal_printer to look into it.
if len(priv_key) <= 51:
self.printer.printChar(priv_key[:17]+"\n")
self.printer.justify("R")
self.printer.printChar(priv_key[17:34]+"\n")
self.printer.justify("L")
self.printer.printChar(priv_key[34:]+"\m")
else:
self.printer.println(priv_key)
示例3: justification
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
printer.inverseOn()
printer.println("Inverse ON")
printer.inverseOff()
# Test character double-height on & off
printer.doubleHeightOn()
printer.println("Double Height ON")
printer.doubleHeightOff()
# Test character double-width on & off
printer.doubleWidthOn()
printer.println("Double Width ON")
printer.doubleWidthOff()
# Set justification (right, center, left) -- accepts 'L', 'C', 'R'
printer.justify('R')
printer.println("Right justified")
printer.justify('C')
printer.println("Center justified")
printer.justify('L')
printer.println("Left justified")
# Test more styles
printer.boldOn()
printer.println("Bold text")
printer.boldOff()
printer.underlineOn()
printer.println("Regular underlined text")
printer.underlineOff()
示例4: printImage
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
def printImage(fileToPrint, result, timeNow, location):
def imageProcessing(fileToPrint):
img = Image.open(fileToPrint)
img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)
img = img.filter(ImageFilter.SHARPEN)
img = img.filter(ImageFilter.MedianFilter)
img = img.rotate(180)
return img
def getTimeElapsed(fileToPrint):
text = ''
now = datetime.now()
last = parseTimeStamp(fileToPrint)
timeElapsed = now - last
seconds = int(timeElapsed.seconds)
minutes = int(round(seconds/60))
hours = int(round(seconds/3600))
days = int(timeElapsed.days)
# days and hours
if (days > 0):
if (days == 1):
text += str(days)+'day '
else:
text += str(days)+'days '
if (hours > 0):
if (hours == 1):
text += str(hours)+'hour '
else:
text += str(hours)+'hours '
elif (days == 0):
# hours and minutes
if (hours > 0):
if (hours == 1):
text += str(hours)+'hour '
else:
text += str(hours)+'hours '
minutes = minutes - 60*hours
if (minutes > 0):
if (minutes == 1):
text += str(minutes)+'minute '
else:
text += str(minutes)+'minutes '
else:
# minutes and seconds
if (minutes > 0):
if (minutes == 1):
text += str(minutes)+'minute '
else:
text += str(minutes)+'minutes '
seconds = seconds - minutes*60
if (seconds > 0):
if (seconds == 1):
text += str(seconds)+'second '
else:
text += str(seconds)+'seconds '
# seconds
else:
text += str(seconds)+'seconds '
text += 'ago @'+location
return text
def getTimeNow(timeNow):
text ='Printed at '
timeNow = parseTimeStamp(timeNow)
year = timeNow.year
month = timeNow.month
day = timeNow.day
hour = timeNow.hour
minute = timeNow.minute
text += fmt(year)+'.'+fmt(month)+'.'+fmt(day)+' '
text += fmt(hour)+':'+fmt(minute)
return text
image = imageProcessing(fileToPrint)
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(image, True) # This does the printing
printer.upsideDownOn()
printer.justify('C')
timeElapsed = getTimeElapsed(result)
printer.println(timeElapsed)
timeNow = getTimeNow(timeNow)
printer.println(timeNow)
printer.upsideDownOff()
printer.feed(3)
示例5: print_keypair
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
#.........这里部分代码省略.........
#---begin the private key qr code generation and drawing section---
#we begin the QR code creation process
#feel free to change the error correct level as you see fit
qr = qrcode.QRCode(
version=None,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=10,
border=0,
)
qr.add_data(privkey)
qr.make(fit=True)
privkeyImg = qr.make_image()
#resize the qr code to match our design
privkeyImg = privkeyImg.resize((220,220), Image.NEAREST)
startPos=(110,807)
charDist=15
lineHeight=23
lastCharPos=0
keyLength = len(privkey)
#draw 2 lines of 17 characters each. keyLength always == 34 so keylength/17 == 2
for x in range(0,keyLength/17):
lastCharPos=0
#print a line
for y in range(0, 17):
theChar = privkey[(x*17)+y]
charSize = draw.textsize(theChar, font=font)
#print charSize
if y == 0:
draw.text((startPos[0],startPos[1]+(lineHeight*x)),theChar, font=font, fill=(0,0,0))
lastCharPos = startPos[0]+charSize[0]+(charDist-charSize[0])
else:
draw.text((lastCharPos,startPos[1]+(lineHeight*x)),theChar, font=font, fill=(0,0,0))
lastCharPos = lastCharPos + charSize[0] + (charDist-charSize[0])
#draw the QR code on the final image
finalImg.paste(privkeyImg, (125, 560))
#---end the private key qr code generation and drawing section---
#create the divider
rightMarkText = "Piperwallet.com"
font = ImageFont.truetype("/usr/share/fonts/ttf/swansea.ttf", 20)
rightMarkSize = draw.textsize(rightMarkText, font=font)
rightMarkOrigin = (384-rightMarkSize[0]-10, 10)
dividerLineImg = Image.open("/home/pi/Printer/dividerline.bmp")
#font = ImageFont.truetype("/home/pi/Helvetica.ttf", 20)
draw = ImageDraw.Draw(dividerLineImg)
draw.text(rightMarkOrigin,rightMarkText, font=font, fill=(255,255,255))
#do the actual printing
printer.printImage(finalImg)
printer.printChar(privkey[:17]+"\n")
printer.justify('R')
printer.printChar(privkey[17:34]+"\n")
printer.justify('L')
printer.printChar(privkey[34:]+"\n")
#print the divider line
time.sleep(0.4)
printer.printImage(dividerLineImg)
#print some blank space so we can get a clean tear of the paper
time.sleep(0.4)
printer.feed(1)
time.sleep(0.4)
printer.feed(1)
time.sleep(0.4)
printer.feed(1)
printer.sleep() # Tell printer to sleep
printer.wake() # Call wake() before printing again, even if reset
printer.setDefault() # Restore printer to defaults
示例6: main
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
def main():
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
deg = chr(0xf8) # Degree symbol on thermal printer
events = get_events()
# Print heading
printer.setSize('M')
printer.justify('C')
printer.println( datetime.datetime.today().date().strftime("%A, %B %-d, %Y") )
printer.justify('L')
printer.setSize('S')
# Print schedule
printer.boldOn()
printer.underlineOn()
printer.justify('C')
printer.println("Today's Schedule")
printer.justify('L')
printer.underlineOff()
printer.boldOff()
printer.feed(1)
if not events:
printer.println('No scheduled events today.')
printer.feed(1)
for event in events:
start = dateutil.parser.parse(event['start'].get('dateTime', event['start'].get('date'))).strftime("%-I:%M%p")
end = dateutil.parser.parse(event['end'].get('dateTime', event['end'].get('date'))).strftime("%-I:%M%p")
location = event.get('location', '')
printer.println(event['summary'])
if start == end:
if location:
printer.println(start + ", " + location)
else:
printer.println(start)
else:
if location == "":
printer.println(start + " - " + end)
else:
printer.println(start + " - " + end + ", " + location)
printer.feed(1)
printer.feed(1)
# Print weather
weather = get_weather()
printer.boldOn()
printer.underlineOn()
printer.justify('C')
printer.println("Today's Weather")
printer.justify('L')
printer.underlineOff()
printer.boldOff()
printer.feed(1)
printer.println("Temperature: " + str(weather.temp_now) + ". Feels like " + str(weather.feels_like_now))
printer.feed(1)
printer.println("Today: " + weather.weather_today)
printer.feed(1)
printer.println("Tonight: " + weather.weather_tonight)
printer.feed(1)
downcase_first = lambda s: s[:1].lower() + s[1:] if s else ''
printer.println("Tomorrow: " + weather.weather_tomorrow + " Tomorrow night, " + downcase_first(weather.weather_tomorrow_night))
printer.feed(1)
printer.feed(2)
示例7: bitmaps
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
# On a command line with a filename, solves the given puzzles
# (files should look like the text generated by the generator).
#
# Adapted for Adafruit_Thermal library by Phil Burgess for Adafruit
# Industries. This version uses bitmaps (in the 'gfx' subdirectory)
# to render the puzzle rather than text symbols. See sudoku-txt
# for a different Sudoku example that's all text-based.
from Adafruit_Thermal import *
import SteriLogo as logo
from subprocess import call
import sys, getopt
printer = Adafruit_Thermal("/dev/ttyS1", 19200, timeout=5)
# Test inverse on & off
printer.inverseOn()
printer.inverseOff()
call(["echo"," 1 >> /dev/ttyS1"])
# Test more styles
printer.justify('L')
printer.boldOn()
printer.println(str(sys.argv[1]))
printer.boldOff()
printer.feed(1)
示例8: range
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
# print List Ingles.
result = []
for i in range(0, 9):
printer.println(lista[i][0].encode("ascii", "ignore"))
result.append(lista[i][1].encode("ascii", "ignore"))
worksheet.update_cell(lista[i][4], 3, int(lista[i][2]) + 1)
result.append("\n")
# print List spaon
for i in range(10, 19):
printer.println(lista[i][1].encode("ascii", "ignore"))
result.append(lista[i][0].encode("ascii", "ignore"))
worksheet.update_cell(lista[i][4], 3, int(lista[i][2]) + 1)
printer.justify("L")
# print reslt
printer.println("********************************")
printer.println("")
for i in range(len(result)):
printer.print_(result[i])
printer.print_(" | ")
printer.feed(1)
printer.printImage(Image.open("gfx/goodbye.png"), True)
time.sleep(20)
printer.feed(3)
subprocess.call("sync")
subprocess.call(["shutdown", "-h", "now"])
示例9: print
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
print(url)
width = payload['image']['width']
height = payload['image']['height']
try:
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.5.17 (KHTML, like Gecko) Version/8.0.5 Safari/600.5.17'}
req = urllib2.Request(url, None, headers)
data = urllib2.urlopen(req).read()
img = Image.open(StringIO(data))
img = aspect_fit(img, 384, 384)
img = img.convert('1') # convert to B&W (use 'L' for monochrome)
printer.printImage(img, True)
except Exception, e:
# The image is not valid
print(e)
printer.justify('C')
printer.boldOn()
printer.setSize('S')
printer.println("Greetings from")
printer.setSize('L')
printer.println('@' + str(username))
printer.setSize('S')
caption = payload['caption']
printer.feed(1)
printer.println('"' + caption.encode('cp437', 'ignore') + '"')
printer.feed(1)
printer.setSize('S')
printer.boldOff()
printer.underlineOn()
printer.println('www.technocreatives.com')
示例10: Adafruit_Thermal
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import justify [as 别名]
if __name__ == '__main__':
# new videocapture object
cap = cv2.VideoCapture(0)
# Create a Adafruit_Thermal object that we can use for printing
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
# python-tesseract initialization
api = tesseract.TessBaseAPI()
api.SetOutputName("hacker_u")
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetPageSegMode(tesseract.PSM_AUTO)
printer.boldOn() # Make text bold
printer.setSize('L') # Set type size, accepts 'S', 'M', 'L'
printer.justify('C') # Center the text to leave lots of whitespace
while(True):
''' Prompt the user to enter some text to be recognized by python-tesseract '''
text_to_print = raw_input("Enter text: ")
# Alert user that we are printing
print("Printing...")
''' Print the user's text out '''
printer.println(text_to_print)
time.sleep(1)
print "Tear off the printed text from printer and show it to the webcam!"
print "Press 'q' to snap the picture"