Coverage for src/robotide/widgets/images.py: 94%
50 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
21class ImageList(wx.ImageList): 1ab
23 def __init__(self, img_width, img_height): 1ab
24 wx.ImageList.__init__(self, img_width, img_height)
26 def add_image(self, image): 1ab
27 self.Add(image)
30class ImageProvider(object): 1ab
31 _BASE = os.path.dirname(__file__) 1ab
33 def __init__(self, size=(16, 16)): 1ab
34 self._size = size
35 self.TESTCASEIMG = self._load_image('robot.png')
36 self.KEYWORDIMG = self._load_image('process.png')
37 self.DATADIRIMG = self._img_from_art_provider(wx.ART_FOLDER)
38 self.DATAFILEIMG = self._img_from_art_provider(wx.ART_NORMAL_FILE)
39 self.PROGICONS = self._load_prog_icons()
40 self.REPORTIMG = self._load_image('report.png')
41 self.REFRESH_ALL = self._load_image('database_refresh.png')
42 self.KW_SEARCH_ICON = self._load_image('kw_search_button.png')
43 self.TEST_SEARCH_ICON = self._load_image('test_search_button.png')
44 self.TOOLBAR_PLAY = self._load_image('control_play.png')
45 self.TOOLBAR_STOP = self._load_image('control_stop.png')
46 self.TOOLBAR_PAUSE = self._load_image('control_pause.png')
47 self.TOOLBAR_CONTINUE = self._load_image('control_play.png')
48 self.TOOLBAR_NEXT = self._load_image('control_fastforward.png')
49 self.SWITCH_FIELDS_ICON = self._load_image('switch.png')
50 self.RIDE_ICON = self._load_image('robot.ico')
51 self._build_icons()
53 def _build_icons(self): 1ab
54 self._icons = {}
55 for name in dir(self):
56 value = getattr(self, name)
57 if isinstance(value, wx.Bitmap):
58 self._icons[name] = getattr(self, name)
60 def get_image_by_name(self, name): 1ab
61 return self._icons.get(name, None)
63 def _load_image(self, name): 1ab
64 path = self._get_img_path(name)
65 no_log = wx.LogNull()
66 # Suppress warnings generated by recent libpng versions.
67 # The png files themselves are most likely ok.
68 img = wx.Image(path, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
69 del no_log
70 return img
72 def _get_img_path(self, name): 1ab
73 return os.path.join(self._BASE, name)
75 def _img_from_art_provider(self, source): 1ab
76 return wx.ArtProvider.GetBitmap(source, wx.ART_OTHER, self._size)
78 def _load_prog_icons(self): 1ab
79 icons = wx.IconBundle()
80 icons.AddIcon(self._get_img_path('robot.ico'), wx.BITMAP_TYPE_ANY)
81 return icons