Robot Framework Integrated Development Environment (RIDE)
usagesdialog.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 
17 import wx
18 
19 from wx import Colour
20 from ..widgets import RIDEDialog, VirtualList, VerticalSizer, ImageList, ImageProvider, ButtonWithHandler
21 from ..widgets.list import ListModel
22 
23 class UsagesDialog(RIDEDialog):
24 
25  def __init__(self, name, usages=None):
26  self._name_name = name
27  self._selection_listeners_selection_listeners = []
28  title = "'%s'" % (name)
29  RIDEDialog.__init__(self, title=title, size=(650, 400))
30  # set Left to Right direction (while we don't have localization)
31  self.SetLayoutDirection(wx.Layout_LeftToRight)
32  self.SetSizer(VerticalSizer())
33  self.SetBackgroundColour(Colour(self.color_background))
34  self.SetForegroundColour(Colour(self.color_foreground))
35  self._add_view_components_add_view_components()
36  self.usagesusages = usages or UsagesListModel([])
37  self.usage_listusage_list = VirtualList(self, self.usagesusages.headers,
38  self.usagesusages)
39  self.usage_listusage_list.SetBackgroundColour(Colour(self.color_secondary_background))
40  self.usage_listusage_list.SetForegroundColour(Colour(self.color_secondary_foreground))
41  self.usage_listusage_list.add_selection_listener(self._usage_selected_usage_selected)
42  self.Sizer.add_expanding(self.usage_listusage_list)
43 
44  def add_usage(self, usage):
45  self.usagesusages.add_usage(usage)
46 
47  def begin_searching(self):
48  from ..ui.searchdots import DottedSearch
49  self._dots_dots = DottedSearch(self, self._update_searching_update_searching)
50  self._dots_dots.start()
51 
52  def _update_searching(self, dots):
53  self.SetTitle("'%s' - %d matches found - Searching%s" % (self._name_name, self.usagesusages.total_usages, dots))
54  self.usage_listusage_list.refresh()
55 
56  def end_searching(self):
57  self._dots_dots.stop()
58  self.SetTitle("'%s' - %d matches" % (self._name_name, self.usagesusages.total_usages))
59  self.usage_listusage_list.refresh()
60 
61  def _usage_selected(self, idx):
62  for listener in self._selection_listeners_selection_listeners:
63  listener(self.usagesusages.usage(idx).item.parent, self._name_name)
64 
65  def add_selection_listener(self, listener):
66  self._selection_listeners_selection_listeners.append(listener)
67 
69  pass
70 
71 
72 class UsagesDialogWithUserKwNavigation(UsagesDialog):
73 
74  def __init__(self, name, highlight, controller, usages=None):
75  self.OnGotodefinitionOnGotodefinition = lambda evt: highlight(controller, name)
76  UsagesDialog.__init__(self, name, usages=usages)
77 
79  button = ButtonWithHandler(self, 'Go to definition')
80  button.SetBackgroundColour(Colour(self.color_secondary_background))
81  button.SetForegroundColour(Colour(self.color_secondary_foreground))
82  self.Sizer.Add(button, 0, wx.ALL, 3)
83 
84 
85 def ResourceImportUsageDialog(name, highlight, controller):
86  return UsagesDialogWithUserKwNavigation(name, highlight, controller, usages=ResourceImportListModel([]))
87 
88 
90 
91  def __init__(self, usages):
92  self._usages_usages = usages
93  self._create_image_list_create_image_list()
94 
95  def _create_image_list(self):
96  images = ImageList(16, 16)
97  provider = ImageProvider()
98  images.add(provider.TESTCASEIMG)
99  images.add(provider.KEYWORDIMG)
100  images.add(provider.DATAFILEIMG)
101  images.add(provider.DATADIRIMG)
102  self._images_images = images
103 
104  @property
105  images = property
106 
107  def images(self):
108  return self._images_images
109 
110  def image(self, item):
111  # TODO: better mechanism for item type recognition
112  parent_type = self._usages_usages[item].parent.__class__.__name__
113  return {'TestCaseController': 0,
114  'UserKeywordController': 1,
115  'TestCaseFileController': 2,
116  'ResourceFileController': 2,
117  'TestDataDirectoryController': 3}.get(parent_type, -1)
118 
119  def add_usage(self, usage):
120  self._usages_usages.append(usage)
121 
122  def usage(self, idx):
123  return self._usages_usages[idx]
124 
125  @property
126  total_usages = property
127 
128  def total_usages(self):
129  return sum(u.count for u in self._usages_usages)
130 
131  @property
132  count = property
133 
134  def count(self):
135  return len(self._usages_usages)
136 
137 
139 
140  def __init__(self, usages):
141  _UsagesListModel.__init__(self, usages)
142  self.headersheaders = ['Location', 'Usage', 'Source']
143 
144  def item_text(self, row, col):
145  u = self.usageusage(row)
146  return [u.location, u.usage, u.source][col]
147 
148 
150 
151  def __init__(self, usages):
152  _UsagesListModel.__init__(self, usages)
153  self.headersheaders = ['Name', 'Location']
154  self._cannot_rename_item_attr_cannot_rename_item_attr = wx.ListItemAttr()
155  self._cannot_rename_item_attr_cannot_rename_item_attr.SetBackgroundColour(wx.Colour(255, 64, 64))
156 
157  def item_text(self, row, col):
158  u = self.usageusage(row)
159  return [u.name, u.location][col]
160 
161  def item_attributes(self, idx):
162  if self._usages_usages[idx].can_be_renamed:
163  return None
164  return self._cannot_rename_item_attr_cannot_rename_item_attr
165 
166  @property
167  total_usages = property
168 
169  def total_usages(self):
170  return len(self._usages_usages)
171 
172 
174 
175  def __init__(self, usages):
176  _UsagesListModel.__init__(self, usages)
177  self.headersheaders = ['Imported name', 'Imported Location', 'Importing Name', 'Importing Location']
178 
179  def item_text(self, row, col):
180  u = self.usageusage(row)
181  return [u.res_name, u.res_src, u.name, u.location][col]
def __init__(self, name, highlight, controller, usages=None)
Definition: usagesdialog.py:74
def __init__(self, name, usages=None)
Definition: usagesdialog.py:25
def ResourceImportUsageDialog(name, highlight, controller)
Definition: usagesdialog.py:85