コード例 #1
0
ファイル: StatusBar.py プロジェクト: octopus89/NanoEngineer-1
    def show_progressbar_and_stop_button(self, progressReporter, cmdname="<unknown command>", showElapsedTime=False):
        """
        Display the statusbar's progressbar and stop button, and
        update it based on calls to the progressReporter.

        When the progressReporter indicates completion, hide the
        progressbar and stop button and return 0. If the user first
        presses the Stop button on the statusbar, hide the progressbar
        and stop button and return 1.

        Parameters:
        progressReporter - See potential implementations below.
        cmdname - name of command (used in some messages and in abort button tooltip)
        showElapsedTime - if True, display duration (in seconds) below progress bar

        Return value: 0 if file reached desired size, 1 if user hit abort button.

        """

        updateInterval = 0.1  # seconds
        startTime = time.time()
        elapsedTime = 0
        displayedElapsedTime = 0

        ###e the following is WRONG if there is more than one task at a time... [bruce 060106 comment]
        self.progressBar.reset()
        self.progressBar.setMaximum(progressReporter.getMaxProgress())
        self.progressBar.setValue(0)
        self.progressBar.show()

        abortHandler = AbortHandler(self, cmdname)

        # Main loop
        while progressReporter.notDoneYet():
            self.progressBar.setValue(progressReporter.getProgress())
            env.call_qApp_processEvents()
            # Process queued events (e.g. clicking Abort button,
            # but could be anything -- no modal dialog involved anymore).

            if showElapsedTime:
                elapsedTime = int(time.time() - startTime)
                if elapsedTime != displayedElapsedTime:
                    displayedElapsedTime = elapsedTime
                    env.history.progress_msg("Elapsed Time: " + hhmmss_str(displayedElapsedTime))

            if abortHandler.getPressCount() > 0:
                env.history.statusbar_msg("Aborted.")
                abortHandler.finish()
                return 1

            time.sleep(updateInterval)  # Take a rest

        # End of Main loop (this only runs if it ended without being aborted)
        self.progressBar.setValue(progressReporter.getMaxProgress())
        time.sleep(updateInterval)  # Give the progress bar a moment to show 100%
        env.history.statusbar_msg("Done.")
        abortHandler.finish()
        return 0
コード例 #2
0
ファイル: sim_commandruns.py プロジェクト: vcsrc/nanoengineer
    def run(self):
        #bruce 050324 made this method from the body of MWsemantics.simSetup
        # and cleaned it up a bit in terms of how it finds the movie to use.
        if not self.part.molecules:  # Nothing in the part to simulate.
            msg = redmsg("Nothing to simulate.")
            env.history.message(self.cmdname + ": " + msg)
            self.win.simSetupAction.setChecked(
                0)  # toggle the Simulator icon ninad061113
            return

        env.history.message(
            self.cmdname + ": " +
            "Enter simulation parameters and select <b>Run Simulation.</b>")

        ###@@@ we could permit this in movie player mode if we'd now tell that mode to stop any movie it's now playing
        # iff it's the current mode.

        previous_movie = self.assy.current_movie
        # might be None; will be used only to restore self.assy.current_movie if we don't make a valid new one
        self.movie = None
        r = self.makeSimMovie(
        )  # will store self.movie as the one it made, or leave it as None if cancelled
        movie = self.movie
        self.assy.current_movie = movie or previous_movie
        # (this restores assy.current_movie if there was an error in making new movie, though perhaps nothing changed it anyway)

        if not r:  # Movie file saved successfully; movie is a newly made Movie object just for the new file
            assert movie
            # if duration took at least 10 seconds, print msg.
            ##            self.progressbar = self.win.progressbar ###k needed???
            ##            duration = self.progressbar.duration [bruce 060103 zapped this kluge]
            try:
                duration = movie.duration  #bruce 060103
            except:
                # this might happen if earlier exceptions prevented us storing one, so nevermind it for now
                duration = 0.0
            if duration >= 10.0:
                spf = "%.2f" % (duration / movie.totalFramesRequested)
                ###e bug in this if too few frames were written; should read and use totalFramesActual
                estr = hhmmss_str(duration)
                msg = "Total time to create movie file: " + estr + ", Seconds/frame = " + spf
                env.history.message(self.cmdname + ": " + msg)
            msg = "Movie written to [" + movie.filename + "]." \
                "<br>To play the movie, select <b>Simulation > Play Movie</b>"
            env.history.message(self.cmdname + ": " + msg)
            self.win.simSetupAction.setChecked(0)
            self.win.simMoviePlayerAction.setEnabled(
                1)  # Enable "Movie Player"
            self.win.simPlotToolAction.setEnabled(1)  # Enable "Plot Tool"
            #bruce 050324 question: why are these enabled here and not in the subr or even if it's cancelled? bug? ####@@@@
        else:
            assert not movie
            # Don't allow uninformative messages to obscure informative ones - wware 060314
            if r == FAILURE_ALREADY_DOCUMENTED:
                env.history.message(self.cmdname + ": " + "Cancelled.")
                # (happens for any error; more specific message (if any) printed earlier)
        return
