-
Notifications
You must be signed in to change notification settings - Fork 3
/
VPECADD.py
765 lines (612 loc) · 31.8 KB
/
VPECADD.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
#########################################################################
#########################################################################
# $Header: /mnt/raid/services/cvs/CADD/VPECADD.py,v 1.6.4.1 2015/08/26 21:18:11 sanner Exp $
# $Id: VPECADD.py,v 1.6.4.1 2015/08/26 21:18:11 sanner Exp $
import re
import sys
import os
import string
import Pmw, Tkinter
import webbrowser
import warnings
import types
from NetworkEditor.simpleNE import NetworkBuilder, NoGuiNetworkBuilder
from mglutil.util.callback import CallBackFunction
from mglutil.gui.BasicWidgets.Tk.toolbarbutton import ToolBarButton
from mglutil.gui.BasicWidgets.Tk.customizedWidgets import kbComboBox
from Vision.VPE import NoGuiVPE, VisualProgramingEnvironment
from CADD.FormsCADD import AboutWF, AboutDialogCADD, AcknowlDialogCADD, ChangeFontsCADD, BugReportCADD, RefDialogCADD
from CADD import WFTypes
from WFType import NodeWFType
class CADDToolBarButton(ToolBarButton):
def __init__(self, balloonmaster=None, master=None, name=None, icon1=None,
icon2=None, command=None, balloonhelp='',
statushelp='', height=20, width=21,
bd=1, activebackground='lightgrey', padx=0, pady=0,
state='normal', bg=None, iconpath=None):
ToolBarButton.__init__(self, balloonmaster=balloonmaster, master=master, name=name, icon1=icon1,
icon2=icon2, command=command, balloonhelp=balloonhelp,
statushelp=statushelp, height=height, width=width,
bd=bd, activebackground=activebackground, padx=padx, pady=pady,
state=state, bg=bg, iconpath=iconpath
)
def recolorButton(self, bg):
self.bg = bg
class CADDCheckbutton (Tkinter.Checkbutton):
def __init__(self, master=None, image=None, indicatoron=0,
variable=None, command=None, selectcolor=None, bg=None):
Tkinter.Checkbutton.__init__(self, master=master,image=image, indicatoron=indicatoron,
variable=variable, command=command, selectcolor=selectcolor, bg=bg)
def recolorButton(self, bg):
self.bg = bg
class CADDMenubutton(Tkinter.Menubutton):
def __init__(self, master=None, text='', image=None):
Tkinter.Menubutton.__init__(self, master=master, text = text, image=image)
def recolorButton(self, bg):
self.bg = bg
class NoGuiVPECADD(NoGuiVPE):
def __init__(self):
self.libraries = {} # stores node libraries
try:
# add VisionLibraries to system path
from Vision.UserLibBuild import addDirToSysPath
from Vision import __path__
addDirToSysPath(__path__[0]+'Libraries')
# add UserLibs to system path
from mglutil.util.packageFilePath import getResourceFolderWithVersion
lCADDResourceFolder = getResourceFolderWithVersion() \
+ os.sep + 'CADD' + os.sep
addDirToSysPath(lCADDResourceFolder + 'UserLibs')
except:
pass
class NoGuiExecCADD(NoGuiNetworkBuilder, NoGuiVPECADD):
def __init__(self):
NoGuiNetworkBuilder.__init__(self)
NoGuiVPECADD.__init__(self)
class VisualProgramingEnvironmentCADD(VisualProgramingEnvironment, NoGuiVPECADD):
def __init__(self, name='CADD', master=None, font=None,
withShell=1, width=750, height=700, **kw):
NoGuiVPECADD.__init__(self)
self.width = width
self.height = height
self.master = master
from CADD.UserLibBuildCADD import ensureDefaultUserLibFileCADD, ensureCADDResourceFile, ensureCADDFontsFile
ensureDefaultUserLibFileCADD()
caddRCFile = ensureCADDResourceFile()
ensureCADDFontsFile()
# set workflows dir and copy workflows from the installed distro
self.setWFDir(caddRCFile)
self.copyWorkflows()
self.top = Pmw.PanedWidget(master, orient='vertical',
hull_relief='sunken',
hull_width=width, hull_height=height)
self.top.component('hull').master.title(name)
wfmenus = self.top.add('WFMenuBars', min=20, max=40,size=20)
menus = self.top.add('MenuBars', min=20, max=40, size=20)
if sys.platform == 'win32':
modulePagesPane = self.top.add('ModulePages', min=150, size=200)
else:
modulePagesPane = self.top.add('ModulePages', min=100, size=200)
# horizontal pane for for buttons
self.buttonBar = self.top.add('ButtonBar', min=20, max=20, size=20)
self.buttonBarFunc = {} # key:buttonName, value:function
# horizontal pane for networks notebook
ed = self.top.add('Editor', min=100)
# create scrolled frame for ModulePage (libraries)
self.modulePagesF = Pmw.ScrolledFrame(modulePagesPane,
borderframe=1, horizscrollbar_width=7, vscrollmode='none',
frame_relief='flat',
frame_borderwidth=0, horizflex='fixed',
vertflex='elastic')
self.modulePagesF.pack(expand=1, fill='both')
self.ModulePages = Pmw.NoteBook(self.modulePagesF.interior(), raisecommand=self.selectLibrary)
self.ModulePages.pack(fill='both', expand = 1)# padx = 5, pady = 5)
self.idToNodes = {} # key is canvas, values {nodeID:nodeType}
self.setColors() # definte clors before toolbar buttons are creaed
self.addButtonsToButtonBar(master) # add buttons to buttonBar
self.modSearch = kbComboBox( self.buttonBar, labelpos='w',
entryfield_entry_width=12, selectioncommand=self.searchModules,
scrolledlist_items = [])
self.modSearch.pack(side='left', anchor=Tkinter.NW)
self.lastSearchString = None
self.searchAfterId = None # used to deselect nodes found by search
self.lastMatchIndices = [0,0,0] # library index and category index of last found node
apply( NetworkBuilder.__init__, (self, name, ed, font, withShell), kw )
self.mBar.destroy()
self.createMenus(menus)
self.setFont("Menus", self.font['Menus'])
self.top.pack(expand=1, fill='both')
handle = self.eventHandler['deleteNetwork']
handle.AddCallback(self.handleDeleteNetworkButtons)
self.setForms()
from NetworkEditor.widgets import widgetsTable
self.widgetsTable = widgetsTable
self.userLibsDirs = {} # stores path to user defined node libs
from Vision.UserLibBuild import ensureDefaultUserLibFile
ensureDefaultUserLibFile()
from Vision.UserLibBuild import ensureVisionResourceFile
ensureVisionResourceFile()
if hasattr(self,"currentNetwork"):
self.currentNetwork.glyphKeywords ={}
self.currentNetwork.glyphKeywords['fontstyle']=''
self.currentNetwork.glyphKeywords['font']= "courier"
self.currentNetwork.glyphKeywords['fontsize'] = 12
self.currentNetwork.glyphKeywords['fill'] = ''
self.currentNetwork.glyphKeywords['outline'] = "black"
self.currentNetwork.glyphKeywords['spray'] = False
self.master.master.master.protocol("WM_DELETE_WINDOW", self.interactiveExit_cb)
self.changeColor()
def setWFDir(self, file):
import user
lines = open(file).read().splitlines()
for line in lines:
if "workflowDir" in line :
dir, val = line.split('=')
self.workflowDir = eval(val)
def copytree(self, source, target, ignore_patterns):
# recursive copy. WIll not be needed as of python 2.7.
from os.path import join, splitext, split, exists
from shutil import copyfile
if not os.path.exists(target):
os.mkdir(target)
for root, dirs, files in os.walk(source):
for pat in ignore_patterns:
if pat in dirs:
dirs.remove(pat) # don't visit ignored directories
for file in files:
if splitext(file)[-1] in ('.pyc', '.pyo', '.fs'):
continue
from_ = join(root, file)
to_ = from_.replace(source, target, 1)
to_directory = split(to_)[0]
if not exists(to_directory):
os.makedirs(to_directory)
copyfile(from_, to_)
def copyWorkflows(self):
# copy workflows from the distribution to user's home
from CADD import __path__
self.__path__ = __path__[0]
print "PATH", self.__path__
if os.path.exists(self.workflowDir):
print "Using existing workflows from %s" % self.workflowDir
else:
print "Copying distribution workflows to %s" % self.workflowDir
wfDistroDir = os.path.join( self.__path__, 'workflows')
print "CADD PATH", wfDistroDir, self.workflowDir
try:
self.copytree(wfDistroDir, self.workflowDir, ('.svn', 'CVS') )
# use next lines for python 2.7+
#from shutil import copytree, ignore_patterns
#copytree(wfDistroDir, self.workflowDir, ignore = ignore_patterns('.svn', 'CVS') )
except:
txt = "Can not copy distribution workflows into directory %s" % self.workflowDir
warnings.warn(txt)
def setColors(self):
# Create the list of colors to cycle through
self.colorList = []
self.colorIndex = 0
self.colorList.append(('ivory', '#000022'))
#for color in Pmw.Color.spectrum(6, 1.5, 1.0, 1.0, 1):
for color in Pmw.Color.spectrum(6, 1.0, 1.0, 1.0, 1, 0):
bg = Pmw.Color.changebrightness(self.master.master, color, 0.85)
self.colorList.append((bg, 'black'))
bg = Pmw.Color.changebrightness(self.master.master, color, 0.65)
self.colorList.append((bg, 'black'))
#bg = Pmw.Color.changebrightness(self.master.master, color, 0.45)
#self.colorList.append((bg, 'white'))
#bg = Pmw.Color.changebrightness(self.master.master, color, 0.25)
#self.colorList.append((bg, 'white'))
self.bg, self.fg = self.colorList[self.colorIndex]
self.colorIndex = -1
def changeColor(self):
self.colorIndex = self.colorIndex + 1
if self.colorIndex == len(self.colorList):
self.colorIndex = 0
self.bg, self.fg = self.colorList[self.colorIndex]
Pmw.Color.changecolor(self.master.master, self.bg, foreground = self.fg)
Pmw.Color.changecolor(self.buttonBar, self.bg, foreground = self.fg)
self.ModulePages.recolorborders()
bl = self.buttonBar.toolbarButtonDict
for buttonName, button in bl.items():
button.config(bg=self.bg, activebackground=self.bg)
button.recolorButton(self.bg)
def setForms(self):
# a dictionary holding various forms:
self.forms = {}
self.forms['configureFontsPanel'] = None # a form to change the fonts
self.forms['loadLibraryPanel'] = None # a widget created by showLoadLibraryForm_cb
self.forms['browseLibsPanel'] = None # a widget created by showBrowseLibraryForm_cb
self.forms['createLibsPanel'] = None # a widget created by showCreateLibraryForm_cb
self.forms['addNodeToLibsPanel'] = None # a widget created by AddNodeToLibrary_cb
self.forms['aboutDialog'] = None # aboutDialog window
self.forms['acknowlDialog'] = None # acknowledgements dialog
self.forms['refDialog'] = None # references dialog window
self.forms['searchNodesDialog'] = None # search nodes dialog window
self.forms['BugReport'] = None # bugreport window
def createMenus(self, parent):
NetworkBuilder.createMenus(self, parent)
self.makeLibrariesMenu()
self.makeHelpMenu()
self.addToEditMenu()
self.hideLibsPane()
wfmenus = self.top.pane('WFMenuBars')
self.createWFMenu(wfmenus)
self.colorButton()
def createWFMenu(self, parent):
self.WFmBar = Tkinter.Frame(parent, relief=Tkinter.RAISED, borderwidth=2)
self.WFmBar.pack(side='top',fill=Tkinter.X)
self.WFTypeButtons = {}
self.WFMenus = {}
entries = WFTypes.keys()
entries.sort()
for item in entries:
self.makeWFTypes(item)
apply( self.WFmBar.tk_menuBar, self.WFTypeButtons.values() )
def colorButton(self):
#buttonbox = Pmw.ButtonBox(self.WFmBar)
#buttonbox.pack(side = Tkinter.TOP, fill = 'none', padx='0m', pady='0m', expand=1)
#buttonbox.add('Change color', command = self.changeColor)
cbutton = Tkinter.Button(self.WFmBar, text="Change color", command = self.changeColor)
cbutton.pack(side=Tkinter.RIGHT)
def makeWFTypes(self, str):
wfType = NodeWFType(str, dir=self.workflowDir)
assert isinstance(wfType, NodeWFType)
self.font['SubMenus'] = ('helvetica', 12, 'bold')
WFType_button = Tkinter.Menubutton(self.WFmBar, text=str,
relief=Tkinter.FLAT,
underline = None
)
self.WFTypeButtons[str] = WFType_button
self.WFMenus[str] = wfType.showWFlist()
WFType_button.pack(side=Tkinter.LEFT, padx="0m")
WFType_button.configure(font=self.font['SubMenus'])
WFType_button.menu = Tkinter.Menu(WFType_button, tearoff=False)
WFType_button.menu.add_separator()
key = "About %s" % str
WFType_button.menu.add_command(label=key, command=(lambda:self.showAboutWF(key, wfType.showType())))
wflist = Tkinter.Menu(WFType_button.menu, tearoff=0)
wflist.configure(font=self.font['SubMenus'])
WFType_button.menu.add_cascade(label="Load workflow", menu=wflist)
for item in self.WFMenus[str]:
label = item[0]
file = item[1]
wflist.add_command(label=label, command=(lambda file=file : self.directLoadNetwork_cb(file)))
WFType_button.menu.add_separator()
WFType_button['menu'] = WFType_button.menu
def showConfigureFontsForm_cb(self, event=None):
if self.forms['configureFontsPanel'] is None:
self.forms['configureFontsPanel'] = ChangeFontsCADD(editor=self)
else:
self.forms['configureFontsPanel'].show()
def directLoadNetwork_cb(self, file):
if file:
self.loadNetwork(file, network=None)
self.recentFiles.add(file, 'loadNetwork')
def hideLibsPane(self):
menu = self.menuButtons['Libraries'].menu
self.modulePagesF.forget()
menu.entryconfigure('Hide libraries', label='Show libraries')
self.top.configurepane('ModulePages', min=0, max=0)
def updateFastLibs(self):
from CADD.nodeLibrariesCADD import libraries
for key, value in libraries.items():
try:
if hasattr(self,'fastLibsMenu'):
self.fastLibsMenu.index(key)
except:
if len(value) == 2:
func = CallBackFunction(self.loadLibModule, value[0], dependents=value[1])
else:
func = CallBackFunction(self.loadLibModule, value)
if hasattr(self,'fastLibsMenu'):
self.fastLibsMenu.add_command(label=key, command=func)
try:
if hasattr(self,'fastLibsMenu2'):
self.fastLibsMenu2.index(key)
except:
if len(value) == 2:
func = CallBackFunction(self.loadLibModule, value[0], dependents=value[1])
else:
func = CallBackFunction(self.loadLibModule, value)
if hasattr(self,'fastLibsMenu2'):
self.fastLibsMenu2.add_command(label=key, command=func)
def showBugReport(self, event=None):
"""the 'CADD Bug Report' dialog window"""
if self.forms['BugReport'] is None:
self.forms['BugReport'] = BugReportCADD(bg = self.bg, fg = self.fg)
else:
self.forms['BugReport'].setDialogColor(self.bg, self.fg)
self.forms['BugReport'].show()
def showAboutWF(self, key, about, event=None):
"""the 'about workflow type' dialog window"""
if not self.forms.has_key(key) :
self.forms[key] = None
if self.forms[key] is None:
self.forms[key] = AboutWF(key, about, self.bg, self.fg)
else:
self.forms[key].setDialogColor(self.bg, self.fg)
self.forms[key].show()
def showAbout(self, event=None):
"""the 'about CADD' dialog window"""
if self.forms['aboutDialog'] is None:
self.forms['aboutDialog'] = AboutDialogCADD(bg = self.bg, fg = self.fg)
else:
self.forms['aboutDialog'].setDialogColor(self.bg, self.fg)
self.forms['aboutDialog'].show()
def showAcknowl(self, event=None):
"""the 'acknowledgements' dialog window"""
if self.forms['acknowlDialog'] is None:
self.forms['acknowlDialog'] = AcknowlDialogCADD(bg = self.bg, fg = self.fg)
else:
self.forms['acknowlDialog'].setDialogColor(self.bg, self.fg)
self.forms['acknowlDialog'].show()
def showTutorials(self):
import tkMessageBox
tkMessageBox.showinfo("Tutorials and examples",
"""Tutorials and examples must be downloaded separately from the section "Supplementary Material" at http://mgltools.scripps.edu/downloads
In the archive file, you will find a beginner's tutorial: doc/Tutorial/tutorial.rtf
and Jose Unpingco has prepared some nice video tutorials http://www.osc.edu/blogs/index.php/sip
""")
def showRefs(self, event=None):
"""the 'references' dialog window"""
if self.forms['refDialog'] is None:
self.forms['refDialog'] = RefDialogCADD(bg = self.bg, fg = self.fg)
else:
self.forms['refDialog'].setDialogColor(self.bg, self.fg)
self.forms['refDialog'].show()
def showFAQ(self, event=None):
from mglutil.util.packageFilePath import findFilePath
file = findFilePath('FAQ.html', 'CADD')
if file:
webbrowser.open(file)
def runWithoutGui_cb(self, event=None):
"""VPE wrapper of runWithoutGui_cb. toggle button bar buttons
"""
if self.currentNetwork is None \
or len(self.currentNetwork.nodes) == 0:
warnings.warn('no Network to run without GUI')
return
else:
print "running current network without GUI"
bl = self.buttonBar.toolbarButtonDict
bl['runWithoutGui'].disable()
bl['stopWithoutGui'].enable()
net = self.currentNetwork
net.canvas.update_idletasks()
# save the temporary file to be run
if self.currentNetwork.filename is not None:
lNetworkDir = os.path.dirname(self.currentNetwork.filename)
else:
import CADD
lNetworkDir = CADD.networkDefaultDirectory
try:
self.removeTemporaryNetworkFile()
from tempfile import mktemp
self.temporaryFilename = mktemp(dir=lNetworkDir)
self.saveNetwork(self.temporaryFilename, temporary=True)
self.killRunWithoutGui()
from subprocess import Popen, PIPE, call, check_call
if sys.platform == 'win32':
net.processWithoutGui = Popen(
['python',
self.temporaryFilename,'-w'],
shell=False, cwd=lNetworkDir)
else:
net.processWithoutGui = Popen(
[self.resourceFolder+'/pythonsh',
self.temporaryFilename,'-w'],
shell=False, cwd=lNetworkDir)
## bind widget in setwork to remote process
for node in self.currentNetwork.nodes:
for p in node.inputPorts:
if p.widget:
p.widget.bindToRemoteProcessNode()
def verifyProcessWithoutGui():
net = self.currentNetwork
#print verifyProcessWithoutGui, net.processWithoutGui.poll()
if hasattr(net, 'processWithoutGui') \
and net.processWithoutGui.poll() != 0:
self.after(1000, verifyProcessWithoutGui)
else:
self.stopWithoutGui_cb()
self.after(1000, verifyProcessWithoutGui)
# wait for process to start and write self.temporaryFilename.sock
from os import path
from time import sleep
while 1:
if path.exists(self.temporaryFilename+'.sock'):
break
else:
sleep(0.1)
f = open(self.temporaryFilename+'.sock')
host, port = f.readlines()[0].split()
f.close()
net = self.currentNetwork
net.remoteProcessSocket = self.currentNetwork.connectToProcess(
host, int(port))
except Exception, e:
warnings.warn("""can't save or run temporary file to run without GUI,
on unix make sure ksh is installed as /bin/ksh""")
print e
def addButtonsToButtonBar(self, master):
# balloons were moved from the cursor to fix a problem with
# node library balloons flashing
buttonList = [
{'sep1':{'icon1':'sep.gif', 'icon2':None, 'state':'disabled',
'func':None, 'balloon':None}},
{'new':{'icon1':'new.gif', 'icon2':None, 'state':'normal',
'func':self.newNet_cb, 'balloon':'new network'}},
{'open':{'icon1':'open.gif', 'icon2':'lib-close.gif', 'state':'normal',
'func':self.loadNetwork_cb, 'balloon':'open network'}},
{'merge':{'icon1':'merge1.gif', 'icon2':'merge2.gif',
'state':'disabled',
'func':self.mergeNetwork_cb, 'balloon':'merge networks'}},
{'loadLib':{'type':'menubutton',
'icon1':'loadLib2.gif',
'func':self.showLoadLibraryForm2_cb,
'balloon':'load library'}},
{'showHideLib':{'state':'normal',
'icon1':'lib-open.gif',
'icon2':'lib-close.gif',
'func':self.showHideLibraries_cb,
'balloon':'show/hide library'}},
{'save':{'icon1':'save1.gif', 'icon2':'save2.gif',
'state':'disabled', 'func':self.saveNetwork_cb,
'balloon':'save network'}},
{'print':{'icon1':'print1.gif', 'icon2':'print2.gif',
'state':'disabled', 'func':self.print_cb,
'balloon':'print network'}},
{'sep3':{'icon1':'sep.gif', 'icon2':None, 'state':'disabled',
'func':None, 'balloon':None}},
{'runOnNewData':{'type':'checkbutton',
'icon1':'tapclosed.gif',
'icon2':'tapopen.gif',
'func':self.setRunOnNewData_cb,
'balloon':'toggle immediate run'}},
{'softrun':{'icon1':'run1.gif', 'icon2':'runGreen.gif',
'state':'disabled', 'func':self.softrunCurrentNet_cb,
'balloon':'soft run current network'}},
{'run':{'icon1':'run1.gif', 'icon2':'run2.gif',
'state':'disabled', 'func':self.runCurrentNet_cb,
'balloon':'hard run current network (force run)'}},
{'pause':{'icon1':'pause1.gif', 'icon2':'pause2.gif',
'state':'disabled', 'func':self.togglePauseCurrentNet_cb,
'balloon':"pause current network's execution"}},
{'stop':{'icon1':'stop1.gif', 'icon2':'stop2.gif',
'state':'disabled', 'func':self.stopCurrentNet_cb,
'balloon':"stop current network's execution"}},
{'sep4':{'icon1':'sep.gif', 'icon2':None, 'state':'disabled',
'func':None, 'balloon':None}},
{'runWithoutGui':{'icon1':'run1.gif', 'icon2':'runBlack.gif',
'state':'disabled', 'func':self.runWithoutGui_cb,
'balloon':'run current network without GUI in a separate process'}},
{'stopWithoutGui':{'icon1':'stop1.gif', 'icon2':'stop2.gif',
'state':'disabled', 'func':self.stopWithoutGui_cb,
'balloon':"stop execution without GUI"}},
{'sep5':{'icon1':'sep.gif', 'icon2':None, 'state':'disabled',
'func':None, 'balloon':None}},
{'gantt':{'icon1':'teprla1.gif', 'icon2':'teprla1.gif',
'state':'enabled', 'func':self.toggleGantt_cb,
'balloon':"show/hide GANTT diagram of execution times"}},
{'debug':{'icon1':'flowengine_6.gif', 'icon2':'flowengine_6.gif',
'state':'enabled', 'func':self.debugCurrentNet_cb,
'balloon':"build the list of node to execute and step through them"}},
{'step':{'icon1':'stepover_6.gif', 'icon2':'stepover_6.gif',
'state':'disabled', 'func':self.debugStep_cb,
'balloon':"Execute current node in node list"}},
{'sep5a':{'icon1':'sep.gif', 'icon2':None, 'state':'disabled',
'func':None, 'balloon':None}},
{'cut':{'icon1':'cut1.gif', 'icon2':'cut2.gif',
'state':'disabled', 'func':self.cutNetwork_cb,
'balloon':'cut'}},
{'copy':{'icon1':'copy1.gif', 'icon2':'copy2.gif',
'state':'disabled', 'func':self.copyNetwork_cb,
'balloon':'copy'}},
{'paste':{'icon1':'paste1.gif', 'icon2':'paste2.gif',
'state':'disabled', 'func':self.pasteNetwork_cb,
'balloon':'paste'}},
{'sep6':{'icon1':'sep.gif', 'icon2':None, 'state':'disabled',
'func':None, 'balloon':None}},
{'find':{'icon1':'find2.gif', 'icon2':'find2.gif',
'state':'enabled', 'func':self.searchNodes_cb,
'balloon':'open search nodes panel'}},
]
from mglutil.util.packageFilePath import findFilePath
ICONPATH = findFilePath('Icons', 'CADD')
self.buttonIcons = {} #otherwise the icon is lost and not displayed (tk bug)
for item in buttonList:
name=item.keys()[0]
icon1 = item[name]['icon1']
func = item[name]['func']
balloon = item[name]['balloon']
self.buttonBarFunc[name] = func
if item[name].has_key('type') is False:
icon2 = item[name]['icon2']
state = item[name]['state']
# Note: we pass balloonmaster=None to class ToolBarButton
# so it will create an attribute 'balloons' in self.buttonBar
# so Pmw.Balloon will be an instance in self.buttonBar.balloons
CADDToolBarButton(None, self.buttonBar, name=name, icon1=icon1,
icon2=icon2, state=state,
command=self.selectFunc, balloonhelp=balloon,
statushelp=balloon,
bg=self.bg,
iconpath=ICONPATH )
else:
head, ext = os.path.splitext(icon1)
ICONPATH1 = os.path.join(ICONPATH, icon1)
if ext == '.gif':
Icon = Tkinter.PhotoImage(file=ICONPATH1, master=master)#, master=self.ROOT)
else:
import Image
import ImageTk
image = Image.open(ICONPATH1)
Icon = ImageTk.PhotoImage(image=image, master=master)
if item[name]['type'] == 'menubutton':
self.buttonIcons[name] = Icon
#lButton = Tkinter.Menubutton(self.buttonBar,
lButton = CADDMenubutton(self.buttonBar,
text = 'load library',
image=Icon
)
self.fastLibsMenu2 = Tkinter.Menu(lButton, tearoff=0)
self.updateFastLibs()
lButton.menu = self.fastLibsMenu2
lButton['menu'] = lButton.menu
elif item[name]['type'] == 'checkbutton':
if hasattr(self, 'buttonVariables') is False:
self.buttonVariables = {}
if self.buttonVariables.has_key(name) is False:
self.buttonVariables[name] = Tkinter.IntVar()
self.buttonIcons[name] = [Icon,]
#lButton = Tkinter.Checkbutton(self.buttonBar,
lButton = CADDCheckbutton(self.buttonBar,
image=Icon,
indicatoron=0,
variable=self.buttonVariables[name],
command=func,
selectcolor='lightgrey',
bg=self.bg,
#background='white',
)
if item[name].has_key('icon2'):
icon2 = item[name]['icon2']
head2, ext2 = os.path.splitext(icon2)
ICONPATH2 = os.path.join(ICONPATH, icon2)
if ext2 == '.gif':
Icon2 = Tkinter.PhotoImage(file=ICONPATH2, master=master)#, master=self.ROOT)
else:
image2 = Image.open(ICONPATH2)
Icon2 = ImageTk.PhotoImage(image=image2, master=master)
self.buttonIcons[name].append(Icon2)
lButton.configure(selectimage=Icon2)
# add ballon to this button
if hasattr(self.buttonBar, 'balloons') is False:
self.buttonBar.balloons = Pmw.Balloon(self.buttonBar, yoffset=0)
self.buttonBar.balloons.bind(lButton, balloon, balloon)
lButton.pack(side=Tkinter.LEFT, padx="1m")
# add the button to the list stored in the master
self.buttonBar.toolbarButtonDict[name] = lButton
def showHideLibraries_cb(self, event=None):
"""Display or hide the node libraries"""
bl = self.buttonBar.toolbarButtonDict
mybutton = bl['showHideLib']
menu = self.menuButtons['Libraries'].menu
try:
menu.index("Show libraries")
show = True
except:
show = False
if show: # pack the frame
self.modulePagesF.pack(expand=1, fill='both')
menu.entryconfigure('Show libraries', label='Hide libraries')
# extend pane, we need 2 steps, else the pane is displd. too big
self.top.configurepane('ModulePages', min=150, max=150)
self.top.configurepane('ModulePages', min=100, max=10000000)
mybutton.config(image=mybutton.icon2)
else: # forget the frame
self.modulePagesF.forget()
menu.entryconfigure('Hide libraries', label='Show libraries')
# and shrink pane
self.top.configurepane('ModulePages', min=0, max=0)
mybutton.config(image=mybutton.icon1)