当前位置: 首页>>代码示例>>Python>>正文


Python QKeySequence.toString方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QKeySequence.toString方法的典型用法代码示例。如果您正苦于以下问题:Python QKeySequence.toString方法的具体用法?Python QKeySequence.toString怎么用?Python QKeySequence.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QKeySequence的用法示例。


在下文中一共展示了QKeySequence.toString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createButton

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]
    def createButton(self, button, propertyDict = dict()):
        """
        Creates the buttons according to the user size definition
        button: Button name
        propertyDict: optional dict parameters that may contain other properties to button, such as color, tooltip and custom category
        """

        pushButton = QtGui.QPushButton(button)
        keys = propertyDict.keys()
        styleSheet = ''
        if 'buttonColor' in keys:
            r, g, b, a = propertyDict['buttonColor'].split(',')
            styleSheet += "background-color:rgba({0},{1},{2},{3});".format(r, g, b, a)
        if 'buttonToolTip' in keys:
            pushButton.setToolTip(propertyDict['buttonToolTip'])
        if 'buttonShortcut' in keys:
            keySequence = QKeySequence(propertyDict['buttonShortcut'])
            pushButton.setText('{0} [{1}]'.format(button, keySequence.toString(format = QKeySequence.NativeText)))
            pushButton.setShortcut(keySequence)

        pushButton.clicked.connect(self.reclassify)
        pushButton.toggled.connect(self.acquire)
        if self.size == 0:
            pushButton.setMinimumSize(100, 25)
            styleSheet += 'font-size:12px;'
        elif self.size == 1:            
            pushButton.setMinimumSize(100, 40)
            styleSheet += 'font-size:20px;'
        elif self.size == 2:            
            pushButton.setMinimumSize(100, 80)
            styleSheet += 'font-size:30px;'
        pushButton.setStyleSheet(styleSheet)
        self.buttons.append(pushButton)
        return pushButton        
开发者ID:lcoandrade,项目名称:DsgTools,代码行数:36,代码来源:field_toolbox.py

示例2: change_keyseq

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]
 def change_keyseq(self, group, name, old_keyseq, keyseq):
     """
     Customize a shortcut's activating key sequence.
     """
     if old_keyseq:
         old_keyseq = QKeySequence(old_keyseq)
         old_keytext = str(old_keyseq.toString())
         self._keyseq_target_actions[old_keytext].remove( (group, name) )        
     try:
         keyseq = QKeySequence(keyseq)
         keytext = str(keyseq.toString())
         target_name_set = self._keyseq_target_actions[keytext]
     except KeyError:
         target_name_set = self._keyseq_target_actions[keytext] = set()
         self._add_global_shortcut_listener( keyseq )
     
     target_name_set.add( (group, name) )
     self._update_tooltip( group, name, keyseq )
开发者ID:CVML,项目名称:volumina,代码行数:20,代码来源:shortcutManager.py

示例3: test_load_default_shortcuts

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]
 def test_load_default_shortcuts(self):
     shorts_count = self.shortcuts_manager.result_widget.topLevelItemCount()
     item = self.shortcuts_manager.result_widget.topLevelItem(0)
     shortcut_keys = item.text(1)
     # Expected data
     expected_key = QKeySequence(Qt.CTRL + Qt.Key_N)
     expected_key_str = expected_key.toString(QKeySequence.NativeText)
     # Just one shortcut should be loaded
     self.assertEqual(shorts_count, 1)
     # The key should be the same as the expected
     self.assertEqual(shortcut_keys, expected_key_str)
开发者ID:AnyBucket,项目名称:ninja-ide,代码行数:13,代码来源:test_preferences.py

示例4: _add_global_shortcut_listener

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]
 def _add_global_shortcut_listener(self, keyseq):
     # Create a shortcut for this new key sequence
     # Note: We associate the shortcut with the ENTIRE WINDOW.
     #       We intercept the shortcut and decide which widget to direct it to.
     #       (We don't rely on Qt to do this for us.)
     # Note: This class assumes that all widgets using shortcuts belong to the SAME main window.
     assert keyseq not in self._global_shortcuts
     keyseq = QKeySequence(keyseq)
     keytext = str(keyseq.toString())
     self._global_shortcuts[keytext] = QShortcut( QKeySequence(keyseq), 
                                                  getMainWindow(), 
                                                  member=partial(self._handle_shortcut_pressed, keytext), 
                                                  context=Qt.ApplicationShortcut )
开发者ID:CVML,项目名称:volumina,代码行数:15,代码来源:shortcutManager.py

示例5: shortcut

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]
def shortcut(item):
    """Returns a suitable text for the keyboard shortcut of the given item.
    
    Item may be a QAction, a QShortcut, a QKeySequence or a
    QKeySequence.StandardKey.
    
    The text is meant to be used in the help docs.
    
    """
    if isinstance(item, QAction):
        seq = item.shortcut()
    elif isinstance(item, QShortcut):
        seq = item.key()
    elif isinstance(item, QKeySequence.StandardKey):
        seq = QKeySequence(item)
    else:
        seq = item
    return seq.toString(QKeySequence.NativeText) or _("(no key defined)")
开发者ID:willingc,项目名称:frescobaldi,代码行数:20,代码来源:helpimpl.py

示例6: eventFilter

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]
 def eventFilter( self, object, event ):
     """
     Filters out key press events for the shortcut section for this edit.
     
     :param      object | <QObject>
                 event  | <QEvent>
     """
     if ( object != self.uiShortcutTXT ):
         return False
         
     if ( event.type() == event.KeyPress ):
         seq = QKeySequence(event.key() + int(event.modifiers()))
         self.uiShortcutTXT.setText( seq.toString() )
         return True
         
     elif ( event.type() == event.KeyRelease):
         return True
     
     return False
