19 import wx.lib.mixins.listctrl
as listmix
23 from ..controller.ctrlcommands
import ChangeTag
24 from ..publish
import RideOpenTagSearch
25 from ..widgets
import ButtonWithHandler, PopupMenuItems, RIDEDialog
31 style = wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN | \
32 wx.FRAME_FLOAT_ON_PARENT
33 RIDEDialog.__init__(self, parent=frame, title=
"View all tags", size=(500, 400), style=style)
34 self.SetBackgroundColour(Colour(self.color_background))
35 self.SetForegroundColour(Colour(self.color_foreground))
37 self.SetLayoutDirection(wx.Layout_LeftToRight)
54 listmix.ColumnSorterMixin.__init__(self, 2)
70 self.SetSizer(wx.BoxSizer(wx.VERTICAL))
78 panel_tag_vw = wx.Panel(self.
_notebook_notebook)
79 panel_tag_vw.SetBackgroundColour(Colour(self.color_background))
80 panel_tag_vw.SetForegroundColour(Colour(self.color_foreground))
81 sizer_tag_vw = wx.BoxSizer(wx.VERTICAL)
82 panel_tag_vw.SetSizer(sizer_tag_vw)
84 colorFG=self.color_secondary_foreground)
85 self.
_tags_list_tags_list.InsertColumn(0,
"Tag", width=200)
86 self.
_tags_list_tags_list.InsertColumn(1,
"Occurrences", width=25,
87 format=wx.LIST_FORMAT_CENTER)
88 self.
_tags_list_tags_list.SetMinSize((450, 250))
90 sizer_tag_vw.Add(self.
_tags_list_tags_list, 1, wx.ALL | wx.EXPAND, 3)
91 self.
_notebook_notebook.AddPage(panel_tag_vw,
"The List")
96 self,
'Included Tag Search')
98 self,
'Excluded Tag Search')
99 self.
_clear_button_clear_button.SetBackgroundColour(Colour(self.color_secondary_background))
100 self.
_clear_button_clear_button.SetForegroundColour(Colour(self.color_secondary_foreground))
105 controls = wx.BoxSizer(wx.HORIZONTAL)
109 self.Sizer.Add(controls, 0, wx.ALL | wx.EXPAND, 3)
112 footer = wx.BoxSizer(wx.HORIZONTAL)
115 self.Sizer.Add(footer, 0, wx.ALL, 3)
118 self.
_notebook_notebook = wx.Notebook(self, wx.ID_ANY, style=wx.NB_TOP)
119 self.
_notebook_notebook.SetBackgroundColour(Colour(self.color_background))
120 self.
_notebook_notebook.SetForegroundColour(Colour(self.color_foreground))
121 self.Sizer.Add(self.
_notebook_notebook, 1, wx.ALL | wx.EXPAND, 3)
130 return [part
if index % 2 == 0
else int(part)
for index, part
in
131 enumerate(re.split(
r'(\d+)', tag_name.lower()))]
139 for tag_name, tests
in self.
_results_results:
140 model_entry = self.
_tags_list_tags_list.add_tag((tests, tag_name))
146 self.
_tags_list_tags_list.SetColumnWidth(1, wx.LIST_AUTOSIZE_USEHEADER)
153 footer_string = (
"Total tests %d, Tests with tags %d, Unique tags %d\n"
154 "Currently selected tests %d") % \
161 if not self.IsShown():
173 unique_tags = utils.NormalizedDict()
176 for test
in self.
frameframe._controller.all_testcases():
178 for tag
in test.tags:
179 if tag.is_empty()
or len(str(tag).strip()) == 0:
183 if tag_name
in unique_tags:
184 unique_tags[tag_name].append(test)
185 self.
_tags_tags[tag_name].append(tag)
187 unique_tags[tag_name] = [test]
188 self.
_tags_tags[tag_name] = [tag]
190 isreversed = (self.
sort_statesort_state[1] != 1)
193 self.
_results_results = sorted(unique_tags.items(),
194 key=
lambda item: item[0].
lower(),
201 self.
sort_statesort_state = self.GetSortState()
206 for _, tag_name
in self.
_tags_list_tags_list.get_checked_items():
207 tags.append(tag_name)
213 excludes=
'').publish()
218 excludes=
' '.join(excluded_tags)).publish()
222 for _, tests
in self.
_results_results:
223 self.
treetree.DeselectTests(tests)
228 for _, tests
in self.
_results_results:
230 self.
treetree.SelectTests(all_tests)
234 self.
_index_index = event.GetIndex()
235 menu_items = [
"Select all",
"Clear",
"---",
"Rename",
"Delete",
"---",
236 "Show tests with this tag",
237 "Show tests without this tag"]
238 self.
treetree._popup_creator.show(self, PopupMenuItems(self, menu_items),
242 self.
_index_index = event.GetIndex()
246 if self.
_index_index == -1:
252 if self.
_index_index == -1:
258 if self.
_index_index == -1:
261 tags_to_rename = self.
_tags_tags[tag_name.lower()]
262 name = wx.GetTextFromUser(message=
"Renaming tag '%s'." % tag_name, default_value=tag_name,
263 caption=
'Rename').strip()
265 for tag
in tags_to_rename:
266 tag.controller.execute(
ChangeTag(tag, name))
268 for tag_name, tests
in self.
_results_results:
269 self.
treetree.DeselectTests(tests)
272 if self.
_index_index == -1:
275 tags_to_delete = self.
_tags_tags[tag_name.lower()]
277 "Delete a tag '%s' ?" % tag_name, caption=
'Confirm',
278 style=wx.YES_NO | wx.ICON_QUESTION) == wx.YES:
279 for tag
in tags_to_delete:
280 tag.controller.execute(
ChangeTag(tag,
''))
282 for tag_name, tests
in self.
_results_results:
283 self.
treetree.DeselectTests(tests)
294 tests, _ = self.
_tags_list_tags_list.get_tag(index)
295 self.
treetree.DeselectTests(tests)
296 if self.
_tags_list_tags_list.get_number_of_checked_items() > 0:
297 for tests, _
in self.
_tags_list_tags_list.get_checked_items():
299 self.
treetree.SelectTests(tests)
305 listmix.ListCtrlAutoWidthMixin):
306 def __init__(self, parent, style, colorBG, colorFG):
308 wx.ListCtrl.__init__(self, parent=parent, style=style)
309 if wx.VERSION < (4, 1, 0):
310 listmix.CheckListCtrlMixin.__init__(self)
311 listmix.ListCtrlAutoWidthMixin.__init__(self)
312 if wx.VERSION >= (4, 1, 0):
314 self.EnableCheckBoxes(
True)
315 self.SetBackgroundColour(Colour(colorBG))
316 self.SetForegroundColour(Colour(colorFG))
317 self.setResizeColumn(2)
322 self.
_dlg_dlg.item_in_kw_list_checked(index, flag)
326 for i
in range(self.GetItemCount()):
327 if self.IsChecked(i):
328 items.append(self.
get_tagget_tag(i))
333 for i
in range(self.GetItemCount()):
334 if self.IsChecked(i):
360 model_index = wx.NewIdRef()
361 position = self.GetItemCount()
362 self.
_clientData_clientData[model_index] = tag_to_tests
363 self.InsertItem(position, str(tag_to_tests[1]))
364 self.SetItem(position, 1, str(len(tag_to_tests[0])))
366 self.SetItemData(position, model_index)
380 model_index = self.GetItemData(index)
381 return self.
_clientData_clientData.get(model_index,
None)
390 model_index = self.GetItemData(index)
391 self.DeleteItem(model_index)
395 self.DeleteAllItems()
399 for i
in range(self.GetItemCount()):
400 if wx.VERSION >= (4, 1, 0):
402 self.CheckItem(i,
True)
Custom dictionary implementation automatically normalizing keys.