Package Pmv :: Module helpCommands
[hide private]
[frames] | no frames]

Source Code for Module Pmv.helpCommands

  1  ############################################################################# 
  2  # 
  3  # Author: Sowjanya Karnati , Michel F Sanner 
  4  # 
  5  # Copyright: M. Sanner TSRI 2000 
  6  # 
  7  ############################################################################# 
  8  """ 
  9  Module implementing classes to provide documentation on the application 
 10  """ 
 11   
 12   
 13  #  
 14  # 
 15  # $Id: helpCommands.py,v 1.15 2007/06/20 17:42:27 sargis Exp $ 
 16  # 
 17   
 18   
 19  import Tkinter, Pmw,re 
 20  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
 21  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser, \ 
 22       kbScrolledListBox 
 23  from ViewerFramework.VFCommand import Command,CommandGUI 
 24  from string import join 
 25  global commandslist 
 26  import webbrowser,os,sys 
 27  from Tkinter import * 
 28  from types import StringType 
 29  #from htmlDoc import * 
 30  try: 
 31      os.remove('Pmv/BugReport.html') 
 32  except OSError: 
 33      pass 
 34  VarDict = { } 
35 -class mailingListsCommand(Command):
36 """Command to show mailing lists of Pmv and Vision. 37 \nPackage : Pmv 38 \nModule : helpCommands 39 \nClass : mailingListsCommand 40 \nCommand : mailingListsCommand 41 \nSynopsis:\n 42 None <--- mailingListsCommand(module, commands=None, package=None, **kw) 43 \nRequired Arguements\n: 44 module --- name of the module (filename) 45 \nOptional Arguements:\n 46 commands --- list of cammnds in that module 47 \nPackage --- package name to which module belongs 48 """ 49 50
51 - def __init__(self, func=None):
52 Command.__init__(self, func)
53
54 - def doit(self, pack, page):
55 56 if page == None or pack == None: 57 return 58 if pack == "Pmv": 59 60 if page == "Login Page": 61 webbrowser.open_new('http://mgldev.scripps.edu/mailman/listinfo/pmv') 62 63 if page == "Archive Page": 64 webbrowser.open_new('http://mgldev.scripps.edu/pipermail/pmv') 65 if pack == "Vision": 66 if page == "Login Page": 67 webbrowser.open_new('http://mgldev.scripps.edu/mailman/listinfo/vision') 68 69 if page == "Archive Page": 70 webbrowser.open_new('http://mgldev.scripps.edu/pipermail/vision')
71 72
73 - def __call__(self,pack,page):
74 """None <--- mailingListsCommand(pack,page) 75 \nRequired Arguements\n: 76 pack --- name of the package(Pmv, or Vision) 77 \npage ---name of the page(Login or Archive) 78 79 """ 80 if page == None: 81 return 82 if type(page) is not StringType or type(pack) is not StringType: 83 return "ERROR: pack or page are not string type" 84 if page not in ["Login Page", "Archive Page"]: 85 return "ERROR: Invalid page name" 86 if pack not in ["Pmv","Vision"]: 87 return "ERROR: Invalid pack name" 88 apply(self.doitWrapper,(pack,page,),{})
89 90 91
92 - def buildFormDescr(self, formName):
93 94 95 if not formName == 'Show MailingLists': 96 return 97 idf = InputFormDescr(title='Show MailingLists') 98 self.mailinglists_pages=["Login Page","Archive Page"] 99 idf.append({'name':'pmvlist', 100 'widgetType':kbScrolledListBox, 101 'wcfg':{'items':self.mailinglists_pages, 102 'listbox_exportselection':0, 103 'labelpos':'nw', 104 'label_text':'Pmv Mailing List', 105 'selectioncommand':self.mailCmds_cb, 106 'listbox_height':3 , 107 #'hscrollmode':'dynamic', 108 }, 109 'gridcfg':{'sticky':'wesn','columnspan':1}}) 110 111 idf.append({'name':'visionlist', 112 'widgetType':kbScrolledListBox, 113 'wcfg':{'items':self.mailinglists_pages, 114 'listbox_exportselection':0, 115 'labelpos':'nw', 116 'label_text':'Vision Mailing List', 117 'selectioncommand':self.mailCmds_cb, 118 'listbox_height':3, 119 #'hscrollmode':'dynamic', 120 }, 121 'gridcfg':{'sticky':'wesn','columnspan':1}}) 122 idf.append({'name':'dismiss', 123 'widgetType':Tkinter.Button, 124 'wcfg':{'text':'DISMISS', 125 'command':self.dismiss_cb, 126 }, 127 'gridcfg':{'sticky':'ew','columnspan':3}}) 128 return idf
129
130 - def guiCallback(self):
131 val = self.showForm('Show MailingLists',force = 1,modal =0,blocking = 0) 132 ebn = val.descr.entryByName
133 134
135 - def dismiss_cb(self, event=None):
136 self.cmdForms['Show MailingLists'].withdraw()
137
138 - def mailCmds_cb(self):
139 ebn = self.cmdForms['Show MailingLists'].descr.entryByName 140 c = self.cmdForms['Show MailingLists'].mf.cget('cursor') 141 cmdW1 = ebn['pmvlist']['widget'] 142 cmdW2 = ebn['visionlist']['widget'] 143 144 CmdName1 = cmdW1.getcurselection() 145 cmdW1.select_clear(0,last=1) 146 147 CmdName2 = cmdW2.getcurselection() 148 cmdW2.select_clear(0,last=1) 149 150 if len(CmdName1) != 0: 151 152 if CmdName1[0] == 'Login Page': 153 page = "Login Page" 154 pack ="Pmv" 155 apply( self.doitWrapper,(pack, page,),{}) 156 157 if CmdName1[0] == 'Archive Page': 158 159 page = "Archive Page" 160 pack ="Pmv" 161 apply( self.doitWrapper,(pack, page,),{}) 162 CmdName1 =() 163 164 if len(CmdName2) != 0: 165 166 if CmdName2[0] == 'Login Page': 167 page = "Login Page" 168 pack = "Vision" 169 apply( self.doitWrapper,(pack, page,),{}) 170 171 if CmdName2[0] == 'Archive Page': 172 page = "Archive Page" 173 pack = "Vision" 174 apply( self.doitWrapper,(pack, page,),{}) 175 CmdName2 =()
176 mailingListsCommandGUI = CommandGUI() 177 mailingListsCommandGUI.addMenuCommand('menuRoot', 'Help', 178 'MailingList') 179 180
181 -class BugReportCommand(Command):
182
183 - def __init__(self, func=None):
184 Command.__init__(self, func)
185
186 - def doit(self):
187 188 self.show_upload_page()
189 190 191 192
193 - def __call__(self):
194 195 apply(self.doitWrapper,(),{})
196 197
198 - def buildFormDescr(self, formName):
199 200 if not formName == 'BugReport': 201 return 202 203 idf = InputFormDescr(title='BugReport') 204 205 206 207 208 209 idf.append({'name':'shortdesclabel', 210 'widgetType':Tkinter.Label, 211 'wcfg':{'text':'Summary(one line description)', 212 }, 213 'gridcfg':{'sticky':'nw','columnspan':3}}) 214 215 216 idf.append({'name':'shortdescadd', 217 'widgetType':Pmw.ScrolledText, 218 #'parent':'SHORTDESCGROUP', 219 220 'label_text':'Summary', 221 'labelpos':'n', 222 'text_padx':20, 223 'text_pady':2, 224 'wcfg':{}, 225 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) 226 idf.append({'name':'desclabel', 227 'widgetType':Tkinter.Label, 228 'wcfg':{'text':'Description', 229 }, 230 'gridcfg':{'sticky':'nw','columnspan':3}}) 231 232 233 234 idf.append({'name':'descadd', 235 'widgetType':Pmw.ScrolledText, 236 #'parent':'DESCGROUP', 237 'labelpos':'n', 238 'label_text':'Description', 239 'wcfg':{}, 240 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) 241 242 243 idf.append({'name':'PMVLOGGROUP', 244 'widgetType':Pmw.Group, 245 246 # 'labelpos':'n', 247 'container':{'PMVLOGGROUP':"w.interior()"}, 248 'wcfg':{'tag_text':'Check to attach Pmv Log','tag_pyclass':Tkinter.Checkbutton,'tag_variable':Tkinter.IntVar(),'tag_command':self.showpmvlog_cb}, 249 'collapsedsize':0, 250 'gridcfg':{'sticky':'wnse', 'columnspan':3}}) 251 idf.append({'name':'pmvlogtext', 252 'widgetType':Pmw.ScrolledText, 253 'tag_text':"PmvLog", 254 'parent':'PMVLOGGROUP', 255 'wcfg':{}, 256 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) 257 258 idf.append({'name':'PDBFILEGROUP', 259 'widgetType':Pmw.Group, 260 'container':{'PDBFILEGROUP':"w.interior()"}, 261 'wcfg':{'tag_text':'Attach Files'}, 262 'collapsedsize':0, 263 'gridcfg':{'sticky':'wnse', 'columnspan':3}}) 264 265 266 idf.append({'name':'pdbfileadd', 267 'widgetType':Pmw.ScrolledListBox, 268 'parent':'PDBFILEGROUP', 269 'wcfg':{}, 270 'listbox_height':1, 271 'gridcfg':{'sticky':'wesn','columnspan':3,'row':1,'column':0} 272 }) 273 274 idf.append({'name':'DeleteSelected', 275 'widgetType':Tkinter.Button, 276 'defaultValue':0, 277 'parent':'PDBFILEGROUP', 278 'wcfg':{'text':'Delete Selected Files', 279 'width':38, 280 'state':'disabled', 281 'command':self.delete_selected_cb, 282 }, 283 'gridcfg':{'sticky':'nw','row':2,'column':0,'columnspan':2}}) 284 idf.append({'name':'AttachMore', 285 'widgetType':Tkinter.Button, 286 'defaultValue':0, 287 'parent':'PDBFILEGROUP', 288 'wcfg':{'text':'Attach File ..', 289 'width':37, 290 'command':self.attachmore_cb, 291 }, 292 'gridcfg':{'sticky':'ne','row':2,'column':1,'columnspan':2,}}) 293 idf.append({'name':'emailentrylab', 294 'widgetType':Tkinter.Label, 295 296 'wcfg':{'text':"Enter your email address(optional:to receive information about submitted bug)" 297 }, 298 'gridcfg':{'sticky':'nw', 'columnspan':3}}) 299 idf.append({'name':'emailentry', 300 'widgetType':Tkinter.Entry, 301 302 'wcfg':{'textvariable':Tkinter.StringVar() 303 }, 304 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) 305 idf.append({'name':'uploadbutton', 306 'widgetType':Tkinter.Button, 307 'defaultValue':0, 308 'wcfg':{'text':'Submit BugReport', 309 'width':37, 310 'command':self.show_upload_page, 311 }, 312 'gridcfg':{'sticky':'nw','columnspan':2,'row':9,'column':0,}}) 313 idf.append({'name':'dismiss', 314 'widgetType':Tkinter.Button, 315 'wcfg':{'text':'DISMISS', 316 'width':38, 317 'command':self.dismiss_cb, 318 }, 319 'gridcfg':{'sticky':'ne','columnspan':2,'row':9,'column':1,}}) 320 321 return idf
322
323 - def guiCallback(self):
324 val = self.showForm('BugReport',force = 1,modal =0,blocking = 0) 325 ebn = val.descr.entryByName 326 pdb_group=ebn['PDBFILEGROUP']['widget'] 327 pdb_group.expand() 328 pmvlog_group=ebn['PMVLOGGROUP']['widget'] 329 pmvlog_group.collapse() 330 shortdesc_tx=ebn['shortdescadd']['widget'] 331 shortdesc_tx.configure(text_height=2) 332 desc_tx=ebn['descadd']['widget'] 333 desc_tx.configure(text_height=8) 334 pdb_addw=ebn['pdbfileadd']['widget'] 335 pdb_addw.configure(listbox_height=1)
336 337
338 - def dismiss_cb(self, event=None):
339 self.cmdForms['BugReport'].withdraw()
340 341
342 - def attachmore_cb(self):
343 """for attching files""" 344 ebn = self.cmdForms['BugReport'].descr.entryByName 345 pdb_group=ebn['PDBFILEGROUP']['widget'] 346 pdb_addw=ebn['pdbfileadd']['widget'] 347 pdb_att=ebn['AttachMore']['widget'] 348 pdb_delw=ebn['DeleteSelected']['widget'] 349 Filename = self.vf.askFileOpen(parent=pdb_att.winfo_toplevel(), types=[('all files','*')], 350 title="ADDFile") 351 if Filename: 352 inputfilename = os.path.abspath(Filename) 353 files=pdb_addw.get() 354 files=list(files) 355 files.append(inputfilename) 356 pdb_addw.setlist(files) 357 pdb_addw.configure(listbox_height=len(files)) 358 pdb_delw.configure(state="active") 359 360 else: 361 if len(pdb_addw.get())==0: 362 pdb_delw.configure(state="disabled") 363 pdb_addw.setlist(pdb_addw.get())
364 365
366 - def delete_selected_cb(self):
367 """deletes selected files""" 368 ebn = self.cmdForms['BugReport'].descr.entryByName 369 pdb_group=ebn['PDBFILEGROUP']['widget'] 370 pdb_addw=ebn['pdbfileadd']['widget'] 371 pdb_delw=ebn['DeleteSelected']['widget'] 372 files=pdb_addw.get() 373 lfiles=list(files) 374 selected_files=pdb_addw.getcurselection() 375 for s in list(selected_files): 376 if s in lfiles: 377 lfiles.remove(s) 378 pdb_addw.setlist(lfiles) 379 pdb_addw.configure(listbox_height=len(lfiles)) 380 if len(pdb_addw.get())==0: 381 pdb_delw.configure(state="disabled")
382
383 - def showpmvlog_cb(self):
384 385 ebn = self.cmdForms['BugReport'].descr.entryByName 386 var=ebn['PMVLOGGROUP']['wcfg']['tag_variable'].get() 387 pmvlog_group=ebn['PMVLOGGROUP']['widget'] 388 pmvlog_txtw=ebn['pmvlogtext']['widget'] 389 if var==0: 390 pmvlog_group.collapse() 391 message_list = "" 392 393 if var==1 : 394 395 pmvlog_group.expand() 396 tx = self.vf.GUI.MESSAGE_BOX.tx 397 message_list = tx.get().split('\n')[:-2] 398 pmvlog_txtw.configure(text_height=3) 399 400 mes ="" 401 for m in message_list: 402 mes=mes+m+"\n" 403 pmvlog_txtw.settext(mes)
404 405 406
407 - def get_description(self):
408 ebn = self.cmdForms['BugReport'].descr.entryByName 409 desc_w =ebn['descadd']['widget'] 410 desc_text = desc_w.get() 411 shortdesc_w = ebn['shortdescadd']['widget'] 412 413 shortdesc_text =shortdesc_w.get() 414 415 VarDict['desc_text'] = desc_text 416 VarDict['shortdesc_text'] = shortdesc_text 417 email_ent = ebn['emailentry']['widget'].get() 418 VarDict['email_recipient'] = email_ent 419 pmvlog_txtw=ebn['pmvlogtext']['widget'] 420 VarDict['pmvlog'] = pmvlog_txtw.get() 421 pdb_addw=ebn['pdbfileadd']['widget'] 422 VarDict['attachfile'] = pdb_addw.get()
423 424 #checking validity of email address
425 - def validateEmail(self,email):
426 427 if len(email) > 7: 428 if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None: 429 return 1 430 return 0
431 - def show_upload_page(self):
432 self.get_description() 433 434 sumcont = VarDict['shortdesc_text'] 435 436 if VarDict.has_key('pmvlog') and len(VarDict['pmvlog'])>0: 437 438 fulldesc = VarDict['desc_text']+"\n"+"PMV LOG:"+"\n"+VarDict['pmvlog'] 439 else: 440 fulldesc = VarDict['desc_text'] 441 442 if len(VarDict['email_recipient'])>1: 443 desccont = fulldesc+"\n"+"-by"+" "+VarDict['email_recipient'] 444 else: 445 desccont = fulldesc 446 if len(sumcont)<=1 or len(desccont)<=1: 447 import tkMessageBox 448 ok = tkMessageBox.askokcancel("Input","Please enter summary and description") 449 return 450 from mglutil.TestUtil import BugReport 451 if VarDict.has_key('attachfile'): 452 upfile = VarDict['attachfile'] 453 else: 454 upfile="" 455 BR=BugReport.BugReportCommand("PMV") 456 from Support.version import __version__ 457 if self.validateEmail(VarDict['email_recipient']): 458 idnum = BR.showuploadpage_cb(sumcont,desccont,upfile, 459 email_ent=VarDict['email_recipient'], 460 product="MGL Applications", 461 version=__version__) 462 else: 463 464 idnum = BR.showuploadpage_cb(sumcont,desccont,upfile, 465 email_ent="", 466 product="MGL Applications", 467 version=__version__) 468 469 470 self.dismiss_cb() 471 #################################### 472 #Tk message Box 473 #################################### 474 475 root = Tk() 476 t = Text(root) 477 t.pack() 478 479 def openHLink(event): 480 start, end = t.tag_prevrange("hlink", 481 t.index("@%s,%s" % (event.x, event.y))) 482 webbrowser.open_new('%s' %t.get(start, end))
483 #print "Going to %s..." % t.get(start, end) 484 485 t.tag_configure("hlink", foreground='blue', underline=1) 486 t.tag_bind("hlink", "<Control-Button-1>", openHLink) 487 t.insert(END, "BugReport has been Submitted Successfully\n") 488 t.insert(END, "BugId is %s" %idnum) 489 t.insert(END,"\nYou can visit Bug at\n") 490 t.insert(END,"http://mgldev.scripps.edu/bugs/show_bug.cgi?id=%i" %int(idnum),"hlink") 491 t.insert(END,"\nControl-click on the link to visit this page\n") 492 t.insert(END,"\n")
493 494 495 496 BugReportCommandGUI = CommandGUI() 497 BugReportCommandGUI.addMenuCommand('menuRoot', 'Help', 498 'BugReport') 499 500 commandList = [ 501 {'name':'mailingListsCommand','cmd':mailingListsCommand(),'gui':mailingListsCommandGUI}, 502 {'name':'BugReportCommand','cmd':BugReportCommand(),'gui':BugReportCommandGUI}, 503 ] 504 505 506
507 -def initModule(viewer):
508 for dict in commandList: 509 viewer.addCommand(dict['cmd'], dict['name'], dict['gui'])
510