Ejemplo n.º 1
0
    def runGNUplot(self, plotfile):
        """Sends plotfile to GNUplot.
        """
        
        # Make sure plotfile exists
        if not os.path.exists(plotfile):
            msg = redmsg("Plotfile [" + plotfile + "] is missing.  Plot aborted.")
            env.history.message(cmd + msg)
            return
            
        # filePath = the current directory NE-1 is running from.
        filePath = os.path.dirname(os.path.abspath(sys.argv[0]))
        
        # "program" is the full path to the GNUplot executable. 
        if sys.platform == 'win32': 
            program = os.path.normpath(filePath + '/../bin/wgnuplot.exe')
        else:
            program = os.path.normpath('/usr/bin/gnuplot')

        # Set environment variables to make gnuplot use a specific AquaTerm on
        # Mac. Originally "Huaicai 3/18", fixed by Brian Helfrich May 23, 2007.
        #
        if sys.platform == 'darwin':
            aquaPath = os.path.normpath(filePath + '/../bin/AquaTerm.app')
            os.environ['AQUATERM_PATH'] = aquaPath
            aquaPath = \
                os.path.normpath(filePath + '/../Frameworks/AquaTerm.framework')
            os.environ['DYLD_LIBRARY_PATH'] = aquaPath
            # Note: I tried using:
            #   environment.append(QString('AQUATERM_PATH=%s' % aquaPath))
            #   environment.append(QString('DYLD_LIBRARY_PATH=%s' % aquaPath))
            # followed by plotProcess.setEnvironment(environment), but it just
            # wouldn't see the AquaTerm library. So, although the above is more
            # heavy-handed than just changing the Process environment, at least
            # it works.

        # Make sure GNUplot executable exists
        if not os.path.exists(program):
            msg = redmsg("GNUplot executable [" + program + "] is missing.  Plot aborted.")
            env.history.message(cmd + msg)
            return
                
        plotProcess = None
        try:
            from processes.Process import Process
            plotProcess = Process()
            
            # Run gnuplot as a new, separate process. 
            started = plotProcess.startDetached(program, QStringList(plotfile))
            ###e It might also be good to pass gnuplot some arg to tell it to ignore ~/.gnuplot. [bruce 060425 guess]

            if not started:
                env.history.message(redmsg("gnuplot failed to run!"))
            else: 
                env.history.message("Running gnuplot file: " + plotfile)
                if debug_gnuplot:
                    try:
                        #bruce 060425 debug code; Qt assistant for QProcess says this won't work on Windows (try it there anyway).
                        pid = plotProcess.pid() # This should work on Windows in Qt 4.2 [mark 2007-05-03]
                        pid = int(pid) # this is what is predicted to fail on Windows
                        env.history.message("(debug: gnuplot is %r, its process id is %d)" % (program, pid))
                    except:
                        print_compact_traceback("debug: exception printing processIdentifier (might be normal on Windows): ")
                    pass
                pass
        except: # We had an exception.
            print"exception in GNUplot; continuing: "
            if plotProcess:
                print ">>> %d" % plotProcess.error()
                print "Killing process"
                plotProcess.kill()
                plotProcess = None
Ejemplo n.º 2
0
    def runGNUplot(self, plotfile):
        """Sends plotfile to GNUplot.
        """
        
        # Make sure plotfile exists
        if not os.path.exists(plotfile):
            msg = redmsg("Plotfile [" + plotfile + "] is missing.  Plot aborted.")
            env.history.message(cmd + msg)
            return
            
        # filePath = the current directory NE-1 is running from.
        filePath = os.path.dirname(os.path.abspath(sys.argv[0]))
        
        # "program" is the full path to the GNUplot executable. 
        if sys.platform == 'win32': 
            program = os.path.normpath(filePath + '/../bin/wgnuplot.exe')
        else:
            program = os.path.normpath(filePath + '/../bin/gnuplot')

        # Set environment variables to make gnuplot use a specific AquaTerm on
        # Mac. Originally "Huaicai 3/18", fixed by Brian Helfrich May 23, 2007.
        #
        if sys.platform == 'darwin':
            aquaPath = os.path.normpath(filePath + '/../bin/AquaTerm.app')
            os.environ['AQUATERM_PATH'] = aquaPath
            aquaPath = \
                os.path.normpath(filePath + '/../Frameworks/AquaTerm.framework')
            os.environ['DYLD_LIBRARY_PATH'] = aquaPath
            # Note: I tried using:
            #   environment.append(QString('AQUATERM_PATH=%s' % aquaPath))
            #   environment.append(QString('DYLD_LIBRARY_PATH=%s' % aquaPath))
            # followed by plotProcess.setEnvironment(environment), but it just
            # wouldn't see the AquaTerm library. So, although the above is more
            # heavy-handed than just changing the Process environment, at least
            # it works.

        # Make sure GNUplot executable exists
        if not os.path.exists(program):
            msg = redmsg("GNUplot executable [" + program + "] is missing.  Plot aborted.")
            env.history.message(cmd + msg)
            return
                
        plotProcess = None
        try:
            from processes.Process import Process
            plotProcess = Process()
            
            # Run gnuplot as a new, separate process. 
            started = plotProcess.startDetached(program, QStringList(plotfile))
            ###e It might also be good to pass gnuplot some arg to tell it to ignore ~/.gnuplot. [bruce 060425 guess]

            if not started:
                env.history.message(redmsg("gnuplot failed to run!"))
            else: 
                env.history.message("Running gnuplot file: " + plotfile)
                if debug_gnuplot:
                    try:
                        #bruce 060425 debug code; Qt assistant for QProcess says this won't work on Windows (try it there anyway).
                        pid = plotProcess.pid() # This should work on Windows in Qt 4.2 [mark 2007-05-03]
                        pid = int(pid) # this is what is predicted to fail on Windows
                        env.history.message("(debug: gnuplot is %r, its process id is %d)" % (program, pid))
                    except:
                        print_compact_traceback("debug: exception printing processIdentifier (might be normal on Windows): ")
                    pass
                pass
        except: # We had an exception.
            print"exception in GNUplot; continuing: "
            if plotProcess:
                print ">>> %d" % plotProcess.error()
                print "Killing process"
                plotProcess.kill()
                plotProcess = None