(self, event)
build and show contextmenu
build and show contextmenu
build and show contextmenu
def _on_context_menu(self, event):
        """ build and show contextmenu
        """
        loc_x = event.pos().x()
        loc_y = event.pos().y()

        context_menu = QMenu()

        def add_default_actions():
            context_menu.addAction('Jump to address', lambda: self.debug_panel.on_cm_jump_to_address(view=1))

            # allow mode switch arm/thumb
            if self._app_window.dwarf.disassembler.capstone_arch == CS_ARCH_ARM:
                if self._app_window.dwarf.disassembler.capstone_mode == CS_MODE_THUMB:
                    mode_str = 'ARM'
                else:
                    mode_str = 'THUMB'
                entry_str = '&Switch to {0} mode'.format(mode_str)
                context_menu.addAction(entry_str, self._on_switch_mode)

        if not self._lines:
            # allow jumpto in empty panel
            glbl_pt = self.mapToGlobal(event.pos())
            context_menu.exec_(glbl_pt)
            return
        
        add_default_actions()
        index = self.pixel_to_line(loc_x, loc_y)
        address = -1
        if 0 <= index < self.visible_lines():
            if index + self.pos < len(self._lines):
                if isinstance(self._lines[index + self.pos], Instruction):
                    address = self._lines[index + self.pos].address
                    addr_str = hex(address)

                    context_menu.addAction(addr_str)
                    context_menu.addSeparator()

                    if self._app_window.watchpoints_panel:
                        if self._app_window.dwarf.is_address_watched(address):
                            context_menu.addAction(
                                'Remove watchpoint', lambda: self._app_window.watchpoints_panel.remove_address(addr_str))
                        else:
                            context_menu.addAction(
                                'Watch address', lambda: self._app_window.watchpoints_panel.do_addwatchpoint_dlg(addr_str))
                    if self._app_window.breakpoints_panel:
                        if address in self._app_window.dwarf.breakpoints:
                            context_menu.addAction(
                                'Remove breakpoint', lambda: self._app_window.dwarf.dwarf_api('deleteBreakpoint', addr_str))
                        else:
                            context_menu.addAction('Breakpoint address', lambda: self._app_window.dwarf.breakpoint_native(addr_str))

                    context_menu.addSeparator()

                    context_menu.addAction(
                        'Copy address', lambda: utils.copy_hex_to_clipboard(address))

        context_menu.addAction("&Jump to address", lambda: self.debug_panel.on_cm_jump_to_address(view=1))

        glbl_pt = self.mapToGlobal(event.pos())
        context_menu.exec_(glbl_pt)
def _on_context_menu ( self , event ) : loc_x = event . pos ( ) . x ( ) loc_y = event . pos ( ) . y ( ) context_menu = QMenu ( ) def add_default_actions ( ) : context_menu . addAction ( 'Jump to address' , lambda : self . debug_panel . on_cm_jump_to_address ( view = 1 ) ) # allow mode switch arm/thumb if self . _app_window . dwarf . disassembler . capstone_arch == CS_ARCH_ARM : if self . _app_window . dwarf . disassembler . capstone_mode == CS_MODE_THUMB : mode_str = 'ARM' else : mode_str = 'THUMB' entry_str = '&Switch to {0} mode' . format ( mode_str ) context_menu . addAction ( entry_str , self . _on_switch_mode ) if not self . _lines : # allow jumpto in empty panel glbl_pt = self . mapToGlobal ( event . pos ( ) ) context_menu . exec_ ( glbl_pt ) return add_default_actions ( ) index = self . pixel_to_line ( loc_x , loc_y ) address = - 1 if 0 <= index < self . visible_lines ( ) : if index + self . pos < len ( self . _lines ) : if isinstance ( self . _lines [ index + self . pos ] , Instruction ) : address = self . _lines [ index + self . pos ] . address addr_str = hex ( address ) context_menu . addAction ( addr_str ) context_menu . addSeparator ( ) if self . _app_window . watchpoints_panel : if self . _app_window . dwarf . is_address_watched ( address ) : context_menu . addAction ( 'Remove watchpoint' , lambda : self . _app_window . watchpoints_panel . remove_address ( addr_str ) ) else : context_menu . addAction ( 'Watch address' , lambda : self . _app_window . watchpoints_panel . do_addwatchpoint_dlg ( addr_str ) ) if self . _app_window . breakpoints_panel : if address in self . _app_window . dwarf . breakpoints : context_menu . addAction ( 'Remove breakpoint' , lambda : self . _app_window . dwarf . dwarf_api ( 'deleteBreakpoint' , addr_str ) ) else : context_menu . addAction ( 'Breakpoint address' , lambda : self . _app_window . dwarf . breakpoint_native ( addr_str ) ) context_menu . addSeparator ( ) context_menu . addAction ( 'Copy address' , lambda : utils . copy_hex_to_clipboard ( address ) ) context_menu . addAction ( "&Jump to address" , lambda : self . debug_panel . on_cm_jump_to_address ( view = 1 ) ) glbl_pt = self . mapToGlobal ( event . pos ( ) ) context_menu . exec_ ( glbl_pt )