From: Warren D. <wa...@de...> - 2005-10-25 15:06:16
|
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 =3D pymol" as follows: def funct(): import __main__ __main__.pymol_argv =3D [ 'pymol', '-qx' ] import pymol __main__.pymol =3D pymol pymol.finish_launching() print "finished"=20 if __name__ =3D=3D '__main__': funct() Cheers, Warren -- Warren L. DeLano, Ph.D. =20 Principal Scientist . DeLano Scientific LLC =20 . 400 Oyster Point Blvd., Suite 213 =20 . South San Francisco, CA 94080 USA =20 . Biz:(650)-872-0942 Tech:(650)-872-0834 =20 . Fax:(650)-872-0273 Cell:(650)-346-1154 . mailto:wa...@de... =20 =20 > -----Original Message----- > From: pym...@li...=20 > [mailto:pym...@li...] On Behalf Of=20 > Dmitriy Igor Bryndin > Sent: Tuesday, October 25, 2005 7:58 AM > To: pym...@li... > Subject: [PyMOL] launching PyMol from a python function >=20 > I'm trying to start PyMol from another python program. > After the 0_99beta17 it is possible to start it from the=20 > __main__ part of a code. But when I start PyMol from a=20 > function 'pymol.finish_launching()' goes in an endless loop.=20 >=20 > Here goes an example: > --------------------------------------------------------------- > def funct(): > import __main__ > __main__.pymol_argv =3D [ 'pymol', '-qx' ] > import pymol > pymol.finish_launching() > print "finished"=20 >=20 > if __name__ =3D=3D '__main__': > funct() > --------------------------------------------------------------- > In this case PyMol window starts, but program never reaches=20 > 'print "finished"'.=20 >=20 > The same time > --------------------------------------------------------------- > if __name__ =3D=3D '__main__': > import __main__ > __main__.pymol_argv =3D [ 'pymol', '-qx' ] > import pymol > pymol.finish_launching() > print "finished" > --------------------------------------------------------------- > works fineand prints "finshed"=20 >=20 > after getting into PyMol's finish_launching() (inside=20 > __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.=20 > When PyMol is=20 > launched not from a function, __main__ indeed have attributes=20 > '__main__' and 'pymol'. Launched from a function, there are=20 > no '__main__' or 'pymol', but 'funct'.=20 >=20 > I'll really appreciate any help or hints how make it possible=20 > to launch PyMol from a function or from a method of some class.=20 >=20 > Dmitriy >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by the JBoss Inc. > Get Certified Today * Register for a JBoss Training Course=20 > Free Certification Exam for All Training Attendees Through=20 > End of 2005 Visit http://www.jboss.com/services/certification=20 > for more information _______________________________________________ > PyMOL-users mailing list > PyM...@li... > https://lists.sourceforge.net/lists/listinfo/pymol-users >=20 >=20 >=20 >=20 |