def launch_qutemol(pdb_file): """ Launch and load QuteMolX with the PDB file I{pdb_file}. @param pdb_file: the PDB filename to load @type pdb_file: string @return: (errorcode, errortext) where errorcode is one of the following: ###k 0 = successful 8 = QuteMolX failed for an unknown reason. @rtype: int, text """ plugin_name = "QuteMolX" plugin_prefs_keys = (qutemol_enabled_prefs_key, qutemol_path_prefs_key) errorcode, errortext_or_path = \ checkPluginPreferences(plugin_name, plugin_prefs_keys, insure_executable = True) if errorcode: return errorcode, errortext_or_path program_path = errortext_or_path workdir, junk_exe = os.path.split(program_path) # This provides a way to tell NE1 which version of QuteMolX is installed. if debug_pref("QuteMol 0.4.1 or later", Choice_boolean_True, prefs_key = True): version = "0.4.1" else: version = "0.4.0" # Start QuteMolX. try: args = [pdb_file] if env.debug(): print "Debug: Launching", plugin_name, \ "\n working directory=", workdir, \ "\n program_path=", program_path, \ "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) p = Process() # QuteMolX must run from the directory its executable lives. Otherwise, # it has serious problems (but still runs). Mark 2007-06-02. p.setWorkingDirectory(QString(workdir)) # Tried p.startDetached() so that QuteMolX would be its own process and # continue to live even if NE1 exits. Unfortunately, # setWorkingDirectory() doesn't work. Seems like a Qt bug to me. # Mark 2007-06-02 p.start(program_path, arguments) except: print_compact_traceback( "exception in launch_qutemol(): " ) return 8, "%s failed for an unknown reason." % plugin_name # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = plugin_name + " launched." else: msg = plugin_name + " had exitcode %r" % exitcode else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns return 0, plugin_name + " launched." # from launch_qutemol
def launch_qutemol(pdb_file): """ Launch and load QuteMolX with the PDB file I{pdb_file}. @param pdb_file: the PDB filename to load @type pdb_file: string @return: (errorcode, errortext) where errorcode is one of the following: ###k 0 = successful 8 = QuteMolX failed for an unknown reason. @rtype: int, text """ plugin_name = "QuteMolX" plugin_prefs_keys = (qutemol_enabled_prefs_key, qutemol_path_prefs_key) errorcode, errortext_or_path = \ checkPluginPreferences(plugin_name, plugin_prefs_keys, insure_executable = True) if errorcode: return errorcode, errortext_or_path program_path = errortext_or_path workdir, junk_exe = os.path.split(program_path) # This provides a way to tell NE1 which version of QuteMolX is installed. if debug_pref("QuteMol 0.4.1 or later", Choice_boolean_True, prefs_key=True): version = "0.4.1" else: version = "0.4.0" # Start QuteMolX. try: args = [pdb_file] if env.debug(): print "Debug: Launching", plugin_name, \ "\n working directory=", workdir, \ "\n program_path=", program_path, \ "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) p = Process() # QuteMolX must run from the directory its executable lives. Otherwise, # it has serious problems (but still runs). Mark 2007-06-02. p.setWorkingDirectory(QString(workdir)) # Tried p.startDetached() so that QuteMolX would be its own process and # continue to live even if NE1 exits. Unfortunately, # setWorkingDirectory() doesn't work. Seems like a Qt bug to me. # Mark 2007-06-02 p.start(program_path, arguments) except: print_compact_traceback("exception in launch_qutemol(): ") return 8, "%s failed for an unknown reason." % plugin_name # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = plugin_name + " launched." else: msg = plugin_name + " had exitcode %r" % exitcode else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns return 0, plugin_name + " launched." # from launch_qutemol
def launch_povray_or_megapov( win, info, povray_ini): #bruce 060707/11 revised this extensively for Mac A8 """ Try to launch POV-Ray or MegaPOV, as specified in <info> (as returned from decode_povray_prefs, assumed already checked), on the given <povray_ini> file (which should already exist), and running in the directory of that file (this is required, since it may contain relative pathnames). <win> must be the main window object (used for .glpane.is_animating). Returns (errorcode, errortext), where errorcode is one of the following: ###k 0 = successful 8 = POV-Ray or MegaPOV failed for an unknown reason. """ (program_nickname, program_path, include_dir) = info #e rename this arg renderer_info? exit = '' program = program_path if sys.platform == 'win32': program = "\"" + program + "\"" # Double quotes needed by Windows. Mark 060602. if program_nickname == 'POV-Ray': exit = "/EXIT" # Later we'll cd to the POV-Ray's INI file directory and use tmp_ini in the POV-Ray command-line. # This helps us get around POV-Ray's I/O Restrictions. Mark 060529. workdir, tmp_ini = os.path.split(povray_ini) # Render scene. try: args = [tmp_ini] if exit: args += [exit] if env.debug(): ## use env.history.message(_graymsg(msg)) ? print "debug: Launching %s: \n" % program_nickname,\ "working directory=",workdir,"\n program_path=", program_path, "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) from processes.Process import Process p = Process() #bruce 060707: this doesn't take advantage of anything not in QProcess, # unless it matters that it reads and discards stdout/stderr # (eg so large output would not block -- unlikely that this matters). # It doesn't echo stdout/stderr. See also blabout/blaberr in other files. Maybe fix this? ###@@@ p.setWorkingDirectory(workdir) p.start(program, arguments) # Put up hourglass cursor to indicate we are busy. Restore the cursor below. Mark 060621. QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) win.glpane.is_animating = True # This disables selection [do you mean highlighting? #k] while rendering the image. import time msg = "Rendering image" while p.state() == QProcess.Running: # Display a message on the status bar that POV-Ray/MegaPOV is rendering. # I'd much rather display a progressbar and stop button by monitoring the size of the output file. # This would require the output file to be written in PPM or BMP format, but not PNG format, since # I don't believe a PNG's final filesize can be predicted. # Check out monitor_progress_by_file_growth() in runSim.py, which does this. [mark] time.sleep(0.25) env.history.statusbar_msg(msg) env.call_qApp_processEvents() if 1: # Update the statusbar message while rendering. if len( msg ) > 40: #bruce changed 100 -> 40 in case of short statusbar msg = "Rendering image" else: #msg = msg + "." msg += "." except: #bruce 060707 moved print_compact_traceback earlier, and its import to toplevel (after Windows A8, before Linux/Mac A8) print_compact_traceback("exception in launch_povray_or_megapov(): ") QApplication.restoreOverrideCursor() win.glpane.is_animating = False return 8, "%s failed for an unknown reason." % program_nickname #bruce 060707 moved the following outside the above try clause, and revised it (after Windows A8, before Linux/Mac A8) QApplication.restoreOverrideCursor() # Restore the cursor. Mark 060621. ## env.history.statusbar_msg("Rendering finished!") # this is wrong if it was not a normal exit. [bruce 060707 removed it] win.glpane.is_animating = False if 1: #bruce 060707 added this (after Windows A8, before Linux/Mac A8): # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = "Rendering finished!" else: msg = "Rendering program had exitcode %r" % exitcode # e.g. 126 for Mac failure; same as shell exitcode, which says "cannot execute binary file"; # but /usr/bin/open helps, so we'll try that above (but not in this commit, which is just to # improve error reporting). ###@@@ # [bruce 060707] else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode or env.debug(): print msg env.history.statusbar_msg(msg) ## if env.debug(): ## env.history.message(_graymsg(msg)) # not needed, caller prints it if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns pass # Display image in separate window here. [Actually I think this is done in the caller -- bruce 060707 comment] return 0, "Rendering finished" # from launch_povray_or_megapov
def launch_povray_or_megapov(win, info, povray_ini): #bruce 060707/11 revised this extensively for Mac A8 """ Try to launch POV-Ray or MegaPOV, as specified in <info> (as returned from decode_povray_prefs, assumed already checked), on the given <povray_ini> file (which should already exist), and running in the directory of that file (this is required, since it may contain relative pathnames). <win> must be the main window object (used for .glpane.is_animating). Returns (errorcode, errortext), where errorcode is one of the following: ###k 0 = successful 8 = POV-Ray or MegaPOV failed for an unknown reason. """ (program_nickname, program_path, include_dir) = info #e rename this arg renderer_info? exit = '' program = program_path if sys.platform == 'win32': program = "\""+program+"\"" # Double quotes needed by Windows. Mark 060602. if program_nickname == 'POV-Ray': exit = "/EXIT" # Later we'll cd to the POV-Ray's INI file directory and use tmp_ini in the POV-Ray command-line. # This helps us get around POV-Ray's I/O Restrictions. Mark 060529. workdir, tmp_ini = os.path.split(povray_ini) # Render scene. try: args = [tmp_ini] if exit: args += [exit] if env.debug(): ## use env.history.message(_graymsg(msg)) ? print "debug: Launching %s: \n" % program_nickname,\ "working directory=",workdir,"\n program_path=", program_path, "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) from processes.Process import Process p = Process() #bruce 060707: this doesn't take advantage of anything not in QProcess, # unless it matters that it reads and discards stdout/stderr # (eg so large output would not block -- unlikely that this matters). # It doesn't echo stdout/stderr. See also blabout/blaberr in other files. Maybe fix this? ###@@@ p.setWorkingDirectory(workdir) p.start(program, arguments) # Put up hourglass cursor to indicate we are busy. Restore the cursor below. Mark 060621. QApplication.setOverrideCursor( QCursor(Qt.WaitCursor) ) win.glpane.is_animating = True # This disables selection [do you mean highlighting? #k] while rendering the image. import time msg = "Rendering image" while p.state() == QProcess.Running: # Display a message on the status bar that POV-Ray/MegaPOV is rendering. # I'd much rather display a progressbar and stop button by monitoring the size of the output file. # This would require the output file to be written in PPM or BMP format, but not PNG format, since # I don't believe a PNG's final filesize can be predicted. # Check out monitor_progress_by_file_growth() in runSim.py, which does this. [mark] time.sleep(0.25) env.history.statusbar_msg(msg) env.call_qApp_processEvents() if 1: # Update the statusbar message while rendering. if len(msg) > 40: #bruce changed 100 -> 40 in case of short statusbar msg = "Rendering image" else: #msg = msg + "." msg += "." except: #bruce 060707 moved print_compact_traceback earlier, and its import to toplevel (after Windows A8, before Linux/Mac A8) print_compact_traceback( "exception in launch_povray_or_megapov(): " ) QApplication.restoreOverrideCursor() win.glpane.is_animating = False return 8, "%s failed for an unknown reason." % program_nickname #bruce 060707 moved the following outside the above try clause, and revised it (after Windows A8, before Linux/Mac A8) QApplication.restoreOverrideCursor() # Restore the cursor. Mark 060621. ## env.history.statusbar_msg("Rendering finished!") # this is wrong if it was not a normal exit. [bruce 060707 removed it] win.glpane.is_animating = False if 1: #bruce 060707 added this (after Windows A8, before Linux/Mac A8): # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = "Rendering finished!" else: msg = "Rendering program had exitcode %r" % exitcode # e.g. 126 for Mac failure; same as shell exitcode, which says "cannot execute binary file"; # but /usr/bin/open helps, so we'll try that above (but not in this commit, which is just to # improve error reporting). ###@@@ # [bruce 060707] else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode or env.debug(): print msg env.history.statusbar_msg(msg) ## if env.debug(): ## env.history.message(_graymsg(msg)) # not needed, caller prints it if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns pass # Display image in separate window here. [Actually I think this is done in the caller -- bruce 060707 comment] return 0, "Rendering finished" # from launch_povray_or_megapov