Package Vision
[hide private]
[frames] | no frames]

Source Code for Package Vision

  1  ################################################################## 
  2  # Vision - A Visual Programming Environment for Python 
  3  # 
  4  # Daniel Stoffler & Michel Sanner 
  5  # The Scripps Research Institute, La Jolla, CA 
  6  # sanner@scripps.edu, stoffler@scripps.edu 
  7  # 
  8  # Web: http://www.scripps.edu/~sanner/python/ 
  9  # 
 10  # References:    
 11  #    ViPEr, a Visual Programming Environment for Python  
 12  #    In the Proceedings of The 10th International Python Conference 2002, 
 13  #    Virginia USA. 
 14  #    Michel F. Sanner, Daniel Stoffler, Arthur J. Olson 
 15  #    Won the award for the best paper at the Python conference 
 16  #     
 17  #    Integrating biomolecular analysis and visual programming: 
 18  #    flexibility and interactivity in the design of bioinformatics tools  
 19  #    In the proceedings of HICSS-36, Hawaii International conference 
 20  #    on system sciences, 2003, Hawaii 
 21  #    Daniel Stoffler, Sophie I. Coon, Ruth Huey, Arthur J. Olson, 
 22  #    and Michel F. Sanner 
 23  # 
 24  # revision: Guillaume Vareille 
 25  # 
 26  ################################################################## 
 27  # 
 28  # $Header: /opt/cvs/python/packages/share1.5/Vision/__init__.py,v 1.24.2.3 2007/08/30 17:12:33 vareille Exp $ 
 29  # 
 30  # $Id: __init__.py,v 1.24.2.3 2007/08/30 17:12:33 vareille Exp $ 
 31  # 
 32   
 33  import time 
 34  import sys 
 35   
 36  #sys.path.insert(0,'.') 
 37   
 38   
