-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWfViewer.py
244 lines (205 loc) · 8.66 KB
/
WfViewer.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/python27 -u
import sys
import tkFileDialog
import tkMessageBox
from Tkinter import *
sys.path.append("./wfwidget")
sys.path.append("./wfm")
sys.path.append("./algor")
from WfCanvas import *
from WfActivity import *
from WfLayoutManager import *
from WfMultiListbox import *
from WfElasticLayout import *
from WfmFromFile import *
from WfmFromXML import *
from WfmFromProj import *
from SaveWfmToFile import *
from Soundness import *
from LocalOptCorrect import *
from ExtAndComb import *
class WfViewer(Frame):
def __init__(self, master=None, width=1100, height=600):
Frame.__init__(self, master, width=1100, height=600)
self.grid(sticky=N+E+S+W)
self.wfm = None
self.view = None
top = self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.menu_bar = Menu(top, tearoff=0)
top["menu"] = self.menu_bar
self.__initFileMenu()
self.__initViewMenu()
self.__initAlgorithmsMenu()
self.file_menu.add_command(label="Exit", command=top.quit)
# Layout
self.rowconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.columnconfigure(0, weight=1, minsize=30)
self.columnconfigure(1, weight=4, minsize=500)
self.columnconfigure(2, weight=4)
# Create main widgets
self.info_panel = WfMultiListbox(self, (('Attribute', 12), ('Value', 20)))
self.info_panel.grid(row=0, column=0, rowspan=2, sticky=N+S+E+W)
self.model_canvas = WfCanvas(self)
self.model_canvas.grid(row=0, column=1, sticky=N+S+E+W)
layoutMan = WfElasticLayout(maxx=1280, maxy=768,
actwidth=20, actheight=20)
self.model_canvas.setLayout(layoutMan)
self.view_canvas = WfCanvas(self, ctype="VIEW")
layoutView = WfElasticLayout(maxx=1280, maxy=768,
actwidth=20, actheight=20)
self.view_canvas.setLayout(layoutView)
self.view_canvas.grid_remove()
def displayInfo(self, act_id):
self.info_panel.delete(0, END)
self.info_panel.insert(END, ("*ID", "%d" %act_id))
d=dict()
for key, val in self.wfm[1].items():
if key[0]==act_id:
d[key[1]]=val
for keyval in d.items():
self.info_panel.insert(END, keyval)
def displayViewActInfo(self, act_id, act_list):
self.info_panel.delete(0, END)
self.info_panel.insert(END, ("*VID", "%d" %act_id))
if act_list != None:
for i in act_list:
self.info_panel.insert(END, ("*id:%d" %i, ""))
d = dict()
for key, val in self.wfm[1].items():
if key[0] == i:
d[key[1]]=val
for keyval in d.items():
self.info_panel.insert(END, keyval)
self.model_canvas.highlightoff()
self.model_canvas.highlight(act_list)
def refreshWfm(self, wfm = None):
if wfm == None:
wfm = self.wfm
self.wfm = None
self.wfm_canvas.clear()
self.wfm = wfm
self.wfm_canvas.drawWf(self.wfm)
def refreshView(self, view = None):
if view == None:
view = self.view
self.view = None
self.view_canvas.clear()
self.view = view
self.wfm = (self.wfm[0], self.wfm[1], self.wfm[2], self.view[3])
self.view_canvas.drawWf(self.view)
def removeInfo(self):
self.info_panel.delete(0, END)
def highlightoff(self):
self.model_canvas.highlightoff()
self.view_canvas.highlightoff()
def __initFileMenu(self):
# add FILE menu items
self.file_menu = Menu(self.menu_bar, tearoff=0)
self.menu_bar.add_cascade(label="File", menu=self.file_menu)
self.file_menu.add_command(label="Open", command=self.__openHandler)
self.file_menu.add_command(label="Save as", command=self.__saveHandler)
self.file_menu.add_command(label="Save view", command=self.__saveViewHandler)
self.file_menu.add_separator()
def __initViewMenu(self):
# add VIEW menu items
self.__view_cb = IntVar()
self.__split_cb = StringVar(value="VER")
self.view_menu = Menu(self.menu_bar, tearoff=0)
self.menu_bar.add_cascade(label="View", menu=self.view_menu)
self.view_menu.add_checkbutton(label="Show workflow view",
variable=self.__view_cb, onvalue=1, offvalue=0, command=self.__viewOnHandler)
self.view_menu.add_radiobutton(label="Split vertically",
variable=self.__split_cb, value="VER", command=self.__splitHandler)
self.view_menu.add_radiobutton(label="Split horizontally",
variable=self.__split_cb, value="HOR", command=self.__splitHandler)
def __initAlgorithmsMenu(self):
# add ALGOR menu items
self.algorithms_menu = Menu(self.menu_bar, tearoff=0)
self.menu_bar.add_cascade(label="Algorithms", menu=self.algorithms_menu)
self.algorithms_menu.add_command(label="Check soundness", command=self.__checkSoundness)
self.algorithms_menu.add_command(label="Weakly local-opt correct", command=self.__weakCorrect)
self.algorithms_menu.add_command(label="Strong local-opt correct", command=self.__strongCorrect)
self.algorithms_menu.add_command(label="Extend and combine", command=self.__extendAndComb)
def __checkSoundness(self):
if self.wfm == None:
tkMessageBox.showerror('ERROR', 'No view is loaded')
return
if self.wfm[3] == None:
tkMessageBox.showerror('ERROR', 'No view is loaded')
return
isSound, unsoundNodes = isViewSound(*(self.wfm))
if isSound:
prompt = "The view is SOUND"
tkMessageBox.showinfo('Check view soundness', prompt)
else:
prompt = "The view is NOT SOUND"
tkMessageBox.showinfo('Check view soundness', \
"%s.\nUnsound view nodes are: %s" %(prompt,str(unsoundNodes)))
def __weakCorrect(self):
print "### weak correct"
new_view = weakOptimalCorrect(self.wfm)
self.refreshView(new_view)
def __strongCorrect(self):
pass #TODO
def __extendAndComb(self):
print "### extend and combine"
new_view = extAndComb(self.wfm)
self.refreshView(new_view)
def __openHandler(self):
filename = tkFileDialog.askopenfilename(defaultextension=".wfm",
filetypes=[("workflow model file", "*.wfm | *.xml"), ("other", "*.*")])
if filename == None or filename.strip() == "":
return
# clean up
self.wfm = None
self.view = None
self.model_canvas.clear()
self.view_canvas.clear()
# add new
if filename[-4:].lower() == '.wfm':
self.wfm = wfmObjectFromFile(filename)
else:
self.wfm = wfmObjectFromXML(filename)
self.view = wfmObjectFromProj(self.wfm)
self.model_canvas.drawWf(self.wfm)
self.view_canvas.drawWf(self.view)
def __saveHandler(self):
if self.wfm == None:
return
filename = tkFileDialog.asksaveasfilename(defaultextension=".wfm",
filetypes=[("workflow model file", "*.wfm"), ("other", "*.*")])
filename = filename.strip()
if filename == None or filename == '':
return
wfmObjectToFile(filename, self.wfm)
def __saveViewHandler(self):
if self.wfm == None or self.wfm[3] == None:
return
filename = tkFileDialog.asksaveasfilename(defaultextension=".wfm",
filetypes=[("workflow model file", "*.wfm"), ("other", "*.*")])
filename = filename.strip()
if filename == None or filename == '':
return
wfmObjectToFile(filename, (self.view[0], None, True, None))
def __viewOnHandler(self):
if self.__view_cb.get() == 1:
if self.__split_cb.get() == "VER":
self.view_canvas.grid(row=0, column=2, sticky=N+S+E+W)
elif self.__split_cb.get() == "HOR":
self.view_canvas.grid(row=1, column=1, sticky=N+S+E+W)
else:
self.view_canvas.grid_remove()
def __splitHandler(self):
if self.__split_cb.get() == "HOR" and self.__view_cb.get() == 1:
self.view_canvas.grid_remove()
self.view_canvas.grid(row=1, column=1, sticky=N+S+E+W)
elif self.__split_cb.get() == "VER" and self.__view_cb.get() == 1:
self.view_canvas.grid_remove()
self.view_canvas.grid(row=0, column=2, sticky=N+S+E+W)
if __name__=="__main__":
root = Tk()
app = WfViewer(root)
root.mainloop()