Beispiel #1
0
def ProgressBar(n_steps, label="", allow_cancel=False, parent=None):
    """
    Progressbar context manager for showing progress of workflow to user. Example::

        with emzed.gui.ProgressBar(n_steps=100, allow_cancel=True) as handler:
            for i in range(100):

                # we simulate work of step i

                # we update progressbar
                handler.update(i, "step %03d" % i)

                # we can check if user pressed "Cancel" button and stop our "workflow":
                if handler.is_canceled():
                    break
    """

    app = guidata.qapplication()
    dlg = QProgressDialog(parent)
    dlg.setLabelText(label)
    dlg.setAutoClose(False)
    dlg.setAutoReset(False)
    if allow_cancel:
        dlg.setCancelButtonText("Cancel")
    dlg.setMaximum(n_steps)

    class ProgressBarHandler(object):
        def __init__(self, n_steps, dlg):
            self._dlg = dlg
            self._n_steps = n_steps
            self._n = 0
            self._canceled = False
            dlg.canceled.connect(self._set_canceled)
            dlg.setValue(0)

        def _set_canceled(self):
            self._canceled = True
            dlg.close()

        def update(self, n, message=None):
            app.processEvents()
            self._n = n
            dlg.setValue(n + 1)
            if message is not None:
                dlg.setLabelText(message)
            dlg.update()
            app.processEvents()

        def is_canceled(self):
            return self._canceled

    dlg.activateWindow()
    dlg.show()
    dlg.raise_()
    app.processEvents()

    handler = ProgressBarHandler(n_steps, dlg)
    yield handler

    dlg.close()
 def _onComputeTranslationButtonPressed(self):        
     self._onMethodChanged()
     
     m = self.mainOperator.TranslationVectors.meta
     maxt = m.shape[0]
     progress = QProgressDialog("Computing Translation Vectors...", "Stop", 0, maxt)
     progress.setWindowModality(Qt.ApplicationModal)
     progress.setMinimumDuration(0)
     progress.setCancelButtonText(QString())
     progress.forceShow()
     
     reqs = []
     for t in range(maxt):
         reqs.append(self.mainOperator.TranslationVectorsComputation([t]))
         reqs[-1].submit()
     
     for i, req in enumerate(reqs):
         progress.setValue(i)
         if progress.wasCanceled():
             req.cancel()
         else:
             req.wait()
     
     progress.setValue(maxt)
     
     roi = SubRegion(self.mainOperator.TranslationVectors, start=5*(0,), stop=m.shape)
     self.mainOperator.TranslationVectors.setDirty(roi)
     
     print 'Translation Vector Computation: done.'
    def _calculateFeaturesButtonPressed(self):
        maxt = self.mainOperator.LabelImage.meta.shape[0]
        progress = QProgressDialog("Calculating featuers...", "Stop", 0, maxt)
        progress.setWindowModality(Qt.ApplicationModal)
        progress.setMinimumDuration(0)
        progress.setCancelButtonText(QString())

        reqs = []
        self.mainOperator._opRegFeats.fixed = False
        for t in range(maxt):
            reqs.append(self.mainOperator.RegionFeatures([t]))
            reqs[-1].submit()

        for i, req in enumerate(reqs):
            progress.setValue(i)
            if progress.wasCanceled():
                req.cancel()
            else:
                req.wait()

        self.mainOperator._opRegFeats.fixed = True
        progress.setValue(maxt)

        self.mainOperator.ObjectCenterImage.setDirty(SubRegion(self.mainOperator.ObjectCenterImage))

        print 'Object Extraction: done.'
