import subprocess
import os
def main():
quickfile = file_existance()
quickdraw = subprocess.Popen(['java', '-jar', quickfile],\
stdin = subprocess.PIPE, \
stdout = subprocess.PIPE)
event = WindowEvents(quickdraw)
def file_existance():
filename = raw_input("Please enter the location of quickdraw: ")
while (not os.path.isfile(filename)):
print "That file does not exist, try again"
filename = raw_input("Please enter the name of the file: ")
print os.path.abspath(filename)
return filename
def mouseclick(event):
quickdraw.stdin.write("mouseclick true")
quickdraw.stdin.write("\n")
while(isQuickdrawClosed(event) == False):
click = quickdraw.stdout.readline()
print click
def isQuickdrawClosed(event) :
if (not("Window" or "Mouse" in event)):
raise ValueError, "this is not a legitimate event"
else:
if (len(event) > 0):
x , y = event.split(":")
y = y.strip()
if (y == "Closed"):
return True
else:
return False
def WindowEvents(quickdraw):
shape = raw_input("What shape would you like to draw, choices are: square, circle or triangle ")
quickdraw.stdin.write("windowevents true\n")
quickdraw.stdin.write("mouseclick true\n")
event = quickdraw.stdout.readline()
if ("Window" in event):
while (not isQuickdrawClosed(event)) :
print event
event = quickdraw.stdout.readline()
if ("Mouse" in event):
while(isQuickdrawClosed(event) == False):
event = quickdraw.stdout.readline()
coordinates(quickdraw, event)
if shape == "square":
square(quickdraw, x, y)
if shape == "circle":
circle(quickdraw, x, y)
print event
def coordinates(quickdraw, event):
if ((len(event) > 0) and ("MousePressed" in event)):
first = event.split(":")[0]
xcoord = event.split(":")[1]
x = xcoord[0:4]
x = x.strip()
y = xcoord[5:8]
y = y.strip()
print x
print y
return x
return y
def circle(quickdraw, x, y):
radius = 10
while(radius < 400):
circle = "circle" + ' ' + str(x) + ' ' + str(y) + ' ' + str(radius)
quickdraw.stdin.write(circle)
quickdraw.stdin.write("\n")
radius= radius +10
def square(quickdraw, x, y):
width = 10
height = 10
while (height and width < 800):
square = "rect" + ' ' + str(x) + ' ' + str(y) + ' ' + str(width) + ' ' + str(height)
quickdraw.stdin.write(square)
quickdraw.stdin.write("\n")
height = height + 10
width = width + 10
main()
Traceback (most recent call last):
File "C:\Users\Gradey\Documents\PYTHON\test4.py", line 91, in <module>
main()
File "C:\Users\Gradey\Documents\PYTHON\test4.py", line 11, in main
event = WindowEvents(quickdraw)
File "C:\Users\Gradey\Documents\PYTHON\test4.py", line 52, in WindowEvents
coordinates(quickdraw, event)
File "C:\Users\Gradey\Documents\PYTHON\test4.py", line 69, in coordinates
return x
UnboundLocalError: local variable 'x' referenced before assignment
This is the error im getting. I want to run the x and y coordinates through to circle and square then run them into windowevents through the if statement but doesnt seem to work. I'm not sure whats wrong...Please help me.
Ps: x and y are both numbers just fyi.