Robot Framework Integrated Development Environment (RIDE)
images.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 
16 import os
17 
18 import wx
19 
20 from ..controller import filecontrollers
21 from ..controller import macrocontrollers
22 from ..controller import settingcontrollers
23 
24 #(TestDataDirectoryController, TestCaseFileController, ResourceFileController, ExcludedDirectoryController)
25 # from ..controller.macrocontrollers import TestCaseController, UserKeywordController
26 # from ..controller.settingcontrollers import VariableController
27 
28 
31 _SIZE = (16, 16)
32 
35 _BASE = os.path.join(os.path.dirname(__file__), '..', 'widgets')
36 
37 ROBOT_IMAGE_INDEX = 3
38 RUNNING_IMAGE_INDEX = 7
39 PASSED_IMAGE_INDEX = 8
40 FAILED_IMAGE_INDEX = 9
41 PAUSED_IMAGE_INDEX = 10
42 SKIPPED_IMAGE_INDEX = 11
43 
44 
45 class TreeImageList(wx.ImageList):
46 
47  def __init__(self):
48  wx.ImageList.__init__(self, *_SIZE)
49  self._execution_results_execution_results = None
50  self._images_images = {
51  filecontrollers.TestDataDirectoryController: _TreeImage(self, 'folder.png'),
52  'resource directory': _TreeImage(self, 'folder_wrench.png'),
53  filecontrollers.TestCaseFileController: _TreeImage(self, 'page_white.png'),
54  macrocontrollers.TestCaseController: _TreeImage(self, 'robot.png'),
55  macrocontrollers.UserKeywordController: _TreeImage(self, 'cog.png'),
56  filecontrollers.ResourceFileController: _TreeImage(self, 'page_white_gear.png'),
57  settingcontrollers.VariableController: _TreeImage(self, 'dollar.png'),
58  'running': _TreeImage(self, 'robot-running.gif'),
59  'passed': _TreeImage(self, 'robot_passed.png'),
60  'failed': _TreeImage(self, 'robot_failed.png'),
61  'paused': _TreeImage(self, 'robot-pause.gif'),
62  'skipped': _TreeImage(self, 'robot_skipped.png'),
63  filecontrollers.ExcludedDirectoryController: _TreeImage(self, 'folder_excluded.png')
64  }
65 # 'running': _TreeImage(self, 'robot_running.png'),
66  @property
67  directory = property
68 
69  def directory(self):
70  return self._images_images['resource directory']
71 
72  def set_execution_results(self, results):
73  self._execution_results_execution_results = results
74 
75  def __getitem__(self, controller):
76  if controller.__class__ == macrocontrollers.TestCaseController:
77  if self._execution_results_execution_results:
78  if self._execution_results_execution_results.is_paused(controller):
79  return self._images_images['paused']
80  if self._execution_results_execution_results.is_running(controller):
81  return self._images_images['running']
82  if self._execution_results_execution_results.has_passed(controller):
83  return self._images_images['passed']
84  if self._execution_results_execution_results.has_failed(controller):
85  return self._images_images['failed']
86  if self._execution_results_execution_results.has_skipped(controller):
87  return self._images_images['skipped']
88  elif controller.__class__ == filecontrollers.TestDataDirectoryController:
89  if not controller.contains_tests():
90  return self._images_images['resource directory']
91  return self._images_images[controller.__class__]
92 
93 
94 class _TreeImage():
95 
96  def __init__(self, image_list, normal, expanded=None):
97  self.normalnormal = self._get_image_get_image(image_list, normal)
98  self.expandedexpanded = self._get_image_get_image(image_list, expanded) if expanded else self.normalnormal
99 
100  def _get_image(self, image_list, source):
101  if source.startswith('wx'):
102  img = wx.ArtProvider_GetBitmap(source, wx.ART_OTHER, _SIZE)
103  else:
104  path = os.path.join(_BASE, source)
105  if source.endswith('gif'):
106  img = wx.Image(path, wx.BITMAP_TYPE_GIF).ConvertToBitmap()
107  else:
108  img = wx.Image(path, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
109  return image_list.Add(img)
def set_execution_results(self, results)
Definition: images.py:72
def __getitem__(self, controller)
Definition: images.py:75
def _get_image(self, image_list, source)
Definition: images.py:100
def __init__(self, image_list, normal, expanded=None)
Definition: images.py:96