<s> from robotide . controller . cellinfo import CellType <EOL> import wx <EOL> wxFONTWEIGHT_BOLD = <NUM_LIT> <EOL> wxFONTWEIGHT_NORMAL = <NUM_LIT> <EOL> class Colorizer ( object ) : <EOL> def __init__ ( self , grid , controller ) : <EOL> self . _grid = grid <EOL> self . _controller = controller <EOL> self . _colors = ColorizationSettings ( grid . settings ) <EOL> self . _current_task_id = <NUM_LIT:0> <EOL> self . _timer = None <EOL> def close ( self ) : <EOL> self . _grid = None <EOL> def colorize ( self , selection_content ) : <EOL> self . _current_task_id += <NUM_LIT:1> <EOL> if self . _timer is None : <EOL> self . _timer = wx . CallLater ( <NUM_LIT:1> , self . _coloring_task , self . _current_task_id , selection_content ) <EOL> else : <EOL> self . _timer . Restart ( <NUM_LIT:50> , self . _current_task_id , selection_content ) <EOL> def _coloring_task ( self , task_index , selection_content , row = <NUM_LIT:0> , col = <NUM_LIT:0> ) : <EOL> if task_index != self . _current_task_id or not ( self . _grid ) : <EOL> return <EOL> if row >= self . _grid . NumberRows : <EOL> self . _grid . ForceRefresh ( ) <EOL> self . _grid . AutoSizeRows ( ) <EOL> elif col < self . _grid . NumberCols : <EOL> self . _colorize_cell ( row , col , selection_content ) <EOL> wx . CallAfter ( self . _coloring_task , task_index , selection_content , row , col + <NUM_LIT:1> ) <EOL> else : <EOL> self . _coloring_task ( task_index , selection_content , row + <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> def _colorize_cell ( self , row , col , selection_content ) : <EOL> cell_info = self . _controller . get_cell_info ( row , col ) <EOL> if cell_info is None : <EOL> self . _set_default_colors ( row , col ) <EOL> return <EOL> self . _grid . SetCellTextColour ( row , col , self . _get_text_color ( cell_info ) ) <EOL> self . _grid . SetCellBackgroundColour ( row , col , self . _get_background_color ( cell_info , selection_content ) ) <EOL> self . _grid . SetCellFont ( row , col , self . _get_cell_font ( row , col , cell_info ) ) <EOL> def _set_default_colors ( self , row , col ) : <EOL> self . _grid . SetCellTextColour ( row , col , self . _colors . DEFAULT_TEXT ) <EOL> self . _grid . SetCellBackgroundColour ( row , col , self . _colors . DEFAULT_BACKGROUND ) <EOL> def _get_text_color ( self , cell_info ) : <EOL> return self . _colors . get_text_color ( cell_info . content_type ) <EOL> def _get_background_color ( self , cell_info , selection_content ) : <EOL> if cell_info . matches ( selection_content ) : <EOL> return self . _colors . get_highlight_color ( ) <EOL> if cell_info . has_error ( ) : <EOL> return self . _colors . get_error_color ( ) <EOL> return self . _colors . get_background_color ( cell_info . cell_type ) <EOL> def _get_cell_font ( self , row , col , cell_info ) : <EOL> font = self . _grid . GetCellFont ( row , col ) <EOL> font . SetWeight ( self . _get_weight ( cell_info ) ) <EOL> return font <EOL> def _get_weight ( self , cell_info ) : <EOL> if cell_info . cell_type == CellType . KEYWORD : <EOL> return wxFONTWEIGHT_BOLD <EOL> return wxFONTWEIGHT_NORMAL <EOL> class ColorizationSettings ( object ) : <EOL> DEFAULT_TEXT = '<STR_LIT>' <EOL> DEFAULT_BACKGROUND = '<STR_LIT>' <EOL> def __init__ ( self , settings = None ) : <EOL> self . _settings = settings <EOL> def get_background_color ( self , type ) : <EOL> if not self . _settings : <EOL> return self . DEFAULT_BACKGROUND <EOL> return self . _get ( '<STR_LIT>' % type ) <EOL> def get_text_color ( self , type ) : <EOL> if not self . _settings : <EOL> return self . DEFAULT_TEXT <EOL> return self . _get ( '<STR_LIT>' % type ) <EOL> def get_highlight_color ( self ) : <EOL> return self . get_background_color ( '<STR_LIT>' ) <EOL> def get_error_color ( self ) : <EOL> return self . get_background_color ( '<STR_LIT:error>' ) <EOL> def _get ( self , name ) : <EOL> return self . _settings [ name . lower ( ) . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) ] </s>
