2018-03-06 11:34:06 +03:00
|
|
|
""" This is helper module for search features """
|
|
|
|
|
|
|
|
|
|
|
2018-03-06 19:06:16 +03:00
|
|
|
class SearchProvider:
|
2018-05-07 18:19:00 +03:00
|
|
|
def __init__(self, views, down_button, up_button):
|
2018-03-06 19:06:16 +03:00
|
|
|
self._paths = []
|
|
|
|
|
self._current_index = -1
|
|
|
|
|
self._max_indexes = 0
|
2018-05-07 18:19:00 +03:00
|
|
|
self._views = views
|
2018-03-20 23:42:06 +03:00
|
|
|
self._up_button = up_button
|
|
|
|
|
self._down_button = down_button
|
2018-03-06 11:34:06 +03:00
|
|
|
|
2018-05-07 18:19:00 +03:00
|
|
|
def search(self, text):
|
2018-03-06 19:06:16 +03:00
|
|
|
self._current_index = -1
|
|
|
|
|
self._paths.clear()
|
2018-05-07 18:19:00 +03:00
|
|
|
for view in self._views:
|
2018-03-07 22:43:42 +03:00
|
|
|
model = view.get_model()
|
2018-03-06 19:06:16 +03:00
|
|
|
selection = view.get_selection()
|
|
|
|
|
selection.unselect_all()
|
|
|
|
|
if not text:
|
|
|
|
|
continue
|
2018-03-06 11:34:06 +03:00
|
|
|
|
2018-03-06 19:06:16 +03:00
|
|
|
text = text.upper()
|
|
|
|
|
for r in model:
|
|
|
|
|
if text in str(r[:]).upper():
|
|
|
|
|
path = r.path
|
|
|
|
|
selection.select_path(r.path)
|
|
|
|
|
self._paths.append((view, path))
|
|
|
|
|
|
|
|
|
|
self._max_indexes = len(self._paths) - 1
|
|
|
|
|
if self._max_indexes > 0:
|
|
|
|
|
self.on_search_down()
|
|
|
|
|
|
|
|
|
|
def scroll_to(self, index):
|
|
|
|
|
view, path = self._paths[index]
|
|
|
|
|
view.scroll_to_cell(path, None)
|
2018-03-20 23:42:06 +03:00
|
|
|
self.update_navigation_buttons()
|
2018-03-06 19:06:16 +03:00
|
|
|
|
|
|
|
|
def on_search_down(self):
|
|
|
|
|
if self._current_index < self._max_indexes:
|
|
|
|
|
self._current_index += 1
|
|
|
|
|
self.scroll_to(self._current_index)
|
|
|
|
|
|
|
|
|
|
def on_search_up(self):
|
|
|
|
|
if self._current_index > -1:
|
|
|
|
|
self._current_index -= 1
|
|
|
|
|
self.scroll_to(self._current_index)
|
2018-03-06 11:34:06 +03:00
|
|
|
|
2018-03-20 23:42:06 +03:00
|
|
|
def update_navigation_buttons(self):
|
|
|
|
|
self._up_button.set_sensitive(self._current_index > 0)
|
|
|
|
|
self._down_button.set_sensitive(self._current_index < self._max_indexes)
|
|
|
|
|
|
2018-03-06 11:34:06 +03:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
pass
|