當前位置: 首頁>>代碼示例>>Python>>正文


Python QKeySequence.isEmpty方法代碼示例

本文整理匯總了Python中PyQt4.QtGui.QKeySequence.isEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Python QKeySequence.isEmpty方法的具體用法?Python QKeySequence.isEmpty怎麽用?Python QKeySequence.isEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt4.QtGui.QKeySequence的用法示例。


在下文中一共展示了QKeySequence.isEmpty方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validateAction

# 需要導入模塊: from PyQt4.QtGui import QKeySequence [as 別名]
# 或者: from PyQt4.QtGui.QKeySequence import isEmpty [as 別名]
 def validateAction(self, row, column):
     if column != 1:
         return
     table = self.actionTable
     item = table.item(row, column)
     shortcutText = QKeySequence(item.text()).toString()
     thisRow = table.row(item)
     if not shortcutText.isEmpty():
         for row in range(table.rowCount()):
             if row == thisRow:
                 continue
             other = table.item(row, 1)
             if other.text() == shortcutText:
                 other.setText(item.oldShortcutText)
                 break
         item.setText(shortcutText)
         item.oldShortcutText = shortcutText
     table.resizeColumnToContents(1)
開發者ID:natural,項目名稱:biblepath,代碼行數:20,代碼來源:actioneditorframe.py

示例2: KeySequenceButton

# 需要導入模塊: from PyQt4.QtGui import QKeySequence [as 別名]
# 或者: from PyQt4.QtGui.QKeySequence import isEmpty [as 別名]
class KeySequenceButton(QPushButton):
    def __init__(self, parent=None):
        super(KeySequenceButton, self).__init__(parent)
        self.setIcon(icons.get("configure"))
        self._modifierlessAllowed = False
        self._seq = QKeySequence()
        self._timer = QTimer()
        self._timer.setSingleShot(True)
        self._isrecording = False
        self.clicked.connect(self.startRecording)
        self._timer.timeout.connect(self.doneRecording)

    def setKeySequence(self, seq):
        self._seq = seq
        self.updateDisplay()

    def keySequence(self):
        if self._isrecording:
            self.doneRecording()
        return self._seq

    def updateDisplay(self):
        if self._isrecording:
            s = self._recseq.toString(QKeySequence.NativeText).replace("&", "&&")
            if self._modifiers:
                if s:
                    s += ","
                s += QKeySequence(self._modifiers).toString(QKeySequence.NativeText)
            elif self._recseq.isEmpty():
                s = _("Input")
            s += " ..."
        else:
            s = self._seq.toString(QKeySequence.NativeText).replace("&", "&&")
        self.setText(s)

    def isRecording(self):
        return self._isrecording

    def event(self, ev):
        if self._isrecording:
            # prevent Qt from special casing Tab and Backtab
            if ev.type() == QEvent.KeyPress:
                self.keyPressEvent(ev)
                return True
        return super(KeySequenceButton, self).event(ev)

    def keyPressEvent(self, ev):
        if not self._isrecording:
            return super(KeySequenceButton, self).keyPressEvent(ev)
        if ev.isAutoRepeat():
            return
        modifiers = int(ev.modifiers() & (Qt.SHIFT | Qt.CTRL | Qt.ALT | Qt.META))
        ev.accept()

        key = ev.key()
        # check if key is a modifier or a character key without modifier (and if that is allowed)
        if (
            # don't append the key if the key is -1 (garbage) or a modifier ...
            key not in (-1, Qt.Key_AltGr, Qt.Key_Shift, Qt.Key_Control, Qt.Key_Alt, Qt.Key_Meta, Qt.Key_Menu)
            # or if this is the first key and without modifier and modifierless keys are not allowed
            and (
                self._modifierlessAllowed
                or self._recseq.count() > 0
                or modifiers & ~Qt.SHIFT
                or not ev.text()
                or (
                    modifiers & Qt.SHIFT
                    and key
                    in (
                        Qt.Key_Return,
                        Qt.Key_Space,
                        Qt.Key_Tab,
                        Qt.Key_Backtab,
                        Qt.Key_Backspace,
                        Qt.Key_Delete,
                        Qt.Key_Escape,
                    )
                )
            )
        ):
            # change Shift+Backtab into Shift+Tab
            if key == Qt.Key_Backtab and modifiers & Qt.SHIFT:
                key = Qt.Key_Tab | modifiers
            # remove the Shift modifier if it doesn't make sense
            #            elif (Qt.Key_Exclam <= key <= Qt.Key_At
            #                  or Qt.Key_Z < key <= 0x0ff):
            #                key = key | (modifiers & ~Qt.SHIFT)
            else:
                key = key | modifiers

            # append max. 4 keystrokes
            if self._recseq.count() < 4:
                l = list(self._recseq)
                l.append(key)
                self._recseq = QKeySequence(*l)

        self._modifiers = modifiers
        self.controlTimer()
        self.updateDisplay()

#.........這裏部分代碼省略.........
開發者ID:philmassart,項目名稱:frescobaldi,代碼行數:103,代碼來源:keysequencewidget.py


注:本文中的PyQt4.QtGui.QKeySequence.isEmpty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。