39 -def createRoot():
40 """ create a root and hide it 41 """ 42 from Tkinter import Tk 43 root = Tk() 44 root.withdraw() 45 return root
46 47
48 -def createVision(root=None, interactive=True):
49 """ 50 """ 51 from Vision.VPE import VisualProgramingEnvironment 52 ed = VisualProgramingEnvironment(master=root, name='Vision', 53 withShell= not interactive) 54 return ed
55 56
57 -def createSplash():
58 """ 59 """ 60 import os 61 import Vision 62 iconsDir = os.path.join( Vision.__path__[0], 'Icons') 63 image_dir = os.path.join( iconsDir, 'Images') 64 65 # insert release date here 66 from Support.version import __version__ 67 version = ' ' + __version__ 68 69 copyright = """(c) 1999-2007 Molecular Simulation Laboratory, The Scripps Research Institute 70 ALL RIGHTS RESERVED """ 71 authors = """Authors: Michel F. Sanner, Daniel Stoffler, Guillaume Vareille""" 72 icon = os.path.join( iconsDir,'vision.png') 73 third_party = """""" 74 75 text = 'Python executable : '+sys.executable+'\n' 76 text += 'Vision script : '+__file__+'\n' 77 text += 'MGLTool packages : '+'\n' 78 79 from user import home 80 updates_rc_dir = home + os.path.sep + ".mgltools" + os.sep + 'update' 81 latest_tested_rc = updates_rc_dir + os.sep + 'latest_tested' 82 latest_rc = updates_rc_dir + os.sep + 'latest' #may or may not be tested 83 84 if os.path.exists(latest_tested_rc): 85 p = open(latest_tested_rc).read() 86 sys.path.insert(0, p) 87 text += ' tested : ' + p +'\n' 88 89 if os.path.exists(latest_rc): 90 p = open(latest_rc).read() 91 sys.path.insert(0, p) 92 text += ' nightly : ' + p +'\n' 93 94 text += version + ': ' + 'ADD PATH HERE' 95 path_data = text 96 97 from mglutil.splashregister.splashscreen import SplashScreen 98 from mglutil.splashregister.about import About 99 about = About(image_dir=image_dir, third_party=third_party, 100 path_data=path_data, 101 title='Vision', version=version, 102 copyright=copyright, authors=authors, icon=icon) 103 splash = SplashScreen(about, noSplash=False) 104 105 return splash, about
106 107
108 -def launchVisionToRunNetworkAsApplication():
109 root = createRoot() 110 splash, about = createSplash() 111 lSplashVisibleTimeStart = time.clock() 112 ed = createVision(root, interactive=True) 113 masterNet = ed.currentNetwork 114 masterNet.isApplication = True 115 lSplashVisibleTimeEnd = time.clock() 116 while lSplashVisibleTimeEnd - lSplashVisibleTimeStart < 2: 117 lSplashVisibleTimeEnd = time.clock() 118 splash.finish() 119 return masterNet
120 121
122 -def mainLoopVisionToRunNetworkAsApplication(ed):
123 ed.master.mainloop()
124 125 126 ################################################################## 127 # Define a bunch of useful methods 128 ##################################################################
129 -def net():
130 return ed.currentNetwork
131 132
133 -def nodes():
134 return ed.currentNetwork.nodes
135 136
137 -def runVision(argv=None):
138 """The main function for running Vision""" 139 ################################################################## 140 # Parse options 141 ################################################################## 142 import time 143 import sys, getopt 144 import os 145 import user 146 import warnings 147 import stat 148 from string import split 149 150 if argv is None: 151 argv = ['Vision/bin/runVision.py', '-i'] 152 153 help_msg = """usage: %s <options> <networknames> 154 -h or --help : print this message 155 -i or --interactive : run interactive""" % sys.argv[0] 156 try: 157 optlist, args = getopt.getopt(argv[1:], 'hi', [ 158 'help', 'interactive', 'noSplash'] ) 159 except: 160 print "Unknown option!" 161 print help_msg 162 sys.exit(1) 163 164 interactive = 0 165 noSplash = False 166 for opt in optlist: 167 if opt[0] in ('-h', '--help'): 168 print help_msg 169 sys.exit() 170 elif opt[0] in ('-i', '--interactive'): 171 interactive = 1 172 elif opt[0] in ('--noSplash',): 173 noSplash = True 174 175 # if MGLPYTHONPATH environment variable exists - insert the specified path 176 # into sys.path 177 178 #if os.environ.has_key("MGLPYTHONPATH"): 179 # if sys.platform == "win32": 180 # mglPath = split(os.environ["MGLPYTHONPATH"], ";") 181 # else: 182 # mglPath = split(os.environ["MGLPYTHONPATH"], ":") 183 # mglPath.reverse() 184 # for p in mglPath: 185 # sys.path.insert(0, os.path.abspath(p)) 186 187 # to take into account any package located in the current 188 # directory before the ones located in site-packages 189 190 from Support.path import path_text, release_path 191 import Vision 192 sys.modules['__main__'] = sys.modules['Vision'] 193 print 'Run Vision from ', Vision.__path__[0] 194 195 196 root = createRoot() 197 root.withdraw() 198 ################################################################## 199 # Splash Screen 200 ################################################################## 201 if noSplash is False: 202 splash, about = createSplash() 203 lSplashVisibleTimeStart = time.clock() 204 205 ################################################################## 206 # Start Vision 207 ################################################################## 208 ed = createVision(root, interactive) 209 globals()['ed'] = ed 210 211 ################################################################## 212 # Workaround: currently, Vision would crash on some Windows2000 and SGI 213 # when running multi-threaded. We turn MT off for those platforms 214 ################################################################## 215 if sys.platform == 'win32' or sys.platform == 'irix646': 216 ed.configure(withThreads=0) 217 218 219 ################################################################## 220 # Register exit function 221 ################################################################## 222 #try: 223 # import atexit 224 # atexit.register(ed.exit) 225 #except: 226 # print 'Quit using the File->exit button or hang .... !' 227 228 229 ################################################################## 230 # Source Resource File (if available) 231 # copy this file to your home directory to customize it 232 ################################################################## 233 from mglutil.util.packageFilePath import findResourceFile 234 ed.sourceFile(resourceFile='_visionrc') 235 236 ################################################################## 237 # Make sure splash is visible long enough before removing it 238 ################################################################## 239 if noSplash is False: 240 lSplashVisibleTimeEnd = time.clock() 241 while lSplashVisibleTimeEnd - lSplashVisibleTimeStart < 2: 242 lSplashVisibleTimeEnd = time.clock() 243 splash.finish() 244 245 ################################################################## 246 # Make vision visible 247 #(before the network loads, so the additional windows will load on top) 248 ################################################################## 249 root.deiconify() 250 #ed.master.master.master.geometry('600x600') 251 #ed.top.configurepane('ModulePages', size=.25) 252 253 ################################################################## 254 # Load network(s) if specified at startup 255 ################################################################## 256 if len(args): 257 ed.root.update() # make sure the canvas is shown b4 loading any network 258 for netName in args: 259 ed.loadNetwork(netName) 260 261 ################################################################## 262 # Set the Python Shell 263 ################################################################## 264 if interactive: 265 sys.stdin = sys.__stdin__ 266 sys.stdout = sys.__stdout__ 267 sys.stderr = sys.__stderr__ 268 import code 269 code.interact( 'Vision Interactive Shell', local=globals() ) 270 else: 271 ed.master.mainloop()
272 273 FlagCheck = 1 274 CRITICAL_DEPENDENCIES = ['Pmw', 'NetworkEditor', 'mglutil', 'Numeric'] 275 NONCRITICAL_DEPENDENCIES = ['magick', 'PIL', 'opengltk', 'DejaVu', 'grail', 'MolKit', 'symserv','Volume', 'Pmv', 'matplotlib', 'Support'] 276