Package ViewerFramework :: Module basicCommand
[hide private]
[frames] | no frames]

Source Code for Module ViewerFramework.basicCommand

   1  ############################################################################ 
   2  # 
   3  # Author: Michel F. SANNER 
   4  # 
   5  # Copyright: M. Sanner TSRI 2000 
   6  # 
   7  ############################################################################# 
   8  """ 
   9  Module implementing the basic commands that are present when instanciating 
  10  a ViewerFramework class or ViewerFramework derived class. 
  11     - loadCommandCommand 
  12     - loadModuleCommand 
  13     - loadMacroCommand 
  14     - ExitCommand 
  15     - ShellCommand 
  16     - UndoCommand 
  17     - ResetUndoCommand. 
  18  """ 
  19   
  20  # $Header: /opt/cvs/python/packages/share1.5/ViewerFramework/basicCommand.py,v 1.92.2.2 2007/07/25 18:36:31 vareille Exp $ 
  21  # 
  22  # $Id: basicCommand.py,v 1.92.2.2 2007/07/25 18:36:31 vareille Exp $ 
  23  # 
  24  import os, sys 
  25   
  26  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
  27  from mglutil.util.callback import CallBackFunction 
  28  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser, \ 
  29       LoadButton, kbScrolledListBox 
  30  from mglutil.util.packageFilePath import findFilePath, findAllPackages, \ 
  31       findModulesInPackage,findAllPmvPackages 
  32   
  33  import types, Tkinter, Pmw, os, sys, traceback 
  34  from string import join 
  35  import tkMessageBox 
  36  from ViewerFramework.VFCommand import Command, CommandGUI 
  37  import warnings 
  38  import string 
  39  commandslist=[] 
  40  cmd_docslist={} 
