Package Vision :: Module Forms
[hide private]
[frames] | no frames]

Source Code for Module Vision.Forms

   1  ######################################################################### 
   2  # 
   3  # Date: Jul 2003  Author: Daniel Stoffler 
   4  # 
   5  #       stoffler@scripps.edu 
   6  # 
   7  #       The Scripps Research Institute (TSRI) 
   8  #       Molecular Graphics Lab 
   9  #       La Jolla, CA 92037, USA 
  10  # 
  11  # Copyright: Daniel Stoffler and TSRI 
  12  # 
  13  ######################################################################### 
  14  #$Id: Forms.py,v 1.24 2007/02/09 21:32:53 sowjanya Exp $ 
  15   
  16  import Tkinter, Pmw 
  17  import sys, re, os 
  18  import string 
  19  from NetworkEditor.customizedWidgets import kbScrolledCanvas 
  20  from mglutil.util.callback import CallBackFunction 
  21  from mglutil.util.packageFilePath import findAllPackages, findModulesInPackage 
  22  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
  23  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser, \ 
  24       kbScrolledListBox 
  25  from string import join 
  26  from Tkinter import * 
  27  import webbrowser,os,sys 
  28  from types import StringType 
  29  import tkFileDialog 
  30  VarDict={} 
  31   
