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.

88 lines
2.4 KiB
Python

# This is a program that takes keyboard input and prints it out ont a card shaped piece of paper using a pen plotter
# Global stuff
import os
import csv
import getch
import random
currentCard = 0
cardHeight = 140
cardWidth = 40
pageHeight = 249
pageWidth = 378
cardX = 0
cardY = pageHeight
lineHeight = 10
locX = 0
locY = 0
newTitle = ""
newLines = [" "]
babelpos = 0
with open('babel.txt', 'r') as fb:
babel = fb.read()
fb.close()
#--------------------------------------------------------
# Sneakily saving it maybe to a txt file for alternative documentation
def fileWrite(char):
with open('the-record.txt', 'a') as file:
file.write(char)
file.close()
#--------------------------------------------------------
# Getting the input from the keyboard one character at a time
def getInput():
incard = 1
while incard:
char = getch.getch()
if char == KEY_STAB:
incard = 0
currentCard+=1
break
elif char == 13:
os.system('echo "LB' + chr(3) + ';" > /dev/ttyUSB0')
fileWrite(char)
else:
os.system('echo "LB' + char + chr(3) + ';" > /dev/ttyUSB0')
fileWrite(char)
#--------------------------------------------------------
# Getting the input from the keyboard one character at a time
def getInputBabel():
incard = 1
while incard:
char = getch.getch()
if char == KEY_STAB:
incard = 0
currentCard+=1
break
else:
os.system('echo "LB' + babel[babelpos] + chr(3) + ';" > /dev/ttyUSB0')
fileWrite(char)
babelpos += 1
#--------------------------------------------------------
# Positioning it on the page at the next card location
# get basic position for the card
def positionCard():
global cardX
global cardY
cardX = 0+currentCard//3*cardWidth
cardY = 59+currentCard%3*cardHeight
os.system('echo "PA' + str(cardX) + ',' + str(cardY) + ';" > /dev/ttyUSB0')
while currentCard < 18:
print("Enter the body line by line. Press ^C to cancel")
os.system('echo "IN;" > /dev/ttyUSB0')
os.system('echo "SC0,379,0,250,2;" > /dev/ttyUSB0')
os.system('echo "DR0,1;" > /dev/ttyUSB0')
# os.system('echo "DT#,1;" > /dev/ttyUSB0')
positionCard()
if(random.random()>0.9):
# getInput()
getInputBabel()
else:
getInput()