(self, event)
build and show contextmenu
build and show contextmenu
build and show contextmenu
def _on_context_menu(self, event):
        """ build and show contextmenu
        """
        context_menu = QMenu()

        loc_x = event.pos().x()
        loc_y = event.pos().y()

        show = False
        address = 0
        addr_str = '0'

        if loc_y > self._header_height + self._ver_spacing:
            # cursor in hex
            index = 0
            if (self._hex_start - self._hor_spacing) < loc_x < self._ascii_start:
                coord_x, coord_y = self.pixel_to_data(
                    loc_x - self._hex_start, loc_y)
                line = int(ceil(coord_x - (coord_x / 3)))
                index = int(
                    floor(self.pos + line / 2 +
                          coord_y * self.bytes_per_line))
                show = True
            elif (self._ascii_start + self._ascii_width) > loc_x > self._ascii_start:
                # elif loc_x > self._ascii_start and
                # loc_x < (self._ascii_start + self._ascii_width):
                coord_x, coord_y = self.pixel_to_data(
                    loc_x - self._ascii_start, loc_y)
                line = int(ceil(coord_x % self.bytes_per_line))
                index = int(
                    floor(self.pos + line +
                          coord_y * self.bytes_per_line))
                show = True

            if show:
                address = self.base + index
                addr_str = hex(address)

                context_menu.addAction(addr_str)
                context_menu.addSeparator()

                context_menu.addAction("&Disassemble", self.on_cm_show_asm)
                context_menu.addAction("&Dump to file", self.on_cm_dump_to_file)
                context_menu.addSeparator()

                context_menu.addAction("Follow &pointer", self.on_cm_follow_pointer)
                context_menu.addSeparator()

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

                context_menu.addSeparator()

        # write_string = context_menu.addAction("&Write string")
        # menu_actions[write_string] = self.on_cm_writestring

        # hide copy section when nothing selected
        if self.selection.start != self.selection.end:
            context_menu.addAction("&Copy", self.on_cm_copy)

            copy_as_content = QMenu("Copy as", context_menu)
            copy_as_content.addAction('C Source')
            copy_as_content.addAction('Python Source')
            copy_as_content.addAction('JS Source')
            copy_as_content.triggered.connect(self.on_cm_copy_as)

            context_menu.addMenu(copy_as_content)

            context_menu.addSeparator()

        if show:
            context_menu.addAction('&Copy address', lambda: utils.copy_hex_to_clipboard(hex(self.base + index)))

        context_menu.addAction("&Jump to address", self.debug_panel.on_cm_jump_to_address)

        if not context_menu.isEmpty():
            context_menu.exec_(QCursor.pos())
def _on_context_menu ( self , event ) : context_menu = QMenu ( ) loc_x = event . pos ( ) . x ( ) loc_y = event . pos ( ) . y ( ) show = False address = 0 addr_str = '0' if loc_y > self . _header_height + self . _ver_spacing : # cursor in hex index = 0 if ( self . _hex_start - self . _hor_spacing ) < loc_x < self . _ascii_start : coord_x , coord_y = self . pixel_to_data ( loc_x - self . _hex_start , loc_y ) line = int ( ceil ( coord_x - ( coord_x / 3 ) ) ) index = int ( floor ( self . pos + line / 2 + coord_y * self . bytes_per_line ) ) show = True elif ( self . _ascii_start + self . _ascii_width ) > loc_x > self . _ascii_start : # elif loc_x > self._ascii_start and # loc_x < (self._ascii_start + self._ascii_width): coord_x , coord_y = self . pixel_to_data ( loc_x - self . _ascii_start , loc_y ) line = int ( ceil ( coord_x % self . bytes_per_line ) ) index = int ( floor ( self . pos + line + coord_y * self . bytes_per_line ) ) show = True if show : address = self . base + index addr_str = hex ( address ) context_menu . addAction ( addr_str ) context_menu . addSeparator ( ) context_menu . addAction ( "&Disassemble" , self . on_cm_show_asm ) context_menu . addAction ( "&Dump to file" , self . on_cm_dump_to_file ) context_menu . addSeparator ( ) context_menu . addAction ( "Follow &pointer" , self . on_cm_follow_pointer ) context_menu . addSeparator ( ) if self . app . watchpoints_panel : if self . app . dwarf . is_address_watched ( address ) : context_menu . addAction ( 'Remove watchpoint' , lambda : self . app . watchpoints_panel . remove_address ( addr_str ) ) else : context_menu . addAction ( 'Watch address' , lambda : self . app . watchpoints_panel . do_addwatchpoint_dlg ( addr_str ) ) if self . app . breakpoints_panel : if address in self . app . dwarf . breakpoints : context_menu . addAction ( 'Remove breakpoint' , lambda : self . app . dwarf . dwarf_api ( 'deleteBreakpoint' , addr_str ) ) else : context_menu . addAction ( 'Breakpoint address' , lambda : self . app . dwarf . breakpoint_native ( addr_str ) ) context_menu . addSeparator ( ) # write_string = context_menu.addAction("&Write string") # menu_actions[write_string] = self.on_cm_writestring # hide copy section when nothing selected if self . selection . start != self . selection . end : context_menu . addAction ( "&Copy" , self . on_cm_copy ) copy_as_content = QMenu ( "Copy as" , context_menu ) copy_as_content . addAction ( 'C Source' ) copy_as_content . addAction ( 'Python Source' ) copy_as_content . addAction ( 'JS Source' ) copy_as_content . triggered . connect ( self . on_cm_copy_as ) context_menu . addMenu ( copy_as_content ) context_menu . addSeparator ( ) if show : context_menu . addAction ( '&Copy address' , lambda : utils . copy_hex_to_clipboard ( hex ( self . base + index ) ) ) context_menu . addAction ( "&Jump to address" , self . debug_panel . on_cm_jump_to_address ) if not context_menu . isEmpty ( ) : context_menu . exec_ ( QCursor . pos ( ) )