-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.py
134 lines (108 loc) · 4.55 KB
/
builder.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/python
import subprocess
import sys
import time
if sys.platform == 'darwin':
sys.path.append('/usr/local/lib/python2.7/site-packages')
import pygtk
pygtk.require('2.0')
import gtk
lp_file = "/usr/local/share/generic.lp"
fitter_script = "/usr/local/bin/fitter-script"
class RTIFitterGUI:
# directory chooser code from John's code
def folderchoose_cb(self, widget, data = None):
chooser = gtk.FileChooserDialog('Select folder to be processed', self.window,
gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, 'Select', 99))
chooser.set_default_response(99)
chooser.set_current_folder("~")
response = chooser.run()
filename = chooser.get_filename()
chooser.hide()
print filename
if filename is None:
print "No folder selected doing nothing"
else:
self.button1.hide
fitps = subprocess.Popen(args ="%s \"%s\" \"%s\""% (fitter_script, lp_file, filename),
shell = True,
stdout = sys.stdout,
stderr = sys.stderr)
retVal = fitps.wait()
if(retVal == 0):
md = gtk.MessageDialog(self.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO,
gtk.BUTTONS_CLOSE, "Fitting completed")
md.run()
md.destroy()
elif (retVal == 1):
md = gtk.MessageDialog(self.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
gtk.BUTTONS_CLOSE, "Error: Wrong parameters sent")
md.run()
md.destroy()
elif(retVal == 2):
md = gtk.MessageDialog(self.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
gtk.BUTTONS_CLOSE, "Error: Not a valid PTM hierachy")
md.run()
md.destroy()
elif (retVal == 3):
md = gtk.MessageDialog(self.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
gtk.BUTTONS_CLOSE, "Error: LP file not found")
md.run()
md.destroy()
elif(retVal == 4):
md = gtk.MessageDialog(self.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
gtk.BUTTONS_CLOSE, "Error: No Valid NEF/JPEG files found")
md.run()
md.destroy()
else:
md = gtk.MessageDialog(self.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
gtk.BUTTONS_CLOSE, "Error: Something really unexpected went wrong")
md.run()
md.destroy()
self.button1.show
# another callback
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("PTM fitter helper")
# Here we just set a handler for delete_event that immediately
# exits GTK.
self.window.connect("delete_event", self.delete_event)
# Sets the border width of the window.
self.window.set_border_width(10)
# We create a box to pack widgets into.
self.box1 = gtk.HBox(False, 0)
# Put the box into the main window.
self.window.add(self.box1)
# Creates a new button with the label
self.button1 = gtk.Button("Build")
# Now when the button is clicked, we call the "callback" method
# with a pointer to "button 1" as its argument
self.button1.connect("clicked", self.folderchoose_cb, "Choose Folder")
# Instead of add(), we pack this button into the invisible
# box, which has been packed into the window.
self.box1.pack_start(self.button1, True, True, 0)
# this button is complete, and it can now be displayed.
self.button1.show()
# Do these same steps again to create a second button
self.button2 = gtk.Button("Quit")
self.button2.connect("clicked", self.delete_event, "Quit")
self.box1.pack_start(self.button2, True, True, 0)
self.button2.show()
self.box1.show()
self.window.show()
def main():
gtk.main()
if __name__ == "__main__":
fitter = RTIFitterGUI()
main()