def eventFilter(self, watched, event): if event.type() == QEvent.MouseButtonPress: # On unix, we want to update cursor position on middle # button press, before deciding whether editing is possible. mouseEvent = event # Qt 4.6 has only "MidButton", not "MiddleButton" if mouseEvent.buttons() == Qt.MidButton: newCursor = self.te.cursorForPosition(mouseEvent.pos()) self.te.setTextCursor(newCursor) elif event.type() == QEvent.KeyPress: keyEvent = event if self.prompt_is_dirty: self.place_new_prompt(True) # CONTROL-keystrokes key = keyEvent.key() if keyEvent.modifiers() & Qt.ControlModifier: # Ctrl-p and Ctrl-n for command history if key == Qt.Key_P: self.show_previous_command() return True elif key == Qt.Key_N: self.show_next_command() return True elif keyEvent.modifiers() & Qt.AltModifier: pass elif keyEvent.modifiers() & Qt.MetaModifier: pass else: # non-Ctrl keystrokes # Use up and down arrows for history if key == Qt.Key_Up: self.show_previous_command() return True elif key == Qt.Key_Down: self.show_next_command() return True # Prevent left arrow from leaving editing area elif (key == Qt.Key_Left) or (key == Qt.Key_Backspace): # Qt 4.6 lacks QTextCursor.positionInBlock if (self.te.textCursor().positionInBlock() == len(self.prompt)) and self.cursor_is_in_editing_region(self.te.textCursor()): return True # no moving left into prompt with arrow key # Trigger command execution with <Return> elif (key == Qt.Key_Return) or (key == Qt.Key_Enter): self.run_console_command() return True # Consume event. We will take care of inserting the newline. # If this is a printing character, make sure the editing console is activated if len(keyEvent.text()) > 0: if not self.cursor_is_in_editing_region(self.te.textCursor()): self.te.setTextCursor(self.latest_good_cursor) return QMainWindow.eventFilter(self, watched, event)
def eventFilter(self, source, event): ''' Check if the event is a button press in the UI, if not then check if it was a mouse or key press in DRZ_detector. ''' pref_pressed = self.pref_buttons.checkForButtonPress(source, event) zoom_pressed = self.zoom_button.checkForButtonPress(source, event, self.controller) if pref_pressed or zoom_pressed: self.show_menus_func() if pref_pressed: self.pref_change(self.shared_prefs, self.layer_manager, pref_pressed, event) else: update = self.DRZ_detector.on_motion_event(event) if pref_pressed or zoom_pressed or update: self.update_rendering() return True return QMainWindow.eventFilter(self, source, event)
def eventFilter(self, source, event): #Override """ Override the QMainWindow eventFilter method to add File Mask Validation. """ if (event.type() == QEvent.FocusOut and source is self.qleVideoTypes): self.ValidateFileMask() return QMainWindow.eventFilter(self, source, event)