The intent of this python file is to read in a file similar to the one below, modify the lines that have "PL" in the shape field. the issues I am having is the OK box is bleeding into the initial file selection button. Also, the OK button does not show up in the initial checkbox, and will not update the first line with "PL" in it. Once the first checkbox and the file selection box is Xed out, the checkbox seems to work as intended for the second line on. Could someone please help me figure this out? it should bring up the file selection box, select file to open, select file to save as. this box should stay open, and the checkbox should open. once you make your selection, it should open again and again until there are no more lines that have "PL" in them. the new file should have the added data in the correct position.
This is in the read file "1288.kss". Save file as "1288r.kss"
D,88C200a,0,88C200a,88C200a,1,HSS,5x5x.375,A500B,4311.65,,S1E,,,,,,,,,,,,,,,,,,,
W,88C200a,0,COLUMN,07/23/15,SDS7.420,,,,,,,,,,,,,,,,,,,,,,,,,
M,88C200a,1,COLUMN,,,,,,,,,,,,,,,,,,,,,,,,,,,
S,2B,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,
D,88C200a,0,88C200a,bs5_2,1,PL,1-1/4x13,A36,330.2,,,,,,,,,,,,,,,,,,,,,
D,88C200a,0,88C200a,p307,1,PL,3/8x9-5/16,A36,838.2,,,,,,,,,,,,,,,,,,,,,
D,88C200a,0,88C200a,p310,1,PL,3/8x7-1/4,A36,379.41,,,,,,,,,,,,,,,,,,,,,
D,88C200a,0,88C200a,p317,1,PL,3/8x6-5/8,A36,533.4,,,,,,,,,,,,,,,,,,,,,
this is the code:
from Tkinter import *
import Tkinter
import tkFileDialog
def main(root):
fn = tkFileDialog.askopenfilename(master=root,
initialdir=r'C:\kiss\Routing',
filetypes=[("KSS", "*.kss")])
if not fn: return
fnFiltered = tkFileDialog.asksaveasfilename(master=root,
initialdir=r'C:\kiss\Routing',
filetypes=[("KSS", "*.kss")])
if not fnFiltered: return
lines = open(fn).readlines()
index0 = 0
indexPage = 1
index2 = 2
indexDetail = 3
# index 4 is the part number
indexPart = 4
indexQty = 5
indexShape = 6
indexDescr = 7
# index 8 is the grade
indexGrade = 8
# length index, length is in millimeters - convert to inches and 16ths
# with function mm_to_imperial
indexLength = 9
index10 = 10
# index 11 is the remarks column
indexRemark = 11
# 1-1/2 | 1 | 15
'''
revisions:
'''
outputLines = []
for i, line in enumerate(lines):
if "," in line or "*" in line:
lineList = line.strip().split(",")
if lineList[0] == "L":
continue
if lineList[0] == "A":
continue
if lineList[0] == "D":
if "PL" in lineList[indexShape]:
#
pn1 = lineList[indexPart]
#
def results():
top.destroy()
top = Tkinter.Tk()
CheckVar1 = Tkinter.IntVar()
CheckVar2 = Tkinter.IntVar()
CheckVar3 = Tkinter.IntVar()
CheckVar4 = Tkinter.IntVar()
CheckVar1.set(1)
CheckVar2.set(0)
CheckVar3.set(0)
CheckVar4.set(0)
C1 = Tkinter.Checkbutton(top, text = "Route 25 - Plate Table",
variable=CheckVar1, height=1, width=20)
C2 = Tkinter.Checkbutton(top, text = "Route 35 - Forming",
variable=CheckVar2, height=1, width=20)
C3 = Tkinter.Checkbutton(top, text = "Route 175 - T-Load#1",
variable=CheckVar3, height=1, width=20)
C4 = Tkinter.Checkbutton(top, text = "Route 176 - T-Load#2",
variable=CheckVar4, height=1, width=20)
C1.pack()
C2.pack()
C3.pack()
C4.pack()
bt = Button(text='OK', command=lambda: top.destroy())
bt.pack(side='left')
top.mainloop()
cv1 = CheckVar1.get()
cv2 = CheckVar2.get()
cv3 = CheckVar3.get()
cv4 = CheckVar4.get()
#
if cv1 == 0:
rt1 = ""
if cv1 == 1:
rt1 = "25"
if cv2 == 1:
rt1 = rt1+"-35"
if cv3 == 1:
rt1 = rt1+"-175"
if cv4 == 1:
rt1 = rt1+"-176"
lineList[index10] = rt1
outputLines.append(lineList)
try:
f = open(fnFiltered, 'w')
f.write("\n".join([','.join(lineList) for lineList in outputLines]))
f.close()
except Exception, e:
print e
# print "\n".join([','.join(lineList) for lineList in outputLines])
root = Tkinter.Tk()
Tkinter.Button(root, text="Select File To Process", command=lambda: main(root)).pack()
Tkinter.Button(root, text="Exit", command=root.destroy).pack()
root.mainloop()
Aucun commentaire:
Enregistrer un commentaire