Statistiques
| Révision :

root / prepareQMX / prepareQMX.GUI.py @ 10

Historique | Voir | Annoter | Télécharger (7,32 ko)

1
#!/usr/bin/env python
2

    
3
# GRAPHICAL interface for setup of QMX calculations
4
#
5
# Torsten Kerber, ENS LYON: 2011, 07, 11
6
#
7
# This work is supported by Award No. UK-C0017, made by King Abdullah
8
# University of Science and Technology (KAUST)
9

    
10
#---------------------------------------------------------------------------------------------------
11
from Tkinter import *
12
from copy import deepcopy
13
import StringIO, os
14

    
15
#---------------------------------------------------------------------------------------------------
16
from qmxEMBED import embedDefinitions
17
from qmxJOB import jobDefinitions
18
from qmxSTR import strDefinitions
19
from qmxCALC import calcDefinitions, QmxCalcDefinition
20

    
21
from qmxWRITE import writeData
22

    
23
#---------------------------------------------------------------------------------------------------
24
#---------------------------------------------------------------------------------------------------
25
#---------------------------------------------------------------------------------------------------
26
class MyLabelFrame(LabelFrame):
27
    def __init__(self, mainWnd, master, title, def_list, extras):
28
        LabelFrame.__init__(self, master, text=title)
29
        self.mainWnd = mainWnd
30
        self.definitions=[]
31
        self.title = title
32

    
33
        for definition in def_list:
34
            definition_new = deepcopy(definition)
35
            definition_new.system = title
36
            self.definitions.append(definition_new)
37

    
38
        fields=['import', 'class', 'class.options']
39
        if extras is not None:
40
            for key in extras:
41
                fields.append(key)
42

    
43
        self.entries=[]
44
        for key in fields:
45
            text=StringVar()
46
            text.set('')
47
            self.entries.append((key, text, Entry(self, textvariable=text, width=15)))
48
            
49
    def grid(self, **arguments):
50
        LabelFrame.grid(self, arguments, sticky=(N+W+E))
51
        self.listbox.selection_set(first=0)
52
        self.select(None)
53
        
54
    def doLayout(self):
55
        irow=0
56
        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)
59
            textfield.bind("<KeyRelease>", self.update)
60
            irow+=1
61
        
62
        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)
65
        self.listbox.bind('<ButtonRelease-1>', self.select)
66

    
67
        scrollbar.config(command=self.listbox.yview)
68
        scrollbar.grid(row=0, column=4, rowspan=irow, sticky=NS)
69
       
70
        for item in self.definitions:
71
            self.listbox.insert(END, item.name)
72
        
73
    def select(self, event):
74
        selection=self.listbox.curselection()
75
        if len(selection) == 1:
76
            self.curr_definition=deepcopy(self.definitions[int(selection[0])])
77
            for (key, text, textfield) in self.entries:
78
                text.set(self.curr_definition.getValue(key))
79
        self.mainWnd.preview()
80
    
81
    def getSelection(self):
82
        return self.curr_definition
83
        
84
    def update(self, event):
85
        for (key, text, textfield) in self.entries:
86
            self.curr_definition.keywords[key]=text.get()
87
        self.mainWnd.preview()
88

    
89
#---------------------------------------------------------------------------------------------------
90
class MainWindow(Frame):
91
    frames=[]
92
    text=None
93
    def __init__(self, master):
94
        Frame.__init__(self, master)
95
        
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 ['High-Level', 'Low-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)
134
        
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)
146
        scrollbar.set(0.0, 1.0)
147
        self.text=Text(frame, yscrollcommand=scrollbar.set, width=60, heigh=10, state=DISABLED)
148
        self.text.grid(sticky=(N+W+S+E))
149
        scrollbar.config(command=self.text.yview)
150
        scrollbar.grid(row=0, column=1, sticky=NS)        
151
        frame.grid(row=2, column=1)
152

    
153
        frame = Frame(self)
154

    
155
        image = PhotoImage(file="exit.gif")
156
        buttonExit=Button(frame, image=image, command=self.quit)
157
        buttonExit.image = image
158
        buttonExit.grid(row=1, column = 1, rowspan=2, sticky= W+E+N+S)
159
        
160
        buttonSave=Button(frame, text='save settings', state=DISABLED)
161
        buttonSave.grid(row=1, column = 2, sticky=(EW))
162

    
163
        buttonPrint=Button(frame, text='Write qmx.py input file', command=self.writeButton)
164
        buttonPrint.grid(row=2, column = 2, sticky=EW)
165

    
166
        frame.grid(row=2, column=2, sticky=SE)
167

    
168
        #--- MainWindow ---
169
        self.grid(sticky=(W+N+S+E))
170
        self.preview()
171
        
172
    def quit(self):
173
        quit()
174
    
175
    def writeButton(self):
176
        file = open("qmx.py","w")
177
        definitions=[]
178
        for frame in self.frames:
179
            definition = frame.getSelection()
180
            if definition is not None:
181
                definitions.append(definition)
182

    
183
        writeData(file, definitions)
184
        file.close()
185
        os.system("chmod u+x qmx.py")
186

    
187
    def preview(self):
188
        stream = StringIO.StringIO()
189
        definitions=[]
190
        for frame in self.frames:
191
            definition = frame.getSelection()
192
            if definition is not None:
193
                definitions.append(definition)
194

    
195
        writeData(stream, definitions)
196
        s = stream.getvalue()
197
        
198
        if self.text is not None:
199
            pos, end = self.text.yview()
200
            self.text.config(state=NORMAL)
201
            self.text.delete(1.0, END)
202
            self.text.insert(END, s)
203
            self.text.config(state=DISABLED)
204
            self.text.yview(MOVETO, pos)
205

    
206
#---------------------------------------------------------------------------------------------------
207
mainWnd=MainWindow(Tk())
208
mainWnd.mainloop()