示例#1
0
def nullable_key(value):
    """
    Returns an instance of PyQt4.QtCore.Qt.Key for the given value, if
    possible. If the incoming value cannot be represented as a key,
    returns None.
    """

    if isinstance(value, Qt.Key):
        return value

    value = nullable_int(value)
    return Qt.Key(value) if value else None
示例#2
0
文件: base.py 项目: MagSec-Arts/enki
    def keyClick(self, key, modifiers=Qt.NoModifier, widget=None):
        """Alias for ``QTest.keyClick``.

        If widget is none - focused widget will be keyclicked

        key may be QKeySequence or string
        """
        if widget is None:
            widget = self.app.focusWidget()

        if widget is None:
            widget = core.mainWindow()

        assert widget is not None

        if isinstance(key, basestring):
            assert modifiers == Qt.NoModifier, 'Do not set modifiers, if using text key'
            code = QKeySequence(key)[0]
            key = Qt.Key(code & 0x01ffffff)
            modifiers = Qt.KeyboardModifiers(code & 0xfe000000)

        QTest.keyClick(widget, key, modifiers)