def keyPressEvent(self, e: QKeyEvent): textCursor = self.textCursor() if (e.key() == Qt.Key_Return or e.key() == Qt.Key_Enter) and self._exitOnReturn: self.parent().accept() elif len(self.toPlainText()) - ( textCursor.selectionEnd() - textCursor.selectionStart()) < self._maxlength: if not self._validator or self._validator.regExp().exactMatch( e.text()): super().keyPressEvent(e) elif not e.text().isprintable(): if e.matches(QKeySequence.Paste): self.paste(QApplication.clipboard().text()) e.ignore() else: super().keyPressEvent(e) else: e.ignore() elif not e.text().isprintable() and not e.matches(QKeySequence.Paste): super().keyPressEvent(e) else: e.ignore()
def keyPressEvent(self, event: QKeyEvent) -> None: if event.key() == Qt.Key_Escape: self.modlist.setFocus() self.searchbar.setText('') elif event.matches(QKeySequence.Find): self.searchbar.setFocus() elif event.matches(QKeySequence.Paste): self.pasteEvent() super().keyPressEvent(event)
def testIt(self): # We need a qapp otherwise Qt will crash when trying to detect the # current platform app = QApplication([]) ev1 = QKeyEvent(QEvent.KeyRelease, Qt.Key_Delete, Qt.NoModifier) ev2 = QKeyEvent(QEvent.KeyRelease, Qt.Key_Copy, Qt.NoModifier) ks = QKeySequence.Delete self.assertTrue(ev1.matches(ks)) self.assertFalse(ev2.matches(ks))
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None: if event.matches(QtGui.QKeySequence.Cancel): self.graphics.endSelection() self.graphics.endWidget() elif event.matches(QtGui.QKeySequence.Paste): mime = QtWidgets.QApplication.clipboard().mimeData() if mime.hasFormat("arplication/x-pew2config"): with BytesIO(mime.data("application/x-pew2config")) as fp: array = np.load(fp) if self.is_srr: config = SRRConfig.from_array(array) else: config = Config.from_array(array) self.applyConfig(config) elif mime.hasFormat("application/x-pew2calibration"): with BytesIO(mime.data("application/x-pew2calibration")) as fp: npy = np.load(fp) calibrations = {k: Calibration.from_array(npy[k]) for k in npy} self.applyCalibration(calibrations) super().keyPressEvent(event)
def keyPressEvent(self, event: QKeyEvent) -> None: if event.matches(QKeySequence.Delete): asyncio.create_task(self.deleteSelectedMods()) super().keyPressEvent(event)
def keyPressEvent(self, event: QtGui.QKeyEvent): if event.matches(QtGui.QKeySequence.Paste): self._handlePaste() super().keyPressEvent(event)