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.

116 lines
3.1 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
userText = ["growing","write seven","words onto","a card"]
currentCard = 0
cardHeight = 95
cardWidth = 70
pageHeight = 249
pageWidth = 378
cardX = 0
cardY = pageHeight
lineHeight = 10
locX = 0
locY = 0
newTitle = ""
newLines = [" "]
#--------------------------------------------------------
# Getting the input from the keyboard one character at a time
def getInput():
global newLines
global newTitle
newLines = [" "]
newTitle = input("Enter a title: ")
print("Enter the body line by line. Press x then enter to cancel")
while newLines[-1] != "x":
newLines.append(input("Type: "))
newLines = newLines[:-1]
#--------------------------------------------------------
# Sneakily saving it maybe to a txt file for alternative documentation
def saveInput():
global newTitle
global newLines
with open('definitions.csv', 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([newTitle, newLines])
file.close()
#--------------------------------------------------------
# Converting it to HPGL with some nice formatting
#--------------------------------------------------------
# Positioning it on the page and sending it to the printer
## A very rough way to do this would be to wrap each hpgl command in bash. Chiplotle is probably better?
# First some hpgl setup. This needs to know which cards have been used in future, and position the pen based on what card were on in a matrix.
print(f"""IN
SP1
SC0,{pageWidth+1},0,{pageHeight+1},2
DT.,1;
""")
# get basic position for the card
def positionCard():
global cardX
global cardY
cardX = 0+currentCard//3*cardWidth
cardY = 59+currentCard%3*cardHeight
# write da writing
def printCard():
print("---------start of card--------")
global currentCard
global cardHeight
global cardWidth
global cardX
global cardY
global locX
global locY
global lineHeight
global newTitle
global newLines
locX = cardX
locY = cardY
print("card " + str(currentCard))
for line in newLines:
# first line is the title
if newLines.index(line) == 0:
# print("PA" + str(locX) + "," + str(locY))
# print("LB"+newTitle+".")
# print(" ")
os.system('echo "PA' + str(locX) + ',' + str(locY) + '" > /dev/ttyUSB0')
os.system('echo "LB' + newTitle + '." > /dev/ttyUSB0')
locY -= 2*lineHeight
# all the other lines
else:
# print("PA" + str(locX) + "," + str(locY))
# print("LB"+line+".")
os.system('echo "PA' + str(locX) + ',' + str(locY) + '" > /dev/ttyUSB0')
os.system('echo "LB' + line + '." > /dev/ttyUSB0')
locY -= lineHeight
print("----------end of card---------")
currentCard+=1
while currentCard < 18:
getInput()
saveInput()
positionCard()
print("cardXY: " +str(cardX) + "," + str(cardY))
printCard()
positionCard()