Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 86 additions & 11 deletions g2g_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import os
import string
import subprocess

from Tkinter import *
from os import path, access, R_OK, W_OK
Expand Down Expand Up @@ -47,6 +48,77 @@
def floats(s):
return map(float,string.split(s,','))

def test_forces():

original_stdout = sys.stdout # keep a reference to STDOUT

if Output_name.get():
sys.stdout = open(Output_name.get(), 'w')

if not offset_str.get():
default_offset_str()
if not matrix_str.get():
default_matrix_str()
if not speed_str.get():
default_speed_str()


offset = floats(offset_str.get())
matrix = floats(matrix_str.get())
speed = floats(speed_str.get())

#
# main program
#

import graphtec
import pic
import optimize

# offset = (5, 1)
# matrix = (1, 0, 0, 1)

g = graphtec.graphtec()

g.start()

g.set(offset=offset, matrix=matrix)
g.set(speed=speed)

for i in range(0, 6):
for j in range(0, 5):
g.set(force=1 + j + 5 * i)
tx = 0.5 * j
ty = 0.5 * i
g.closed_path([(tx, ty), (tx + 0.3, ty), (tx + 0.3, ty + 0.3), (tx, ty + 0.3)])

g.end()

if Output_name.get():
sys.stdout = original_stdout # restore STDOUT back to its original value
tkMessageBox.showinfo("G2G_GUI Message", "File '%s' created" % (Output_name.get()))


def show_gerber():

if not os.path.exists(Gerber_name.get()):
get_input_filename()
if not os.path.exists(Gerber_name.get()):
tkMessageBox.showerror("G2G_GUI ERROR", "The path provided for the input Gerber file is invalid.")
return

head, tail = os.path.split(Gerber_name.get())

if not os.path.exists(gerbv_path.get()):
tkMessageBox.showerror("G2G_GUI ERROR", "The path provided for gerbv is invalid.")
return

if not os.path.exists(pstoedit_path.get()):
tkMessageBox.showerror("G2G_GUI ERROR", "The path provided for pstoedit is invalid.")
return

subprocess.Popen([os.path.normpath(gerbv_path.get()), os.path.normpath(Gerber_name.get())])

def main_program():
#
# convert file to pic format
Expand Down Expand Up @@ -76,7 +148,7 @@ def main_program():
if not os.path.exists(pstoedit_path.get()):
tkMessageBox.showerror("G2G_GUI ERROR", "The path provided for pstoedit is invalid.")
return

if os.name=='nt':
os.system("echo \"%s\" --export=pdf --output=%s --border=0 \"%s\" > \"%s\"" % (os.path.normpath(gerbv_path.get()),temp_pdf,os.path.normpath(Gerber_name.get()),temp_bat))
os.system("echo \"%s\" -q -f pic \"%s\" \"%s\" >> \"%s\"" % (os.path.normpath(pstoedit_path.get()),temp_pdf,temp_pic, temp_bat))
Expand All @@ -102,7 +174,7 @@ def main_program():
default_force_str()
if not cut_mode_str.get():
default_cut_mode_str()

offset = floats(offset_str.get())
border = floats(border_str.get())
matrix = floats(matrix_str.get())
Expand Down Expand Up @@ -179,15 +251,15 @@ def Send_to_Cutter():
if not Output_name.get():
return
src=os.path.normpath(Output_name.get())

if not cutter_shared_name_str.get():
tkMessageBox.showerror("G2G_GUI ERROR", "The name of the cutter (as a shared printer) was not provided.")
return

#if not os.path.exists(cutter_shared_name_str.get()):
# tkMessageBox.showerror("G2G_GUI ERROR", "The name of the cutter (as a shared printer) does not exist.")
# return

dst=os.path.normpath(cutter_shared_name_str.get())
if os.name=='nt':
os.system("copy /B \"%s\" \"%s\"" % (src, dst))
Expand Down Expand Up @@ -216,10 +288,10 @@ def get_pstoedit_path():

def default_offset_str():
offset_str.set("4.0,0.5")

def default_border_str():
border_str.set("1,1")

def default_matrix_str():
matrix_str.set("1,0,0,1")

Expand All @@ -228,7 +300,7 @@ def default_speed_str():

def default_force_str():
force_str.set("8,30")

def default_cut_mode_str():
cut_mode_str.set("0")

Expand Down Expand Up @@ -279,10 +351,13 @@ def default_cut_mode_str():
Label(top, text="Cutter Device Name").grid(row=11, column=0, sticky=W)
Entry(top, bd =1, width=60, textvariable=cutter_shared_name_str).grid(row=11, column=1, sticky=E)

Tkinter.Button(top, width=40, text = "Create Graphtec File", command = main_program).grid(row=12, column=1)
Tkinter.Button(top, width=40, text = "Send Graphtec File to Silhouette Cutter", command = Send_to_Cutter).grid(row=13, column=1)
Tkinter.Button(top, width=40, text = "Save Configuration", command = Save_Configuration).grid(row=14, column=1)
Tkinter.Button(top, width=40, text = "Exit", command = Just_Exit).grid(row=15, column=1)
Tkinter.Button(top, width=40, text="Show Gerber in Gerbv", command=show_gerber).grid(row=12, column=1)
Tkinter.Button(top, width=40, text="Create Graphtec File from Input", command=main_program).grid(row=13, column=1)
Tkinter.Button(top, width=40, text="Send Graphtec File to Silhouette Cutter", command=Send_to_Cutter).grid(row=14, column=1)
Tkinter.Button(top, width=40, text="Save Configuration", command=Save_Configuration).grid(row=15, column=1)
Tkinter.Button(top, width=40, text="Exit", command=Just_Exit).grid(row=16, column=1)
Tkinter.Button(top, width=40, text="Create test_forces Graphtec file", command=test_forces).grid(row=17, column=1)


if path.isfile(CONFPATH) and access(CONFPATH, R_OK):
f = open(CONFPATH,'r')
Expand Down