#!/usr/bin/python
from Tkinter import *
import math
root = Tk() #makes the window, root is just a convention
root.title("DangerCam") #name for title bar
def gcodeme(): #this function is called below, see "Button"
saved = name.get() #collect the "saved as" name for file
f = file(saved, 'w') #open that file for writing
speed = int(rpm.get()) #collect the other entry box values
firstcut = float(rough.get())
tool = float(cutter.get())
permin = float(feed.get())
cx = float(cenx.get())
cy = float(ceny.get())
secondcut = float(final.get())
depth = float(deep.get())
pathone = (firstcut / 2) - (tool / 2) #followed by a few
pathtwo = ((secondcut - firstcut) / 2) + pathone #calculations
threeoclock = pathone + cx
nineoclock = cx - pathone
twelveoclock = cy + pathtwo
sixoclock = cy - pathtwo
#and then write the gcode to file
f.write("% n")
f.write("S%i M03 n" % (speed))
f.write("G00 X% 8.4f Y% 8.4f n" % (threeoclock, cy))
f.write("Z.1000 n")
f.write("G01 Z% 8.4f F% 8.4f n" % (depth, permin))
f.write("G03 X% 8.4f Y% 8.4f R% 8.4f n" % (nineoclock, cy, pathone))
f.write("X% 8.4f Y% 8.4f R% 8.4f n" % (threeoclock, cy, pathone))
f.write("X% 8.4f Y% 8.4f R% 8.4f n" % (cx, twelveoclock, pathtwo))
f.write("X% 8.4f Y% 8.4f R% 8.4f n" % (cx, sixoclock, pathtwo))
f.write("X% 8.4f Y% 8.4f R% 8.4f n" % (cx, twelveoclock, pathtwo))
f.write("G00 Z2 n")
f.write("M02 n")
f.write("% n")
f.close() #close file
This might not be quite right??
root.destroy() #destroys window, end of function gcodeme
rpmlabel = Label(root, text = "Spindle RPM") #a few labels
roughlabel = Label(root, text = "Rough Diameter")
cutterlabel = Label(root, text = "Cutter Diameter")
feedlabel = Label(root, text = "Feed Rate")
cenxlabel = Label(root, text = "X center")
cenylabel = Label(root, text = "Y center")
finallabel = Label(root, text = "Finish Diameter")
deeplabel = Label(root, text = "Depth")
namelabel = Label(root, text = "Save File as")
rpm = Entry(root, width = 30) #a few entry widgets
rough = Entry(root, width = 30)
cutter = Entry(root, width = 30)
feed = Entry(root, width = 30)
cenx = Entry(root, width = 30)
ceny = Entry(root, width = 30)
final = Entry(root, width = 30)
deep = Entry(root, width = 30)
name = Entry(root, width =30)
Label(root, text = "DANGER!", fg = '#006699', font = ('Papyrus', 20)).grid()
# some descriptive text, you've been warned !
rpmlabel.grid() #add stuff to the window
rpm.grid()
roughlabel.grid()
rough.grid()
cutterlabel.grid()
cutter.grid()
feedlabel.grid()
feed.grid()
cenxlabel.grid()
cenx.grid()
cenylabel.grid()
ceny.grid()
finallabel.grid()
final.grid()
deeplabel.grid()
deep.grid()
namelabel.grid()
name.grid()
Button(root, text = "Make it so", command = gcodeme).grid()
# command calls function gcodeme()
root.mainloop() #keeps window open until killed in gcodeme function
################################################## #########################
# the gcode program the python program is based on
################################################## #########################
# %
# #100= 1000 (RPM)
# #101= 2 (rough diam)
# #102 = .5 (cutter diam)
# #103= 60 (feed)
# #104= 0 (x center)
# #105= 0 (y center)
# #106= -.25 (depth)
#
# #107= [[#101/2]-[#102/2]]
# (circle r - cutter r)
#
# #108= 2.02 (finish diam)
# #109= [[[#108-#101]/2]+#107]
#
# S#100 m03
# g00 x[#107+#104] y#105
# z.1
# g01 z#106 f#103
# g03 x[[-1*#107]+#104] y#105 r#107
# x[#107+#104] y#105 R#107
# x#104 y[#105+#109] r#109
# x#104 y[#105-#109] r#109
# x#104 y[#105+#109] r#109
# g00 z2
# m02
# %
################################################## #########################