Dmitriy,

This is easily solved:

PyMOL expects be imported at the global level as __main__.pymol, but you
can spoof it by adding "__main__.pymol = pymol" as follows:

def funct():
   import __main__
   __main__.pymol_argv = [ 'pymol', '-qx' ]
   import pymol
   __main__.pymol = pymol
   pymol.finish_launching()
   print "finished" 

if __name__ == '__main__':
   funct()

Cheers,
Warren


--
Warren L. DeLano, Ph.D.                     
Principal Scientist

. DeLano Scientific LLC  
. 400 Oyster Point Blvd., Suite 213           
. South San Francisco, CA 94080 USA   
. Biz:(650)-872-0942  Tech:(650)-872-0834     
. Fax:(650)-872-0273  Cell:(650)-346-1154
. mailto:war...@delsci.com      
 

> -----Original Message-----
> From: pymol-users-ad...@lists.sourceforge.net 
> [mailto:pymol-users-ad...@lists.sourceforge.net] On Behalf Of 
> Dmitriy Igor Bryndin
> Sent: Tuesday, October 25, 2005 7:58 AM
> To: pymol-users@lists.sourceforge.net
> Subject: [PyMOL] launching PyMol from a python function
> 
> I'm trying to start PyMol from another python program.
> After the 0_99beta17 it is possible to start it from the 
> __main__ part of a code. But when I start PyMol from a 
> function 'pymol.finish_launching()' goes in an endless loop. 
> 
> Here goes an example:
>  ---------------------------------------------------------------
> def funct():
>    import __main__
>    __main__.pymol_argv = [ 'pymol', '-qx' ]
>    import pymol
>    pymol.finish_launching()
>    print "finished" 
> 
> if __name__ == '__main__':
>    funct()
>  ---------------------------------------------------------------
> In this case PyMol window starts, but program never reaches 
> 'print "finished"'. 
> 
> The same time
>  ---------------------------------------------------------------
> if __name__ == '__main__':
>    import __main__
>    __main__.pymol_argv = [ 'pymol', '-qx' ]
>    import pymol
>    pymol.finish_launching()
>    print "finished"
>  ---------------------------------------------------------------
> works fineand prints "finshed" 
> 
> after getting into PyMol's finish_launching()  (inside 
> __init__.py) while not hasattr(__main__,'pymol'):
>    e.wait(0.01)
> Goes in an endless loop.
> I've tried   print dir(__main__)   just before this loop. 
> When PyMol is 
> launched not from a function, __main__ indeed have attributes 
> '__main__' and 'pymol'.  Launched from a function, there are 
> no '__main__' or 'pymol', but 'funct'. 
> 
> I'll really appreciate any help or hints how make it possible 
> to launch PyMol from a function or from a method of some class. 
> 
>   Dmitriy
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course 
> Free Certification Exam for All Training Attendees Through 
> End of 2005 Visit http://www.jboss.com/services/certification 
> for more information _______________________________________________
> PyMOL-users mailing list
> PyMOL-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pymol-users
> 
> 
> 
> 

Reply via email to