Ejemplo n.º 1
0
    def __search_changed(self, entry: Gtk.SearchEntry):
        """
            Handles search-changed signal.
        """
        def filter_func(row, data, *_):
            """
                Filter function
            """
            data = data.lower()
            if len(data) > 0:
                username = row.account.username.lower()
                provider_name = row.account.provider.name.lower()
                return (data in username or data in provider_name)
            else:
                return True

        data = entry.get_text().strip()
        search_lists = AccountsWidget.get_default().accounts_lists
        results_count = 0
        for search_list in search_lists:
            search_list.set_filter_func(filter_func, data, False)
            for elem in search_list:

                if elem.get_child_visible():
                    results_count += 1

        if results_count == 0:
            self.accounts_stack.set_visible_child_name("empty_results")
        else:
            self.accounts_stack.set_visible_child_name("accounts")
    def on_search_down_button_clicked(self, widget: Gtk.Button,
                                      search: Gtk.SearchEntry):
        view = self._explorerscript_view
        context = self._explorerscript_search_context
        if search == self._ssb_script_search:
            view = self._ssb_script_view
            context = self._ssb_script_search_context
        buffer: Gtk.TextBuffer = view.get_buffer()

        settings: GtkSource.SearchSettings = context.get_settings()
        settings.set_search_text(search.get_text())
        cursor = buffer.get_iter_at_offset(buffer.props.cursor_position)
        found, match_start, match_end, wrap = context.forward2(cursor)
        if found:
            if match_start.get_offset() == cursor.get_offset():
                # Repeat once, to really get down
                found, match_start, match_end, wrap = context.forward2(
                    match_end)
            if found:
                buffer.select_range(match_start, match_end)
                if buffer == self._ssb_script_view.get_buffer():
                    self._ssb_script_view.scroll_to_iter(
                        match_start, 0.1, False, 0.5, 0.5)
                else:
                    self._explorerscript_view.scroll_to_iter(
                        match_start, 0.1, False, 0.5, 0.5)
Ejemplo n.º 3
0
    def search_changed(self, sender: Gtk.SearchEntry):
        self.result_store.remove_all()

        search_text = sender.get_text().strip()

        if not search_text:
            return

        documents = storage.find(search_text=search_text)
        for document in documents:
            self.result_store.append(document)
Ejemplo n.º 4
0
    def searchIt(self, search_entry: SearchEntry) -> None:
        """
        Searchs over the _subtitles_liststore.

        :return:
        """

        term_searched: str = search_entry.get_text()

        for i, term in enumerate(self._subtitles_liststore):
            if term_searched and term_searched in term[1].lower():
                self._subtitles_treeview.set_cursor(i)
                break
Ejemplo n.º 5
0
    def _on_response_filter_changed(self, entry: Gtk.SearchEntry):
        filter_text = entry.get_text()
        if filter_text == '':
            self._set_response_text()

        ct = get_content_type(self.last_response)
        try:
            if ct == 'application/json':
                path_expr = jsonpath_rw.parse(filter_text)
                j = self.last_response.json()
                match_text = json.dumps(
                    [match.value for match in path_expr.find(j)],
                    indent=4) or 'No matches found'
                self.response_text.get_buffer().set_text(match_text)
            elif ct in {'text/xml', 'application/xml'}:
                root = etree.fromstring(self.last_response.text)
                matches = root.xpath(filter_text)
                matches_root = etree.Element('matches')
                for m in matches:
                    matches_root.append(m)

                matches_html = etree.tostring(matches_root,
                                              encoding='unicode',
                                              pretty_print=True)
                self.response_text.get_buffer().set_text(matches_html)
            elif ct == 'text/html':
                root = html.fromstring(self.last_response.text)
                matches = root.xpath(filter_text)
                matches_root = etree.Element('matches')
                for m in matches:
                    matches_root.append(m)

                matches_html = etree.tostring(matches_root,
                                              encoding='unicode',
                                              pretty_print=True)
                self.response_text.get_buffer().set_text(matches_html)
            else:
                log.warning(
                    'Got unexpected content type %s when filtering response.',
                    ct)
        except Exception as e:
            log.debug('Failed to filter response json %s', e)
    def on_search_entry_search_changed(self, widget: Gtk.SearchEntry):
        view = self._explorerscript_view
        context = self._explorerscript_search_context
        if widget == self._ssb_script_search:
            view = self._ssb_script_view
            context = self._ssb_script_search_context
        buffer: Gtk.TextBuffer = view.get_buffer()

        settings: GtkSource.SearchSettings = context.get_settings()
        settings.set_search_text(widget.get_text())
        found, match_start, match_end = context.forward2(
            buffer.get_iter_at_offset(buffer.props.cursor_position))[:3]
        if found:
            buffer.select_range(match_start, match_end)
            if buffer == self._ssb_script_view.get_buffer():
                self._ssb_script_view.scroll_to_iter(match_start, 0.1, False,
                                                     0.5, 0.5)
            else:
                self._explorerscript_view.scroll_to_iter(
                    match_start, 0.1, False, 0.5, 0.5)
Ejemplo n.º 7
0
 def on_main_item_list_search_search_changed(self, search: Gtk.SearchEntry):
     """Filter the main item view using the search field"""
     self._search_text = search.get_text().strip()
     self._filter__refresh_results()
Ejemplo n.º 8
0
 def on_search_search_changed(self, search: Gtk.SearchEntry):
     self._search_text = search.get_text()
     self._filter.refilter()
Ejemplo n.º 9
0
 def search(self, entry: Gtk.SearchEntry) -> None:
     query = entry.get_text()
     self.populate(query)