Exemplo n.º 1
0
    def _createToolButtonWidget(self, parent):
        """
        @see: self.createWidget()
        """
        btn = QToolButton(parent)
        btn.setAutoFillBackground(True)
        btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        btn.setMinimumWidth(75)
        btn.setMaximumWidth(75)
        btn.setMinimumHeight(62)
        btn.setAutoRaise(True)

        btn.setCheckable(True)
        btn.setDefaultAction(self)

        text = truncateText(self.text())
        btn.setText(text)

        if self._toolButtonPalette:
            btn.setPalette(self._toolButtonPalette)

        #@@@ ninad070125 The following function
        #adds a newline character after each word in toolbutton text.
        #but the changes are reflected only on 'mode' toolbuttons
        #on the flyout toolbar (i.e.only Checkable buttons..don't know
        #why. Disabling its use for now.
        debug_wrapText = False

        if debug_wrapText:
            text = wrapToolButtonText(action.text())
            if text:
                action.setText(text)

        return btn
Exemplo n.º 2
0
class StatusBar(QStatusBar):
    def __init__(self, win):
        QStatusBar.__init__(self, win)
        self._progressLabel = QLabel()

        self._progressLabel.setMinimumWidth(200)
        self._progressLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
        self.addPermanentWidget(self._progressLabel)

        self.progressBar = QProgressBar(win)
        self.progressBar.setMaximumWidth(250)
        qt4todo('StatusBar.progressBar.setCenterIndicator(True)')
        self.addPermanentWidget(self.progressBar)
        self.progressBar.hide()

        self.simAbortButton = QToolButton(win)
        self.simAbortButton.setIcon(
            geticon("ui/actions/Simulation/Stopsign.png"))
        self.simAbortButton.setMaximumWidth(32)
        self.addPermanentWidget(self.simAbortButton)
        self.connect(self.simAbortButton, SIGNAL("clicked()"), self.simAbort)
        self.simAbortButton.hide()

        self.dispbarLabel = QLabel(win)
        #self.dispbarLabel.setFrameStyle( QFrame.Panel | QFrame.Sunken )
        self.dispbarLabel.setText("Global display style:")
        self.addPermanentWidget(self.dispbarLabel)

        # Global display styles combobox
        self.globalDisplayStylesComboBox = GlobalDisplayStylesComboBox(win)
        self.addPermanentWidget(self.globalDisplayStylesComboBox)

        # Selection lock button. It always displays the selection lock state
        # and it is available to click.
        self.selectionLockButton = QToolButton(win)
        self.selectionLockButton.setDefaultAction(win.selectLockAction)
        self.addPermanentWidget(self.selectionLockButton)

        self.abortableCommands = {}

        #bruce 081230 debug code:
        ## self.connect(self, SIGNAL('messageChanged ( const QString &)'),
        ##              self.slotMessageChanged )


##     def slotMessageChanged(self, message): # bruce 081230 debug code
##         print "messageChanged: %r" % str(message)

    def showMessage(self, text):  #bruce 081230
        """
        [extends superclass method]
        """
        ## QStatusBar.showMessage(self, " ")
        QStatusBar.showMessage(self, text)
        ## print "message was set to %r" % str(self.currentMessage())
        return

    def _f_progress_msg(self, text):  #bruce 081229 refactoring
        """
        Friend method for use only by present implementation
        of env.history.progress_msg. Display text in our
        private label widget dedicated to progress messages.
        """
        self._progressLabel.setText(text)
        return

    def makeCommandNameUnique(self, commandName):
        index = 1
        trial = commandName
        while (self.abortableCommands.has_key(trial)):
            trial = "%s [%d]" % (commandName, index)
            index += 1
        return trial

    def addAbortableCommand(self, commandName, abortHandler):
        uniqueCommandName = self.makeCommandNameUnique(commandName)
        self.abortableCommands[uniqueCommandName] = abortHandler
        return uniqueCommandName

    def removeAbortableCommand(self, commandName):
        del self.abortableCommands[commandName]

    def simAbort(self):
        """
        Slot for Abort button.
        """
        if debug_flags.atom_debug and self.sim_abort_button_pressed:  #bruce 060106
            print "atom_debug: self.sim_abort_button_pressed is already True before we even put up our dialog"

        # Added confirmation before aborting as part of fix to bug 915. Mark 050824.
        # Bug 915 had to do with a problem if the user accidently hit the space bar or espace key,
        # which would call this slot and abort the simulation.  This should no longer be an issue here
        # since we aren't using a dialog.  I still like having this confirmation anyway.
        # IMHO, it should be kept. Mark 060106.
        ret = QMessageBox.warning(
            self,
            "Confirm",
            "Please confirm you want to abort.\n",
            "Confirm",
            "Cancel",
            "",
            1,  # The "default" button, when user presses Enter or Return (1 = Cancel)
            1)  # Escape (1= Cancel)

        if ret == 0:  # Confirmed
            for abortHandler in self.abortableCommands.values():
                abortHandler.pressed()

    def show_indeterminate_progress(self):
        value = self.progressBar.value()
        self.progressBar.setValue(value)

    def possibly_hide_progressbar_and_stop_button(self):
        if (len(self.abortableCommands) <= 0):
            self.progressBar.reset()
            self.progressBar.hide()
            self.simAbortButton.hide()

    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
