Révision 16 prepareQMX/prepareQMX.GUI.py
prepareQMX.GUI.py (revision 16) | ||
---|---|---|
10 | 10 |
#--------------------------------------------------------------------------------------------------- |
11 | 11 |
from Tkinter import * |
12 | 12 |
from copy import deepcopy |
13 |
import tkFileDialog |
|
13 | 14 |
import StringIO, os |
14 | 15 |
|
15 | 16 |
#--------------------------------------------------------------------------------------------------- |
16 | 17 |
from qmxEMBED import embedDefinitions |
17 | 18 |
from qmxJOB import jobDefinitions |
18 |
from qmxSTR import strDefinitions |
|
19 |
from qmxSTR import strClusterDefinitions, strSystemDefinitions
|
|
19 | 20 |
from qmxCALC import calcDefinitions, QmxCalcDefinition |
20 | 21 |
|
21 | 22 |
from qmxWRITE import writeData |
... | ... | |
24 | 25 |
#--------------------------------------------------------------------------------------------------- |
25 | 26 |
#--------------------------------------------------------------------------------------------------- |
26 | 27 |
class MyLabelFrame(LabelFrame): |
27 |
def __init__(self, mainWnd, master, title, def_list, extras):
|
|
28 |
def __init__(self, mainWnd, master, title, name, def_list, fields):
|
|
28 | 29 |
LabelFrame.__init__(self, master, text=title) |
29 | 30 |
self.mainWnd = mainWnd |
30 | 31 |
self.definitions=[] |
31 |
self.title = title |
|
32 | 32 |
|
33 | 33 |
for definition in def_list: |
34 | 34 |
definition_new = deepcopy(definition) |
35 |
definition_new.system = title
|
|
35 |
definition_new.system = name
|
|
36 | 36 |
self.definitions.append(definition_new) |
37 | 37 |
|
38 |
fields=['import', 'class', 'class.options'] |
|
39 |
if extras is not None: |
|
40 |
for key in extras: |
|
41 |
fields.append(key) |
|
38 |
if fields is None: |
|
39 |
fields = [''] |
|
42 | 40 |
|
43 | 41 |
self.entries=[] |
44 | 42 |
for key in fields: |
45 | 43 |
text=StringVar() |
46 | 44 |
text.set('') |
47 |
self.entries.append((key, text, Entry(self, textvariable=text, width=15)))
|
|
45 |
self.entries.append((key, text, Entry(self, textvariable=text, width=25)))
|
|
48 | 46 |
|
49 | 47 |
def grid(self, **arguments): |
50 | 48 |
LabelFrame.grid(self, arguments, sticky=(N+W+E)) |
... | ... | |
54 | 52 |
def doLayout(self): |
55 | 53 |
irow=0 |
56 | 54 |
for (key, text, textfield) in self.entries: |
57 |
Label(self, text=key, width=15, anchor=W).grid(row=irow) |
|
58 |
textfield.grid(row=irow, column=1)
|
|
55 |
Label(self, text=key, width=15, anchor=W).grid(row=irow, column=2)
|
|
56 |
textfield.grid(row=irow, column=3)
|
|
59 | 57 |
textfield.bind("<KeyRelease>", self.update) |
60 | 58 |
irow+=1 |
61 | 59 |
|
62 | 60 |
scrollbar=Scrollbar(self, orient=VERTICAL) |
63 |
self.listbox=Listbox(self, yscrollcommand=scrollbar.set, height=0, width=15, selectmode=SINGLE)
|
|
64 |
self.listbox.grid(row=0, column=2, rowspan=irow, columnspan=2, sticky=NS)
|
|
61 |
self.listbox=Listbox(self, yscrollcommand=scrollbar.set, height=5, width=15, selectmode=SINGLE, exportselection=0)
|
|
62 |
self.listbox.grid(row=0, column=0, rowspan=irow, sticky=NS)
|
|
65 | 63 |
self.listbox.bind('<ButtonRelease-1>', self.select) |
66 | 64 |
|
67 | 65 |
scrollbar.config(command=self.listbox.yview) |
68 |
scrollbar.grid(row=0, column=4, rowspan=irow, sticky=NS)
|
|
66 |
scrollbar.grid(row=0, column=1, rowspan=irow, sticky=NS)
|
|
69 | 67 |
|
70 | 68 |
for item in self.definitions: |
71 | 69 |
self.listbox.insert(END, item.name) |
... | ... | |
93 | 91 |
def __init__(self, master): |
94 | 92 |
Frame.__init__(self, master) |
95 | 93 |
|
96 |
#--- Structures --- |
|
97 |
bigFrame = LabelFrame(self, text='Structures') |
|
98 |
irow=0; icol=0 |
|
99 |
def_list=embedDefinitions |
|
100 |
extras=['method', 'method.options', 'calculator'] |
|
101 |
frame=MyLabelFrame(self, bigFrame, 'Embed', def_list, extras) |
|
102 |
frame.doLayout() |
|
103 |
frame.grid(row=irow, column=icol) |
|
104 |
self.frames.append(frame) |
|
105 |
|
|
106 |
icol+=1; |
|
107 |
for label in ['System', 'Cluster']: |
|
108 |
def_list=strDefinitions |
|
109 |
frame=MyLabelFrame(self, bigFrame, label, def_list, None) |
|
110 |
frame.doLayout() |
|
111 |
frame.grid(row=irow, column=icol) |
|
112 |
self.frames.append(frame) |
|
113 |
icol+=1 |
|
114 |
bigFrame.grid(row=0, columnspan=3) |
|
115 |
|
|
116 |
#--- Methods --- |
|
117 |
bigFrame = LabelFrame(self, text='Methods') |
|
118 |
irow=0; icol=0 |
|
119 |
def_list=[QmxCalcDefinition()] |
|
120 |
frame=MyLabelFrame(self, bigFrame, 'Qmx', def_list, None) |
|
121 |
frame.doLayout() |
|
122 |
frame.grid(row=irow, column=icol) |
|
123 |
self.frames.append(frame) |
|
124 |
|
|
125 |
icol+=1 |
|
126 |
for label in ['Low-Level', 'High-Level']: |
|
127 |
def_list=calcDefinitions |
|
128 |
frame=MyLabelFrame(self, bigFrame, label, def_list, None) |
|
129 |
frame.doLayout() |
|
130 |
frame.grid(row=irow, column=icol) |
|
131 |
self.frames.append(frame) |
|
132 |
icol+=1 |
|
133 |
bigFrame.grid(row=1, columnspan=3) |
|
94 |
fields=['import', 'class', 'class.options'] |
|
134 | 95 |
|
135 |
#--- General --- |
|
136 |
bigFrame = LabelFrame(self, text='General') |
|
137 |
extras=['method', 'method.options'] |
|
138 |
frame=MyLabelFrame(self, bigFrame, 'Job', jobDefinitions, extras) |
|
139 |
frame.doLayout() |
|
140 |
frame.grid() |
|
141 |
self.frames.append(frame) |
|
142 |
bigFrame.grid(row=2, sticky=NW) |
|
143 |
|
|
144 |
frame=LabelFrame(self, text="PREVIEW") |
|
145 |
scrollbar=Scrollbar(frame, orient=VERTICAL) |
|
96 |
irow=0 |
|
97 |
for calcLabel, strLabel, strDefinitions in ( |
|
98 |
("high-level", "cluster", strClusterDefinitions), |
|
99 |
("low-level", "system", strSystemDefinitions)): |
|
100 |
#column |
|
101 |
icolLocal=0; |
|
102 |
#build outFrame |
|
103 |
outFrame = LabelFrame(self, text=calcLabel+" method - "+strLabel) |
|
104 |
outFrame.grid(row=irow, columnspan=3, sticky=W, pady=5) |
|
105 |
irow+=1 |
|
106 |
|
|
107 |
for title, def_list in ((calcLabel, calcDefinitions), (strLabel, strDefinitions)): |
|
108 |
# build frame |
|
109 |
myFrame=MyLabelFrame(self, outFrame, title, title, def_list, fields) |
|
110 |
myFrame.doLayout() |
|
111 |
myFrame.grid(row=0, column=icolLocal, padx=5, pady=5) |
|
112 |
# add frame for analyssis |
|
113 |
self.frames.append(myFrame) |
|
114 |
# move column |
|
115 |
icolLocal += 1 |
|
116 |
|
|
117 |
outFrame = LabelFrame(self, text="General") |
|
118 |
outFrame.grid(row=irow, columnspan=3, pady=5); irow+=1 |
|
119 |
for title, name, def_list, extra_list, irowLocal, icolLocal, irspan in ( |
|
120 |
("Optimization Method", "job", jobDefinitions, fields + ['method', 'method.options'], 0, 0, 2), |
|
121 |
("Embedding Method", "embed", embedDefinitions, fields + ['set_calculator'], 0, 1, 1), |
|
122 |
("Hybrid Method", "hybrid", [QmxCalcDefinition()], fields, 1, 1, 1)): |
|
123 |
# build frame |
|
124 |
myFrame=MyLabelFrame(self, outFrame, title, name, def_list, extra_list) |
|
125 |
myFrame.doLayout() |
|
126 |
myFrame.grid(row=irowLocal, column=icolLocal, rowspan=irspan, padx=5, pady=5) |
|
127 |
# add frame for analyssis |
|
128 |
self.frames.append(myFrame) |
|
129 |
|
|
130 |
outFrame=LabelFrame(self, text="PREVIEW") |
|
131 |
scrollbar=Scrollbar(outFrame, orient=VERTICAL) |
|
146 | 132 |
scrollbar.set(0.0, 1.0) |
147 |
self.text=Text(frame, yscrollcommand=scrollbar.set, width=60, heigh=10, state=DISABLED)
|
|
133 |
self.text=Text(outFrame, yscrollcommand=scrollbar.set, width=80, heigh=10, state=DISABLED)
|
|
148 | 134 |
self.text.grid(sticky=(N+W+S+E)) |
149 | 135 |
scrollbar.config(command=self.text.yview) |
150 | 136 |
scrollbar.grid(row=0, column=1, sticky=NS) |
151 |
frame.grid(row=2, column=1)
|
|
137 |
outFrame.grid(row=irow, column=0, sticky=W, pady=5);
|
|
152 | 138 |
|
153 |
frame = Frame(self) |
|
154 |
|
|
155 |
#image = PhotoImage(file="exit.gif") |
|
156 |
buttonExit=Button(frame, text="Quit!", command=self.quit) |
|
157 |
#buttonExit.image = image |
|
139 |
myFrame = Frame(self) |
|
140 |
buttonExit=Button(myFrame, text="Quit!", command=self.quit) |
|
158 | 141 |
buttonExit.grid(row=1, column = 1, rowspan=3, sticky= W+E+N+S) |
159 | 142 |
|
160 |
buttonSave=Button(frame, text='save settings', state=DISABLED)
|
|
143 |
buttonSave=Button(myFrame, text='save settings', state=DISABLED)
|
|
161 | 144 |
buttonSave.grid(row=1, column = 2, sticky=(EW)) |
162 | 145 |
|
163 |
buttonScript=Button(frame, text='Write qmx.in input file', command=self.writeScript)
|
|
146 |
buttonScript=Button(myFrame, text='Write SCRIPT file', command=self.writeScript)
|
|
164 | 147 |
buttonScript.grid(row=2, column = 2, sticky=EW) |
165 | 148 |
|
166 |
buttonPython=Button(frame, text='Write qmx.py script file', command=self.writePython)
|
|
149 |
buttonPython=Button(myFrame, text='Write PYTHON file', command=self.writePython)
|
|
167 | 150 |
buttonPython.grid(row=3, column = 2, sticky=EW) |
168 | 151 |
|
169 |
frame.grid(row=2, column=2, sticky=SE)
|
|
152 |
myFrame.grid(row=irow, column=2, sticky=SE)
|
|
170 | 153 |
|
171 | 154 |
#--- MainWindow --- |
172 | 155 |
self.grid(sticky=(W+N+S+E)) |
... | ... | |
176 | 159 |
quit() |
177 | 160 |
|
178 | 161 |
def writePython(self): |
179 |
file = open("qmx.py","w") |
|
162 |
fileName = tkFileDialog.asksaveasfile(mode='w') |
|
163 |
if fileName is None: |
|
164 |
return |
|
165 |
file = open(fileName,"w") |
|
180 | 166 |
definitions=[] |
181 | 167 |
for frame in self.frames: |
182 | 168 |
definition = frame.getSelection() |
... | ... | |
189 | 175 |
|
190 | 176 |
|
191 | 177 |
def writeScript(self): |
192 |
file = open("qmx.in","w") |
|
178 |
fileName = tkFileDialog.asksaveasfile(mode='w') |
|
179 |
if fileName is None: |
|
180 |
return |
|
181 |
file = open(fileName,"w") |
|
193 | 182 |
for frame in self.frames: |
194 | 183 |
definition = frame.getSelection() |
195 | 184 |
if definition is None: |
Formats disponibles : Unified diff