(self, event)
main paint
main paint
main paint
def do_paint(self, event):
        """ main paint
        """
        if not self.isVisible():
            return

        old_offset_start = self._offset_start
        old_hex_start = self._hex_start
        old_ascii_start = self._ascii_start
        scroll_x = self.horizontalScrollBar().value()
        self._offset_start -= scroll_x
        self._hex_start -= scroll_x
        self._ascii_start -= scroll_x

        painter = QPainter(self.viewport())
        painter.setRenderHint(QPainter.HighQualityAntialiasing)

        # fill background
        painter.fillRect(self.viewport().rect(),
                         self._ctrl_colors['background'])

        # no data stop paint
        if self.data is None:
            return

        # hover current line
        if self._hover_lines and self._hovered_line != -1:
            screen_x, screen_y = self.data_to_pixel(0, self._hovered_line)
            screen_y -= self._base_line
            painter.fillRect(0, screen_y - 1,
                             self.viewport().width(), self._char_height + 2,
                             self._ctrl_colors['linecol'])

        # update carets
        if not self._error_message:
            if event.rect() == self.caret_to_hexcol(self.caret):
                if self._blink:
                    painter.fillRect(
                        self.caret_to_hexcol(self.caret), QColor('#ef5350'))
                self.viewport().update(self.caret_to_asciicol(self.caret))
                return

            if event.rect() == self.caret_to_asciicol(self.caret):
                if self._blink:
                    painter.fillRect(
                        self.caret_to_asciicol(self.caret), QColor('#ef5350'))
                return

        self.pos = self.verticalScrollBar().value() * self.bytes_per_line

        # set pos_y
        drawing_pos_y = self._header_height + self._char_height + self._ver_spacing

        # draw carets
        if self._blink:
            if self.caret_to_hexcol(self.caret).top() < self.height():
                if self.caret_to_hexcol(self.caret).bottom() > 0:
                    painter.fillRect(
                        self.caret_to_hexcol(self.caret), QColor('#ef5350'))
                    painter.fillRect(
                        self.caret_to_asciicol(self.caret), QColor('#ef5350'))

        # paint selection
        self.paint_selection(painter)

        # paint visisble lines
        for i, line in enumerate(self.get_lines(self.pos)):

            if i > self.visible_lines() - 1:
                break

            has_highlight = False

            # get data
            (address, length, ascii_) = line
            data = self.data[address:address + length]

            # fixup offset
            address += self.base

            # paint address
            if i == self._hovered_line:
                painter.setPen(QColor('#ef5350'))
            else:
                painter.setPen(self._ctrl_colors['foreground'])

            addr = '{0:08X}'
            if self._is_64bit_addr:
                if self._hex_style == 'upper':
                    addr = "{0:016X}"
                else:
                    addr = "{0:016x}"
            else:
                if self._hex_style == 'upper':
                    addr = "{0:08X}"
                else:
                    addr = "{0:08x}"

            # paint addr
            rect = QRectF(self._offset_start, drawing_pos_y - self._base_line,
                          self._offset_width, self._char_height)
            painter.drawText(rect, addr.format(address),
                             QTextOption(Qt.AlignHCenter | Qt.AlignBaseline))

            drawing_pos_x = self._hex_start
            is_in_selection = False

            # hex data
            for j, byte in enumerate(data):
                if self._dual_color_bytes and not j % 2:
                    if i == self._hovered_line:
                        painter.setPen(self._ctrl_colors['selection_fg'])
                    else:
                        painter.setPen(self._ctrl_colors['byte_col_1'])
                elif self._dual_color_bytes and j % 2:
                    if i == self._hovered_line:
                        painter.setPen(self._ctrl_colors['selection_fg'])
                    else:
                        painter.setPen(self._ctrl_colors['byte_col_2'])
                else:
                    painter.setPen(self._ctrl_colors['foreground'])

                if self.selection.start <= (
                        address + j) - self.base < self.selection.end:
                    painter.setPen(self._ctrl_colors['selection_fg'])
                    is_in_selection = True

                # set highlightcolor if needed
                highlight = self.is_highlighted(address + j)
                if highlight:
                    has_highlight = True
                    painter.setPen(self._highlight_colors[highlight])

                # paint hex
                if self._hex_style == 'upper':
                    painter.drawText(drawing_pos_x, drawing_pos_y,
                                     "{:02X} ".format(byte))
                else:
                    painter.drawText(drawing_pos_x, drawing_pos_y,
                                     "{:02x} ".format(byte))
                drawing_pos_x += (3 * self._char_width)

            # restore color
            if i == self._hovered_line:
                painter.setPen(self._ctrl_colors['selection_fg'])
            else:
                painter.setPen(self._ctrl_colors['foreground'])

            # draw whole ascii if no highlight
            if not has_highlight and not is_in_selection:
                painter.drawText(self._ascii_start, drawing_pos_y, ascii_)
            else:
                for a, c in enumerate(ascii_):
                    highlight = self.is_highlighted(address + a)
                    if highlight:
                        painter.setPen(self._highlight_colors[highlight])
                    else:
                        if i == self._hovered_line:
                            painter.setPen(self._ctrl_colors['selection_fg'])
                        else:
                            painter.setPen(self._ctrl_colors['foreground'])

                        if self.selection.start <= (
                                address + a) - self.base < self.selection.end:
                            painter.setPen(self._ctrl_colors['selection_fg'])

                    painter.drawText(
                        self._ascii_start + (a * self._char_width),
                        drawing_pos_y, c)

            # new y
            drawing_pos_y += self._char_height + self._ver_spacing
            # reset x
            drawing_pos_x = self._hex_start

        # paint ctrl stuff - header etc
        self.paint_control(painter)

        # paint errorstr
        if self._error_message:
            self.paint_error(painter)

        self._offset_start = old_offset_start
        self._hex_start = old_hex_start
        self._ascii_start = old_ascii_start
