Coverage for src/robotide/widgets/list.py: 35%
61 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
19from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin 1ab
21IS_WINDOWS = os.sep == '\\' 1ab
24class VirtualList(wx.ListCtrl, ListCtrlAutoWidthMixin): 1ab
25 _style = wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_HRULES | wx.LC_VIRTUAL 1ab
27 def __init__(self, parent, headers, model): 1ab
28 wx.ListCtrl.__init__(self, parent, style=self._style)
29 ListCtrlAutoWidthMixin.__init__(self)
30 """
31 self.SetBackgroundColour(Colour(200, 222, 40))
32 self.SetOwnBackgroundColour(Colour(200, 222, 40))
33 self.SetForegroundColour(Colour(7, 0, 70))
34 self.SetOwnForegroundColour(Colour(7, 0, 70))
35 """
36 self._model = model
37 self._selection_listeners = []
38 self._create_headers(headers)
39 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_list_item_selected)
40 if IS_WINDOWS:
41 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down)
42 self.SetItemCount(model.count)
43 self.SetImageList(model.images, wx.IMAGE_LIST_SMALL)
45 def on_left_down(self, event): 1ab
46 item, flags = self.HitTest(event.Position)
47 if flags | wx.LIST_HITTEST_ONITEM:
48 wx.CallAfter(self.inform_listeners, item)
49 event.Skip()
51 def _create_headers(self, headers): 1ab
52 for idx, name in enumerate(headers):
53 self.InsertColumn(idx, name)
54 self.SetColumnWidth(0, 200)
55 self.SetColumnWidth(1, 160)
57 def refresh_items(self): 1ab
58 self.SetItemCount(self._model.count)
59 self.SetImageList(self._model.images, wx.IMAGE_LIST_SMALL)
61 def add_selection_listener(self, listener): 1ab
62 self._selection_listeners.append(listener)
64 def on_list_item_selected(self, event): 1ab
65 self.inform_listeners(event.Index)
67 def inform_listeners(self, selected_index): 1ab
68 for listener in self._selection_listeners:
69 listener(selected_index)
71 def OnGetItemText(self, row, col): # Overrides wx method 1ab
72 return self._model.item_text(row, col)
74 def OnGetItemImage(self, item): # Overrides wx method 1ab
75 return self._model.image(item)
77 def OnGetItemAttr(self, item): # Overrides wx method 1ab
78 return self._model.item_attributes(item)
81class ListModel(object): 1ab
83 @property 1ab
84 def count(self): 1ab
85 return 0
87 @property 1ab
88 def images(self): 1ab
89 return None
91 def item_text(self, row, col): 1ab
92 _ = row
93 _ = col
94 return ''
96 def image(self, row): 1ab
97 _ = row
98 return -1
100 def item_attributes(self, row): 1ab
101 _ = row
102 return None