Beispiel #4
0
    def on_btn_save_udf_param_clicked(self):
        """
        Slot documentation goes here.
        """
        msg = u'保存参数并同时更新UDF中建筑负载文件名,确定吗?'
        reply = self.show_yesno_msgbox(msg)
        if reply == 0:
            return
        fname = self.le_fluent_udf_file.text()
        if fname == '':
            msg = u'UDF文件名为空, 请先设置一个有效的UDF文件'
            self._show_tips(msg, tip_type=1)
            return
        # check if file path exists
        if not os.path.exists(fname):  
            msg = u'UDF文件路径不存在, 请打开一个有效的UDF文件!'
            self._show_tips(msg, tip_type=1)
            return

        # first, get params from widgets
        params = self.get_udf_param_from_widgets()
        # read the load file
        progress_dlg = QProgressDialog(self)
        progress_dlg.setModal(True)
        progress_dlg.setMinimumDuration(1)  
        progress_dlg.setWindowTitle(u"处理数据")  
        progress_dlg.setLabelText(u"正在处理建筑负荷数据...")  
        progress_dlg.setCancelButtonText("Cancel")  
        # we don't know how many lines in the load file
        progress_dlg.setMinimum(1)
        progress_dlg.setMaximum(10000)
        max_q = 0.0
        min_q = 0.0
        line_cnt = 0
        with open(params['load_file'], 'r') as rfh:
            for line in rfh:
                val = float(line)
                if val > max_q:
                    max_q = val
                if val < min_q:
                    min_q = val
                progress_dlg.setValue(line_cnt)  
                if progress_dlg.wasCanceled():
                    return
                line_cnt += 1
        # set the max value to terminate the progress dialog
        if line_cnt < 10000:
            QThread.sleep(1)
            progress_dlg.setValue(10000)  
        params['copc_max_q'] = max_q
        params['coph_max_q'] = min_q
        # modify the udf file
        result = self.udf_model.write_params(params, fname)
        if result == True:
            msg = u'文件%s更新成功' % fname
            self._show_tips(msg)
        else:
            msg = u'文件更新失败, 请确保%s是有效的UDF文件' % fname
            self._show_tips(msg, tip_type=1)
Beispiel #5
0
 def on_actionOpenSession_triggered(self, filename=None):
     if not filename:
         filename = QFileDialog.getOpenFileName(self, 'Open Session')
     if filename:
         if self.session.messages:
             args = argv[:]
             if len(args) > 1:
                 args[1] = filename
             else:
                 args.append(abspath(str(filename)))
             try:
                 pid = spawnvp(P_NOWAIT, args[0], args)
             except (NameError, ):
                 Popen('"%s" "%s" "%s"' % (executable, args[0], args[1]))
             return
         if not self.warningOpenTabs():
             return
         dlg = QProgressDialog(self)
         dlg.setLabelText('Reading session file.')
         dlg.setCancelButtonText('Abort')
         dlg.setWindowModality(Qt.WindowModal)
         dlg.setWindowTitle('Reading...')
         self.show()
         processEvents()
         dlg.show()
         processEvents()
         try:
             loadit = self.session.load(str(filename))
             count = loadit.next()
             last = count - 1
         except (StopIteration, ):
             msg = 'Warning session not loaded from "%s"' % filename
             dlg.close()
         else:
             dlg.setLabelText('Loading session messages.')
             dlg.setWindowTitle('Loading...')
             dlg.setMaximum(last)
             msgid = -1
             for msgid in loadit:
                 processEvents()
                 dlg.setValue(msgid)
                 if dlg.wasCanceled():
                     dlg.close()
                     break
             if msgid == last:
                 msg = 'Loaded all %s messages from file "%s".'
                 msg %= (count, filename)
                 self.setCurrentSession(filename)
             else:
                 msg = 'Load aborted; loaded %s messages of %s.'
                 msg %= (msgid+1, count)
         self.statusBar().showMessage(msg, 5000)
Beispiel #6
0
def ProgressBar(n_steps, label="", allow_cancel=False, parent=None):
    """
    Progressbar context manager for showing progress of workflow to user. Example::

        with emzed.gui.ProgressBar(n_steps=100, allow_cancel=True) as handler:
            for i in range(100):

                # we simulate work of step i

                # we update progressbar
                handler.update(i, "step %03d" % i)

                # we can check if user pressed "Cancel" button and stop our "workflow":
                if handler.is_canceled():
                    break
    """

    app = guidata.qapplication()
    dlg = QProgressDialog(parent)
    dlg.setLabelText(label)
    dlg.setAutoClose(False)
    dlg.setAutoReset(False)
    if allow_cancel:
        dlg.setCancelButtonText("Cancel")
    dlg.setMaximum(n_steps)

    class ProgressBarHandler(object):

        def __init__(self, n_steps, dlg):
            self._dlg = dlg
            self._n_steps = n_steps
            self._n = 0
            self._canceled = False
            dlg.canceled.connect(self._set_canceled)
            dlg.setValue(0)

        def _set_canceled(self):
            self._canceled = True
            dlg.close()

        def update(self, n, message=None):
            app.processEvents()
            self._n = n
            dlg.setValue(n + 1)
            if message is not None:
                dlg.setLabelText(message)
            dlg.update()
            app.processEvents()

        def is_canceled(self):
            return self._canceled

    dlg.activateWindow()
    dlg.show()
    dlg.raise_()
    app.processEvents()

    handler = ProgressBarHandler(n_steps, dlg)
    yield handler

    dlg.close()