Hi all, I'm trying to pretty up the next version of the APBS plugin and I've run into two issues that I'm hoping others have solved:
1. Does anyone have any experience with PMW's OptionMenu? I've been trying something where I call an OptionMenu's setitem() and it keeps failing no matter what I do. Perhaps someone can just point me at some working sample code. 2. I'm having trouble launching command-line Python scripts from my plugin on OS X. Scripts complain about things like "import time" failing that work from the command line. I have a wrapper function that works on Windows, OS X and Linux for normal binaries, and I've included it below. It looks to me like programs launched via PyMOL (either via os.system or via subprocess.call) just don't get a proper environment set up, thus causing Python imports to fail, but I'm not entirely sure. I typically work around this in an ugly way: I mess around with sys.path, import whatever.py and then call whatever.main() directly. This is obviously quite fragile and depends on whatever.py to have a nice whatever.main() defined. It gets substantially worse when whatever.py wants lots of things in its own path. Has anyone else experienced this? Do you know a nice workaround? Thanks, -Michael def run(prog,args): ''' wrapper to handle spaces on windows. prog is the full path to the program. args is a string that we will split up for you. or a tuple. or a list. your call. return value is (retval,prog_out) e.g. (retval,prog_out) = run("/bin/ls","-al /tmp/myusername") ''' import subprocess,tempfile if type(args) == type(''): args = tuple(args.split()) elif type(args) in (type([]),type(())): args = tuple(args) args = (prog,) + args try: output_file = tempfile.TemporaryFile(mode="w+") # <-- shouldn't this point to the temp dir except IOError: print "Error opening output_file when trying to run the APBS command." print "Running:\n\tprog=%s\n\targs=%s" % (prog,args) retcode = subprocess.call(args,stdout=output_file.fileno(),stderr=subprocess.STDOUT) output_file.seek(0) #prog_out = output_file.read() prog_out = ''.join(output_file.readlines()) output_file.close() #windows doesn't do this automatically if DEBUG: print "Results were:" print "Return value:",retcode print "Output:" print prog_out return (retcode,prog_out) -- Michael Lerner, Ph.D. IRTA Postdoctoral Fellow Laboratory of Computational Biology NIH/NHLBI 5635 Fishers Lane, Room T909, MSC 9314 Rockville, MD 20852 (UPS/FedEx/Reality) Bethesda MD 20892-9314 (USPS) ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net) Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net