Coverage for src/robotide/ui/images.py: 64%
59 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
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.
16import os 1ab
18import wx 1ab
20from ..controller import filecontrollers 1ab
21from ..controller import macrocontrollers 1ab
22from ..controller import settingcontrollers 1ab
24_SIZE = (16, 16) 1ab
25_BASE = os.path.join(os.path.dirname(__file__), '..', 'widgets') 1ab
27ROBOT_IMAGE_INDEX = 3 1ab
28RUNNING_IMAGE_INDEX = 7 1ab
29PASSED_IMAGE_INDEX = 8 1ab
30FAILED_IMAGE_INDEX = 9 1ab
31PAUSED_IMAGE_INDEX = 10 1ab
32SKIPPED_IMAGE_INDEX = 11 1ab
34RESOURCE_DIR = 'resource directory' 1ab
37class TreeImageList(wx.ImageList): 1ab
39 def __init__(self): 1ab
40 wx.ImageList.__init__(self, *_SIZE)
41 self._execution_results = None
42 self._images = {
43 filecontrollers.TestDataDirectoryController: _TreeImage(self, 'folder.png'),
44 RESOURCE_DIR: _TreeImage(self, 'folder_wrench.png'),
45 filecontrollers.TestCaseFileController: _TreeImage(self, 'page_white.png'),
46 macrocontrollers.TestCaseController: _TreeImage(self, 'robot.png'),
47 macrocontrollers.UserKeywordController: _TreeImage(self, 'cog.png'),
48 filecontrollers.ResourceFileController: _TreeImage(self, 'page_white_gear.png'),
49 settingcontrollers.VariableController: _TreeImage(self, 'dollar.png'),
50 'running': _TreeImage(self, 'robot-running.gif'),
51 'passed': _TreeImage(self, 'robot_passed.png'),
52 'failed': _TreeImage(self, 'robot_failed.png'),
53 'paused': _TreeImage(self, 'robot-pause.gif'),
54 'skipped': _TreeImage(self, 'robot_skipped.png'),
55 filecontrollers.ExcludedDirectoryController: _TreeImage(self, 'folder_excluded.png'),
56 filecontrollers.ExcludedFileController: _TreeImage(self, 'folder_excluded.png')
57 }
59 @property 1ab
60 def directory(self): 1ab
61 return self._images[RESOURCE_DIR]
63 def set_execution_results(self, results): 1ab
64 self._execution_results = results
66 def _get_image(self, controller): 1ab
67 if self._execution_results.is_paused(controller):
68 return self._images['paused']
69 if self._execution_results.is_running(controller):
70 return self._images['running']
71 if self._execution_results.has_passed(controller):
72 return self._images['passed']
73 if self._execution_results.has_failed(controller):
74 return self._images['failed']
75 if self._execution_results.has_skipped(controller):
76 return self._images['skipped']
77 return None
79 def __getitem__(self, controller): 1ab
80 if controller.__class__ == macrocontrollers.TestCaseController: 1adefc
81 if self._execution_results: 81 ↛ 82line 81 didn't jump to line 82 because the condition on line 81 was never true1adc
82 image = self._get_image(controller)
83 if image is not None:
84 return image
85 elif controller.__class__ == filecontrollers.TestDataDirectoryController: 1aefc
86 if not controller.contains_tests():
87 return self._images[RESOURCE_DIR]
88 return self._images[controller.__class__] 1adefc
91class _TreeImage(object): 1ab
93 def __init__(self, image_list, normal, expanded=None): 1ab
94 self.normal = self._get_image(image_list, normal)
95 self.expanded = self._get_image(image_list, expanded) if expanded else self.normal
97 @staticmethod 1ab
98 def _get_image(image_list, source): 1ab
99 if source.startswith('wx'): 99 ↛ 100line 99 didn't jump to line 100 because the condition on line 99 was never true
100 img = wx.ArtProvider_GetBitmap(source, wx.ART_OTHER, _SIZE)
101 else:
102 path = os.path.join(_BASE, source)
103 if source.endswith('gif'):
104 img = wx.Image(path, wx.BITMAP_TYPE_GIF).ConvertToBitmap()
105 else:
106 img = wx.Image(path, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
107 return image_list.Add(img)