def keyPressEvent(self, e: QtGui.QKeyEvent): if not self.m_isEditing: return if e.key() == QtCore.Qt.Key_Delete: self.deleteLater() # Moving container with arrows if QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier: newPos = QPoint(self.x(), self.y()) if e.key() == QtCore.Qt.Key_Up: newPos.setY(newPos.y() - 1) if e.key() == QtCore.Qt.Key_Down: newPos.setY(newPos.y() + 1) if e.key() == QtCore.Qt.Key_Left: newPos.setX(newPos.x() - 1) if e.key() == QtCore.Qt.Key_Right: newPos.setX(newPos.x() + 1) self.move(newPos) if QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier: if e.key() == QtCore.Qt.Key_Up: self.resize(self.width(), self.height() - 1) if e.key() == QtCore.Qt.Key_Down: self.resize(self.width(), self.height() + 1) if e.key() == QtCore.Qt.Key_Left: self.resize(self.width() - 1, self.height()) if e.key() == QtCore.Qt.Key_Right: self.resize(self.width() + 1, self.height()) self.newGeometry.emit(self.geometry())
def keyPressEvent(self, event): key = event.key() node = self.node_under_cursor() if key == Qt.Key_N: if node is not None: self.rename_node(node=node) return True if key == Qt.Key_Y: # setting the type if isinstance(node, (CVariable, )): # find existing type self.retype_node(node=node, node_type=node.variable_type) return True if key in (Qt.Key_Slash, Qt.Key_Question): self.comment(expr=event.modifiers() & Qt.ShiftModifier == Qt.ShiftModifier) return True if key == Qt.Key_Minus and QApplication.keyboardModifiers( ) & Qt.CTRL != 0: self.zoomOut() if key == Qt.Key_Equal and QApplication.keyboardModifiers( ) & Qt.CTRL != 0: self.zoomIn() if self._code_view.keyPressEvent(event): return True saved_mode = self.textInteractionFlags() if key in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down, Qt.Key_PageDown, Qt.Key_PageUp, Qt.Key_Home, Qt.Key_End): self.setTextInteractionFlags(saved_mode | Qt.TextEditable) result = super().keyPressEvent(event) self.setTextInteractionFlags(saved_mode) return result
def keyPressEvent(self, event): key = event.key() if key == Qt.Key_G: # jump to window self.popup_jumpto_dialog() return elif key == Qt.Key_Escape or (key == Qt.Key_Left and QApplication.keyboardModifiers() & Qt.ALT != 0): # jump back self.jump_back() return elif key == Qt.Key_Right and QApplication.keyboardModifiers() & Qt.ALT != 0: # jump forward self.jump_forward() return elif key == Qt.Key_A: # switch between highlight mode self.toggle_smart_highlighting(not self.infodock.smart_highlighting) return elif key == Qt.Key_Tab: # decompile self.decompile_current_function() return elif key == Qt.Key_Semicolon: # add comment self.popup_comment_dialog() return super().keyPressEvent(event)
def _on_keypressed_event(self, key_event): key = key_event.key() if key == Qt.Key_G: # jump to window self.disassembly_view.popup_jumpto_dialog() return True elif key == Qt.Key_N: # rename a label self.disassembly_view.popup_rename_label_dialog() return True elif key == Qt.Key_X: # XRef # get the variable if self.selected_operands: ins_addr, operand_idx = next(iter(self.selected_operands)) block = self._insn_addr_to_block.get(ins_addr, None) if block is not None: operand = block.addr_to_insns[ins_addr].get_operand( operand_idx) if operand is not None and operand.variable is not None: self.disassembly_view.popup_xref_dialog( operand.variable) return True elif key == Qt.Key_Escape or ( key == Qt.Key_Left and QApplication.keyboardModifiers() & Qt.ALT != 0): # jump back self.disassembly_view.jump_back() return True elif key == Qt.Key_Right and QApplication.keyboardModifiers( ) & Qt.ALT != 0: # jump forward self.disassembly_view.jump_forward() return True elif key == Qt.Key_A: # switch between highlight mode self.disassembly_view.toggle_smart_highlighting( not self.infodock.smart_highlighting) return True elif key == Qt.Key_Tab: # decompile self.disassembly_view.decompile_current_function() return True elif key == Qt.Key_Semicolon: # add comment self.disassembly_view.popup_comment_dialog() return True return False
def search_result(self): p = self.result_text_edit.palette() p.setColor(QPalette.Highlight, QColor("#ee799f")) self.result_text_edit.setPalette(p) search_settings = QTextDocument.FindFlags() mod = QApplication.keyboardModifiers() if (mod & Qt.ShiftModifier) != 0: search_settings |= QTextDocument.FindBackward r = self.result_text_edit.find(self.search_line.text(), search_settings) if not r: if (mod & Qt.ShiftModifier) != 0: self.goto(QTextCursor.End) else: self.goto(QTextCursor.Start) self.result_text_edit.find(self.search_line.text(), search_settings) if self.search_line.text() == '': self.search_summary_label.hide() return current_position = self.result_text_edit.textCursor().position() try: current_index = self.search_positions.index(current_position) except ValueError: current_index = -1 self.search_summary_label.show() self.search_summary_label.setText( '%s/%s' % (current_index + 1, len(self.search_positions)))
def mouseMoveEvent(self, event): """pass event along to scenes before changing the own state""" #cam_pos = self.graphics_context.camera.get_world_position() #pos_2d = [event.x(),event.y()] #ray_direction = self.get_ray_from_pixel(pos_2d) cam_pos, cam_ray = self.getRayFromClick(event.x(), event.y()) cam_pos = cam_pos[:3] cam_ray = cam_ray[:3] self.mouse_move.emit(event, self.lastMousePosition, cam_pos, cam_ray) modifiers = QApplication.keyboardModifiers() newPosition = QPointF(event.x(), event.y()) diff = newPosition - self.lastMousePosition self.lastMousePosition = newPosition if event.buttons() & Qt.MiddleButton and modifiers != Qt.ShiftModifier: # set rotation self.graphics_context.camera.updateRotationMatrix( self.graphics_context.camera.pitch + diff.y() * self.rotation_scale, self.graphics_context.camera.yaw + diff.x() * self.rotation_scale) self.showMessageOnStatusBar( "rotation x: " + str(self.graphics_context.camera.yaw) + ", rotation y: " + str(self.graphics_context.camera.pitch)) elif event.buttons( ) & Qt.MiddleButton and modifiers == Qt.ShiftModifier: # set position self.graphics_context.camera.moveHorizontally( -diff.x() * self.movement_scale * 2) self.graphics_context.camera.position[1] -= diff.y( ) * self.movement_scale * 2 #/(10*self.zoom_factor)
def keyReleaseEvent(self, event): if event.key() == Qt.Key_Return and QApplication.keyboardModifiers( ) == Qt.ControlModifier: if self._textconfirmed_callback is not None: self._textconfirmed_callback() return True return super().keyReleaseEvent(event)
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.infodock.toggle_operand_selection(self.insn.addr, self.operand_index, self.operand_descriptor, insn_pos=self.parentItem().scenePos(), unique=QApplication.keyboardModifiers() != Qt.ControlModifier) else: super().mousePressEvent(event)
def mousePressEvent(self, event: QGraphicsSceneMouseEvent): if event.button() == Qt.LeftButton and QApplication.keyboardModifiers() in (Qt.NoModifier, Qt.ControlModifier): # toggle selection self.infodock.toggle_instruction_selection( self.addr, insn_pos=self.scenePos(), unique=QApplication.keyboardModifiers() != Qt.ControlModifier) event.accept() elif event.button() == Qt.RightButton and QApplication.keyboardModifiers() == Qt.NoModifier: if self.addr not in self.infodock.selected_insns: self.infodock.toggle_instruction_selection(self.addr, insn_pos=self.scenePos(), unique=True) self.disasm_view.instruction_context_menu(self.insn, QCursor.pos()) event.accept() elif self.workspace.plugins.handle_click_insn(self, event): event.accept() else: super().mousePressEvent(event)
def mouseMoveEvent(self, event): """ Mouse move event handler @param event: @type event: """ modifiers = QApplication.keyboardModifiers() # mouse coordinates, relative to parent widget pos = self.mapToParent(event.pos()) img = self.tool.layer.parentImage r = self.tool.resizingCoeff self.tool.targetQuad_old = self.tool.getTargetQuad( ) # TODO added 15/05/18 validate self.posRelImg = (pos - QPoint(img.xOffset, img.yOffset)) / r if modifiers == Qt.ControlModifier | Qt.AltModifier: if self.tool.isModified(): dlgWarn("A transformation is in progress", "Reset first") return # update the new starting position self.posRelImg_ori = self.posRelImg # (pos - QPoint(img.xOffset, img.yOffset)) / r self.posRelImg_frozen = self.posRelImg self.tool.moveRotatingTool() self.tool.parent().repaint() return curimg = self.tool.layer.getCurrentImage() w, h = curimg.width(), curimg.height() s = w / self.tool.img.width() form = self.tool.getForm() if form.options['Free']: pass elif form.options['Rotation']: center = self.tool.getTargetQuad().boundingRect().center() v = QPointF(self.posRelImg.x() - center.x(), self.posRelImg.y() - center.y()) v0 = QPointF(self.posRelImg_frozen.x() - center.x(), self.posRelImg_frozen.y() - center.y()) theta = (np.arctan2(v.y(), v.x()) - np.arctan2(v0.y(), v0.x())) * 180.0 / np.pi T = QTransform() # self.tool.geoTrans_ori) T.translate(center.x(), center.y()).rotate(theta).translate( -center.x(), -center.y()) q = T.map(self.tool.getFrozenQuad()) for i, role in enumerate( ['topLeft', 'topRight', 'bottomRight', 'bottomLeft']): self.tool.btnDict[role].posRelImg = q.at(i) elif form.options['Translation']: # translation vector (coordinates are relative to the full size image) p = QPointF(self.posRelImg) - QPointF(self.posRelImg_frozen) T = QTransform() T.translate(p.x(), p.y()) q = T.map(self.tool.getFrozenQuad()) for i, role in enumerate( ['topLeft', 'topRight', 'bottomRight', 'bottomLeft']): self.tool.btnDict[role].posRelImg = q.at(i) self.tool.moveRotatingTool() self.tool.modified = True self.tool.layer.applyToStack() self.parent().repaint()
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.infodock.select_label(self.addr) elif event.button( ) == Qt.RightButton and QApplication.keyboardModifiers( ) == Qt.NoModifier: if self.addr not in self.infodock.selected_labels: self.infodock.select_label(self.addr) self._disasm_view.label_context_menu(self.addr, QCursor.pos())
def mousePressEvent(self, event): """ Call appropriate functions given mouse key presses. """ x, y = event.x() * self.pixel_ratio, event.y() * self.pixel_ratio buttons = event.buttons() modifiers = QApplication.keyboardModifiers() self.on_mouse_press(x, y, buttons, modifiers) self.updateGL()
def handle_node_mouse_press(self, event, *, id): if event.button() == Qt.LeftButton: self.select_item(id) event.accept() elif (event.button() == Qt.RightButton and QApplication.keyboardModifiers() == Qt.NoModifier): self.label_context_menu(id, QCursor.pos()) event.accept()
def _menu_about_to_show(self): """ Setup method before menu is visible """ # Hide hidden actions self.hidden_actions.setVisible(False) # Show hidden actions with Ctrl Key if QApplication.keyboardModifiers() & QtCore.Qt.ControlModifier: self.hidden_actions.setVisible(True) self._apply_settings()
def handle_click_block(self, qblock, event): btn = event.button() if QApplication.keyboardModifiers() == Qt.ControlModifier and btn == Qt.RightButton: if self.multi_trace is not None and self.multi_trace.am_obj is not None: the_trace = self.multi_trace.get_any_trace(qblock.addr) if the_trace is not None: self.trace.am_obj = TraceStatistics(self.workspace, the_trace, self.multi_trace.base_addr) self.trace.am_event() return True return False
def mousePressEvent(self, event): modifiers = QApplication.keyboardModifiers() if modifiers & Qt.ShiftModifier: self.disable_gamma_correction = True if self.gradient_edit or self.ramp_sketch: self.draw_path = True self.path.moveTo(event.pos()) self.path_item.setPath(self.path) else: self.picked_color = self.color_info.color
def wheelEvent(self, event): if QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier: brush_pixle_size = int(self.edit_brush_pixle_size.text()) delta = event.delta() if delta > 0: brush_pixle_size += 1 elif delta < 0: brush_pixle_size -= 1 if brush_pixle_size >= self.min_brush_pixle_size and brush_pixle_size <= self.max_brush_pixle_size: self.edit_brush_pixle_size.setText(f'{brush_pixle_size}') elif QApplication.keyboardModifiers() == QtCore.Qt.AltModifier: eraser_pixle_size = int(self.edit_eraser_pixle_size.text()) delta = event.delta() if delta > 0: eraser_pixle_size += 1 elif delta < 0: eraser_pixle_size -= 1 if eraser_pixle_size >= self.min_eraser_pixle_size and eraser_pixle_size <= self.max_eraser_pixle_size: self.edit_eraser_pixle_size.setText(f'{eraser_pixle_size}')
def mouseDoubleClickEvent(self, event): if QApplication.keyboardModifiers() == Qt.ShiftModifier: # go to the source self.disasm_view.jump_to(self.edge.src.addr, src_ins_addr=self.edge.dst.addr) event.accept() else: # go to the destination self.disasm_view.jump_to(self.edge.dst.addr, src_ins_addr=self.edge.src.addr) event.accept() super().mouseDoubleClickEvent(event)
def mousePressEvent(self, event): if event.button() == QtCore.Qt.LeftButton: if QApplication.keyboardModifiers() == QtCore.Qt.AltModifier: self.eraser_painting_model = True self.setCursor(self.eraser_model_cursor) else: self.eraser_painting_model = False self.setCursor(self.brush_model_cursor) self.mouse_press_flag = True self.mouse_pos = event.pos() self.update()
def wheelEvent(self, event): if QApplication.keyboardModifiers() == Qt.ControlModifier: point_delta = event.angleDelta().y() // 120 for edit in (self.before_edit, self.after_edit, self.change_edit): font = edit.font() size = font.pointSize() + point_delta if size > 0: font.setPointSize(size) edit.setFont(font) else: super().wheelEvent(event)
def keyPressEvent(self, event): if self.completer and self.completer.popup() and self.completer.popup( ).isVisible(): if event.key() in (Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab, Qt.Key_Backtab): event.ignore() #print("Event ignored") return text_cursor = self.textCursor() process_event = True if event.key() == Qt.Key_Tab: text_cursor.insertText(" " * self.tab_spaces) process_event = False if process_event: QPlainTextEdit.keyPressEvent(self, event) if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return: prev_line = self.get_previous_line() prev_line_leading_spaces = len(prev_line) - len( prev_line.lstrip(" ")) new_line_spaces = " " * prev_line_leading_spaces if prev_line.startswith(" "): text_cursor.insertText(new_line_spaces) arrow_pressed = event.key() in (Qt.Key_Right, Qt.Key_Left, Qt.Key_Up, Qt.Key_Down, Qt.Key_Shift, Qt.Key_Control) modifiers = QApplication.keyboardModifiers() if event.key() == Qt.Key_Space and modifiers == Qt.ControlModifier: arrow_pressed = False completionPrefix = self.textUnderCursor() #print(f"Completion prefix is {completionPrefix}") if len(completionPrefix) > 0 and not arrow_pressed: if not (completionPrefix in self.keywords and sum( k.startswith(completionPrefix) for k in self.keywords) == 1): self.completer.setCompletionPrefix(completionPrefix) popup = self.completer.popup() popup.setCurrentIndex(self.completer.completionModel().index( 0, 0)) cr = self.cursorRect() cr.setWidth(self.completer.popup().sizeHintForColumn(0) + self.completer.popup().verticalScrollBar( ).sizeHint().width()) self.completer.complete(cr) elif self.completer.popup(): self.completer.popup().hide()
def mouseMoveEvent(self, event): if not self.mouse_press_flag: return if QApplication.keyboardModifiers() == QtCore.Qt.AltModifier: self.eraser_painting_model = True self.setCursor(self.eraser_model_cursor) else: self.eraser_painting_model = False self.setCursor(self.brush_model_cursor) self.mouse_pos = event.pos() self.update()
def toggle_instruction_selection(self, insn_addr): """ Toggle the selection state of an instruction in the disassembly view. :param int insn_addr: Address of the instruction to toggle. :return: None """ if insn_addr in self.current_graph.selected_insns: self.current_graph.unselect_instruction(insn_addr) else: self.current_graph.select_instruction(insn_addr, unique=QApplication.keyboardModifiers() & Qt.CTRL == 0) self.current_graph.show_instruction(insn_addr)
def keyReleaseEvent(self, event): key = event.key() if key == Qt.Key_G: # jump to window self.popup_jumpto_dialog() return elif key == Qt.Key_Left and QApplication.keyboardModifiers( ) & Qt.ALT != 0: # jump back self.jump_back() return elif key == Qt.Key_Right and QApplication.keyboardModifiers( ) & Qt.ALT != 0: # jump forward self.jump_forward() return elif key == Qt.Key_A: # switch between highlight mode self.toggle_smart_highlighting( not self.infodock.smart_highlighting) return elif key == Qt.Key_Tab and self._tab_pressed: # decompile self.decompile_current_function() self._tab_pressed = False return elif key == Qt.Key_Semicolon: # add comment self.popup_comment_dialog() return elif key == Qt.Key_Space: # switch to linear view self.toggle_disasm_view() event.accept() return super().keyReleaseEvent(event)
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: selected = self.infodock.toggle_operand_selection( self.insn.addr, self.operand_index, self.operand_descriptor, insn_pos=self.parentItem().scenePos(), unique=QApplication.keyboardModifiers() != Qt.ControlModifier) if selected: # select the current instruction, too self.infodock.select_instruction(self.insn.addr, insn_pos=QPointF( self.x(), self.y()), unique=True) else: super().mousePressEvent(event)
def toggle_operand_selection(self, insn_addr, operand_idx): """ Toggle the selection state of an operand of an instruction in the disassembly view. :param int insn_addr: Address of the instruction to toggle. :param int operand_idx: The operand to toggle. :return: None """ if (insn_addr, operand_idx) in self.current_graph.selected_operands: self.current_graph.unselect_operand(insn_addr, operand_idx) else: self.current_graph.select_operand( insn_addr, operand_idx, unique=QApplication.keyboardModifiers() != Qt.ControlModifier) self.current_graph.show_instruction(insn_addr)
def mousePressEvent(self, event): # print("Remove index=", self.index) self.imageClicked.emit(self.index, event) return # print("Hover", event.type()) modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ShiftModifier: print('Shift+Click') elif modifiers == Qt.ControlModifier: print('Control+Click') elif modifiers == (Qt.ControlModifier | Qt.ShiftModifier): print('Control+Shift+Click') elif modifiers == (Qt.AltModifier): print('Alt') else: print('Click')
def recruit_handler( self, recruit_type: RecruitType, item: TransactionItemType ) -> None: # Lookup if Keyboard Modifiers were pressed # Shift = 10 times # CTRL = 5 Times modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ShiftModifier: amount = 10 elif modifiers == Qt.ControlModifier: amount = 5 else: amount = 1 if recruit_type == RecruitType.SELL: self.sell(item, amount) elif recruit_type == RecruitType.BUY: self.buy(item, amount)
def mousePressEvent(self, event): """ :param QGraphicsSceneMouseEvent event: :return: """ if event.button() == Qt.LeftButton: # toggle selection self.infodock.toggle_instruction_selection(self.addr, insn_pos=self.scenePos(), unique=QApplication.keyboardModifiers() != Qt.ControlModifier) event.accept() elif event.button() == Qt.RightButton: # display the context menu self.disasm_view.instruction_context_menu(self.insn, QCursor.pos()) event.accept() else: super().mousePressEvent(event)
def recruit_handler(self, recruit_type: RecruitType, unit_type: UnitType) -> None: # Lookup if Keyboard Modifiers were pressed # Shift = 10 times # CTRL = 5 Times modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ShiftModifier: amount = 10 elif modifiers == Qt.ControlModifier: amount = 5 else: amount = 1 for i in range(amount): if recruit_type == RecruitType.SELL: if not self.sell(unit_type): return elif recruit_type == RecruitType.BUY: if not self.buy(unit_type): return