当前位置: 首页>>代码示例>>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;未经允许,请勿转载。