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
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)