Exemplo n.º 3
0
class StatusBar(QStatusBar):
    def __init__(self, win):
        QStatusBar.__init__(self, win)
        self.statusMsgLabel = QLabel()

        self.statusMsgLabel.setMinimumWidth(200)
        self.statusMsgLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
        self.addPermanentWidget(self.statusMsgLabel)

        self.progressBar = QProgressBar(win)
        self.progressBar.setMaximumWidth(250)
        qt4todo("StatusBar.progressBar.setCenterIndicator(True)")
        self.addPermanentWidget(self.progressBar)
        self.progressBar.hide()

        self.simAbortButton = QToolButton(win)
        self.simAbortButton.setIcon(geticon("ui/actions/Simulation/Stopsign.png"))
        self.simAbortButton.setMaximumWidth(32)
        self.addPermanentWidget(self.simAbortButton)
        self.connect(self.simAbortButton, SIGNAL("clicked()"), self.simAbort)
        self.simAbortButton.hide()

        self.dispbarLabel = QLabel(win)
        # self.dispbarLabel.setFrameStyle( QFrame.Panel | QFrame.Sunken )
        self.dispbarLabel.setText("Global display style:")
        self.addPermanentWidget(self.dispbarLabel)

        # Global display styles combobox
        self.globalDisplayStylesComboBox = GlobalDisplayStylesComboBox(win)
        self.addPermanentWidget(self.globalDisplayStylesComboBox)

        # Selection lock button. It always displays the selection lock state
        # and it is available to click.
        self.selectionLockButton = QToolButton(win)
        self.selectionLockButton.setDefaultAction(win.selectLockAction)
        self.addPermanentWidget(self.selectionLockButton)

        # Only use of this appears to be commented out in MWsemantics as of 2007/12/14
        self.modebarLabel = QLabel(win)
        self.addPermanentWidget(self.modebarLabel)
        self.abortableCommands = {}

    def makeCommandNameUnique(self, commandName):
        index = 1
        trial = commandName
        while self.abortableCommands.has_key(trial):
            trial = "%s [%d]" % (commandName, index)
            index += 1
        return trial

    def addAbortableCommand(self, commandName, abortHandler):
        uniqueCommandName = self.makeCommandNameUnique(commandName)
        self.abortableCommands[uniqueCommandName] = abortHandler
        return uniqueCommandName

    def removeAbortableCommand(self, commandName):
        del self.abortableCommands[commandName]

    def simAbort(self):
        """
        Slot for Abort button.
        """
        if debug_flags.atom_debug and self.sim_abort_button_pressed:  # bruce 060106
            print "atom_debug: self.sim_abort_button_pressed is already True before we even put up our dialog"

        # Added confirmation before aborting as part of fix to bug 915. Mark 050824.
        # Bug 915 had to do with a problem if the user accidently hit the space bar or espace key,
        # which would call this slot and abort the simulation.  This should no longer be an issue here
        # since we aren't using a dialog.  I still like having this confirmation anyway.
        # IMHO, it should be kept. Mark 060106.
        ret = QMessageBox.warning(
            self,
            "Confirm",
            "Please confirm you want to abort.\n",
            "Confirm",
            "Cancel",
            "",
            1,  # The "default" button, when user presses Enter or Return (1 = Cancel)
            1,
        )  # Escape (1= Cancel)

        if ret == 0:  # Confirmed
            for abortHandler in self.abortableCommands.values():
                abortHandler.pressed()

    def show_indeterminate_progress(self):
        value = self.progressBar.value()
        self.progressBar.setValue(value)

    def possibly_hide_progressbar_and_stop_button(self):
        if len(self.abortableCommands) <= 0:
            self.progressBar.reset()
            self.progressBar.hide()
            self.simAbortButton.hide()

    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