Robot Framework Integrated Development Environment (RIDE)
gridcolorizer.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 import wx
16 from wx import Colour
17 
18 from ..controller.cellinfo import CellType
19 
20 
21 # this import fails in HUDSON
22 # from wxPython._gdi import wxFONTWEIGHT_BOLD, wxFONTWEIGHT_NORMAL
23 # wxFONTWEIGHT_BOLD = 92
24 # wxFONTWEIGHT_NORMAL = 90
25 # DEBUG using wx.FONTWEIGHT_BOLD, wx.FONTWEIGHT_NORMAL
26 
27 
28 class Colorizer():
29 
30  def __init__(self, grid, controller):
31  self._grid_grid = grid
32  self._controller_controller = controller
33  self._colors_colors = ColorizationSettings(grid.settings)
34  self._current_task_id_current_task_id = 0
35  self._timer_timer = None
36 
37  def close(self):
38  self._grid_grid = None
39 
40  def colorize(self, selection_content):
41  self._current_task_id_current_task_id += 1
42  if self._timer_timer is None:
43  self._timer_timer = wx.CallLater(1, self._coloring_task_coloring_task, self._current_task_id_current_task_id, selection_content)
44  else:
45  self._timer_timer.Restart(50, self._current_task_id_current_task_id, selection_content)
46 
47  def _coloring_task(self, task_index, selection_content, row=0, col=0):
48  if task_index != self._current_task_id_current_task_id or self._grid_grid is None:
49  return
50  if row >= self._grid_grid.NumberRows:
51  self._grid_grid.ForceRefresh()
52  elif col < self._grid_grid.NumberCols:
53  self._colorize_cell_colorize_cell(row, col, selection_content)
54  wx.CallAfter(self._coloring_task_coloring_task, task_index, selection_content, row, col+1)
55  else:
56  self._coloring_task_coloring_task(task_index, selection_content, row+1, 0)
57 
58  def _colorize_cell(self, row, col, selection_content):
59  cell_info = self._controller_controller.get_cell_info(row, col)
60  if cell_info is None:
61  self._set_default_colors_set_default_colors(row, col)
62  return
63  self._grid_grid.SetCellTextColour(row, col, self._get_text_color_get_text_color(cell_info))
64  self._grid_grid.SetCellBackgroundColour(row, col, self._get_background_color_get_background_color(cell_info, selection_content))
65  self._grid_grid.SetCellFont(row, col, self._get_cell_font_get_cell_font(row, col, cell_info))
66 
67  def _set_default_colors(self, row, col):
68  self._grid_grid.SetCellTextColour(row, col, self._colors_colors.DEFAULT_TEXT)
69  self._grid_grid.SetCellBackgroundColour(row, col, self._colors_colors.DEFAULT_BACKGROUND)
70 
71  def _get_text_color(self, cell_info):
72  return self._colors_colors.get_text_color(cell_info.content_type)
73 
74  def _get_background_color(self, cell_info, selection_content):
75  if cell_info.matches(selection_content):
76  return self._colors_colors.get_highlight_color()
77  if cell_info.has_error():
78  return self._colors_colors.get_error_color()
79  return self._colors_colors.get_background_color(cell_info.cell_type)
80 
81  def _get_cell_font(self, row, col, cell_info):
82  font = self._grid_grid.GetCellFont(row, col)
83  font.SetWeight(self._get_weight_get_weight(cell_info))
84  return font
85 
86  def _get_weight(self, cell_info):
87  if cell_info.cell_type == CellType.KEYWORD:
88  return wx.FONTWEIGHT_BOLD
89  return wx.FONTWEIGHT_NORMAL
90 
91 
93 
94  DEFAULT_TEXT = '' # Colour('black') # Colour(7, 0, 70) # 'black'
95  DEFAULT_BACKGROUND = '' # 'light grey' # Colour('light grey') # Colour(200, 222, 40) # 'white'
96 
97  def __init__(self, settings=None):
98  self._settings_settings = settings
99 
100  def get_background_color(self, type):
101  if not self._settings_settings:
102  return self.DEFAULT_BACKGROUNDDEFAULT_BACKGROUND
103  return self._get_get('background %s' % type)
104 
105  def get_text_color(self, type):
106  if not self._settings_settings:
107  return self.DEFAULT_TEXTDEFAULT_TEXT
108  return self._get_get('text %s' % type)
109 
111  return self.get_background_colorget_background_color('highlight')
112 
113  def get_error_color(self):
114  return self.get_background_colorget_background_color('error')
115 
116  def _get(self, name):
117  return self._settings_settings[name.lower().replace('_', ' ')]
def colorize(self, selection_content)
def _coloring_task(self, task_index, selection_content, row=0, col=0)
def __init__(self, grid, controller)
def _get_background_color(self, cell_info, selection_content)
def _get_cell_font(self, row, col, cell_info)
def _colorize_cell(self, row, col, selection_content)