41 -class UndoCommand(Command):
42 """pops undo string from the stack and executes it in the ViewerFrameworks 43 scope 44 \nPackage : ViewerFramework 45 \nModule : basicCommand.py 46 \nClass : UndoCommand 47 \nCommand : Undo 48 \nSynopsis:\n 49 None <- Undo() 50 """ 51
52 - def __init__(self, func=None):
53 Command.__init__(self, func) 54 self.ctr = 1 # used to assure unique keys for _undoArgs 55 self._undoArgs = {} # this dict is used to save large Python objects
56 # that we do not want to turn into strings 57
58 - def get_ctr(self):
59 #used to build unique '_undoArg_#' strings 60 #cannot simply use len(self_undoArgs)+1 61 #because some entries may have been removed 62 # for instance, using len(self_undoArgs)+1 only 63 # add 1: _undoArg_1, add another: _undoArg_2 64 # remove _undoArg_1 65 # next addition would replicate _undoArg_2 66 if not len(self._undoArgs): 67 self.ctr = 1 68 else: 69 self.ctr += 1 70 return self.ctr
71 72
73 - def saveUndoArg(self, arg):
74 """Add arg to self._undoArgs under a unique name and returns this name 75 """ 76 name = '_undoArg_%d'%len(self._undoArgs) 77 i = 1 78 while self._undoArgs.has_key(name): 79 name = '_undoArg_%d'%(self.get_ctr()) 80 i += 1 81 self._undoArgs[name] = arg 82 return name
83 84
85 - def validateUserPref(self, value):
86 try: 87 val = int(value) 88 if val >-1: 89 return 1 90 else: 91 return 0 92 except: 93 return 0
94 95 96
97 - def onAddCmdToViewer(self):
98 doc = """Number of commands that can be undone""" 99 self.setLabel() 100 self.vf.userpref.add( 'NumberOfUndo', 100, 101 validateFunc=self.validateUserPref, 102 doc=doc)
103
104 - def doit(self):
105 if len(self.vf.undoCmdStack): 106 command = self.vf.undoCmdStack.pop()[0] 107 localDict = {'self':self.vf} 108 localDict.update( self._undoArgs ) # add undoArgs to local dict 109 exec( command, sys.modules['__main__'].__dict__, localDict) 110 # remove _undoArg_%d used by this command from self._undoArgs dict 111 ind = command.find('_undoArg_') 112 while ind != -1 and ind < len(command)-10: 113 name = command[ind: ind+9] 114 end = ind+9 115 # add digits following string 116 while command[end].isdigit(): 117 name += command[end] 118 end +=1 119 nodes = self._undoArgs[name] 120 del self._undoArgs[name] 121 new_start = ind + len(name) 122 ind = command[new_start:].find('_undoArg_') 123 if ind!=-1: 124 ind = ind + new_start 125 126 #exec( command, self.vf.__dict__ ) 127 self.setLabel()
128 129
130 - def guiCallback(self, event=None):
131 self.doitWrapper(topCommand=0, log=0, busyIdle=1)
132 133
134 - def __call__(self, **kw):
135 """None<---Undo() 136 """ 137 self.doitWrapper(topCommand=0, log=0, busyIdle=1)
138 139
140 - def addEntry(self, undoString, menuString):
141 self.vf.undoCmdStack.append( (undoString, menuString) ) 142 maxLen = self.vf.userpref['NumberOfUndo']['value'] 143 if maxLen>0 and len(self.vf.undoCmdStack)>maxLen: 144 self.vf.undoCmdStack = self.vf.undoCmdStack[-maxLen:] 145 self.vf.undo.setLabel()
146 147
148 - def setLabel(self):
149 """change menu entry label to show comand name""" 150 151 if not self.vf.hasGui: return 152 cmdmenuEntry = self.GUI.menu[4]['label'] 153 if len(self.vf.undoCmdStack)==0: 154 state = 'disabled' 155 label = 'Undo ' 156 if self.vf.GUI.menuBars.has_key('Toolbar'): 157 TButton = self.vf.GUI.menuBars['Toolbar']._frame.toolbarButtonDict['Undo'] 158 TButton.disable() 159 if hasattr(self,'balloon'): 160 self.balloon.destroy() 161 162 self.balloon = Pmw.Balloon(self.vf.GUI.ROOT) 163 self.balloon.bind(TButton, 'Undo') 164 #rebind other functions from toolbarbutton 165 TButton.bind("<Enter>", TButton.buttonEnter, '+') 166 TButton.bind("<Leave>", TButton.buttonLeave, '+') 167 TButton.bind("<ButtonPress-1>", TButton.buttonDown) 168 TButton.bind("<ButtonRelease-1>", TButton.buttonUp) 169 170 else: 171 state='normal' 172 label = 'Undo ' + self.vf.undoCmdStack[-1][1] 173 if self.vf.GUI.menuBars.has_key('Toolbar'): 174 TButton = self.vf.GUI.menuBars['Toolbar']._frame.toolbarButtonDict['Undo'] 175 TButton.enable() 176 if hasattr(self,'balloon'): 177 self.balloon.destroy() 178 self.balloon = Pmw.Balloon(self.vf.GUI.ROOT) 179 self.balloon.bind(TButton, label) 180 #rebind other functions from toolbarbutton 181 TButton.bind("<Enter>", TButton.buttonEnter, '+') 182 TButton.bind("<Leave>", TButton.buttonLeave, '+') 183 TButton.bind("<ButtonPress-1>", TButton.buttonDown) 184 TButton.bind("<ButtonRelease-1>", TButton.buttonUp) 185 self.vf.GUI.configMenuEntry(self.GUI.menuButton, cmdmenuEntry, 186 label=label, state=state) 187 self.GUI.menu[4]['label']=label
188 189
190 -class ResetUndoCommand(Command):
191 """ Class to reset Undo() 192 \nPackage : ViewerFramework 193 \nModule : basicCommand.py 194 \nClass : ResetUndoCommand 195 \nCommand : resetUndo 196 \nSynopsis:\n 197 None<---resetUndo() 198 """ 199
200 - def doit(self):
201 self.vf.undoCmdStack = [] 202 self.vf.undo._undoArgs = {} # reset dict used to save large Python objects 203 self.vf.undo.setLabel()
204
205 - def __call__(self, **kw):
206 """None<---resetUndo() 207 """ 208 apply( self.doitWrapper, (), kw )
209 210
211 -class BrowseCommandsCommand(Command):
212 """Command to load dynamically either modules or individual commands 213 in the viewer. 214 \nPackage : ViewerFramework 215 \nModule : basicCommand.py 216 \nClass : BrowseCommandsCommand 217 \nCommand : browseCommands 218 \nSynopsis:\n 219 None <-- browseCommands(module, commands=None, package=None, **kw) 220 \nRequired Arguements:\n 221 module --- name of the module(eg:colorCommands) 222 \nOptional Arguements:\n 223 commnads --- one list of commands to load 224 \npackage --- name of the package to which module belongs(eg:Pmv,Vision) 225 """
226 - def __init__(self, func=None):
227 Command.__init__(self, func) 228 self.allPack = {} 229 self.packMod = {} 230 self.allPackFlag = False
231
232 - def doit(self, module, commands=None, package=None):
233 # If the package is not specified the default is the first library 234 global commandslist,cmd_docslist 235 if package is None: package = self.vf.libraries[0] 236 237 importName = package + '.' + module 238 try: 239 mod = __import__(importName, globals(), locals(), 240 [module]) 241 except: 242 if self.cmdForms.has_key('loadCmds') and \ 243 self.cmdForms['loadCmds'].f.winfo_toplevel().wm_state() == \ 244 'normal': 245 self.vf.warningMsg("ERROR: Could not load module %s"%module, 246 parent = self.cmdForms['loadCmds'].root) 247 elif self.vf.loadModule.cmdForms.has_key('loadModule') and \ 248 self.vf.loadModule.cmdForms['loadModule'].f.winfo_toplevel().wm_state() == \ 249 'normal': 250 self.vf.warningMsg("ERROR: Could not load module %s"%module, 251 parent = self.vf.loadModule.cmdForms['loadModule'].root) 252 else: 253 self.vf.warningMsg("ERROR: Could not load module %s"%module) 254 traceback.print_exc() 255 return 'ERROR' 256 if commands is None: 257 if hasattr(mod,"initModule"): 258 mod.initModule(self.vf) 259 if hasattr(mod, 'commandList'): 260 for x in mod.commandList: 261 cmd=x['name'] 262 c=x['cmd'] 263 if cmd not in cmd_docslist: 264 if hasattr(c,'__doc__'): 265 cmd_docslist[cmd]=c.__doc__ 266 if cmd not in commandslist: 267 commandslist.append(cmd) 268 269 else: 270 if self.cmdForms.has_key('loadCmds') and \ 271 self.cmdForms['loadCmds'].f.winfo_toplevel().wm_state() == \ 272 'normal': 273 self.vf.warningMsg("ERROR: Could not load module %s"%module, 274 parent = self.cmdForms['loadCmds'].root) 275 elif self.vf.loadModule.cmdForms.has_key('loadModule') and \ 276 self.vf.loadModule.cmdForms['loadModule'].f.winfo_toplevel().wm_state() == \ 277 'normal': 278 self.vf.warningMsg("ERROR: Could not load module %s"%module, 279 parent = self.vf.loadModule.cmdForms['loadModule'].root) 280 else: 281 self.vf.warningMsg("ERROR: Could not load module %s"%module) 282 return "ERROR" 283 else: 284 if not type(commands) in [types.ListType, types.TupleType]: 285 commands = [commands,] 286 if not hasattr(mod, 'commandList'): 287 return 288 for cmd in commands: 289 d = filter(lambda x: x['name'] == cmd, mod.commandList) 290 if len(d) == 0: 291 self.vf.warningMsg("Command %s not found in module %s.%s"% 292 (cmd, package, module)) 293 continue 294 d = d[0] 295 if cmd not in cmd_docslist: 296 if hasattr(d['cmd'],'__doc__'): 297 cmd_docslist[cmd]=d['cmd'].__doc__ 298 if cmd not in commandslist: 299 commandslist.append(cmd) 300 self.vf.addCommand(d['cmd'], d['name'], d['gui'])
301 302
303 - def __call__(self, module, commands=None, package=None, **kw):
304 """None<---browseCommands(module, commands=None, package=None, **kw) 305 \nmodule --- name of the module(eg:colorCommands) 306 \ncommnads --- one list of commands to load 307 \npackage --- name of the package to which module belongs(eg:Pmv,Vision) 308 """ 309 kw['commands'] = commands 310 kw['package'] = package 311 apply(self.doitWrapper, (module,), kw )
312 313
314 - def buildFormDescr(self, formName):
315 import Tkinter 316 if not formName == 'loadCmds': return 317 idf = InputFormDescr(title='Load Modules and Commands') 318 pname = self.vf.libraries 319 #when Pvv.startpvvCommnads is loaded some how Volume.Pvv is considered 320 #as seperate package and is added to packages list in the widget 321 #To avoid this packages having '.' are removed 322 for p in pname: 323 if '.' in p: 324 ind = pname.index(p) 325 del pname[ind] 326 327 idf.append({'name':'packList', 328 'widgetType':kbScrolledListBox, 329 'wcfg':{'items':pname, 330 #'defaultValue':pname[0], 331 'listbox_exportselection':0, 332 'labelpos':'nw', 333 'label_text':'Select a package:', 334 #'dblclickcommand':self.loadMod_cb, 335 'selectioncommand':self.displayMod_cb 336 }, 337 'gridcfg':{'sticky':'wesn'}}) 338 339 340 idf.append({'name':'modList', 341 'widgetType':kbScrolledListBox, 342 'wcfg':{'items':[], 343 'listbox_exportselection':0, 344 'labelpos':'nw', 345 'label_text':'Select a module:', 346 #'dblclickcommand':self.loadMod_cb, 347 'selectioncommand':self.displayCmds_cb, 348 }, 349 'gridcfg':{'sticky':'wesn', 'row':-1}}) 350 351 idf.append({'name':'cmdList', 352 'widgetType':kbScrolledListBox, 353 'wcfg':{'items':[], 354 'listbox_exportselection':0, 355 'listbox_selectmode':'extended', 356 'labelpos':'nw', 357 'label_text':'Select commands:', 358 #'dblclickcommand':self.loadCmd_cb, 359 'selectioncommand':self.displayCmds_cb, 360 }, 361 'gridcfg':{'sticky':'wesn', 'row':-1}}) 362 363 364 365 idf.append({'name':'docbutton', 366 'widgetType':Tkinter.Checkbutton, 367 #'parent':'DOCGROUP', 368 'defaultValue':0, 369 'wcfg':{'text':'Show documentation', 370 'onvalue':1, 371 'offvalue':0, 372 'command':self.showdoc_cb, 373 'variable':Tkinter.IntVar()}, 374 'gridcfg':{'sticky':'nw','columnspan':3}}) 375 376 idf.append({'name':'DOCGROUP', 377 'widgetType':Pmw.Group, 378 'container':{'DOCGROUP':"w.interior()"}, 379 'collapsedsize':0, 380 'gridcfg':{'sticky':'wnse', 'columnspan':3}}) 381 idf.append({'name':'doclist', 382 'widgetType':kbScrolledListBox, 383 'parent':'DOCGROUP', 384 'wcfg':{'items':[], 385 'listbox_exportselection':0, 386 'listbox_selectmode':'extended', 387 }, 388 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) 389 390 idf.append({'name':'allPacks', 391 'widgetType':Tkinter.Button, 392 'wcfg':{'text':'Show all', 393 'command':self.allPacks_cb}, 394 'gridcfg':{'sticky':'ew'}}) 395 396 idf.append({'name':'loadMod', 397 'widgetType':Tkinter.Button, 398 'wcfg':{'text':'Load Module', 399 'command':self.loadMod_cb}, 400 'gridcfg':{'sticky':'ew', 'row':-1}}) 401 402 idf.append({'name':'loadCmd', 403 'widgetType':Tkinter.Button, 404 'wcfg':{'text':'Load Command', 405 'command':self.loadCmd_cb}, 406 'gridcfg':{'sticky':'ew', 'row':-1}}) 407 408 idf.append({'name':'dismiss', 409 'widgetType':Tkinter.Button, 410 'wcfg':{'text':'DISMISS', 411 'command':self.dismiss_cb, 412 }, 413 'gridcfg':{'sticky':Tkinter.E+Tkinter.W,'columnspan':3}}) 414 415 416 return idf
417
418 - def guiCallback(self):
419 self.vf.GUI.ROOT.config(cursor='watch') 420 self.vf.GUI.ROOT.update() 421 if self.allPack == {}: 422 self.allPack = findAllPmvPackages() 423 val = self.showForm('loadCmds', force=1,modal=0,blocking=0) 424 ebn = self.cmdForms['loadCmds'].descr.entryByName 425 docb=ebn['docbutton']['widget'] 426 var=ebn['docbutton']['wcfg']['variable'].get() 427 if var==0: 428 dg=ebn['DOCGROUP']['widget'] 429 dg.collapse() 430 self.vf.GUI.ROOT.config(cursor='')
431
432 - def dismiss_cb(self, event=None):
433 self.cmdForms['loadCmds'].withdraw()
434
435 - def allPacks_cb(self, event=None):
436 ebn = self.cmdForms['loadCmds'].descr.entryByName 437 packW = ebn['packList']['widget'] 438 if not self.allPackFlag: 439 packName = self.allPack.keys() 440 packW.setlist(packName) 441 ebn['allPacks']['widget'].configure(text='Show default') 442 self.allPackFlag = True 443 else: 444 packName = self.vf.libraries 445 packW.setlist(packName) 446 ebn['allPacks']['widget'].configure(text='Show all') 447 self.allPackFlag = False 448 449 ebn['modList']['widget'].clear() 450 ebn['cmdList']['widget'].clear()
451 452
453 - def showdoc_cb(self,event=None):
454 #when a show documentation is on and a module is selected then 455 #expands dg else dg is collapsed 456 ebn = self.cmdForms['loadCmds'].descr.entryByName 457 docb=ebn['docbutton']['widget'] 458 var=ebn['docbutton']['wcfg']['variable'].get() 459 dg=ebn['DOCGROUP']['widget'] 460 docw=ebn['doclist']['widget'] 461 packW = ebn['packList']['widget'] 462 psel=packW.getcurselection() 463 if var==0: 464 dg.collapse() 465 if var==1 and psel: 466 if docw.size()>0: 467 dg.expand()
468 469
470 - def displayMod_cb(self, event=None):
471 472 # c = self.cmdForms['loadCmds'].mf.cget('cursor') 473 474 # self.cmdForms['loadCmds'].mf.configure(cursor='watch') 475 # self.cmdForms['loadCmds'].mf.update_idletasks() 476 ebn = self.cmdForms['loadCmds'].descr.entryByName 477 docb=ebn['docbutton']['widget'] 478 var=ebn['docbutton']['wcfg']['variable'].get() 479 dg = ebn['DOCGROUP']['widget'] 480 dg.collapse() 481 packW = ebn['packList']['widget'] 482 packs = packW.getcurselection() 483 if len(packs) == 0: 484 return 485 packName = packs[0] 486 if not self.packMod.has_key(packName): 487 package = self.allPack[packName] 488 self.packMod[packName] = findModulesInPackage(package,"^def initModule",fileNameFilters=['Command']) 489 self.currentPack = packName 490 modNames = [] 491 for key, value in self.packMod[packName].items(): 492 pathPack = key.split(os.path.sep) 493 if pathPack[-1] == packName: 494 newModName = map(lambda x: x[:-3], value) 495 #for mname in newModName: 496 #if "Command" not in mname : 497 #ind = newModName.index(mname) 498 #del newModName[ind] 499 modNames = modNames+newModName 500 else: 501 pIndex = pathPack.index(packName) 502 prefix = join(pathPack[pIndex+1:], '.') 503 newModName = map(lambda x: "%s.%s"%(prefix, x[:-3]), value) 504 #for mname in newModName: 505 #if "Command" not in mname : 506 #ind = newModName.index(mname) 507 #del newModName[ind] 508 modNames = modNames+newModName 509 modNames.sort() 510 modW = ebn['modList']['widget'] 511 modW.setlist(modNames) 512 # and clear contents in self.libraryGUI 513 cmdW = ebn['cmdList']['widget'] 514 cmdW.clear() 515 m = __import__(packName, globals(), locals(),[]) 516 d = [] 517 docstring=m.__doc__ 518 #d.append(m.__doc__) 519 docw = ebn['doclist']['widget'] 520 docw.clear() 521 #formatting documentation. 522 if docstring!=None : 523 if '\n' in docstring: 524 x = string.split(docstring,"\n") 525 for i in x: 526 if i !='': 527 d.append(i) 528 if len(d)>8: 529 docw.configure(listbox_height=8) 530 else: 531 docw.configure(listbox_height=len(d)) 532 else: 533 x = string.split(docstring," ") 534 #formatting documenation 535 if len(x)>10: 536 docw.configure(listbox_height=len(x)/10) 537 else: 538 docw.configure(listbox_height=1) 539 540 541 542 docw.setlist(d) 543 544 # self.cmdForms['loadCmds'].mf.configure(cursor=c) 545 #when show documentation on after selcting a package 546 #dg is expanded to show documenttation 547 if var==1 and docw.size()>0: 548 dg.expand()
549
550 - def displayCmds_cb(self, event=None):
551 global cmd_docslist 552 self.cmdForms['loadCmds'].mf.update_idletasks() 553 554 ebn = self.cmdForms['loadCmds'].descr.entryByName 555 docb=ebn['docbutton']['widget'] 556 var=ebn['docbutton']['wcfg']['variable'].get() 557 modName = ebn['modList']['widget'].getcurselection() 558 if modName == (0 or ()): return 559 else: 560 561 modName = modName[0] 562 importName = self.currentPack + '.' + modName 563 try: 564 m = __import__(importName, globals(), locals(),['commandList']) 565 except: 566 567 self.warningMsg("ERROR: Cannot find commands for %s"%modName) 568 return 569 570 if not hasattr(m, 'commandList'): 571 return 572 cmdNames = map(lambda x: x['name'], m.commandList) 573 cmdNames.sort() 574 dg = ebn['DOCGROUP']['widget'] 575 dg.collapse() 576 if modName: 577 self.var=1 578 d =[] 579 docstring =m.__doc__ 580 import string 581 docw = ebn['doclist']['widget'] 582 docw.clear() 583 if docstring!=None : 584 if '\n' in docstring: 585 x = string.split(docstring,"\n") 586 for i in x: 587 if i !='': 588 d.append(i) 589 #formatting documenation 590 if len(d)>8: 591 docw.configure(listbox_height=8) 592 else: 593 docw.configure(listbox_height=len(d)) 594 else: 595 d.append(docstring) 596 x = string.split(docstring," ") 597 #formatting documenation 598 if len(x)>10: 599 docw.configure(listbox_height=len(x)/10) 600 else: 601 docw.configure(listbox_height=1) 602 603 docw.setlist(d) 604 cmdW = ebn['cmdList']['widget'] 605 CmdName=ebn['cmdList']['widget'].getcurselection() 606 cmdW.setlist(cmdNames) 607 if len(CmdName)!=0: 608 for i in m.commandList: 609 if i['name']==CmdName[0]: 610 c = i['cmd'] 611 if CmdName[0] in cmdNames: 612 ind= cmdNames.index(CmdName[0]) 613 cmdW.selection_clear() 614 cmdW.selection_set(ind) 615 d =[] 616 docstring=c.__doc__ 617 docw = ebn['doclist']['widget'] 618 docw.clear() 619 if CmdName[0] not in cmd_docslist.keys(): 620 cmd_docslist[CmdName[0]]=d 621 import string 622 if docstring!=None : 623 if '\n' in docstring: 624 x = string.split(docstring,"\n") 625 for i in x: 626 if i !='': 627 d.append(i) 628 if len(d)>8: 629 docw.configure(listbox_height=8) 630 else: 631 docw.configure(listbox_height=len(d)) 632 else: 633 d.append(docstring) 634 x = string.split(docstring," ") 635 if len(x)>10: 636 docw.configure(listbox_height=len(x)/10) 637 else: 638 docw.configure(listbox_height=1) 639 640 docw.setlist(d) 641 #when show documentation is on after selcting a module or a command 642 #dg is expanded to show documenttation 643 if var==1 and docw.size()>0: 644 dg.expand()
645 - def loadMod_cb(self, event=None):
646 ebn = self.cmdForms['loadCmds'].descr.entryByName 647 selMod = ebn['modList']['widget'].getcurselection() 648 if len(selMod)==0: return 649 else: 650 apply(self.doitWrapper, ( selMod[0],), 651 {'commands':None, 'package':self.currentPack})
652
653 - def loadCmd_cb(self, event=None):
654 ebn = self.cmdForms['loadCmds'].descr.entryByName 655 selCmds = ebn['cmdList']['widget'].getcurselection() 656 selMod = ebn['modList']['widget'].getcurselection() 657 if len(selCmds)==0: return 658 else: 659 apply(self.doitWrapper, (selMod[0],), {'commands':selCmds, 660 'package':self.currentPack})
661
662 -class loadModuleCommand(Command):
663 """Command to load dynamically modules to the Viewer import the file called name.py and execute the function initModule defined in that file Raises a ValueError exception if initModule is not defined 664 \nPackage : ViewerFramework 665 \nModule : basicCommand.py 666 \nClass : loadModuleCommand 667 \nCommand : loadModule 668 \nSynopsis:\n 669 None<--loadModule(filename, package=None, **kw) 670 \nRequired Arguements:\n 671 filename --- name of the module 672 \nOptional Arguements:\n 673 package --- name of the package to which filename belongs 674 """ 675 676 active = 0 677
678 - def doit(self, filename, package):
679 # This is NOT called because we call browseCommand()" 680 if package is None: 681 _package = filename 682 else: 683 _package = "%s.%s"%(package, filename) 684 try: 685 mod = __import__( _package, globals(), locals(), ['initModule']) 686 if hasattr(mod, 'initModule') or not callable(mod.initModule): 687 mod.initModule(self.vf) 688 else: 689 self.vf.warningMsg('module %s has not initModule function') 690 except ImportError: 691 self.vf.warningMsg('module %s could not be imported'%_package)
692 693 694 ## if package is None: 695 ## _package = filename 696 ## else: 697 ## _package = "%s.%s"%(package, filename) 698 ## module = self.vf.tryto( __import__ , _package, globals(), locals(), 699 ## [filename]) 700 ## if module=='ERROR': 701 ## print '\nWARNING: Could not load module %s' % filename 702 ## return 703 704
705 - def __call__(self, filename, package=None, **kw):
706 """None<---loadModule(filename, package=None, **kw) 707 \nRequired Arguements:\n 708 filename --- name of the module 709 \nOptional Arguements:\n 710 package --- name of the package to which filename belongs 711 """ 712 if package==None: 713 package=self.vf.libraries[0] 714 if not kw.has_key('redraw'): 715 kw['redraw'] = 0 716 kw['package'] = package 717 apply(self.vf.browseCommands, (filename,), kw)
718 #apply( self.doitWrapper, (filename, package), kw ) 719 720
721 - def loadModule_cb(self, event=None):
722 723 # c = self.cmdForms['loadModule'].mf.cget('cursor') 724 # self.cmdForms['loadModule'].mf.configure(cursor='watch') 725 # self.cmdForms['loadModule'].mf.update_idletasks() 726 ebn = self.cmdForms['loadModule'].descr.entryByName 727 moduleName = ebn['Module List']['widget'].get() 728 package = ebn['package']['widget'].get() 729 if moduleName: 730 self.vf.browseCommands(moduleName[0], package=package, redraw=0)
731 # self.cmdForms['loadModule'].mf.configure(cursor=c)
732 - def loadModules(self, package, library=None):
733 modNames = [] 734 doc = [] 735 self.filenames={} 736 self.allPack={} 737 self.allPack=findAllPmvPackages() 738 if package is None: return [], [] 739 if not self.filenames.has_key(package): 740 pack=self.allPack[package] 741 #finding modules in a package 742 self.filenames[pack] =findModulesInPackage(pack,"^def initModule",fileNameFilters=['Command']) 743 # dictionary of files keys=widget, values = filename 744 for key, value in self.filenames[pack].items(): 745 pathPack = key.split(os.path.sep) 746 if pathPack[-1] == package: 747 newModName = map(lambda x: x[:-3], value) 748 #for mname in newModName: 749 #if not modulename has Command in it delete from the 750 #modules list 751 #if "Command" not in mname : 752 #ind = newModName.index(mname) 753 #del newModName[ind] 754 #if "Command" in mname : 755 if hasattr(newModName,"__doc__"): 756 doc.append(newModName.__doc__) 757 else: 758 doc.append(None) 759 modNames = modNames + newModName 760 761 else: 762 pIndex = pathPack.index(package) 763 prefix = join(pathPack[pIndex+1:], '.') 764 newModName = map(lambda x: "%s.%s"%(prefix, x[:-3]), value) 765 #for mname in newModName: 766 #if not modulename has Command in it delete from the 767 #modules list 768 #if "Command" not in mname : 769 #ind = newModName.index(mname) 770 #del newModName[ind] 771 if hasattr(newModName,"__doc__"): 772 doc.append(newModName.__doc__) 773 else: 774 doc.append(None) 775 modNames = modNames + newModName 776 modNames.sort() 777 return modNames, doc
778 779
780 - def package_cb(self, event=None):
781 ebn = self.cmdForms['loadModule'].descr.entryByName 782 pack = ebn['package']['widget'].get() 783 names, docs = self.loadModules(pack) 784 w = ebn['Module List']['widget'] 785 w.clear() 786 for n,d in map(None, names, docs): 787 w.insert('end', n, d)
788
789 - def buildFormDescr(self, formName):
790 """create the cascade menu for selecting modules to be loaded""" 791 if not formName == 'loadModule':return 792 ifd = InputFormDescr(title='Load command Modules') 793 names, docs = self.loadModules(self.vf.libraries[0]) 794 entries = map(lambda x: (x, None), names) 795 pname=self.vf.libraries 796 for p in pname: 797 if '.' in p: 798 ind = pname.index(p) 799 del pname[ind] 800 ifd.append({ 801 'name':'package', 802 'widgetType': Pmw.ComboBox, 803 'defaultValue': pname[0], 804 'wcfg':{ 'labelpos':'nw', 'label_text':'Package:', 805 'selectioncommand': self.package_cb, 806 'scrolledlist_items':pname 807 }, 808 'gridcfg':{'sticky':'ew', 'padx':2, 'pady':1} 809 }) 810 811 ifd.append({'name': 'Module List', 812 'widgetType':ListChooser, 813 'wcfg':{ 814 'title':'Choose a module', 815 'entries': entries, 816 'lbwcfg':{'width':27,'height':10}, 817 'command':self.loadModule_cb, 818 'commandEvent':"<Double-Button-1>" 819 }, 820 'gridcfg':{'sticky':Tkinter.E+Tkinter.W} 821 }) 822 823 ifd.append({'name': 'Load Module', 824 'widgetType':Tkinter.Button, 825 'wcfg':{'text':'Load Module', 826 'command': self.loadModule_cb, 827 'bd':6}, 828 'gridcfg':{'sticky':Tkinter.E+Tkinter.W}, 829 }) 830 831 ifd.append({'widgetType':Tkinter.Button, 832 'wcfg':{'text':'Dismiss', 833 'command': self.Dismiss_cb}, 834 'gridcfg':{'sticky':Tkinter.E+Tkinter.W}}) 835 return ifd
836
837 - def Dismiss_cb(self):
838 self.cmdForms['loadModule'].withdraw() 839 self.active = 0
840 841
842 - def guiCallback(self, event=None):
843 if self.active: return 844 self.active = 1 845 form = self.showForm('loadModule', force=1,modal=0,blocking=0) 846 form.root.protocol('WM_DELETE_WINDOW',self.Dismiss_cb)
847 848 849
850 -class loadCommandCommand(loadModuleCommand):
851 """Command to load dynamically individual commands in the Viewer. 852 \nPackage : ViewerFramework 853 \nModule : basicCommand.py 854 \nClass : loadCommandCommand 855 \nCommand : loadCommand 856 \nSynopsis:\n 857 None <- loadCommand(moduleName, commandsName, package=None, 858 gui=None) 859 \nRequired Arguements:\n 860 moduleName --- name of the module to be loaded 861 commandsName --- name of the Command or list of Commands 862 \nOptional Arguements:\n 863 package --- name of the package to which filename belongs 864 """ 865 active = 0 866
867 - def doit(self, module, commands, package=None, gui=None):
868 """Load a command instance with the given alias and gui""" 869 if package is None: 870 package = self.vf.libraries[0] 871 872 if not type(commands)!=types.ListType: 873 commands = [commands,] 874 875 for command in commands: 876 cmd, name, gui = self.getDefaults(package, module, command) 877 if cmd is None: 878 print 'Could not add %s.%s.%s'%(package, module, command) 879 continue 880 self.vf.addCommand( cmd, name, gui )
881
882 - def guiCallback(self, event=None):
883 if self.active: return 884 self.active = 1 885 form = self.showForm('loadCommand', force=1,modal=0,blocking=0) 886 form.root.protocol('WM_DELETE_WINDOW',self.Dismiss_cb)
887
888 - def package_cb(self, event=None):
889 # Get Package. 890 ebn = self.cmdForms['loadCommand'].descr.entryByName 891 pack = ebn['package']['widget'].get() 892 # Get Modules for the new package and update the listChooser. 893 names, docs = self.loadModules(pack) 894 mw = ebn['Module List']['widget'] 895 mw.clear() 896 for n in names: 897 mw.insert('end',n) 898 mw.set(names[0]) 899 900 # Get Commands for the first module and update the listChooser 901 cw = ebn['Command List']['widget'] 902 cw.clear() 903 cmds = self.getModuleCmds(modName=names[0], 904 package=pack) 905 if cmds==None: 906 return 907 for cmd in map(lambda x: x[0],cmds): 908 cw.insert('end', cmd)
909 910
911 - def Dismiss_cb(self):
912 self.cmdForms['loadCommand'].withdraw() 913 self.active = 0
914 915
916 - def __call__(self, moduleName, commandsName, 917 package=None, gui=None, **kw):
918 """None <- loadCommand(moduleName, commandsName, package=None, 919 gui=None) 920 \nRequired Arguements:\n 921 moduleName --- name of the module to be loaded 922 commandsName --- name of the Command or list of Commands 923 \nOptional Arguements:\n 924 package --- name of the package to which filename belongs 925 """ 926 kw['package'] = package 927 #kw['gui'] = gui 928 #apply(self.doitWrapper, (moduleName, commandsName), kw) 929 kw['commands']=commandsName 930 apply(self.vf.browseCommands, (moduleName,), kw)
931 932
933 - def getDefaults(self, package, filename, commandName):
934 if package is None: _package = filename 935 else: _package = "%s.%s"%(package, filename) 936 937 mod = self.vf.tryto(__import__,_package, globals(), locals(), 938 [filename]) 939 if mod=='ERROR': 940 print '\nERROR: Could not load module %s.%s' % (_package, 941 filename) 942 return None,None,None 943 944 for d in mod.commandList: 945 if d['name']==commandName: 946 break 947 if d['name']!=commandName: 948 print '\nERROR: command %s not found in module %s.%s\n' % \ 949 (commandName, package, filename) 950 return None,None,None 951 952 return d['cmd'], d['name'], d['gui']
953 954
955 - def loadCmd_cb(self, event=None):
956 # c = self.cmdForms['loadCommand'].mf.cget('cursor') 957 # self.cmdForms['loadCommand'].mf.configure(cursor='watch') 958 # self.cmdForms['loadCommand'].mf.update_idletasks() 959 ebn = self.cmdForms['loadCommand'].descr.entryByName 960 module = ebn['Module List']['widget'].get() 961 commands = ebn['Command List']['widget'].get() 962 package = ebn['package']['widget'].get() 963 if commands: 964 kw = {'package': package} 965 #apply(self.doitWrapper, (module, commands), kw) 966 kw['commands'] = commands 967 apply(self.vf.browseCommands, (module[0],), kw)
968 969 # self.cmdForms['loadCommand'].mf.configure(cursor=c)
970 - def getModuleCmds(self, modName=None, package=None):
971 """ Callback method of the module chooser to get the corresponding 972 commands: 973 """ 974 filename = modName 975 if package is None: _package = filename 976 else: _package = "%s.%s"%(package, filename) 977 try: 978 mod = __import__(_package,globals(),locals(),['commandList']) 979 except: 980 981 self.vf.warningMsg("ERROR: Could not load module %s "%filename) 982 return "ERROR" 983 if hasattr(mod,"initModule"): 984 mod.initModule(self.vf) 985 else: 986 self.vf.warningMsg("ERROR: Could not load module %s"%filename) 987 return 988 if not hasattr(mod, 'commandList'): 989 cmdEntries = [] 990 else: 991 cmdsName = map(lambda x: x['name'], mod.commandList) 992 cmdsName.sort() 993 cmdEntries = map(lambda x: (x,None), cmdsName) 994 return cmdEntries
995 996
997 - def modChooser_cb(self, event=None):
998 """CallBack method that gets called when clicking on an entry 999 of the mocule cjooser.""" 1000 1001 ebn = self.cmdForms['loadCommand'].descr.entryByName 1002 modChooser = ebn['Module List']['widget'] 1003 filename = modChooser.get()[0] 1004 package = ebn['package']['widget'].get() 1005 cmdEntries = self.getModuleCmds(modName=filename, package=package) 1006 cmdChooser = ebn['Command List']['widget'] 1007 cmdChooser.clear() 1008 #cmdEntries should be a list if there are no commands for a module then getModuleCmds returns None or Error in that case cmdEntries is made equal to emptylist 1009 if cmdEntries=="ERROR" or cmdEntries==None: 1010 cmdEntries=[] 1011 map(cmdChooser.add, cmdEntries)
1012 1013
1014 - def buildFormDescr(self, formName):
1015 """Create the pulldown menu and Listchooser to let for the 1016 selection of commands.""" 1017 if not formName == 'loadCommand': return 1018 ifd = InputFormDescr(title='Load Individual Commands') 1019 moduleNames, docs = self.loadModules(self.vf.libraries[0]) 1020 moduleNames.sort() 1021 moduleEntries = map(lambda x: (x, None), moduleNames) 1022 pname = self.vf.libraries 1023 for p in pname: 1024 if '.' in p: 1025 ind = pname.index(p) 1026 del pname[ind] 1027 ifd.append({ 1028 'name':'package', 1029 'widgetType': Pmw.ComboBox, 1030 'defaultValue': pname[0], 1031 'wcfg':{ 'labelpos':'nw', 'label_text':'Package:', 1032 'selectioncommand': self.package_cb, 1033 'scrolledlist_items':pname 1034 }, 1035 'gridcfg':{'columnspan':2,'sticky':'ew', 'padx':2, 'pady':1} 1036 }) 1037 1038 1039 ifd.append({'name': 'Module List', 1040 'widgetType':ListChooser, 1041 'wcfg':{'title':'Choose a module', 1042 'entries': moduleEntries, 1043 'lbwcfg':{ 'width':25, 1044 'height':10, 1045 'exportselection':0}, 1046 'command':self.modChooser_cb, 1047 }, 1048 'gridcfg':{'sticky':'ew'} 1049 } ) 1050 1051 CmdEntries = [] 1052 ifd.append({'name': 'Command List', 1053 'widgetType':ListChooser, 1054 'wcfg':{'title':'Choose a command', 1055 'mode':'multiple', 1056 'entries': CmdEntries, 1057 'command':self.loadCmd_cb, 1058 'commandEvent':"<Double-Button-1>", 1059 'lbwcfg':{'width':25,'height':10, 1060 'exportselection':0} 1061 }, 1062 'gridcfg':{'row':-1,'sticky':'we'} 1063 } ) 1064 1065 ifd.append({'name': 'Load Command', 1066 'widgetType':Tkinter.Button, 1067 'wcfg':{'text':'Load Command', 1068 'bd':6, 'command': self.loadCmd_cb}, 1069 'gridcfg':{'columnspan':2,'sticky':'ew'}, 1070 }) 1071 1072 ifd.append({'widgetType':Tkinter.Button, 1073 'wcfg':{'text':'Dismiss', 1074 'command': self.Dismiss_cb}, 1075 'gridcfg':{'columnspan':2,'sticky':'ew'}}) 1076 return ifd
1077 1078
1079 -class loadMacroCommand(Command):
1080 """Command to load dynamically macro commands. 1081 \nPackage : ViewerFramework 1082 \nModule : basicCommand.py 1083 \nClass : loadMacroCommand 1084 \nCommand : loadMacro 1085 \nSynopsis:\n 1086 None<---loadMacro(macroName, macroFile, menuBar='menuRoot', 1087 menuButton='Macros', menuEntry=None, cascade=None, **kw) 1088 """ 1089 active = 0 1090
1091 - def getMacros(self, file):
1092 """load all macro functions from a given file""" 1093 names = [] 1094 macros = [] 1095 doc = [] 1096 #if not os.path.exists(file) : return names, macros, doc 1097 _dir, file = os.path.split(file) 1098 if file[-3:]=='.py': file = file[:-3] 1099 import sys 1100 sys.path.insert(0, _dir) 1101 m = __import__(file, globals(), locals(), []) 1102 sys.path = sys.path[1:] 1103 #m.__dict__['self'] = self.vf 1104 setattr(m, 'self', self.vf) 1105 import types 1106 for key, value in m.__dict__.items(): 1107 if type(value) == types.FunctionType: 1108 names.append(key) 1109 macros.append(value) 1110 doc.append(value.__doc__) 1111 return names, macros, doc
1112 1113
1114 - def loadMacLib_cb(self, filename):
1115 """Call back function for 'Open Macro library' button""" 1116 ebn = self.cmdForms['loadMacro'].descr.entryByName 1117 ebn['openMacLib']['widget'].button.configure(relief='sunken') 1118 names, macros, docs = self.getMacros(filename) 1119 self.macroFile = filename 1120 self.macNames = names 1121 self.macMacros = macros 1122 self.macDoc = docs 1123 1124 # Get a handle to the listchooser widget 1125 lc = ebn['macros']['widget'] 1126 lc.clear() 1127 if len(names) == len(docs): 1128 entries = map(lambda x, y: (x, y), names, docs) 1129 else: 1130 entries = map(lambda x: (x, None), names) 1131 map(lc.add, entries) 1132 ebn['openMacLib']['widget'].button.configure(relief='raised') 1133 1134 # set cascade name to libary Name - "mac" 1135 w = ebn['cascade']['widget'] 1136 w.delete(0, 'end') 1137 w.insert(0, os.path.split(filename)[1][:-3])
1138 1139
1140 - def setDefaultEntryName(self, event=None):
1141 """Call back function for the listchooser showing macros. 1142 gets the name of the currently selected macro and puts it in the entry 1143 type in""" 1144 # enable add button 1145 ebn = self.cmdForms['loadMacro'].descr.entryByName 1146 ebn['loadMacro']['widget'].configure(state='normal') 1147 1148 # put default name into name entry 1149 val = ebn['macros']['widget'].get() 1150 w = ebn['menuentry']['widget'] 1151 w.delete(0, 'end') 1152 w.insert(0, val[0])
1153 #self.selectedMac = val[0] 1154 1155
1156 - def loadMacro_cb(self, event=None):
1157 ebn = self.cmdForms['loadMacro'].descr.entryByName 1158 bar = ebn['menubar']['widget'].get() 1159 1160 menub = ebn['menubutton']['widget'].get() 1161 name = ebn['menuentry']['widget'].get() 1162 cascade = ebn['cascade']['widget'].get() 1163 if cascade=='': cascade=None 1164 lc = ebn['macros']['widget'] 1165 macNames = lc.get() 1166 if len(macNames) != 0: macName = macNames[0] 1167 #macIndex = self.macNames.index(self.selectedMac) 1168 #macFunc = self.macMacros[macIndex] 1169 self.doitWrapper(macName, self.macroFile, menuBar=bar, 1170 menuButton=menub, 1171 menuEntry=name, cascade=cascade) 1172 1173 ###self.addMacro(macFunc, bar, menub, name, cascade) 1174 ebn['openMacLib']['widget'].button.configure(relief='raised')
1175
1176 - def dismiss_cb(self):
1177 self.cmdForms['loadMacro'].withdraw() 1178 self.active = 0
1179
1180 - def buildFormDescr(self, formName):
1181 if not formName=='loadMacro': return None 1182 1183 ifd = InputFormDescr(title='Load Macros') 1184 if len(self.vf.libraries) is None: 1185 modu = __import__('ViewerFramework') 1186 else: 1187 modu = __import__(self.vf.libraries[0]) 1188 1189 idir = os.path.split(modu.__file__)[0] + '/Macros' 1190 if not os.path.exists(idir): 1191 idir = None 1192 # 0 1193 ifd.append({'widgetType':LoadButton, 1194 'name':'openMacLib', 1195 'wcfg':{'buttonType':Tkinter.Button, 1196 'title':'Open Macro Library...', 1197 'types':[('Macro Module Library', '*Mac.py'), 1198 ('Any Python Function', '*.py')], 1199 'callback':self.loadMacLib_cb, 1200 'idir':idir, 1201 'widgetwcfg':{'text':'Open Macro Library'}}, 1202 1203 'gridcfg':{'sticky':'we'}}) 1204 1205 # 1 1206 ifd.append({'name':'macros', 1207 'widgetType':ListChooser, 1208 'wcfg':{'title':'Choose a macro', 1209 'command':self.setDefaultEntryName, 1210 'title':'Choose a macro'}, 1211 'gridcfg':{'sticky':Tkinter.E+Tkinter.W}} ) 1212 # 2 1213 ifd.append({'widgetType':Tkinter.Entry, 1214 'name':'menubar', 1215 'defaultValue':'menuRoot', 1216 'wcfg':{'label':'menu bar'}, 1217 'gridcfg':{'sticky':Tkinter.E} 1218 }) 1219 # 3 1220 ifd.append({'widgetType':Tkinter.Entry, 1221 'name':'menubutton', 1222 'defaultValue':'Macros', 1223 'wcfg':{'label':'menu button'}, 1224 'gridcfg':{'sticky':Tkinter.E} 1225 }) 1226 1227 # 4 1228 ifd.append({'widgetType':Tkinter.Entry, 1229 'name':'menuentry', 1230 'defaultValue':'', 1231 'wcfg':{'label':'menu entry'}, 1232 'gridcfg':{'sticky':Tkinter.E} 1233 }) 1234 1235 # 5 1236 ifd.append({'widgetType':Tkinter.Entry, 1237 'name':'cascade', 1238 'defaultValue':'', 1239 'wcfg':{'label':'cascade'}, 1240 'gridcfg':{'sticky':Tkinter.E} 1241 }) 1242 1243 # 6 1244 ifd.append({'name': 'loadMacro', 1245 'widgetType':Tkinter.Button, 1246 'wcfg':{'text':'Load Macro', 1247 'bd':6,'command': self.loadMacro_cb}, 1248 'gridcfg':{'sticky':Tkinter.E+Tkinter.W}, 1249 }) 1250 1251 # 7 1252 ifd.append({'widgetType':Tkinter.Button, 1253 'wcfg':{'text':'Dismiss', 1254 'command': self.dismiss_cb}}) 1255 1256 return ifd
1257
1258 - def guiCallback(self, event=None):
1259 if self.active: return 1260 self.active = 1 1261 val = self.showForm("loadMacro", force=1,modal=0,blocking=0) 1262 ebn = self.cmdForms['loadMacro'].descr.entryByName 1263 ebn['loadMacro']['widget'].configure(state='disabled')
1264
1265 - def __call__(self, macroName, macroFile, menuBar='menuRoot', 1266 menuButton='Macros', menuEntry=None, cascade=None, **kw):
1267 """None<---loadMacro(macroName, macroFile, menuBar='menuRoot', 1268 menuButton='Macros', menuEntry=None, cascade=None, **kw) 1269 """ 1270 self.doitWrapper(macroName, macroFile, menuBar=menuBar, 1271 menuButton=menuButton, menuEntry=menuEntry, 1272 cascade=cascade)
1273
1274 - def doit(self, macroName, macroFile, menuBar='menuRoot', 1275 menuButton='Macros', menuEntry=None, cascade=None):
1276 1277 if not hasattr(self, 'macroFile') or macroFile != self.macroFile: 1278 names, macros, docs = self.getMacros(macroFile) 1279 else: 1280 names = self.macNames 1281 macros = self.macMacros 1282 docs = self.macDoc 1283 if len(names) == 0 or len(macros)==0 or len(docs)==0: return 1284 macIndex = names.index(macroName) 1285 macro = macros[macIndex] 1286 1287 from VFCommand import Command, CommandGUI 1288 c = Command(func=macro) 1289 g = CommandGUI() 1290 if cascade: 1291 g.addMenuCommand(menuBar, menuButton, menuEntry, 1292 cascadeName=cascade) 1293 else: 1294 g.addMenuCommand(menuBar, menuButton, menuEntry) 1295 self.vf.addCommand(c, macro.__name__, g)
1296 1297 1298 1299 ## class loadMacroCommand(Command): 1300 ## """ 1301 ## Command to load dynamically macro commands. 1302 ## Using the Gui the user can open a macro file. The macros available in 1303 ## that file are then displayed in a list chooser. When a macro is selected 1304 ## in the listchooser, its documentation string is deisplayed and a default 1305 ## name for the macro in the viewer is suggested. The user can also specify 1306 ## a menuBar, a menuButton as well as an optional cascade name. 1307 ## """ 1308 1309 ## active = 0 1310 ## def getMacros(self, file): 1311 ## """load all macro functions from file""" 1312 ## self.file = file 1313 ## _dir, file = os.path.split(file) 1314 ## if file[-3:]=='.py': file = file[:-3] 1315 ## import sys 1316 ## sys.path.insert(0, _dir) 1317 ## m = __import__(file, globals(), locals(), []) 1318 ## sys.path = sys.path[1:] 1319 ## m.__dict__['self'] = self.vf 1320 ## import types 1321 ## names = [] 1322 ## macros = [] 1323 ## doc = [] 1324 ## for key,value in m.__dict__.items(): 1325 ## if type(value)==types.FunctionType: 1326 ## names.append(key) 1327 ## macros.append(value) 1328 ## doc.append(value.__doc__) 1329 ## return names, macros, doc 1330 1331 1332 ## def loadMacLib_cb(self, filename): 1333 ## """Call back function for 'Open Macro library' button""" 1334 ## # self.ifd[0]['widget'] is the 'Open Macro Library' button 1335 ## self.ifd[0]['widget'].configure(relief='sunken') 1336 1337 ## #file = os.path.split(filename)[1][:-3] 1338 ## names, macros, docs = self.getMacros(filename) 1339 ## self.macNames = names 1340 ## self.macMacros = macros 1341 ## self.macDoc = docs 1342 ## # Get a handle to the listchooser widget 1343 ## lc = self.ifd[1]['widget'] 1344 ## lc.clear() 1345 ## if len(names) == len(docs): 1346 ## entries = map(lambda x, y: (x, y), names, docs) 1347 ## else: 1348 ## entries = map(lambda x: (x, None), names) 1349 ## map(lc.add, entries) 1350 ## self.ifd[0]['widget'].configure(relief='raised') 1351 ## # set cascade name to libary Name - "mac" 1352 ## w = self.ifd[5]['widget'] 1353 ## w.delete(0, 'end') 1354 ## w.insert(0, os.path.split(filename)[1][:-3]) 1355 1356 1357 ## def setDefaultEntryName(self, event=None): 1358 ## """Call back function for the listchooser showing macros. 1359 ## gets the name of the currently selected macro and puts it in the entry 1360 ## type in""" 1361 ## # enable add button 1362 ## self.ifd.entryByName['Load Macro']['widget'].configure(state='normal') 1363 ## # put default name into name entry 1364 ## val = self.ifd[1]['widget'].get() 1365 ## w = self.ifd[4]['widget'] 1366 ## w.delete(0, 'end') 1367 ## w.insert(0, val[0]) 1368 ## self.selectedMac = val[0] 1369 1370 ## def addMacro(self, macro, menuBar, menuButton, name, cascade=None): 1371 ## from VFCommand import Command, CommandGUI 1372 1373 ## c = Command(func=macro) 1374 ## g = CommandGUI() 1375 ## if cascade: 1376 ## g.addMenuCommand(menuBar, menuButton, name, cascadeName=cascade) 1377 ## else: 1378 ## g.addMenuCommand(menuBar, menuButton, name) 1379 ## self.vf.addCommand(c, macro.__name__, g) 1380 ## ## g.register(self.vf) 1381 ## self.log(file=self.file, macroName=macro.__name__, menuBar=menuBar, 1382 ## menuButton=menuButton, name=name, cascade=cascade) 1383 1384 1385 ## def loadMacro_cb(self, event=None): 1386 ## bar = self.ifd[2]['widget'].get() 1387 ## menub = self.ifd[3]['widget'].get() 1388 ## name = self.ifd[4]['widget'].get() 1389 ## cascade = self.ifd[5]['widget'].get() 1390 ## if cascade=='': cascade=None 1391 ## macIndex = self.macNames.index(self.selectedMac) 1392 ## macFunc = self.macMacros[macIndex] 1393 ## self.addMacro(macFunc, bar, menub, name, cascade) 1394 ## self.ifd[0]['widget'].configure(relief='raised') 1395 1396 1397 ## def customizeGUI(self): 1398 ## """create the cascade menu for selecting modules to be loaded""" 1399 1400 ## self.selectedMac = '' 1401 ## # create the for descriptor 1402 ## ifd = self.ifd = InputFormDescr(title='Load macro commands') 1403 ## if len(self.vf.libraries) is None: 1404 ## modu = __import__('ViewerFramework') 1405 ## else: 1406 ## modu = __import__(self.vf.libraries[0]) 1407 ## idir = os.path.split(modu.__file__)[0] + '/Macros' 1408 ## if not os.path.exists(idir): 1409 ## idir = None 1410 1411 ## ifd.append( {'widgetType':'OpenButton', 'text':'Open Macro library ...', 1412 ## 'types':[('Macro Module Library', '*Mac.py'), 1413 ## ('Any Python Function', '*.py')], 1414 ## 'idir':idir, 1415 ## 'title':'Open Macro File', 1416 ## 'callback': self.loadMacLib_cb } ) 1417 ## ifd.append({'title':'Choose a macro', 1418 ## 'widgetType':ListChooser, 1419 ## 'wcfg':{ 1420 ## 'command':self.setDefaultEntryName, 1421 ## 'title':'Choose a macro'}, 1422 ## 'gridcfg':{'sticky':Tkinter.E+Tkinter.W}} ) 1423 1424 ## ifd.append({'widgetType':Tkinter.Entry, 1425 ## 'defaultValue':'menuRoot', 1426 ## 'wcfg':{'label':'menu bar'}, 1427 ## 'gridcfg':{'sticky':Tkinter.E} 1428 ## }) 1429 ## ifd.append({'widgetType':Tkinter.Entry, 1430 ## 'defaultValue':'Macros', 1431 ## 'wcfg':{'label':'menu button'}, 1432 ## 'gridcfg':{'sticky':Tkinter.E} 1433 ## }) 1434 ## ifd.append({'widgetType':Tkinter.Entry, 1435 ## 'defaultValue':'', 1436 ## 'wcfg':{'label':'menu entry'}, 1437 ## 'gridcfg':{'sticky':Tkinter.E} 1438 ## }) 1439 ## ifd.append({'widgetType':Tkinter.Entry, 1440 ## 'defaultValue':'', 1441 ## 'wcfg':{'label':'cascade'}, 1442 ## 'gridcfg':{'sticky':Tkinter.E} 1443 ## }) 1444 ## ifd.append({'name': 'Load Macro', 1445 ## 'widgetType':Tkinter.Button, 1446 ## 'text':'Load Macro', 1447 ## 'wcfg':{'bd':6}, 1448 ## 'gridcfg':{'sticky':Tkinter.E+Tkinter.W}, 1449 ## 'command': self.loadMacro_cb}) 1450 ## ifd.append({'widgetType':Tkinter.Button, 1451 ## 'text':'Dismiss', 1452 ## 'command': self.Dismiss_cb}) 1453 1454 1455 ## def Dismiss_cb(self): 1456 ## #self.cmdForms['loadMacro'].withdraw() 1457 ## self.ifd.form.destroy() 1458 ## self.active = 0 1459 1460 ## def guiCallback(self, event=None, file=None): 1461 ## if self.active: return 1462 ## self.active = 1 1463 1464 1465 ## self.customizeGUI() 1466 ## self.form = self.vf.getUserInput(self.ifd, modal=0, blocking=0) 1467 ## self.ifd.entryByName['Load Macro']['widget'].configure(state='disabled') 1468 ## if file: self.loadMacLib_cb(file) 1469 1470 1471 ## def __call__(self, file=None, macroName=None, menuBar='menuRoot', 1472 ## menuButton='Macros', name=None, cascade=None): 1473 ## """file=None, macroName=None, menuBar='menuRoot', menuButton='Macros', 1474 ## name=None, cascade=None""" 1475 ## if not macroName: self.guiCallback(file=file) 1476 ## else: 1477 ## if file[-3:]=='.py': file = file[:-3] 1478 ## names, macros, docs = self.getMacros(file) 1479 ## i = names.index(macroName) 1480 ## if name==None: name=macroName 1481 ## self.addMacro(macros[i], menuBar, menuButton, name, cascade) 1482 1483 1484
1485 -class ShellCommand(Command):
1486 """Command to show/Hide the Python shell. 1487 \nPackage : ViewerFramework 1488 \nModule : basicCommand.py 1489 \nClass : ShellCommand 1490 \nCommand : Shell 1491 \nSynopsis:\n 1492 None<---Shell() 1493 """ 1494
1495 - def onAddCmdToViewer(self):
1496 self.vf.GUI.pyshell.top.protocol('WM_DELETE_WINDOW', self.vf.Shell.onDestroy)
1497
1498 - def show(self):
1499 self.vf.GUI.pyshell.top.deiconify()
1500
1501 - def hide(self):
1502 self.vf.GUI.pyshell.top.withdraw()
1503
1504 - def __call__(self, *args):
1505 """None<---Shell() 1506 """ 1507 if args[0]: 1508 self.show() 1509 self.vf.GUI.toolbarCheckbuttons['Shell']['Variable'].set(1) 1510 else: 1511 self.hide() 1512 self.vf.GUI.toolbarCheckbuttons['Shell']['Variable'].set(0)
1513
1514 - def guiCallback(self):
1515 on = self.vf.GUI.toolbarCheckbuttons['Shell']['Variable'].get() 1516 if on: self.show() 1517 else: self.hide()
1518
1519 - def onDestroy(self):
1520 self.vf.GUI.toolbarCheckbuttons['Shell']['Variable'].set(0) 1521 self.hide()
1522 1523 ShellCommandGUI = CommandGUI() 1524 ShellCommandGUI.addToolBar('Shell', icon1='PyShell.gif', 1525 balloonhelp='Python IDLE Shell', index=1) 1526 1527
1528 -class SaveSessionCommand(Command):
1529 """Command to allow the user to save the session as it is in a file. 1530 It copies the .pmvrc in that file and also log all the transformation. 1531 \nPackage : Pmv 1532 \nModule : customizationCommands.py 1533 \nClass : SaveSessionCommand 1534 """
1535 - def guiCallback(self, event=None):
1536 ### FIXME all the logs should be in a stack and not in a file. 1537 if self.vf.logMode == 'no': 1538 self.vf.warningMsg("No log information because logMode was set to no.") 1539 return 1540 newfile = self.vf.askFileSave(types = [('all files','*.*')], 1541 title = 'Save Session in File:') 1542 if not newfile is None: 1543 self.doitWrapper(newfile, redraw=0)
1544
1545 - def doit(self, filename):
1546 import shutil 1547 # get the current log. 1548 logFileName = self.vf.logAllFile.name 1549 self.vf.logAllFile.close() 1550 if filename!=logFileName: 1551 shutil.copy(logFileName, filename) 1552 self.vf.logAllFile = open(logFileName,'a') 1553 # Add to it the transformation log. 1554 logFile = open(filename,'a') 1555 vi = self.vf.GUI.VIEWER 1556 code = vi.getViewerStateDefinitionCode('self.GUI.VIEWER') 1557 code.extend( vi.getObjectsStateDefinitionCode('self.GUI.VIEWER') ) 1558 1559 if code: 1560 for line in code: 1561 logFile.write(line) 1562 if vi.GUI.contourTk.get(): 1563 controlpoints=vi.GUI.curvetool.getControlPoints() 1564 sensitivity=vi.GUI.d1scalewheel.get() 1565 logFile.write("self.GUI.VIEWER.GUI.curvetool.setControlPoints(%s)" %controlpoints) 1566 logFile.write("\n") 1567 logFile.write("self.GUI.VIEWER.GUI.curvetool.setSensitivity(%s)" %sensitivity) 1568 1569 #sceneLog = self.vf.Exit.logScene() 1570 #for l in sceneLog: 1571 # l1 = l+'\n' 1572 # logFile.write(l1) 1573 logFile.close() 1574 if hasattr(self.vf, 'recentFiles'): 1575 self.vf.recentFiles.add(filename, 'source')
1576 1577 1578 # SaveSessionCommand Command GUI 1579 SaveSessionCommandGUI = CommandGUI() 1580 SaveSessionCommandGUI.addMenuCommand('menuRoot', 'File', 1581 'Current Session', cascadeName='Save',index=2) 1582 1583 SaveSessionCommandGUI.addToolBar('Save', icon1='filesave.gif', 1584 type='ToolBarButton', 1585 balloonhelp='Save Session', index=1) 1586
1587 -class ExitCommand(Command):
1588 """Command to destroy application 1589 \nPackage : ViewerFramework 1590 \nModule : basicCommand.py 1591 \nClass : ExitCommand 1592 \nCommand : Exit 1593 \nSynopsis:\n 1594 None<---Exit(ask) 1595 \nask = Flag when set to 1 a form asking you if you really want to quit 1596 will popup, it will quit directly if set to 0 1597 """ 1598
1599 - def onAddCmdToViewer(self):
1600 #print "ExitComand.onAddCmdToViewer" 1601 import warnings 1602 self.vf.GUI.ROOT.protocol('WM_DELETE_WINDOW',self.askquit)
1603 1604
1605 - def logObjectTransformations(self, object):
1606 warnings.warn( "logObjectTransformations is deprecated", 1607 DeprecationWarning, stacklevel=2) 1608 log = [] 1609 # FIXME won't work with instance matrices 1610 mat = object.GetMatrix(object) 1611 import Numeric 1612 log.append("self.transformObject('rotation', '%s', matrix=%s,log=0)"%(object.fullName,tuple(object.rotation))) 1613 log.append("self.transformObject('translation', '%s', matrix=%s, log=0 )"%(object.fullName, tuple(object.translation))) 1614 log.append("self.transformObject('scale', '%s', matrix=%s, log=0 )"%(object.fullName,tuple(object.scale))) 1615 log.append("self.transformObject('pivot', '%s', matrix=%s, log=0 )"%(object.fullName,tuple(object.pivot))) 1616 return log
1617
1618 - def logObjectMaterial(self, object):
1619 warnings.warn("logObjectMaterial is deprecated", 1620 DeprecationWarning, stacklevel=2) 1621 log = [] 1622 from opengltk.OpenGL import GL 1623 log.append("from opengltk.OpenGL import GL") 1624 mat = object.materials[GL.GL_FRONT] 1625 log.append("self.setObject('%s', materials=%s, propName='ambi', matBind=%d)" % (object.fullName, repr(mat.prop[0])[6:-5],mat.binding[0])) 1626 log.append("self.setObject('%s', materials=%s, propName='diff', matBind=%d)" % (object.fullName, repr(mat.prop[1])[6:-5],mat.binding[1])) 1627 log.append("self.setObject('%s', materials=%s, propName='emis', matBind=%d)" % (object.fullName, repr(mat.prop[2])[6:-5],mat.binding[2])) 1628 log.append("self.setObject('%s', materials=%s, propName='spec', matBind=%d)" % (object.fullName, repr(mat.prop[3])[6:-5],mat.binding[3])) 1629 log.append("self.setObject('%s', materials=%s, propName='shini', matBind=%d)" % (object.fullName, repr(mat.prop[4])[6:-5],mat.binding[4])) 1630 mat = object.materials[GL.GL_BACK] 1631 log.append("self.setObject('%s', materials=%s, polyFace=GL.GL_BACK,propName='ambi', matBind=%d)" % (object.fullName, repr(mat.prop[0])[6:-5],mat.binding[0])) 1632 log.append("self.setObject('%s', materials=%s, polyFace=GL.GL_BACK,propName='diff', matBind=%d)" % (object.fullName, repr(mat.prop[1])[6:-5],mat.binding[1])) 1633 log.append("self.setObject('%s', materials=%s, polyFace=GL.GL_BACK,propName='spec', matBind=%d)" % (object.fullName, repr(mat.prop[2])[6:-5],mat.binding[2])) 1634 log.append("self.setObject('%s', materials=%s, polyFace=GL.GL_BACK,propName='emis', matBind=%d)" % (object.fullName, repr(mat.prop[3])[6:-5],mat.binding[3])) 1635 log.append("self.setObject('%s', materials=%s, polyFace=GL.GL_BACK,propName='shini', matBind=%d)" % (object.fullName, repr(mat.prop[4])[6:-5],mat.binding[4])) 1636 return log
1637 1638
1639 - def logCameraTransformations(self, camera):
1640 warnings.warn("logCameraTransformations is deprecated", 1641 DeprecationWarning, stacklevel=2) 1642 logStr = "self.setCamera('%s', \n"%camera.name 1643 logStr = logStr + "rotation=(%9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f),\n"%tuple(camera.rotation) 1644 logStr=logStr + "translation=(%9.3f, %9.3f, %9.3f),\n"%tuple(camera.translation) 1645 logStr = logStr + "scale=(%9.3f, %9.3f, %9.3f),\n"%tuple(camera.scale) 1646 logStr = logStr + "pivot=(%9.3f, %9.3f, %9.3f),\n"%tuple(camera.pivot) 1647 logStr = logStr + "lookAt=(%9.3f, %9.3f, %9.3f),\n"%tuple(camera.lookAt) 1648 logStr = logStr + "lookFrom=(%9.3f, %9.3f, %9.3f),\n"%tuple(camera.lookFrom) 1649 logStr = logStr + "direction=(%9.3f, %9.3f, %9.3f))"%tuple(camera.direction) 1650 return logStr+'\n'
1651
1652 - def logCameraProp(self, camera):
1653 warnings.warn("logCameraProp is deprecated", 1654 DeprecationWarning, stacklevel=2) 1655 logStr = "self.setCamera('%s', \n"%camera.name 1656 logStr = logStr + "width=%d, height=%d, rootx=%d, rooty=%d,"%\ 1657 (camera.width, camera.height, camera.rootx, camera.rooty) 1658 logStr = logStr + "fov=%f, near=%f, far=%f,"%\ 1659 (camera.fovy, camera.near, camera.far) 1660 logStr = logStr + "color=(%6.3f,%6.3f,%6.3f,%6.3f))"%\ 1661 tuple(camera.backgroundColor) 1662 return logStr+'\n'
1663 1664
1665 - def logLightTransformations(self, light):
1666 warnings.warn("logLightTransformations is deprecated", 1667 DeprecationWarning, stacklevel=2) 1668 logStr = "self.setLight('%s', \n"%light.name 1669 logStr = logStr + "rotation=(%9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f),\n"%tuple(light.rotation) 1670 logStr = logStr + "translation=(%9.3f, %9.3f, %9.3f),\n"%tuple(light.translation) 1671 logStr = logStr + "scale=(%9.3f, %9.3f, %9.3f),\n"%tuple(light.scale) 1672 logStr = logStr + "pivot=(%9.3f, %9.3f, %9.3f),\n"%tuple(light.pivot) 1673 logStr = logStr + "direction=(%9.3f,%9.3f,%9.3f,%9.3f))"%tuple(light.direction) 1674 return logStr+'\n'
1675 1676
1677 - def logLightProp(self, light):
1678 warnings.warn("logLightProp is deprecated", 1679 DeprecationWarning, stacklevel=2) 1680 logStr = "self.setLight('%s', \n"%light.name 1681 logStr = logStr + "enable=%d, visible=%d, length=%f,\n"%\ 1682 (light.enabled, light.visible, light.length) 1683 logStr = logStr + "ambient=(%6.3f,%6.3f,%6.3f,%6.3f),\n"%\ 1684 tuple(light.ambient) 1685 logStr = logStr + "specular=(%6.3f,%6.3f,%6.3f,%6.3f),\n"%\ 1686 tuple(light.specular) 1687 logStr = logStr + "diffuse=(%6.3f,%6.3f,%6.3f,%6.3f))\n"%\ 1688 tuple(light.diffuse) 1689 return logStr+'\n'
1690 1691
1692 - def logClipTransformations(self, clip):
1693 warnings.warn("logClipTransformations is deprecated", 1694 DeprecationWarning, stacklevel=2) 1695 logStr = "self.setClip('%s', \n"%clip.name 1696 logStr = logStr + "rotation=(%9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f, %9.3f),\n"%tuple(clip.rotation) 1697 logStr = logStr + "translation=(%9.3f, %9.3f, %9.3f),\n"%tuple(clip.translation) 1698 logStr = logStr + "scale=(%9.3f, %9.3f, %9.3f),\n"%tuple(clip.scale) 1699 logStr = logStr + "pivot=(%9.3f, %9.3f, %9.3f))\n"%tuple(clip.pivot) 1700 return logStr+'\n'
1701 1702
1703 - def logClipProp(self, clip):
1704 warnings.warn("logClipProp is deprecated", 1705 DeprecationWarning, stacklevel=2) 1706 logStr = "self.setClip('%s', \n"%clip.name 1707 logStr = logStr + "visible=%d, lineWidth=%f,\n"%\ 1708 (clip.visible, clip.lineWidth) 1709 logStr = logStr + "color=(%6.3f,%6.3f,%6.3f,%6.3f))\n"%\ 1710 tuple(clip.color) 1711 return logStr+'\n'
1712 1713
1714 - def logAddClipPlanes(self, object):
1715 warnings.warn("logAddClipPlanes is deprecated", 1716 DeprecationWarning, stacklevel=2) 1717 log = [] 1718 for c in object.clipP: 1719 log.append("self.addClipPlane('%s','%s', %d, %d)\n"%\ 1720 (object.fullName, c.name, object.clipSide[c.num], 0)) 1721 for c in object.clipPI: 1722 log.append("self.addClipPlane('%s','%s', %d, %d)\n"%\ 1723 (object.fullName, c.name, object.clipSide[c.num], 1)) 1724 return log
1725 1726
1727 - def logScene(self):
1728 warnings.warn("logScene is deprecated", 1729 DeprecationWarning, stacklevel=2) 1730 log = [] 1731 vi = self.vf.GUI.VIEWER 1732 for c in vi.cameras: 1733 if c._modified: 1734 log.append(self.logCameraTransformations(c)) 1735 log.append(self.logCameraProp(c)) 1736 1737 for l in vi.lights: 1738 if l._modified: 1739 log.append(self.logLightTransformations(l)) 1740 log.append(self.logLightProp(l)) 1741 1742 for c in vi.clipP: 1743 if c._modified: 1744 log.append(self.logClipTransformations(c)) 1745 log.append(self.logClipProp(c)) 1746 1747 root = self.vf.GUI.VIEWER.rootObject 1748 for o in root.AllObjects(): 1749 if not o.transformIsIdentity(): 1750 log.extend(self.logObjectTransformations(o)) 1751 if o._modified: 1752 log.extend(self.logAddClipPlanes(o)) 1753 log.extend(self.logObjectMaterial(o)) 1754 # Trigger a Viewer Redraw at the end. 1755 log.append("self.GUI.VIEWER.Redraw()") 1756 return log
1757
1758 - def __call__(self, ask, **kw):
1759 """None <- Exit(ask, **kw) 1760 \nask = Flag when set to 1 a form asking you if you really want to quit 1761 will popup, it will quit directly if set to 0. 1762 """ 1763 kw['redraw'] = 0 1764 kw['log'] = 0 1765 kw['busyIdle'] = 0 1766 kw['setupUndo'] = 0 1767 1768 apply(self.doitWrapper, (ask,),kw)
1769
1770 - def doit(self, ask):
1771 #print "ExitComand.quit_cb" 1772 logPref = self.vf.userpref['transformationLogging']['value'] 1773 if logPref == 'continuous': 1774 if hasattr(self.vf.GUI,'pendingLog') and self.vf.GUI.pendingLog: 1775 self.vf.log(self.vf.GUI.pendingLog[-1]) 1776 1777 elif logPref == 'final': 1778 #changed 10/24/2005-RH 1779 ##code = self.logScene() 1780 #vi = self.vf.GUI.VIEWER 1781 #code = vi.getViewerStateDefinitionCode('self.GUI.VIEWER') 1782 #code.extend( vi.getObjectsStateDefinitionCode('self.GUI.VIEWER') ) 1783 #if code: 1784 # for line in code: 1785 # self.vf.log(line) 1786 if hasattr(self.vf, 'logAllFile'): 1787 self.vf.saveSession(self.vf.logAllFile.name) 1788 1789 if ask: 1790 ## from ViewerFramework.gui import InputFormDescr 1791 # from mglutil.gui.InputForm.Tk.gui import InputFormDescr 1792 # self.idf = InputFormDescr(title='Do you wish to Quit?') 1793 # self.idf.append({'widgetType':Tkinter.Button, 1794 # 'wcfg':{'text':'QUIT', 1795 # 'width':10, 1796 # 'command':self.quit_cb}, 1797 # 'gridcfg':{'sticky':'we'}}) 1798 # 1799 # self.idf.append({'widgetType':Tkinter.Button, 1800 # 'wcfg':{'text':'CANCEL', 1801 # 'width':10, 1802 # 'command':self.cancel_cb}, 1803 # 'gridcfg':{'sticky':'we', 'row':-1}}) 1804 # val = self.vf.getUserInput(self.idf, modal=1, blocking=0, 1805 # okcancel=0) 1806 self.vf.GUI.ROOT.after(10,self.askquit) 1807 else: 1808 self.quit_cb()
1809 1810
1811 - def quit_cb(self):
1812 #print "ExitComand.quit_cb" 1813 self.vf.GUI.softquit_cb()
1814 1815
1816 - def cancel_cb(self):
1817 form = self.idf.form 1818 form.root.destroy() 1819 return
1820 1821
1822 - def guiCallback(self):
1823 #print "ExitComand.guiCallback" 1824 self.doitWrapper(1, redraw=0, log=0)
1825 1826
1827 - def askquit(self):
1828 #print "ExitComand.askquit" 1829 import tkMessageBox 1830 ok = tkMessageBox.askokcancel("Quit?","Do you Wish to Quit?") 1831 if ok: 1832 self.afterDoit = None 1833 self.vf.GUI.ROOT.after(10,self.vf.GUI.quit_cb)
1834