def eventFilter(self, obj, event): if isinstance(obj, KTextEdit): if event.type() == QEvent.KeyPress: key_event = QKeyEvent(event) key = key_event.key() if (key_event.modifiers() == Qt.ControlModifier) and (key == Qt.Key_Enter or key == Qt.Key_Return): self.update_status() return True safe_keys = [Qt.Key_Delete, Qt.Key_Backspace, Qt.Key_Up, Qt.Key_Down, Qt.Key_Right, Qt.Key_Left, Qt.Key_Home, Qt.Key_End] if key not in safe_keys: if self.status_edit.nativeWidget().toPlainText().length() >= 140: return True return False elif isinstance(obj, KTabBar) and event.type() == QEvent.MouseButtonPress: self.scroll_widget.ensureItemVisible(self.main_frame) self.status_edit.setFocus() return False else: return self.applet.eventFilter(obj, event)
def appendQKeyEvent(self, keyEvent: QtGui.QKeyEvent): """ Append another key to the key sequence represented by this object. |Args| * ``keyEvent`` (**QKeyEvent**): the key to add. |Returns| **None** |Raises| * **QtmacsArgumentError** if at least one argument has an invalid type. """ # Store the QKeyEvent. self.keylistKeyEvent.append(keyEvent) # Convenience shortcuts. mod = keyEvent.modifiers() key = keyEvent.key() # Add the modifier and key to the list. The modifier is a # QFlag structure and must by typecast to an integer to avoid # difficulties with the hashing in the ``match`` routine of # the ``QtmacsKeymap`` object. self.keylistQtConstants.append((int(mod), key))
def keys(self, pattern, text, native=False, blur=False): """Simulate typing by focusing on elements that match the pattern and triggering key events. If native is True then will use GUI key event simulation, else JavaScript. If blur is True then will blur focus at the end of typing. Returns the number of elements matched. """ es = self.find(pattern) for e in es: if native: key_map = { '\t': Qt.Key_Tab, '\n': Qt.Key_Enter, 'DOWN': Qt.Key_Down, 'UP': Qt.Key_Up } self.click_by_gui_simulation(e) self.wait(0.1) for c in text: key = key_map.get(c, QKeySequence(c)[0]) press = QKeyEvent(QEvent.KeyPress, key, Qt.NoModifier) release = QKeyEvent(QEvent.KeyRelease, key, Qt.NoModifier) QApplication.postEvent(self, press) QApplication.postEvent(self, release) else: #e.evaluateJavaScript("this.focus()") #self.click_by_user_event_simulation(e) self.fill(pattern, text, es=[e]) for event_name in ('focus', 'keydown', 'change', 'keyup', 'keypress'): self.trigger_js_event(e, event_name) if blur: e.evaluateJavaScript("this.blur()") return len(es)
def keyPressEvent(self, event): if event.type() == QEvent.KeyPress: key_event = QKeyEvent(event) if(key_event.key() == Qt.Key_Down or key_event.key() == Qt.Key_Up): return self.list_widget.keyPressEvent(event) elif((event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return) and self.list_widget.currentItem()>=0): self.hide() self.event_selected_command(str(self.full_command.toPlainText())) return super(CommandWindow, self).keyPressEvent(event)
def test_enter_pressed(self): data = [] self.patch(self.console_widget, "_write_command", lambda: data.append(True)) event = QKeyEvent(QEvent.KeyPress, Qt.Key_Enter, Qt.NoModifier, "") self.console_widget.keyPressEvent(event) self.assertEqual(data, [True]) event = QKeyEvent(QEvent.KeyPress, Qt.Key_Return, Qt.NoModifier, "") self.console_widget.keyPressEvent(event) self.assertEqual(data, [True, True])
def event(self, event): retVal = HistoryBase.event(self, event) if event.type() == QEvent.KeyPress and self.isQueryKey(event): self.returnPressed.emit() return True if not retVal: if self._triggerOnEnter and \ event.type() == QEvent.KeyPress and \ event.key() == Qt.Key_Return and \ ((int(event.modifiers()) & Qt.AltModifier) == Qt.AltModifier or \ (int(event.modifiers()) & Qt.ShiftModifier) == Qt.ShiftModifier): event = QKeyEvent(QEvent.KeyPress, Qt.Key_Return, Qt.NoModifier, event.text(), event.isAutoRepeat(), event.count()) return super(HistoryTextEdit, self).event(event) return True
def notify(self, receiver, event): if event.type() == QEvent.KeyPress: key_event = QKeyEvent(event) key_text = PyQt4.QtGui.QKeySequence(key_event.key() | key_event.modifiers().__int__()).toString() text = key_event.text() if (key_text, text) == KEY_STOP_RECORDING and not self.recording: self.reproduce_keys(self._keys_recorded) elif (key_text, text) == KEY_STOP_RECORDING and self.recording: self.recording = False elif self.recording: self._keys_recorded.append((key_text, unicode(text))) if (key_text, text) == KEY_START_RECORDING: self.recording = True self._keys_recorded = [] # ============================================================================== # key = { # "key": key_event.key(), # "modifiers": int(key_event.modifiers()), # "text": key_event.text(), # "autorepeat": key_event.isAutoRepeat(), # "autorepeat": key_event.isAutoRepeat(), # "count": key_event.count() # } # print key # ============================================================================== # ============================================================================== # if event.type() == QEvent.KeyPress: # key_event = QKeyEvent(event) # ker = QKeyEvent(QEvent.KeyPress, # key_event.key(), # key_event.modifiers(), # key_event.text(), # key_event.isAutoRepeat(), # key_event.count()) # super(MiowApplication, self).notify(receiver, ker) # ============================================================================== for key_as_text, method in self.keys_map: if key_as_text == (key_text, text): replace = method(key_event, key_as_text) if replace == None: return True elif replace == False: return super(MiowApplication, self).notify(receiver, event) else: return self.notify(receiver, replace) return super(MiowApplication, self).notify(receiver, event)
def eventFilter(self, obj, event): if event.type() == QEvent.FocusIn: if obj is self.ui.chatLogView: if event.reason() == Qt.ActiveWindowFocusReason: self.ui.chatInputEdit.setFocus() if event.type() == QEvent.KeyPress: if obj is self.ui.chatInputEdit: if event.key() in (Qt.Key_Enter, Qt.Key_Return): if event.modifiers() & Qt.ShiftModifier: pass elif event.modifiers() & Qt.ControlModifier: # QTextEdit inserts <br/> with Ctrl+Enter, and a new # <p> element with Shift+Enter. There seem to be some # rendering issues with <br/>, so convert all Ctrl+Enter # keys to Shift+Enter. mod = event.modifiers() & (~Qt.ControlModifier) mod = mod | Qt.ShiftModifier newEvent = QKeyEvent(event.type(), event.key(), mod, event.text(), event.isAutoRepeat(), event.count()) QApplication.sendEvent(self.ui.chatInputEdit, newEvent) return True else: self._onChatInputEnter() return True return False
def keyPressEvent(self, event): "Atiene el evento de pulsación de tecla." self._cambios_sin_guardar = True # Permite usar tab como seleccionador de la palabra actual # en el popup de autocompletado. if event.key() in [Qt.Key_Tab]: if self.completer and self.completer.popup().isVisible(): event.ignore() nuevo_evento = QKeyEvent(QKeyEvent.KeyPress, Qt.Key_Return, Qt.NoModifier) try: if self.autocomplete(nuevo_evento): return None except UnicodeEncodeError: pass return None if editor_base.EditorBase.keyPressEvent(self, event): return None # Elimina los pares de caracteres especiales si los encuentra if event.key() == Qt.Key_Backspace: self._eliminar_pares_de_caracteres() if self.autocomplete(event): return None return QTextEdit.keyPressEvent(self, event)
def keyPressEvent(self, event: QKeyEvent): if event.modifiers() and Qt.ControlModifier: handled = False if event.key() == Qt.Key_B: self.toggleTextBold() # bolden text handled = True elif event.key() == Qt.Key_I: self.toggleTextItalics() # italicise text handled = True print("Ctrl+I") if handled: event.accept() return else: QTextEdit.keyPressEvent(self.currentPage, event)
def test_home_pressed_with_shift(self): self.console_widget._write_command() self.console_widget._write_command() self.console_widget.textCursor().insertText('a = 5') event = QKeyEvent(QEvent.KeyPress, Qt.Key_Home, Qt.ShiftModifier, "") self.console_widget._home_pressed(event) text = self.console_widget.textCursor().selectedText() self.assertEqual(text, "a = 5")
def test_remove_tag_with_delete_key(self): tw = TagsWidget() QTest.keyClicks(tw.lineEdit, 'lourd') tw.addTag() tw.listWidget.setCurrentRow(0) tw.keyPressEvent( QKeyEvent(QEvent.KeyPress, Qt.Key_Delete, Qt.NoModifier)) self.assertEqual(tw.listWidget.count(), 0)
def test_step_space(self): """ Test step """ w = self.widget event = QKeyEvent( QEvent.KeyPress, Qt.Key_Space, Qt.KeyboardModifiers(0)) # test function not crashes when no data and learner w.keyPressEvent(event) self.send_signal("Data", self.iris) # test theta set after step if not set yet w.keyPressEvent(event) self.assertIsNotNone(w.learner.theta) # check theta is changing when step old_theta = np.copy(w.learner.theta) w.keyPressEvent(event) self.assertNotEqual(sum(old_theta - w.learner.theta), 0) # with linear regression self.send_signal("Data", self.housing) # test theta set after step if not set yet w.keyPressEvent(event) self.assertIsNotNone(w.learner.theta) # check theta is changing when step old_theta = np.copy(w.learner.theta) w.keyPressEvent(event) self.assertNotEqual(sum(old_theta - w.learner.theta), 0) old_theta = np.copy(w.learner.theta) # to cover else example and check not crashes event = QKeyEvent( QEvent.KeyPress, Qt.Key_Q, Qt.KeyboardModifiers(0)) w.keyPressEvent(event) # check nothing changes assert_array_equal(old_theta, w.learner.theta)
def test_home_pressed(self): self.console_widget._write_command() self.console_widget._write_command() self.console_widget.textCursor().insertText('a = 5') event = QKeyEvent(QEvent.KeyPress, Qt.Key_Home, Qt.NoModifier, "") self.console_widget._home_pressed(event) self.assertEqual( self.console_widget.textCursor().position(), self.console_widget.document().lastBlock().position() + len(self.console_widget.prompt))
def keyPressEvent(self, event): key = event.key() modifier = event.modifiers() numChars = len(self.toPlainText()) if key in [Qt.Key_Return, Qt.Key_Enter]: if modifier == Qt.ShiftModifier: event = QKeyEvent(event.type(), Qt.Key_Return, Qt.NoModifier, event.text()) else: self.enviarTexto() return #Atualizando o texto do Edit QTextEdit.keyPressEvent(self, event) if numChars > 0 and len(self.toPlainText()) == 0: self._modificarSituacao(EditEnviar.APAGANDO) QTimer.singleShot(2000, lambda: self._analisarSituacao()) elif numChars == 0 and len(self.toPlainText()) > 0: self._modificarSituacao(EditEnviar.DIGITANDO)
def test_backspace(self): self.console_widget._write_command() self.console_widget._write_command() self.console_widget.textCursor().insertText('a = 5') self.console_widget.selectAll() text = self.console_widget.textCursor().selectedText()[:-1] self.console_widget.moveCursor(QTextCursor.End) event = QKeyEvent(QEvent.KeyPress, Qt.Key_Backspace, Qt.NoModifier, "") self.console_widget.keyPressEvent(event) self.console_widget.selectAll() text_after = self.console_widget.textCursor().selectedText() self.assertEqual(text, text_after)
def test_backspace_remove_selection(self): self.console_widget._write_command() self.console_widget._write_command() self.console_widget.textCursor().insertText("a = 5") self.console_widget.selectAll() text = self.console_widget.textCursor().selectedText()[:-2] self.console_widget.moveCursor(QTextCursor.End) self.console_widget.setCursorPosition(3, QTextCursor.KeepAnchor) event = QKeyEvent(QEvent.KeyPress, Qt.Key_Backspace, Qt.NoModifier, "") self.console_widget.keyPressEvent(event) self.console_widget.selectAll() text_after = self.console_widget.textCursor().selectedText() self.assertEqual(text, text_after)
def test_check_event_on_selection_all_selected_no_text(self): self.console_widget._write_command() self.console_widget._write_command() self.console_widget.textCursor().insertText('a = 5') self.console_widget.selectAll() text = self.console_widget.textCursor().selectedText() self.assertTrue(self.console_widget.textCursor().hasSelection()) event = QKeyEvent(QEvent.KeyPress, Qt.Key_A, Qt.NoModifier, "") self.console_widget.keyPressEvent(event) self.assertTrue(self.console_widget.textCursor().hasSelection()) self.console_widget.selectAll() text_after = self.console_widget.textCursor().selectedText() self.assertEqual(text, text_after)
def keyPressEvent(self, event): "Atiene el evento de pulsación de tecla." self._cambios_sin_guardar = True # Permite usar tab como seleccionador de la palabra actual # en el popup de autocompletado. if event.key() in [Qt.Key_Tab]: if self.completer and self.completer.popup().isVisible(): event.ignore() nuevo_evento = QKeyEvent(QKeyEvent.KeyPress, Qt.Key_Return, Qt.NoModifier) try: if self.autocomplete(nuevo_evento): return None except UnicodeEncodeError: pass return None if editor_base.EditorBase.keyPressEvent(self, event): return None # Elimina los pares de caracteres especiales si los encuentra if event.key() == Qt.Key_Backspace: self._eliminar_pares_de_caracteres() self._borrar_un_grupo_de_espacios(event) if self.autocomplete(event): return None if event.key() == Qt.Key_Return: cursor = self.textCursor() block = self.document().findBlockByNumber(cursor.blockNumber()) whitespace = re.match(r"(\s*)", unicode(block.text())).group(1) linea_anterior = str(block.text()[:]) cantidad_espacios = linea_anterior.count(' ') / 4 if linea_anterior[-1:] == ':': whitespace = ' ' * (cantidad_espacios + 1) else: whitespace = ' ' * (cantidad_espacios) QTextEdit.keyPressEvent(self, event) return self.insertPlainText(whitespace) return QTextEdit.keyPressEvent(self, event)
def eventFilter(self, editor, event): # check some key presses if event.type() == QEvent.KeyPress: # if we pressed return and aren't at the last column send a tab # if event.key() == Qt.Key_Return and not self.lastcolumn: # event.accept() # event = QKeyEvent(QEvent.KeyPress, Qt.Key_Tab, Qt.NoModifier) # if we pressed tab and are in the last column send a return if event.key() == Qt.Key_Tab and self.lastcolumn: event.accept() event = QKeyEvent(QEvent.KeyPress, Qt.Key_Return, Qt.NoModifier) # just pass the event up return QItemDelegate.eventFilter(self, editor, event)
def event(self, event): if (event.type() == QEvent.KeyPress) and (event.key() == Qt.Key_Tab): if self.completionType == QCompleter.InlineCompletion: eventTab = QKeyEvent(QEvent.KeyPress, Qt.Key_End, Qt.NoModifier) super(LineEditTabCompleter, self).event(eventTab) else: completion = self.completer.currentCompletion() completion += os.path.sep self.selectAll() self.insert(completion) self.completer.popup().hide() return True return super(LineEditTabCompleter, self).event(event)
def test_check_event_on_selection_last_block_selected(self): self.console_widget._write_command() self.console_widget._write_command() self.console_widget.textCursor().insertText('a = 5') self.console_widget.selectAll() text = self.console_widget.textCursor().selectedText()[:-2] + '2' self.console_widget.moveCursor(QTextCursor.End) self.console_widget.setCursorPosition(3, QTextCursor.KeepAnchor) self.assertTrue(self.console_widget.textCursor().hasSelection()) event = QKeyEvent(QEvent.KeyPress, Qt.Key_2, Qt.NoModifier, "2") self.console_widget.keyPressEvent(event) self.assertFalse(self.console_widget.textCursor().hasSelection()) self.console_widget.selectAll() text_after = self.console_widget.textCursor().selectedText() self.assertEqual(text, text_after)
def keyPressEvent(self, keyEvent: QtGui.QKeyEvent): """ Undo safe wrapper for the native ``keyPressEvent`` method. |Args| * ``keyEvent`` (**QKeyEvent**): the key event to process. |Returns| **None** |Raises| * **QtmacsArgumentError** if at least one argument has an invalid type. """ undoObj = UndoInsert(self, keyEvent.text()) self.qteUndoStack.push(undoObj)
def onExpandKeyEvent(self, keyEvent): """One of expand selection key events""" if self._start is None: currentBlockText = self._qpart.textCursor().block().text() line = self._qpart.cursorPosition[0] visibleColumn = self._realToVisibleColumn( currentBlockText, self._qpart.cursorPosition[1]) self._start = (line, visibleColumn) modifiersWithoutAltShift = keyEvent.modifiers() & ( ~(Qt.AltModifier | Qt.ShiftModifier)) newEvent = QKeyEvent(keyEvent.type(), keyEvent.key(), modifiersWithoutAltShift, keyEvent.text(), keyEvent.isAutoRepeat(), keyEvent.count()) self._qpart.cursorPositionChanged.disconnect(self._reset) self._qpart.selectionChanged.disconnect(self._reset) super(self._qpart.__class__, self._qpart).keyPressEvent(newEvent) self._qpart.cursorPositionChanged.connect(self._reset) self._qpart.selectionChanged.connect(self._reset)
def keyPressEvent(self, event): if self.autocomplete.active: if self.autocomplete.keyPressEvent(event): return elif self.calltip.active: if self.calltip.keyPressEvent(event): return m = event.modifiers() k = event.key() t = event.text() # Disable some shortcuts if self.disable_shortcuts and \ m & Qt.ControlModifier and k in [Qt.Key_A, Qt.Key_R, Qt.Key_C, Qt.Key_K, Qt.Key_X, Qt.Key_V, Qt.Key_Y, Qt.Key_Z]: new_ev = QKeyEvent(event.type(), k, m, t) event.ignore() QCoreApplication.postEvent(self.parent(), new_ev) return elif k == Qt.Key_Tab: if self.tab_pressed(): return elif k == Qt.Key_Backtab: if self.backtab_pressed(): return elif k == Qt.Key_Backspace: if self.backspace_pressed(): return elif k == Qt.Key_Period or \ (k == Qt.Key_Space and event.modifiers() == Qt.ControlModifier): QPlainTextEdit.keyPressEvent(self, event) self.autocomplete_pressed() return elif k in [Qt.Key_ParenLeft, Qt.Key_BraceLeft, Qt.Key_BracketLeft]: QPlainTextEdit.keyPressEvent(self, event) self.paren_opened(k) return QPlainTextEdit.keyPressEvent(self, event) if k == Qt.Key_Return or k == Qt.Key_Enter: self.after_return_pressed()
if __name__ == "__main__": import sys app = QApplication(sys.argv) # create an app from PyQt4.QtGui import QWidget import pqIMC IMC = pqIMC.tricorder() IMC.mainWindow = QWidget() beep() noteEvent("about to call infoMsg") infoMsg("This is the message","Did you hear that beep?") noteEvent("about to call getStringMsg") (s, b) = getStringMsg("TITLE STRING", "label text") if b : print( "got "+s) else: print("cancel") (s, b) = getStringMsg("TITLE STRING", "what you should enter", "prepared") if b : print( "got "+s) else: print("cancel") noteEvent("Whatever...") #ew = QTextEdit() #(b,qs) = getFindMsg(ew) #print(b,qs) qsl = QStringList() qsl.append("ONE") qsl.append("TWO") (s, b) = getChoiceMsg("TITLE STRING", "label text",qsl) if b : print ("Choice "+unicode(s)) else: print ("Cancel "+unicode(s)) printKeyEvent( QKeyEvent(QEvent.KeyPress,43,Qt.AltModifier|Qt.ControlModifier) )
def keyPressEvent(self, event): # Permite usar tab como seleccionador de la palabra actual # en el popup de autocompletado. if event.key() in [Qt.Key_Tab]: if self.completer and self.completer.popup().isVisible(): event.ignore() nuevo_evento = QKeyEvent(QKeyEvent.KeyPress, Qt.Key_Return, Qt.NoModifier) try: if self.autocomplete(nuevo_evento): return None except UnicodeEncodeError: pass return None if editor_base.EditorBase.keyPressEvent(self, event): return None textCursor = self.textCursor() # Permite mantener pulsada la tecla CTRL para copiar o pegar. if event.modifiers() & Qt.ControlModifier: # Ignorando pegar texto si cursor está en medio de consola. if textCursor.blockNumber() != self.document().blockCount() - 1: if event.key() == Qt.Key_V: textCursor = self._mover_cursor_al_final() return # Ignorando pegar texto si cursor está sobre el prompt de consola. elif textCursor.positionInBlock() < 2: if event.key() == Qt.Key_V: textCursor = self._mover_cursor_al_final() return return QTextEdit.keyPressEvent(self, event) # Ignorando la pulsación de tecla si está en medio de la consola. if textCursor.blockNumber() != self.document().blockCount() - 1: textCursor = self._mover_cursor_al_final() return # Ignora el evento si está sobre el cursor de la consola. if textCursor.positionInBlock() < 2: textCursor = self._mover_cursor_al_final() return if event.key() in [Qt.Key_Left, Qt.Key_Backspace]: if self.textCursor().positionInBlock() == 2: return # Elimina los pares de caracteres especiales si los encuentra if event.key() == Qt.Key_Backspace: self._eliminar_pares_de_caracteres() # navegar por el historial if event.key() == Qt.Key_Down: if self.historyIndex == len(self.history): self.historyIndex -= 1 try: if self.historyIndex > -1: self.historyIndex -= 1 self.recall_history() else: self.clearCurrentBlock() except: pass return None # navegar por el historial if event.key() == Qt.Key_Up: try: if len(self.history) - 1 > self.historyIndex: self.historyIndex += 1 self.recall_history() else: self.historyIndex = len(self.history) except: pass return None # ir al primer caracter del interprete cuando pulsa HOME if event.key() == Qt.Key_Home: blockLength = len(self.document().lastBlock().text()[2:]) lineLength = len(self.document().toPlainText()) position = lineLength - blockLength textCursor = self.textCursor() textCursor.setPosition(position) self.setTextCursor(textCursor) return None try: if self.autocomplete(event): return None except UnicodeEncodeError: pass if event.key() in [Qt.Key_Return, Qt.Key_Enter]: self.limpiar_consejo() # Limpiando consejo si existe line = self._get_entered_line() self.historyIndex = -1 if line == "clear": self.limpiar() return try: line[-1] self.haveLine = True if line[-1] in [':', ',', '[', '(']: self.multiline = True self.history.insert(0, line) except: self.haveLine = False # Cuando pulsa ENTER luego de haber hecho un texto multilinea y borrado todos los caracteres. if self.multiline and (not self.haveLine or self._ha_ingresado_solo_espacios(line)): # multi line done self.append('') # move down one line try: self.interpreter.runsource(self.command) except Exception, e: self.insertar_error_desde_exception(e) self.command = '' # clear command self.multiline = False # back to single line self.marker() # handle marker style return None if self.haveLine and self.multiline: # multi line command self.command += line + '\n' # + command and line self.append('') self.marker() return None # Permite escribir lineas terminas con '?' para consultar la documentacion # de manera similar a como lo hace ipython. if line.endswith('?'): line = 'print ' + line[:-1] + '.__doc__' if self.haveLine and not self.multiline: # one line command self.command = line # line is the command self.append('') # move down one line if '=' in line: primer_parte = line.split('=')[0] if self.interpreter.es_metodo(primer_parte): print "ES METOPDO" self.insertar_error("No puedes sobre-escribir un metodo, lo siento.") self.command = '' # clear command self.marker() # handle marker style return None try: self.interpreter.runsource(self.command) except Exception, e: self.insertar_error_desde_exception(e) self.command = '' # clear command self.marker() # handle marker style return None
def keyPressEvent(self, e: QKeyEvent): print('here') if e.key() == Qt.Key_Delete: self.delete_selected_elements() self.repaint()
def keyPressEvent(self, event): keyEvent = QKeyEvent(event) if keyEvent.key() == Qt.Key_Enter or keyEvent.key() == Qt.Key_Return: self.run()
def keyPressEvent(self, event): keyEvent = QKeyEvent(event) if keyEvent.key() == QtCore.Qt.Key_Enter or keyEvent.key() == QtCore.Qt.Key_Return: self.qmc.get_value() if keyEvent.key() == QtCore.Qt.Key_0: self.get_value()
def keyPressEvent(self, event): keyEvent = QKeyEvent(event) if keyEvent.key() == QtCore.Qt.Key_Enter or keyEvent.key() == QtCore.Qt.Key_Return: self.qmc.draw_all() if keyEvent.key() == QtCore.Qt.Key_0: self.draw_all()
def tuple2keyevent(past_event): """Convert tuple into a QKeyEvent instance""" return QKeyEvent(*past_event)
def f2(e: QtGui.QKeyEvent): if e.key() == QtCore.Qt.Key_Delete: self.delete_test()
def keyPressEvent(self, event): keyEvent = QKeyEvent(event) if keyEvent.key() == Qt.Key_Enter or keyEvent.key() == Qt.Key_Return: if not self.ensureBtn.isHidden(): self.slotCheckPassWord()
# # Spec is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> # from PyQt4.QtCore import Qt, QEvent from PyQt4.QtGui import QKeyEvent def tackon(self): print "hooah kaching, I gots key", self.key() QKeyEvent.other = tackon ke = QKeyEvent(QEvent.KeyPress, 70, Qt.NoModifier) ke.other()
def _cut(self): event = QKeyEvent(QEvent.KeyPress, Qt.Key_X, Qt.ControlModifier, "x") self.keyPressEvent(event)
def keyPressEvent(self, e: QtGui.QKeyEvent): if e.key() == QtCore.Qt.Key_Delete: self.delete_row(self.currentRow())