def _create_tests_dialog(self): self._dialog = TestsDialog( fuzzy_search_handler=self.show_search_for, tag_search_handler=self.show_search_for_tag_patterns, add_to_selected_handler=self._add_to_selected) self._dialog.add_selection_listener(self._selected) self._dialog.Bind(wx.EVT_CLOSE, self._dialog_closed) self._selected_timer = wx.Timer(self._dialog) self._dialog.Bind(wx.EVT_TIMER, self._do_with_selection) self._dialog.Show()
def _create_tests_dialog(self): self._dialog = TestsDialog(fuzzy_search_handler=self.show_search_for, tag_search_handler=self.show_search_for_tag_patterns, add_to_selected_handler=self._add_to_selected) self._dialog.add_selection_listener(self._selected) self._dialog.Bind(wx.EVT_CLOSE, self._dialog_closed) self._selected_timer = wx.Timer(self._dialog) self._dialog.Bind(wx.EVT_TIMER, self._do_with_selection) self._dialog.Show()
class TestSearchPlugin(Plugin): """A plugin for searching tests based on name, tags and documentation""" HEADER = 'Search Tests' _selection = None def enable(self): self.register_action( ActionInfo('Tools', self.HEADER, self.show_empty_search, shortcut='F3', doc=self.__doc__, icon=ImageProvider().TEST_SEARCH_ICON, position=50)) self.register_search_action(self.HEADER, self.show_search_for, ImageProvider().TEST_SEARCH_ICON, default=True) self.subscribe(self.show_tag_search, RideOpenTagSearch) self._dialog = None def show_search_for(self, text): if self._dialog is None: self._create_tests_dialog() self._dialog.set_search_model( text, self._search_results(TestSearchMatcher(text))) self._dialog.set_focus_to_default_location() def show_search_for_tag_patterns(self, includes, excludes): matcher = TagSearchMatcher(includes, excludes) self._dialog.set_tag_search_model(includes, excludes, self._search_results(matcher)) self._dialog.set_focus_to_default_location() def show_tag_search(self, data): if self._dialog is None: self._create_tests_dialog() self.show_search_for_tag_patterns(data.includes, data.excludes) self._dialog._select_page(1) def _create_tests_dialog(self): self._dialog = TestsDialog( fuzzy_search_handler=self.show_search_for, tag_search_handler=self.show_search_for_tag_patterns, add_to_selected_handler=self._add_to_selected) self._dialog.add_selection_listener(self._selected) self._dialog.Bind(wx.EVT_CLOSE, self._dialog_closed) self._selected_timer = wx.Timer(self._dialog) self._dialog.Bind(wx.EVT_TIMER, self._do_with_selection) self._dialog.Show() def _add_to_selected(self, tests): self.tree.SelectTests(tests) def _dialog_closed(self, event): self._dialog = None event.Skip() def show_empty_search(self, event): self.show_search_for('') def _do_with_selection(self, evt=None): test, match_location = self._selection self.tree.select_node_by_data(test) self._dialog.set_focus_to_default_location(test) def _selected(self, selection): self._selection = selection self._selected_timer.Start(400, True) def _search_results(self, matcher): current_suite = self.frame._controller.data if not current_suite: return [] result = self._search(matcher, current_suite) return sorted(result, key=cmp_to_key(lambda x, y: self.m_cmp(x[1], y[1]))) def _search(self, matcher, data): for test in data.tests: match = matcher.matches(test) if match: yield test, match for s in data.suites: for test, match in self._search(matcher, s): yield test, match def disable(self): self.unregister_actions() @staticmethod def m_cmp(a, b): return (a > b) - (a < b) def __eq__(self, other): return self.name.lower() == other.name.lower() def __hash__(self): return hash(repr(self)) def __lt__(self, other): return self.name.lower() < other.name.lower()
class TestSearchPlugin(Plugin): """A plugin for searching tests based on name, tags and documentation""" HEADER = 'Search Tests' _selection = None def enable(self): self.register_action(ActionInfo('Tools', self.HEADER, self.show_empty_search, shortcut='F3', doc=self.__doc__,icon=ImageProvider().TEST_SEARCH_ICON,position=50)) self.register_search_action(self.HEADER, self.show_search_for, ImageProvider().TEST_SEARCH_ICON, default=True) self.subscribe(self.show_tag_search, RideOpenTagSearch) self._dialog = None def show_search_for(self, text): if self._dialog is None: self._create_tests_dialog() self._dialog.set_search_model(text, self._search_results(TestSearchMatcher(text))) self._dialog.set_focus_to_default_location() def show_search_for_tag_patterns(self, includes, excludes): matcher = TagSearchMatcher(includes, excludes) self._dialog.set_tag_search_model(includes, excludes, self._search_results(matcher)) self._dialog.set_focus_to_default_location() def show_tag_search(self, data): if self._dialog is None: self._create_tests_dialog() self.show_search_for_tag_patterns(data.includes, data.excludes) self._dialog._select_page(1) def _create_tests_dialog(self): self._dialog = TestsDialog(fuzzy_search_handler=self.show_search_for, tag_search_handler=self.show_search_for_tag_patterns, add_to_selected_handler=self._add_to_selected) self._dialog.add_selection_listener(self._selected) self._dialog.Bind(wx.EVT_CLOSE, self._dialog_closed) self._selected_timer = wx.Timer(self._dialog) self._dialog.Bind(wx.EVT_TIMER, self._do_with_selection) self._dialog.Show() def _add_to_selected(self, tests): self.tree.SelectTests(tests) def _dialog_closed(self, event): self._dialog = None event.Skip() def show_empty_search(self, event): self.show_search_for('') def _do_with_selection(self, evt=None): test, match_location = self._selection self.tree.select_node_by_data(test) self._dialog.set_focus_to_default_location(test) def _selected(self, selection): self._selection = selection self._selected_timer.Start(400, True) def _search_results(self, matcher): current_suite = self.frame._controller.data if not current_suite: return [] result = self._search(matcher, current_suite) return sorted(result, cmp=lambda x,y: cmp(x[1], y[1])) def _search(self, matcher, data): for test in data.tests: match = matcher.matches(test) if match: yield test, match for s in data.suites: for test, match in self._search(matcher, s): yield test, match def disable(self): self.unregister_actions()