def do_paint ( self , event ) : if not self . isVisible ( ) : return old_offset_start = self . _offset_start old_hex_start = self . _hex_start old_ascii_start = self . _ascii_start scroll_x = self . horizontalScrollBar ( ) . value ( ) self . _offset_start -= scroll_x self . _hex_start -= scroll_x self . _ascii_start -= scroll_x painter = QPainter ( self . viewport ( ) ) painter . setRenderHint ( QPainter . HighQualityAntialiasing ) # fill background painter . fillRect ( self . viewport ( ) . rect ( ) , self . _ctrl_colors [ 'background' ] ) # no data stop paint if self . data is None : return # hover current line if self . _hover_lines and self . _hovered_line != - 1 : screen_x , screen_y = self . data_to_pixel ( 0 , self . _hovered_line ) screen_y -= self . _base_line painter . fillRect ( 0 , screen_y - 1 , self . viewport ( ) . width ( ) , self . _char_height + 2 , self . _ctrl_colors [ 'linecol' ] ) # update carets if not self . _error_message : if event . rect ( ) == self . caret_to_hexcol ( self . caret ) : if self . _blink : painter . fillRect ( self . caret_to_hexcol ( self . caret ) , QColor ( '#ef5350' ) ) self . viewport ( ) . update ( self . caret_to_asciicol ( self . caret ) ) return if event . rect ( ) == self . caret_to_asciicol ( self . caret ) : if self . _blink : painter . fillRect ( self . caret_to_asciicol ( self . caret ) , QColor ( '#ef5350' ) ) return self . pos = self . verticalScrollBar ( ) . value ( ) * self . bytes_per_line # set pos_y drawing_pos_y = self . _header_height + self . _char_height + self . _ver_spacing # draw carets if self . _blink : if self . caret_to_hexcol ( self . caret ) . top ( ) < self . height ( ) : if self . caret_to_hexcol ( self . caret ) . bottom ( ) > 0 : painter . fillRect ( self . caret_to_hexcol ( self . caret ) , QColor ( '#ef5350' ) ) painter . fillRect ( self . caret_to_asciicol ( self . caret ) , QColor ( '#ef5350' ) ) # paint selection self . paint_selection ( painter ) # paint visisble lines for i , line in enumerate ( self . get_lines ( self . pos ) ) : if i > self . visible_lines ( ) - 1 : break has_highlight = False # get data ( address , length , ascii_ ) = line data = self . data [ address : address + length ] # fixup offset address += self . base # paint address if i == self . _hovered_line : painter . setPen ( QColor ( '#ef5350' ) ) else : painter . setPen ( self . _ctrl_colors [ 'foreground' ] ) addr = '{0:08X}' if self . _is_64bit_addr : if self . _hex_style == 'upper' : addr = "{0:016X}" else : addr = "{0:016x}" else : if self . _hex_style == 'upper' : addr = "{0:08X}" else : addr = "{0:08x}" # paint addr rect = QRectF ( self . _offset_start , drawing_pos_y - self . _base_line , self . _offset_width , self . _char_height ) painter . drawText ( rect , addr . format ( address ) , QTextOption ( Qt . AlignHCenter | Qt . AlignBaseline ) ) drawing_pos_x = self . _hex_start is_in_selection = False # hex data for j , byte in enumerate ( data ) : if self . _dual_color_bytes and not j % 2 : if i == self . _hovered_line : painter . setPen ( self . _ctrl_colors [ 'selection_fg' ] ) else : painter . setPen ( self . _ctrl_colors [ 'byte_col_1' ] ) elif self . _dual_color_bytes and j % 2 : if i == self . _hovered_line : painter . setPen ( self . _ctrl_colors [ 'selection_fg' ] ) else : painter . setPen ( self . _ctrl_colors [ 'byte_col_2' ] ) else : painter . setPen ( self . _ctrl_colors [ 'foreground' ] ) if self . selection . start <= ( address + j ) - self . base < self . selection . end : painter . setPen ( self . _ctrl_colors [ 'selection_fg' ] ) is_in_selection = True # set highlightcolor if needed highlight = self . is_highlighted ( address + j ) if highlight : has_highlight = True painter . setPen ( self . _highlight_colors [ highlight ] ) # paint hex if self . _hex_style == 'upper' : painter . drawText ( drawing_pos_x , drawing_pos_y , "{:02X} " . format ( byte ) ) else : painter . drawText ( drawing_pos_x , drawing_pos_y , "{:02x} " . format ( byte ) ) drawing_pos_x += ( 3 * self . _char_width ) # restore color if i == self . _hovered_line : painter . setPen ( self . _ctrl_colors [ 'selection_fg' ] ) else : painter . setPen ( self . _ctrl_colors [ 'foreground' ] ) # draw whole ascii if no highlight if not has_highlight and not is_in_selection : painter . drawText ( self . _ascii_start , drawing_pos_y , ascii_ ) else : for a , c in enumerate ( ascii_ ) : highlight = self . is_highlighted ( address + a ) if highlight : painter . setPen ( self . _highlight_colors [ highlight ] ) else : if i == self . _hovered_line : painter . setPen ( self . _ctrl_colors [ 'selection_fg' ] ) else : painter . setPen ( self . _ctrl_colors [ 'foreground' ] ) if self . selection . start <= ( address + a ) - self . base < self . selection . end : painter . setPen ( self . _ctrl_colors [ 'selection_fg' ] ) painter . drawText ( self . _ascii_start + ( a * self . _char_width ) , drawing_pos_y , c ) # new y drawing_pos_y += self . _char_height + self . _ver_spacing # reset x drawing_pos_x = self . _hex_start # paint ctrl stuff - header etc self . paint_control ( painter ) # paint errorstr if self . _error_message : self . paint_error ( painter ) self . _offset_start = old_offset_start self . _hex_start = old_hex_start self . _ascii_start = old_ascii_start