开发者ID:satishgoda,项目名称:DPS_PIPELINE,代码行数:21,代码来源:xshortcutdialog.py

示例7: test_save_shortcuts

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]
    def test_save_shortcuts(self):
        data = []

        def called():
            data.append(True)

        actions = gui.FakeActions()
        setattr(actions, 'update_shortcuts', called)
        self.patch(shortcut_manager.actions, 'Actions', lambda: actions)
        self.shortcuts_manager.result_widget.clear()
        key = QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_N)
        key_str = key.toString(QKeySequence.NativeText)
        tree_data = ["New File", key_str, "New-File"]
        item = QTreeWidgetItem(self.shortcuts_manager.result_widget, tree_data)
        item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
        # Before save there is nothing in QSettings
        self.assertEqual(self.settings.value("New-File", None), None)
        # Save
        self.shortcuts_manager.save()
        # After save there is a value for New-File QSettings
        self.assertEqual(self.settings.values["New-File"], key_str)
        # After save check if NINJA call the update_shortcuts in actios.Actions
        self.assertEqual(data, [True])
开发者ID:AnyBucket,项目名称:ninja-ide,代码行数:25,代码来源:test_preferences.py

示例8: KeySequenceButton

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [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

示例9: ShortcutChooserWidget

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]

#.........这里部分代码省略.........
        After button is clicked, focus is needed to use keyPressEvent and keyReleaseEvent
        """
        self.setFocus()
    
    @pyqtSlot(bool)
    def on_assignShortcutPushButton_toggled(self, toggled):
        """
        Button toggled reset self.modifiers and self.keys and also prepairs button text
        """
        if toggled:
            self.resetVariables()
            self.assignShortcutPushButton.setText(self.tr('Enter Value'))
    
    @pyqtSlot(bool, name = 'on_clearPushButton_clicked')
    def clearAll(self):
        """
        Clears push button and also resets self.modifiers and self.keys
        """
        self.assignShortcutPushButton.setChecked(False)
        self.assignShortcutPushButton.setText(self.tr('Assign Shortcut'))
        self.resetVariables()
    
    def resetVariables(self):
        """
        Resets self.modifiers, self.key and self.keySequence to 0
        """
        self.modifiers = 0
        self.key = 0
        self.keySequence = 0

    def keyPressEvent(self, event):
        """
        """
        if not self.assignShortcutPushButton.isChecked():
            super(ShortcutChooserWidget, self).keyPressEvent(event)
            return
        key = int(event.key())
        if key == Qt.Key_Meta:
            self.modifiers |= Qt.META
            self.updateShortcutText()
        elif key == Qt.Key_Alt:
            self.modifiers |= Qt.ALT
            self.updateShortcutText()
        elif key == Qt.Key_Control:
            self.modifiers |= Qt.CTRL
            self.updateShortcutText()
        elif key == Qt.Key_Shift:
            self.modifiers |= Qt.SHIFT
            self.updateShortcutText()
        elif key == Qt.Key_Escape:
            self.assignShortcutPushButton.setChecked(False)
            return
        else:
            self.key = key
            self.updateShortcutText()

    def keyReleaseEvent(self, event):
        if not self.assignShortcutPushButton.isChecked():
            super(ShortcutChooserWidget, self).keyReleaseEvent(event)
            return
        key = event.key()
        if key == Qt.Key_Meta:
            self.modifiers &= Qt.META
            self.updateShortcutText()
        elif key == Qt.Key_Alt:
            self.modifiers &= Qt.ALT
            self.updateShortcutText()
        elif key == Qt.Key_Control:
            self.modifiers &= Qt.CTRL
            self.updateShortcutText()
        elif key == Qt.Key_Shift:
            self.modifiers &= Qt.SHIFT
            self.updateShortcutText()
        elif key == Qt.Key_Escape:
            return
        else:
            self.assignShortcutPushButton.setChecked(False)
            self.updateShortcutText()
            self.setShortcut(self.keySequence)
    
    def setEnabled(self, enabled):
        if not enabled:
            self.clearAll()
        super(ShortcutChooserWidget, self).setEnabled(enabled)

    def setShortcut(self, shortcut):
        self.keySequence = QKeySequence(shortcut)
        self.assignShortcutPushButton.setChecked(False)
        self.assignShortcutPushButton.setText(self.keySequence.toString(format = QKeySequence.NativeText))
    
    def getShortcut(self, asQKeySequence = False):
        if asQKeySequence:
            return self.keySequence
        else:
            return int(self.keySequence)

    def updateShortcutText(self):
        self.keySequence = QKeySequence(self.modifiers+self.key)
        #this uses QKeySequence.NativeText to show in the interface. To store data, no filter should be provided
        self.assignShortcutPushButton.setText(self.tr('Input: {0}').format(self.keySequence.toString(format = QKeySequence.NativeText)))
开发者ID:lcoandrade,项目名称:DsgTools,代码行数:104,代码来源:shortcutChooserWidget.py

示例10: stringWithAppendedShortcut

# 需要导入模块: from PyQt4.QtGui import QKeySequence [as 别名]
# 或者: from PyQt4.QtGui.QKeySequence import toString [as 别名]
 def stringWithAppendedShortcut(string: str, shortcut: QKeySequence) -> str:
     """
     :returns: An HTML string that contains the given string with a suffixed shortcut key in grey.
     """
     s = shortcut.toString(QKeySequence.NativeText)
     return "{0} <span style=\"color: gray; font-size: small\">{1}</span>".format(string, s)
开发者ID:nerdocs,项目名称:MedUX,代码行数:8,代码来源:proxyaction.py


注:本文中的PyQt4.QtGui.QKeySequence.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。