コード例 #3
0
    def run(self):
        # bruce 050324 made this method from the body of MWsemantics.simSetup
        # and cleaned it up a bit in terms of how it finds the movie to use.
        if not self.part.molecules:  # Nothing in the part to simulate.
            msg = redmsg("Nothing to simulate.")
            env.history.message(self.cmdname + ": " + msg)
            self.win.simSetupAction.setChecked(0)  # toggle the Simulator icon ninad061113
            return

        env.history.message(self.cmdname + ": " + "Enter simulation parameters and select <b>Run Simulation.</b>")

        ###@@@ we could permit this in movie player mode if we'd now tell that mode to stop any movie it's now playing
        # iff it's the current mode.

        previous_movie = self.assy.current_movie
        # might be None; will be used only to restore self.assy.current_movie if we don't make a valid new one
        self.movie = None
        r = self.makeSimMovie()  # will store self.movie as the one it made, or leave it as None if cancelled
        movie = self.movie
        self.assy.current_movie = movie or previous_movie
        # (this restores assy.current_movie if there was an error in making new movie, though perhaps nothing changed it anyway)

        if not r:  # Movie file saved successfully; movie is a newly made Movie object just for the new file
            assert movie
            # if duration took at least 10 seconds, print msg.
            ##            self.progressbar = self.win.progressbar ###k needed???
            ##            duration = self.progressbar.duration [bruce 060103 zapped this kluge]
            try:
                duration = movie.duration  # bruce 060103
            except:
                # this might happen if earlier exceptions prevented us storing one, so nevermind it for now
                duration = 0.0
            if duration >= 10.0:
                spf = "%.2f" % (duration / movie.totalFramesRequested)
                ###e bug in this if too few frames were written; should read and use totalFramesActual
                estr = hhmmss_str(duration)
                msg = "Total time to create movie file: " + estr + ", Seconds/frame = " + spf
                env.history.message(self.cmdname + ": " + msg)
            msg = (
                "Movie written to [" + movie.filename + "]."
                "<br>To play the movie, select <b>Simulation > Play Movie</b>"
            )
            env.history.message(self.cmdname + ": " + msg)
            self.win.simSetupAction.setChecked(0)
            self.win.simMoviePlayerAction.setEnabled(1)  # Enable "Movie Player"
            self.win.simPlotToolAction.setEnabled(1)  # Enable "Plot Tool"
            # bruce 050324 question: why are these enabled here and not in the subr or even if it's cancelled? bug? ####@@@@
        else:
            assert not movie
            # Don't allow uninformative messages to obscure informative ones - wware 060314
            if r == FAILURE_ALREADY_DOCUMENTED:
                env.history.message(self.cmdname + ": " + "Cancelled.")
                # (happens for any error; more specific message (if any) printed earlier)
        return
コード例 #4
0
ファイル: GamessJob.py プロジェクト: ematvey/NanoEngineer-1
 def launchProgressDialog(self):
     """
     """
     stime = time.time()
     self.show()
     while 1:
         env.call_qApp_processEvents()
         if self.Rejected:
             break
         duration = time.time() - stime
         elapmsg = "Elapsed Time: " + hhmmss_str(int(duration))
         self.msgLabel2.setText(elapmsg) 
         time.sleep(0.01)
     return