32 -class Dialog:
33
34 - def __init__(self):
35 self.panel = None 36 self.bg = 'royalblue' 37 self.fg = 'white' 38 39 self.buildPanel() 40 41 # bind OK button callback 42 self.panel.protocol("WM_DELETE_WINDOW", self.Ok) 43 # disable typing stuff in the window 44 self.textFrame.configure(state='disabled')
45 ## # disable resizing 46 ## self.panel.resizable(height='false', width='false') 47 48
49 - def buildPanel(self):
50 # prevent re-creation 51 if self.panel is not None: 52 self.panel.show() 53 return 54 55 root = self.panel = Tkinter.Toplevel() 56 self.frame = Tkinter.Frame(root, borderwidth=2, 57 relief='sunken', padx=5, pady=5) 58 self.frame.pack(side='top', expand=1, fill='both') 59 60 txtFrame = Tkinter.Frame(self.frame) 61 62 self.textFrame = Tkinter.Text(txtFrame, background=self.bg, 63 exportselection=1, padx=10, pady=10,) 64 65 self.textFrame.tag_configure('big', font=('courier', 24, 'bold'), 66 foreground=self.fg) 67 self.textFrame.tag_configure('medium', font=('helvetica', 14, 'bold'), 68 foreground=self.fg) 69 self.textFrame.tag_configure('normal12', 70 font=('helvetica', 12, 'bold'), 71 foreground=self.fg) 72 self.textFrame.tag_configure('normal10', 73 font=('helvetica', 10, 'bold'), 74 foreground=self.fg) 75 self.textFrame.tag_configure('normal8', 76 font=('helvetica', 8, 'bold'), 77 foreground=self.fg) 78 self.textFrame.tag_configure('email', font=('times', 10, 'bold'), 79 foreground='lightblue') 80 self.textFrame.tag_configure('http', font=('times', 12, 'bold'), 81 foreground='lightblue') 82 self.textFrame.tag_configure('normal10b', 83 font=('helvetica', 10, 'bold'), 84 foreground='lightblue') 85 86 self.textFrame.pack(side='left', expand=1, fill='both') 87 88 # provide a scrollbar 89 self.scroll = Tkinter.Scrollbar(txtFrame, command=self.textFrame.yview) 90 self.textFrame.configure(yscrollcommand = self.scroll.set) 91 self.scroll.pack(side='right', fill='y') 92 txtFrame.pack(expand=1, fill='both') 93 94 # proved an OK button 95 buttonFrame = Tkinter.Frame(self.frame) 96 buttonFrame.pack(side='bottom', fill='x') 97 self.buttonOk = Tkinter.Button(buttonFrame, text=' Ok ', 98 command=self.Ok) 99 self.buttonOk.pack(padx=6, pady=6)
100 101
102 - def Ok(self, event=None):
103 self.hide()
104 105
106 - def show(self, event=None):
107 self.panel.deiconify()
108 109
110 - def hide(self, event=None):
111 self.panel.withdraw()
112 113
114 -class AboutDialog(Dialog):
115
116 - def __init__(self):
117 Dialog.__init__(self)
118 119
120 - def buildPanel(self):
121 Dialog.buildPanel(self) # call base class method 122 123 # remove scrollbar 124 self.scroll.forget() 125 126 # add own stuff 127 self.panel.title('About Vision') 128 129 self.textFrame.configure() 130 131 self.textFrame.insert('end', 'Vision\n', 'big') 132 self.textFrame.insert('end', 133 'A Visual Programming Environment for Python.\n\n', 134 'medium') 135 self.textFrame.insert('end', 136 'Michel F. Sanner','normal12') 137 self.textFrame.insert('end', '\t\tsanner@scripps.edu\n', 'email') 138 self.textFrame.insert('end', 'Daniel Stoffler', 'normal12') 139 self.textFrame.insert('end', '\t\tstoffler@scripps.edu\n','email') 140 self.textFrame.insert('end', 'Guillaume Vareille', 'normal12') 141 self.textFrame.insert('end', '\tvareille@scripps.edu\n\n','email') 142 self.textFrame.insert('end', 'Vision home page:\t', 'normal12') 143 self.textFrame.insert('end', 144 'http://mgltools.scripps.edu/\n\n', 145 'http') 146 self.textFrame.insert('end', 'The Scripps Research Institute\n'+\ 147 'Molecular Graphics Lab\n'+\ 148 '10550 N Torrey Pines Rd\n'+\ 149 'La Jolla CA 92037 USA\n\n', 'normal10') 150 self.textFrame.insert('end', 151 'Python version: %s\t'%sys.version.split()[0], 152 'normal8') 153 154 # handle weird tk version num in windoze python >= 1.6 (?!?) 155 # Credits for this code go to the people who brought us idlelib! 156 tkVer = `Tkinter.TkVersion`.split('.') 157 tkVer[len(tkVer)-1] = str('%.3g'%( 158 float('.'+tkVer[len(tkVer)-1])))[2:] 159 if tkVer[len(tkVer)-1] == '': 160 tkVer[len(tkVer)-1] = '0' 161 tkVer = string.join(tkVer,'.') 162 self.textFrame.insert('end', 'Tk version: %s\n'%tkVer, 163 'normal8')
164 165 #self.panel.geometry("+%d+%d" %(self.panel.winfo_rootx()+30, 166 # self.panel.winfo_rooty()+30)) 167 168 169
170 -class AcknowlDialog(Dialog):
171
172 - def __init__(self):
173 Dialog.__init__(self)
174 175
176 - def buildPanel(self):
177 Dialog.buildPanel(self) # call base class method 178 179 # add own stuff 180 self.panel.title('Acknowledgements') 181 182 self.textFrame.insert('end', 'Vision Acknowledgements\n', 'big') 183 self.textFrame.insert('end', 184 '\nThis work is supported by:\n\n', 'medium') 185 self.textFrame.insert('end', 186 'Swiss National Science Foundation\n'+\ 187 'Grant No. 823A-61225\n', 'normal12') 188 self.textFrame.insert('end', 'http://www.snf.ch\n\n', 'http') 189 190 self.textFrame.insert('end', 191 'National Biomedical Computation Resource\n'+\ 192 'Grant No. NBCR/NIH RR08605\n', 'normal12') 193 self.textFrame.insert('end', 'http://nbcr.sdsc.edu\n\n', 'http') 194 195 self.textFrame.insert('end', 196 'National Partnership for Advanced Computational Infrastructure\n'+\ 197 'Grant No. NPACI/NSF CA-ACI-9619020\n', 'normal12') 198 self.textFrame.insert('end', 'http://www.npaci.edu\n\n', 'http') 199 200 201 self.textFrame.insert('end', 202 'The authors would like to thank all the people in the Olson lab\n'+\ 203 'for their support and constructive criticism.\n', 'normal10') 204 self.textFrame.insert('end', 'http://www.scripps.edu/pub/olson-web\n', 205 'http')
206 207
208 -class RefDialog(Dialog):
209
210 - def __init__(self):
211 Dialog.__init__(self)
212 213
214 - def buildPanel(self):
215 Dialog.buildPanel(self) # call base class method 216 217 # remove scrollbar 218 self.scroll.forget() 219 220 # add own stuff 221 self.panel.title('References') 222 223 self.textFrame.insert('end', 'Vision References\n\n', 'big') 224 225 self.textFrame.insert('end', 226 'ViPEr, a Visual Programming Environment for Python\n','normal12') 227 self.textFrame.insert('end', 228 'Sanner, M.F., Stoffler, D., and Olson, A.J. (2002)\n','normal10b') 229 self.textFrame.insert('end', 230 'In proceedings of the 10th International Python Conference 2002,\n'+\ 231 'Virginia USA.\n\n','normal10') 232 233 234 self.textFrame.insert('end', 235 'Integrating biomolecular analysis and visual programming:\n'+\ 236 'flexibility and interactivity in the design of bioinformatics tools\n', 237 'normal12') 238 self.textFrame.insert('end', 239 'Stoffler, D., Coon, S.I., Huey, R., Olson, '+\ 240 'A.J., and Sanner, M.F. (2003)\n','normal10b') 241 self.textFrame.insert('end', 242 'In proceedings of HICSS-36, Hawaii International conference\n'+\ 243 'on system sciences, 2003, Hawaii.\n\n','normal10')
244 245
246 -class ChangeFonts:
247
248 - def __init__(self, editor=None):
249 self.panel = None 250 self.editor = editor # instance of VPE 251 252 self.buildPanel() 253 254 # bind Cancel button callback on kill window 255 self.panel.protocol("WM_DELETE_WINDOW", self.Cancel_cb)
256 257
258 - def buildPanel(self):
259 # prevent re-creation 260 if self.panel is not None: 261 self.panel.show() 262 return 263 264 root = self.panel = Tkinter.Toplevel() 265 frame = Tkinter.Frame(root, borderwidth=2, 266 relief='sunken')#, padx=5, pady=5) 267 frame.pack(side='top', expand=1, fill='both') 268 269 ## Font Group ## 270 fontGroup = Pmw.Group(frame, tag_text='Font Chooser') 271 fontGroup.pack(fill='both', expand=1, padx=6, pady=6) 272 273 f1 = Tkinter.Frame(fontGroup.interior()) 274 f1.pack(side='top', fill='both', expand=1) 275 f2 = Tkinter.Frame(fontGroup.interior()) 276 f2.pack(side='bottom', fill='both', expand=1) 277 278 familyNames=list(root.tk.splitlist(root.tk.call('font','families'))) 279 familyNames.sort() 280 self.fontChooser = Pmw.ComboBox( 281 f1, 282 label_text = 'Font Name', 283 labelpos = 'n', 284 scrolledlist_items = familyNames, 285 selectioncommand = None 286 ) 287 self.fontChooser.pack(side='left', expand=1, fill='both', 288 padx=6, pady=6) 289 290 sizes = [6,8,10,12,14,18,24,48] 291 self.sizeChooser = Pmw.ComboBox( 292 f1, 293 label_text = 'Font Size', 294 labelpos = 'n', 295 scrolledlist_items = sizes, 296 selectioncommand = None, 297 entryfield_entry_width=4, 298 ) 299 self.sizeChooser.pack(side='left', expand=1, fill='both', 300 padx=6, pady=6) 301 302 303 styles = ['normal', 'bold', 'italic', 'bold italic'] 304 self.styleVarTk = Tkinter.StringVar() 305 for i in range(len(styles)): 306 b = Tkinter.Radiobutton( 307 f2, 308 variable = self.styleVarTk, 309 text=styles[i], value=styles[i]) 310 b.pack(side='left', expand=1, fill='both') 311 312 ## End Font Group ## ########################################## 313 314 ## GUI Group ## 315 316 guiGroup = Pmw.Group(frame, tag_text='GUI Component to Apply Font') 317 guiGroup.pack(fill='both', expand=1, padx=6, pady=6) 318 group1 = ['All', 'Menus', 'LibTabs', 'Categories'] 319 group2 = ['LibNodes', 'NetTabs', 'Nodes', 'Root'] 320 self.groupVarTk = Tkinter.StringVar() 321 frame1 = Tkinter.Frame(guiGroup.interior()) 322 frame2 = Tkinter.Frame(guiGroup.interior()) 323 frame1.pack(side='top', fill='both', expand=1) 324 frame2.pack(side='bottom', fill='both', expand=1) 325 326 for i in range(len(group1)): 327 b = Tkinter.Radiobutton( 328 frame1, 329 variable = self.groupVarTk, 330 text=group1[i], value=group1[i]) 331 b.grid(row=0, column=i, pady=6) 332 333 for i in range(len(group2)): 334 b = Tkinter.Radiobutton( 335 frame2, 336 variable = self.groupVarTk, 337 text=group2[i], value=group2[i]) 338 b.grid(row=0, column=i, pady=6) 339 340 buttonFrame = Tkinter.Frame(root, borderwidth=2, 341 relief='sunken', padx=5, pady=5) 342 buttonFrame.pack(side='top', expand=1, fill='both') 343 self.buttonOk = Tkinter.Button(buttonFrame, text=' Ok ', 344 command=self.Ok_cb) 345 self.buttonApply = Tkinter.Button(buttonFrame, text=' Apply ', 346 command=self.Apply_cb) 347 self.buttonCancel = Tkinter.Button(buttonFrame, text=' Cancel ', 348 command=self.Cancel_cb) 349 350 self.buttonOk.grid(row=0, column=0, padx=6, pady=6) 351 self.buttonApply.grid(row=0, column=1, padx=6, pady=6) 352 self.buttonCancel.grid(row=0, column=2, padx=6, pady=6) 353 354 # set default values 355 try: 356 if sys.platform == 'win32': 357 self.fontChooser.selectitem('Arial') 358 else: 359 self.fontChooser.selectitem('helvetica') 360 self.sizeChooser.selectitem(1) # choose '8' 361 self.styleVarTk.set('normal') 362 self.groupVarTk.set('Nodes') 363 except: 364 pass
365 366
367 - def get(self, event=None):
368 gui = self.groupVarTk.get() 369 ft = self.fontChooser.get() 370 sz = self.sizeChooser.get() 371 sty = self.styleVarTk.get() 372 font = (ft, sz, sty) 373 return (gui, font)
374 375
376 - def Ok_cb(self, event=None):
377 self.Apply_cb() 378 self.Cancel_cb()
379 380
381 - def Apply_cb(self, event=None):
382 if self.editor is not None: 383 cfg = self.get() 384 self.editor.setFont(cfg[0], cfg[1])
385 386
387 - def Cancel_cb(self, event=None):
388 self.hide()
389 390
391 - def show(self, event=None):
392 self.panel.deiconify()
393 394
395 - def hide(self, event=None):
396 self.panel.withdraw()
397 398 399
400 -class SearchNodesDialog:
401 """Search Vision nodes: the string matches either the node name or the 402 node's document string. Found nodes are displayed in the scrolled canvas of 403 this widget, and can be drag-and-drop-ed to the network canvas. 404 A new search clears the previously found nodes""" 405
406 - def __init__(self, editor=None):
407 self.panel = None 408 self.editor = editor # instance of VPE 409 self.entryVarTk = Tkinter.StringVar() # Entry var 410 self.cbVarTk = Tkinter.IntVar() # checkbutton var 411 self.choicesVarTk = Tkinter.StringVar()# radiobutton choices var 412 self.choices = ['Search current lib only', 'Search all loaded libs', 413 'Search all packages\non disk (slower)'] 414 415 self.searchNodes = [] # list of found nodes 416 self.libNodes = [] # list of nodes displayed in our libCanvas 417 self.posyForLibNode = 15 # posy for nodes in lib canvas 418 self.maxxForLibNode = 0 # maxx for nodes in lib canvas 419 # build GUI 420 self.buildPanel() 421 # bind Cancel button callback on kill window 422 self.panel.protocol("WM_DELETE_WINDOW", self.Cancel_cb)
423 424
425 - def buildPanel(self):
426 # prevent re-creation 427 if self.panel is not None: 428 self.panel.show() 429 return 430 431 root = self.panel = Tkinter.Toplevel() 432 433 # add menu bar 434 self.menuBar = Tkinter.Menu(root) 435 self.optionsMenu = Tkinter.Menu(self.menuBar, tearoff=0) 436 self.optionsMenu.add_command(label="Hide Search Options", 437 command=self.showHideOptions_cb) 438 439 self.menuBar.add_cascade(label="Options", menu=self.optionsMenu) 440 root.config(menu=self.menuBar) 441 442 frame = Tkinter.Frame(root, borderwidth=2, relief='sunken') 443 frame.pack(side='top', expand=1, fill='both') 444 445 # build infrastructure for search panes with scrolled canvas 446 sFrame = Tkinter.Frame(frame) 447 sFrame.pack(expand=1, fill='both') 448 # add panes 449 self.searchPane = Pmw.PanedWidget(sFrame, orient='horizontal', 450 hull_relief='sunken', 451 hull_width=120, hull_height=120, 452 ) 453 self.searchPane.pack(expand=1, fill="both") 454 455 searchPane = self.searchPane.add("SearchNodes", min=60) 456 self.searchPane.configurepane("SearchNodes", min=10) 457 usedPane = self.searchPane.add("UsedNodes", min=10) 458 # this is the canvas we use to display found nodes 459 self.searchCanvas = kbScrolledCanvas( 460 searchPane, 461 borderframe=1, 462 #usehullsize=1, hull_width=60, hull_height=80, 463 #vscrollmode='static',#hscrollmode='static', 464 vertscrollbar_width=8, 465 horizscrollbar_width=8, 466 labelpos='n', label_text="Found Nodes", 467 ) 468 self.searchCanvas.pack(side='left', expand=1, fill='both') 469 470 self.editor.idToNodes[self.searchCanvas] = {} 471 472 # this is the canvas we use to display nodes we have drag-and-dropped 473 # to the network 474 self.libCanvas = kbScrolledCanvas( 475 usedPane, 476 borderframe=1, 477 #usehullsize=1, hull_width=60, hull_height=80, 478 #vscrollmode='static',#hscrollmode='static', 479 vertscrollbar_width=8, 480 horizscrollbar_width=8, 481 labelpos='n', label_text="Used Nodes", 482 ) 483 self.libCanvas.pack(side='right', expand=1, fill='both') 484 485 self.editor.idToNodes[self.libCanvas] = {} 486 487 488 lowerFrame = Tkinter.Frame(frame) 489 lowerFrame.pack() # no expand 490 491 # add options buttons 492 self.optionsGroup = Pmw.Group(lowerFrame, tag_text="Search Options") 493 self.optionsGroup.grid(row=0,column=0, sticky='we',padx=6, pady=6) 494 495 cb = Tkinter.Checkbutton(self.optionsGroup.interior(), 496 text="Case sensitive", variable=self.cbVarTk) 497 cb.grid(row=0, column=0, columnspan=2, sticky='we') 498 499 for i in range(len(self.choices)): 500 b = Tkinter.Radiobutton( 501 self.optionsGroup.interior(), 502 variable = self.choicesVarTk, value=self.choices[i]) 503 l = Tkinter.Label(self.optionsGroup.interior(), 504 text=self.choices[i]) 505 b.grid(row=i+1, column=0, sticky='we') 506 l.grid(row=i+1, column=1, sticky='w') 507 508 self.choicesVarTk.set(self.choices[1]) 509 510 # add Entry 511 eFrame = Tkinter.Frame(lowerFrame) 512 eFrame.grid(row=1, column=0, sticky='we') 513 eLabel = Tkinter.Label(eFrame, text='Search string:') 514 eLabel.pack(side='left', expand=1, fill='x') 515 entry = Tkinter.Entry(eFrame, textvariable=self.entryVarTk) 516 entry.bind('<Return>', self.search) 517 entry.pack(side='right', expand=1, fill='x') 518 519 # add buttons 520 bFrame = Tkinter.Frame(lowerFrame) 521 bFrame.grid(row=2, column=0, sticky='we') 522 button1 = Tkinter.Button(bFrame, text="Search", relief="raised", 523 command=self.Apply_cb) 524 button2 = Tkinter.Button(bFrame, text="Dismiss", relief="raised", 525 command=self.Cancel_cb) 526 button1.pack(side='left', expand=1, fill='x') 527 button2.pack(side='right', expand=1, fill='x') 528 529 # Pmw Balloon 530 self.balloons = Pmw.Balloon(master=None, yoffset=10) 531 532 # Drag-and-Drop callback for searchCanvas 533 cb = CallBackFunction(self.editor.startDNDnode, self.searchCanvas) 534 self.searchCanvas.component('canvas').bind('<Button-1>', cb ) 535 # Drag-and-Drop callback for libCanvas 536 cb = CallBackFunction(self.editor.startDNDnode, self.libCanvas) 537 self.libCanvas.component('canvas').bind('<Button-1>', cb )
538 539
540 - def Apply_cb(self, event=None):
541 if self.editor is not None: 542 self.search()
543 544
545 - def Cancel_cb(self, event=None):
546 self.hide()
547 548
549 - def show(self, event=None):
550 self.panel.deiconify()
551 552
553 - def hide(self, event=None):
554 self.panel.withdraw()
555 556
557 - def search(self, event=None):
558 searchStr = self.entryVarTk.get() 559 if searchStr is None or len(searchStr) == 0: 560 return 561 562 canvas = self.searchCanvas.component('canvas') 563 564 # clear previous matches 565 if len(self.searchNodes): 566 for node in self.searchNodes: 567 self.deleteNodeFromPanel(node) 568 569 self.searchNodes = [] 570 self.editor.idToNodes[self.searchCanvas] = {} 571 posy = 15 572 maxx = 0 573 574 nodes = {} 575 576 caseSensitive = self.cbVarTk.get() 577 if not caseSensitive: 578 searchStr = string.lower(searchStr) 579 pat = re.compile(searchStr) 580 581 # loop over libraries 582 choice = self.choicesVarTk.get() 583 if choice == self.choices[0]: # current lib 584 lib = self.editor.ModulePages.getcurselection() 585 libraries = [ (lib, self.editor.libraries[lib]) ] 586 587 elif choice == self.choices[1]: # all loaded libs 588 libraries = self.editor.libraries.items() 589 590 else: # all packages on disk 591 libraries = self.searchDisk() 592 593 594 for libInd in range(len(libraries)): 595 libName, lib = libraries[libInd] 596 categories = lib.libraryDescr.values() 597 # loop over categories 598 for catInd in range(len(lib.libraryDescr)): 599 cat = categories[catInd] 600 for nodeInd in range(len(cat['nodes'])): 601 node = cat['nodes'][nodeInd] 602 603 # match node name 604 name = node.name 605 if not caseSensitive: 606 name = string.lower(node.name) 607 res = pat.search(name) 608 if res: 609 nodes, maxx, posy = self.addNodeToSearchPanel( 610 node, nodes, maxx, posy) 611 continue 612 613 # match node document string 614 doc = node.nodeClass.__doc__ 615 if doc is None or doc == '': 616 continue 617 618 if not caseSensitive: 619 doc = string.lower(doc) 620 res = pat.search(doc) 621 if res: 622 nodes, maxx, posy = self.addNodeToSearchPanel( 623 node, nodes, maxx, posy) 624 625 # update scrolled canvas 626 canvas.configure(width=60, height=150, 627 scrollregion=tuple((0,0,maxx,posy))) 628 629 self.editor.idToNodes[self.searchCanvas] = nodes
630 631
632 - def addNodeToSearchPanel(self, node, nodes, maxx, posy):
633 from NetworkEditor.items import NetworkNode 634 sc_canvas = self.searchCanvas 635 636 font = self.editor.font['LibNodes'] 637 canvas = sc_canvas.component('canvas') 638 639 n1 = NetworkNode(name=node.name) 640 n1.iconMaster = sc_canvas 641 n1.buildSmallIcon(sc_canvas, 10, posy, font) 642 643 color = node.kw['library'].color 644 canvas.itemconfigure(n1.id, fill=color) 645 646 self.balloons.tagbind(sc_canvas, n1.iconTag, 647 node.nodeClass.__doc__) 648 649 bb = sc_canvas.bbox(n1.id) 650 w = bb[2]-bb[0] 651 h = bb[3]-bb[1] 652 maxx = max(maxx, w) 653 posy = posy + h + 8 654 655 nodes[n1.id] = (n1, node) 656 self.searchNodes.append(n1) 657 658 return nodes, maxx, posy
659 660
661 - def addNodeToLibPanel(self, node):
662 if node in self.libNodes: 663 return 664 665 from NetworkEditor.items import NetworkNode 666 sc_canvas = self.libCanvas 667 668 font = self.editor.font['LibNodes'] 669 canvas = sc_canvas.component('canvas') 670 671 n1 = NetworkNode(name=node.name) 672 n1.iconMaster = sc_canvas 673 674 posy = self.posyForLibNode 675 n1.buildSmallIcon(sc_canvas, 10, posy, font) 676 677 color = node.kw['library'].color 678 canvas.itemconfigure(n1.id, fill=color) 679 680 self.balloons.tagbind(sc_canvas, n1.iconTag, 681 node.nodeClass.__doc__) 682 683 bb = sc_canvas.bbox(n1.id) 684 w = bb[2]-bb[0] 685 h = bb[3]-bb[1] 686 self.maxxForLibNode = max(self.maxxForLibNode, w) 687 posy = posy + h + 8 688 self.posyForLibNode = posy 689 690 self.libNodes.append(node) 691 nodes = self.editor.idToNodes[self.libCanvas] 692 nodes[n1.id] = (n1, node) 693 self.editor.idToNodes[self.libCanvas] = nodes 694 695 # update scrolled canvas 696 maxx = self.maxxForLibNode 697 canvas.configure(width=60, height=150, 698 scrollregion=tuple((0,0,maxx,posy)))
699 700
701 - def deleteNodeFromPanel(self, node):
702 canvas = self.searchCanvas.component('canvas') 703 # unbind proxy node balloon 704 self.balloons.tagunbind(canvas, node.iconTag) 705 # delete node icon 706 canvas.delete(node.textId) 707 canvas.delete(node.innerBox) 708 canvas.delete(node.outerBox) 709 canvas.delete(node.iconTag)
710 711
712 - def showHideOptions_cb(self, event=None):
713 mode = 'show' 714 try: 715 index = self.optionsMenu.index("Hide Search Options") 716 mode = 'hide' 717 except: 718 pass 719 720 if mode == 'hide': 721 self.optionsGroup.grid_forget() 722 self.optionsMenu.entryconfig("Hide Search Options", 723 label="Show Search Options") 724 else: 725 self.optionsGroup.grid(row=0, padx=6, pady=6) 726 self.optionsMenu.entryconfig("Show Search Options", 727 label="Hide Search Options")
728 729 730
731 - def searchDisk(self):
732 libraries = [] 733 packages = findAllPackages() 734 for packName in packages: 735 modNames = self.getModules(packName) 736 if len(modNames): 737 for modName in modNames: 738 moduleName = packName+'.'+modName 739 try: 740 mod = __import__( 741 moduleName, globals(), locals(), 742 modName.split('.')[-1]) 743 libs = self.getLibraries(mod) 744 for name,lib in libs.items(): 745 lib.modName = moduleName 746 libraries.append( (name,lib) ) 747 except: 748 print "Could not import module %s from %s!"%( 749 modName, os.getcwd() ) 750 751 return libraries
752 753
754 - def getModules(self, packName):
755 modules = findModulesInPackage(packName, 'NodeLibrary') 756 modNames = [] 757 for key, value in modules.items(): 758 pathPack = key.split(os.path.sep) 759 if pathPack[-1] == packName: 760 newModName = map(lambda x: x[:-3], value) 761 modNames = modNames + newModName 762 else: 763 pIndex = pathPack.index(packName) 764 prefix = string.join(pathPack[pIndex+1:], '.') 765 newModName = map(lambda x: "%s.%s"%(prefix, x[:-3]), value) 766 modNames = modNames + newModName 767 modNames.sort() 768 return modNames
769 770
771 - def getLibraries(self, mod):
772 from Vision.VPE import NodeLibrary 773 libs = {} 774 for name in dir(mod): 775 obj = getattr(mod, name) 776 if isinstance(obj, NodeLibrary): 777 obj.varName = name 778 libs[obj.name] = obj 779 return libs
780 781
782 -class HelpDialog:
783
784 - def __init__(self, title="Help Dialog", message="", bg=None, 785 fg=None, font=('helvetica', 8, 'bold'),):
786 self.panel = None 787 self.title = title # Title of this Dialog window 788 self.message = message # Help message 789 self.bg = bg # Frame background 790 self.fg = fg # text color 791 self.font = font # text font 792 793 self.buildPanel() 794 795 self.panel.title(self.title) 796 797 # bind OK button callback 798 self.panel.protocol("WM_DELETE_WINDOW", self.Ok) 799 # disable typing stuff in the window 800 self.textFrame.configure(state='disabled')
801 802
803 - def buildPanel(self):
804 # prevent re-creation 805 if self.panel is not None: 806 self.panel.show() 807 return 808 809 root = self.panel = Tkinter.Toplevel() 810 self.frame = Tkinter.Frame( 811 root, borderwidth=2, relief='sunken', padx=5, pady=5) 812 self.frame.pack(side='top', expand=1, fill='both') 813 814 txtFrame = Tkinter.Frame(self.frame) 815 816 self.textFrame = Tkinter.Text( 817 txtFrame, exportselection=1, padx=10, pady=10,) 818 819 if self.bg is not None: 820 self.textFrame.configure(bg=self.bg) 821 822 self.textFrame.tag_configure('standard', font=self.font) 823 if self.fg is not None: 824 self.textFrame.tag_configure('standard', foreground=self.fg) 825 826 self.textFrame.pack(side='left', expand=1, fill='both') 827 828 # now add the message 829 self.textFrame.insert('end', self.message, 'standard') 830 831 832 # provide a scrollbar 833 self.scroll = Tkinter.Scrollbar(txtFrame, command=self.textFrame.yview) 834 self.textFrame.configure(yscrollcommand = self.scroll.set) 835 self.scroll.pack(side='right', fill='y') 836 txtFrame.pack(expand=1, fill='both') 837 838 # proved an OK button 839 buttonFrame = Tkinter.Frame(self.frame) 840 buttonFrame.pack(side='bottom', fill='x') 841 self.buttonOk = Tkinter.Button(buttonFrame, text=' Ok ', 842 command=self.Ok) 843 self.buttonOk.pack(padx=6, pady=6)
844 845
846 - def Ok(self, event=None):
847 self.hide()
848 849
850 - def show(self, event=None):
851 self.panel.deiconify()
852 853
854 - def hide(self, event=None):
855 self.panel.withdraw()
856 857 858
859 -class BugReport:
860 - def __init__(self, title="Bug Report", message="", bg=None, 861 fg=None, font=('helvetica', 8, 'bold'),):
862 self.panel = None 863 self.title = title # Title of this Dialog window 864 self.message = message # Help message 865 self.bg = bg # Frame background 866 self.fg = fg # text color 867 self.font = font # text font 868 869 self.buildPanel() 870 871 self.panel.title(self.title) 872 873 # bind OK button callback 874 self.panel.protocol("WM_DELETE_WINDOW", self.Ok)
875 876 877
878 - def doit(self):
879 self.showpdbfile_cb() 880 self.show_upload_page()
881 882 883
884 - def __call__(self):
885 886 apply(self.doitWrapper,(),{})
887 888
889 - def buildPanel(self):
890 891 892 root = self.panel = Tkinter.Toplevel() 893 self.frame = Tkinter.Frame(root, background='white',borderwidth=2, relief='sunken', padx=5, pady=5) 894 self.frame.pack(side='top', expand=1, fill='both') 895 ##### short desc################ 896 897 self.shortdesctext = Pmw.ScrolledText(self.frame, 898 label_text='Summary(one line description)', 899 labelpos='nw',text_padx=20, 900 text_pady=2,) 901 self.shortdesctext.pack(side='left', expand=1, fill='both') 902 self.shortdesctext.grid(sticky='nw',row=0,column=0,columnspan=2) 903 904 #########desc text################ 905 906 self.desctext = Pmw.ScrolledText(self.frame, 907 label_text='Description', 908 labelpos='nw',text_padx=20, 909 text_pady=2,) 910 self.desctext.pack(side='left', expand=1, fill='both') 911 self.desctext.grid(sticky='nw',row=1,column=0,columnspan=2) 912 #pdb file button 913 self.pdbvar = Tkinter.IntVar() 914 915 916 917 ### pdbfile group#### 918 self.pdbGroup = Pmw.Group(self.frame,tag_text="AttachFile") 919 self.pdbGroup.pack(side='left',fill='both', expand=1, padx=1, pady=1) 920 921 f1 = Tkinter.Frame(self.pdbGroup.interior()) 922 f1.pack(side='top', fill='both', expand=1) 923 self.pdbGroup.grid(row=3,column=0,columnspan=2,sticky="nesw") 924 self.pdbfileadd= kbScrolledListBox(f1,items=[],listbox_exportselection=0,listbox_height=1,listbox_width=85) 925 self.pdbfileadd.pack(expand=1, fill='both') 926 self.pdbfileadd.grid(sticky='nw',row=0) 927 self.deletefilebutton=Tkinter.Button(f1,text='Delete Selected', 928 command=self.delete_selected,state="disabled",width=40) 929 self.deletefilebutton.pack(side='left', expand=1,fill='both') 930 self.deletefilebutton.grid(sticky='nw',row=1,column=0,columnspan=1) 931 self.attachmorebutton=Tkinter.Button(f1,text='Attach File ..', 932 command=self.attach_more,width=40) 933 self.attachmorebutton.pack(side='left', expand=1,fill='both') 934 self.attachmorebutton.grid(sticky='ne',row=1,columnspan=2) 935 #email-entry 936 self.email_entrylab=Tkinter.Label(self.frame,text="Enter your email address(optional:to recieve information about submitted bug)") 937 self.email_entrylab.pack(side='top', fill='both', expand=1) 938 self.email_entrylab.grid(sticky='nw',row=4,column=0) 939 self.email_entryvar = Tkinter.StringVar() 940 self.email_entry=Tkinter.Entry(self.frame,textvariable=self.email_entryvar) 941 942 self.email_entry.pack(side='top', fill='both', expand=1) 943 self.email_entry.grid(sticky='nesw',row=5,column=0,columnspan=2) 944 945 946 947 ###############upload,dismiss buttons################ 948 self.uploadbutton=Tkinter.Button(self.frame,text='UpLoad Bug Report', 949 command=self.show_upload_page,width=40) 950 self.uploadbutton.pack(side='left', expand=1,fill='both') 951 self.uploadbutton.grid(sticky='nw',row=6,column=0,columnspan=1) 952 self.dismiss=Tkinter.Button(self.frame,text='DISMISS', 953 command=self.Ok,width=37) 954 self.dismiss.pack( expand=1,fill='both') 955 self.dismiss.grid(sticky='ne',row=6,columnspan=2) 956 pdb_group=self.pdbGroup 957 pdb_group.expand() 958 shortdesc_tx=self.shortdesctext 959 shortdesc_tx.configure(text_height=2) 960 desc_tx=self.desctext 961 desc_tx.configure(text_height=8)
962
963 - def Ok(self, event=None):
964 self.hide()
965 966
967 - def show(self, event=None):
968 #self.panel.deiconify() 969 self.buildPanel()
970
971 - def hide(self, event=None):
972 #self.panel.withdraw() 973 self.panel.destroy()
974 975
976 - def attach_more(self):
977 """for attching files""" 978 pdb_addw=self.pdbfileadd 979 pdb_delw=self.deletefilebutton 980 981 Filename = tkFileDialog.askopenfilename(filetypes=[('all files','*')],title="ADDFile") 982 if Filename: 983 inputfilename = os.path.abspath(Filename) 984 files=pdb_addw.get() 985 files=list(files) 986 files.append(inputfilename) 987 pdb_addw.setlist(files) 988 pdb_addw.configure(listbox_height=len(files)) 989 pdb_delw.configure(state="active") 990 991 else: 992 if len(pdb_addw.get())==0: 993 pdb_delw.configure(state="disabled") 994 pdb_addw.setlist(pdb_addw.get()) 995 VarDict['attachfile'] = pdb_addw.get()
996
997 - def delete_selected(self):
998 """deletes selected files""" 999 pdb_addw=self.pdbfileadd 1000 pdb_delw=self.deletefilebutton 1001 files=pdb_addw.get() 1002 lfiles=list(files) 1003 selected_files=pdb_addw.getcurselection() 1004 for s in list(selected_files): 1005 if s in lfiles: 1006 lfiles.remove(s) 1007 pdb_addw.setlist(lfiles) 1008 pdb_addw.configure(listbox_height=len(lfiles)) 1009 if len(pdb_addw.get())==0: 1010 pdb_delw.configure(state="disabled") 1011 VarDict['attachfile'] = pdb_addw.get()
1012 - def get_description(self):
1013 1014 desc_w =self.desctext 1015 desc_text = self.desctext.get() 1016 shortdesc_w = self.shortdesctext 1017 shortdesc_text =shortdesc_w.get() 1018 1019 VarDict['desc_text'] = desc_text 1020 VarDict['shortdesc_text'] = shortdesc_text 1021 email_ent = self.email_entry.get() 1022 VarDict['email_recipient'] = email_ent
1023 1024 #checking validity of email address
1025 - def validateEmail(self,email):
1026 1027 if len(email) > 7: 1028 if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None: 1029 return 1 1030 return 0
1031 - def show_upload_page(self):
1032 self.get_description() 1033 1034 sumcont = VarDict['shortdesc_text'] 1035 1036 fulldesc = VarDict['desc_text'] 1037 1038 desccont = fulldesc 1039 if len(sumcont)<=1 or len(desccont)<=1: 1040 import tkMessageBox 1041 ok = tkMessageBox.askokcancel("Input","Please enter summary and description") 1042 return 1043 from mglutil.TestUtil import BugReport 1044 if VarDict.has_key('attachfile'): 1045 upfile = VarDict['attachfile'] 1046 else: 1047 upfile=[] 1048 1049 BR = BugReport.BugReportCommand("Vision") 1050 if self.validateEmail(VarDict['email_recipient']): 1051 idnum = BR.showuploadpage_cb(sumcont,desccont,upfile,email_ent=VarDict['email_recipient']) 1052 else: 1053 idnum = BR.showuploadpage_cb(sumcont,desccont,upfile,email_ent="") 1054 1055 self.Ok() 1056 1057 1058 1059 1060 #################################### 1061 #Tk message Box 1062 #################################### 1063 1064 root = Tk() 1065 t = Text(root) 1066 t.pack() 1067 1068 def openHLink(event): 1069 start, end = t.tag_prevrange("hlink", 1070 t.index("@%s,%s" % (event.x, event.y))) 1071 webbrowser.open_new('%s' %t.get(start, end))
1072 #print "Going to %s..." % t.get(start, end) 1073 1074 t.tag_configure("hlink", foreground='blue', underline=1) 1075 t.tag_bind("hlink", "<Control-Button-1>", openHLink) 1076 t.insert(END, "BugReport has been Submiited Successfully\n") 1077 t.insert(END, "BugId is %s" %idnum) 1078 t.insert(END,"\nYou can visit Bug at\n") 1079 t.insert(END,"http://mgldev.scripps.edu/bugs/show_bug.cgi?id=%i" %int(idnum),"hlink") 1080 t.insert(END,"\nControl-click on the link to visit this page\n") 1081 t.insert(END,"\n")
1082