-
Notifications
You must be signed in to change notification settings - Fork 0
/
pp-idf-tk.py
78 lines (68 loc) · 2.13 KB
/
pp-idf-tk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from Tkinter import *
from tkFileDialog import askopenfilename
from tkFileDialog import askdirectory
from tkSimpleDialog import askstring
import tkMessageBox
# What do we want to replace it with?
angles = (0, 90, 180, 270)
# Provide user with dialog box to select the IDF file to process
def userDialog():
global getfile
filename = askopenfilename(
filetypes=[("All Files","*"),("IDF Files","*.idf")],
initialdir=["C:\\"],
title="Select IDF File to Process..")
if filename == "":
tkMessageBox.showinfo("Info", "User Cancelled")
else:
getfile = filename
userEntry()
# Have user select the search string to be replaced
def userEntry():
global searchstring
searchstring = askstring(
title="Search String",
prompt="Enter Search String to be Replaced",
initialvalue="$$ReplaceThis$$")
if searchstring == None:
tkMessageBox.showinfo("Info", "User Cancelled")
quit()
elif searchstring == "":
tkMessageBox.showinfo("Info", "Invalid String")
quit()
else:
userSave()
# Provide user with dialog box to select folder where processed
# files should be placed
def userSave():
global getsave
foldername = askdirectory(
initialdir=["C:\\"],
title="Select Output Directory...")
if foldername == "":
tkMessageBox.showinfo("Info", "User Cancelled")
quit()
else:
getsave = foldername + "/"
idfReplace(getfile)
def idfReplace(infile):
# For every replacement value in list of values:
for thisAngle in angles:
# Open the input file
idfFile = open(infile)
# Open the output file
outFileName = str(getsave) + "output-" + str(thisAngle) + "-degree-rotation.idf";
outFile = open(outFileName,'w')
print "Now writing file:", outFileName
# For every line in the input file:
for line in idfFile:
# If searchstring is found, replace it with thisAngle
newLine = line.replace(searchstring, str(thisAngle))
# Write the line to the output file
outFile.write(newLine)
outFile.close()
print "Finished writing!"
idfFile.close()
tkMessageBox.showinfo("Info", "Finished the whole script!\n\nWrote files to " + getsave)
if __name__ == "__main__":
userDialog()