コード例 #5
0
ファイル: GamessJob.py プロジェクト: ematvey/NanoEngineer-1
 def processTimeout(self):
     if self.process.isRunning():
         if not self.progressDialog.isShown() or self.progressDialog.Rejected:
             return
             
         msgLabel = self.progressDialog.getMsgLabel()
         duration = time.time() - self.stime
         elapmsg = "Elapsed Time: " + hhmmss_str(int(duration))
         msgLabel.setText(elapmsg)
         
         ####bytes = self.process.readStdout()
         ####if bytes:
         ####    self.fwThread.putData(bytes)
     return
コード例 #6
0
 def launchProgressDialog(self):
     """
     """
     stime = time.time()
     self.show()
     while 1:
         env.call_qApp_processEvents()
         if self.Rejected:
             break
         duration = time.time() - stime
         elapmsg = "Elapsed Time: " + hhmmss_str(int(duration))
         self.msgLabel2.setText(elapmsg)
         time.sleep(0.01)
     return
コード例 #7
0
    def processTimeout(self):
        if self.process.isRunning():
            if not self.progressDialog.isShown(
            ) or self.progressDialog.Rejected:
                return

            msgLabel = self.progressDialog.getMsgLabel()
            duration = time.time() - self.stime
            elapmsg = "Elapsed Time: " + hhmmss_str(int(duration))
            msgLabel.setText(elapmsg)

            ####bytes = self.process.readStdout()
            ####if bytes:
            ####    self.fwThread.putData(bytes)
        return
コード例 #8
0
ファイル: StatusBar.py プロジェクト: elfion/nanoengineer
    def show_progressbar_and_stop_button(self,
                                         progressReporter,
                                         cmdname="<unknown command>",
                                         showElapsedTime=False):
        """
        Display the statusbar's progressbar and stop button, and
        update it based on calls to the progressReporter.

        When the progressReporter indicates completion, hide the
        progressbar and stop button and return 0. If the user first
        presses the Stop button on the statusbar, hide the progressbar
        and stop button and return 1.

        Parameters:
        progressReporter - See potential implementations below.
        cmdname - name of command (used in some messages and in abort button tooltip)
        showElapsedTime - if True, display duration (in seconds) below progress bar

        Return value: 0 if file reached desired size, 1 if user hit abort button.

        """

        updateInterval = .1  # seconds
        startTime = time.time()
        elapsedTime = 0
        displayedElapsedTime = 0

        ###e the following is WRONG if there is more than one task at a time... [bruce 060106 comment]
        self.progressBar.reset()
        self.progressBar.setMaximum(progressReporter.getMaxProgress())
        self.progressBar.setValue(0)
        self.progressBar.show()

        abortHandler = AbortHandler(self, cmdname)

        # Main loop
        while progressReporter.notDoneYet():
            self.progressBar.setValue(progressReporter.getProgress())
            env.call_qApp_processEvents()
            # Process queued events (e.g. clicking Abort button,
            # but could be anything -- no modal dialog involved anymore).

            if showElapsedTime:
                elapsedTime = int(time.time() - startTime)
                if (elapsedTime != displayedElapsedTime):
                    displayedElapsedTime = elapsedTime
                    env.history.progress_msg("Elapsed Time: " +
                                             hhmmss_str(displayedElapsedTime))
                    # note: it's intentional that this doesn't directly call
                    # self._f_progress_msg. [bruce 081229 comment]

            if abortHandler.getPressCount() > 0:
                env.history.statusbar_msg("Aborted.")
                abortHandler.finish()
                return 1

            time.sleep(updateInterval)  # Take a rest

        # End of Main loop (this only runs if it ended without being aborted)
        self.progressBar.setValue(progressReporter.getMaxProgress())
        time.sleep(
            updateInterval)  # Give the progress bar a moment to show 100%
        env.history.statusbar_msg("Done.")
        abortHandler.finish()
        return 0