<s> """<STR_LIT>""" <EOL> from pyqode . core . api . panel import Panel <EOL> from pyqode . core . api . utils import drift_color , TextHelper <EOL> from pyqode . qt import QtCore , QtGui <EOL> class LineNumberPanel ( Panel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Panel . __init__ ( self ) <EOL> self . scrollable = True <EOL> self . _selecting = False <EOL> self . _start_line = - <NUM_LIT:1> <EOL> self . _sel_start = - <NUM_LIT:1> <EOL> self . _line_color_u = self . palette ( ) . color ( <EOL> QtGui . QPalette . Disabled , QtGui . QPalette . WindowText ) <EOL> self . _line_color_s = self . palette ( ) . color ( <EOL> QtGui . QPalette . Normal , QtGui . QPalette . WindowText ) <EOL> def sizeHint ( self ) : <EOL> """<STR_LIT>""" <EOL> return QtCore . QSize ( self . line_number_area_width ( ) , <NUM_LIT:50> ) <EOL> def line_number_area_width ( self ) : <EOL> """<STR_LIT>""" <EOL> digits = <NUM_LIT:1> <EOL> count = max ( <NUM_LIT:1> , self . editor . blockCount ( ) ) <EOL> while count >= <NUM_LIT:10> : <EOL> count /= <NUM_LIT:10> <EOL> digits += <NUM_LIT:1> <EOL> space = <NUM_LIT:5> + self . editor . fontMetrics ( ) . width ( "<STR_LIT>" ) * digits <EOL> return space <EOL> def mousePressEvent ( self , e ) : <EOL> """<STR_LIT>""" <EOL> self . _selecting = True <EOL> self . _sel_start = e . pos ( ) . y ( ) <EOL> start = end = TextHelper ( self . editor ) . line_nbr_from_position ( <EOL> self . _sel_start ) <EOL> self . _start_line = start <EOL> TextHelper ( self . editor ) . select_lines ( start , end ) <EOL> def cancel_selection ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _selecting = False <EOL> self . _sel_start = - <NUM_LIT:1> <EOL> def mouseReleaseEvent ( self , event ) : <EOL> self . cancel_selection ( ) <EOL> def mouseMoveEvent ( self , e ) : <EOL> if self . _selecting : <EOL> end_pos = e . pos ( ) . y ( ) <EOL> end_line = TextHelper ( self . editor ) . line_nbr_from_position ( <EOL> end_pos ) <EOL> if end_line == - <NUM_LIT:1> and self . editor . visible_blocks : <EOL> if end_pos < <NUM_LIT:50> : <EOL> _ , end_line , _ = self . editor . visible_blocks [ <NUM_LIT:0> ] <EOL> end_line -= <NUM_LIT:1> <EOL> else : <EOL> _ , end_line , _ = self . editor . visible_blocks [ - <NUM_LIT:1> ] <EOL> end_line += <NUM_LIT:1> <EOL> TextHelper ( self . editor ) . select_lines ( self . _start_line , end_line ) <EOL> def paintEvent ( self , event ) : <EOL> self . _line_color_u = drift_color ( self . _background_brush . color ( ) , <NUM_LIT> ) <EOL> self . _line_color_s = drift_color ( self . _background_brush . color ( ) , <NUM_LIT> ) <EOL> Panel . paintEvent ( self , event ) <EOL> if self . isVisible ( ) : <EOL> painter = QtGui . QPainter ( self ) <EOL> width = self . width ( ) <EOL> height = self . editor . fontMetrics ( ) . height ( ) <EOL> font = self . editor . font ( ) <EOL> bold_font = self . editor . font ( ) <EOL> bold_font . setBold ( True ) <EOL> pen = QtGui . QPen ( self . _line_color_u ) <EOL> pen_selected = QtGui . QPen ( self . _line_color_s ) <EOL> painter . setFont ( font ) <EOL> sel_start , sel_end = TextHelper ( self . editor ) . selection_range ( ) <EOL> has_sel = sel_start != sel_end <EOL> cl = TextHelper ( self . editor ) . current_line_nbr ( ) <EOL> for top , line , block in self . editor . visible_blocks : <EOL> if ( ( has_sel and sel_start <= line <= sel_end ) or <EOL> ( not has_sel and cl == line ) ) : <EOL> painter . setPen ( pen_selected ) <EOL> painter . setFont ( bold_font ) <EOL> else : <EOL> painter . setPen ( pen ) <EOL> painter . setFont ( font ) <EOL> painter . drawText ( - <NUM_LIT:3> , top , width , height , <EOL> QtCore . Qt . AlignRight , str ( line + <NUM_LIT:1> ) ) </s>
