diff --git a/app/ui/main.glade b/app/ui/main.glade
index ad7aa962..0d245115 100644
--- a/app/ui/main.glade
+++ b/app/ui/main.glade
@@ -1218,182 +1218,6 @@ Author: Dmitriy Yefremov
False
vertical
5
-
-
-
- False
- True
- 0
-
-
True
@@ -1405,8 +1229,10 @@ Author: Dmitriy Yefremov
True
- True
+ False
+ True
True
+
True
@@ -1485,7 +1311,6 @@ Author: Dmitriy Yefremov
False
5
5
- 5
5
vertical
@@ -1502,6 +1327,7 @@ Author: Dmitriy Yefremov
True
False
False
+ False
True
Filter
win.filter
@@ -1520,13 +1346,12 @@ Author: Dmitriy Yefremov
-
False
@@ -1607,7 +1607,6 @@ Author: Dmitriy Yefremov
edit-find-symbolic
False
False
-
False
@@ -1621,7 +1620,6 @@ Author: Dmitriy Yefremov
False
True
True
-
True
@@ -1642,7 +1640,6 @@ Author: Dmitriy Yefremov
False
True
True
-
True
diff --git a/app/ui/satellites.py b/app/ui/satellites.py
index 8b12f626..cd7018cb 100644
--- a/app/ui/satellites.py
+++ b/app/ui/satellites.py
@@ -38,7 +38,7 @@ from app.eparser import get_satellites, write_satellites, Satellite, Transponder
from app.eparser.ecommons import PLS_MODE, get_key_by_value
from app.tools.satellites import SatellitesParser, SatelliteSource, ServicesParser
from .dialogs import show_dialog, DialogType, get_chooser_dialog, get_message, get_builder
-from .main_helper import move_items, scroll_to, append_text_to_tview, get_base_model, on_popup_menu
+from .main_helper import move_items, append_text_to_tview, get_base_model, on_popup_menu
from .search import SearchProvider
from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, MOVE_KEYS, KeyboardKey, MOD_MASK
@@ -412,9 +412,6 @@ class UpdateDialog:
"on_select_all": self.on_select_all,
"on_unselect_all": self.on_unselect_all,
"on_filter": self.on_filter,
- "on_search": self.on_search,
- "on_search_down": self.on_search_down,
- "on_search_up": self.on_search_up,
"on_quit": self.on_quit}
self._settings = settings
@@ -457,9 +454,11 @@ class UpdateDialog:
self._filter_positions = (0, 0)
# Search
self._search_bar = builder.get_object("sat_update_search_bar")
- self._search_provider = SearchProvider((self._sat_view,),
- builder.get_object("sat_update_search_down_button"),
- builder.get_object("sat_update_search_up_button"))
+ search_provider = SearchProvider(self._sat_view,
+ builder.get_object("sat_update_search_entry"),
+ builder.get_object("sat_update_search_down_button"),
+ builder.get_object("sat_update_search_up_button"))
+ builder.get_object("sat_update_find_button").connect("toggled", search_provider.on_search_toggled)
window_size = self._settings.get(self._size_name)
if window_size:
@@ -585,15 +584,6 @@ class UpdateDialog:
to_pos = round(self._to_pos_button.get_value(), 1) * (-1 if self._filter_to_combo_box.get_active() else 1)
return from_pos, to_pos
- def on_search(self, entry):
- self._search_provider.search(entry.get_text())
-
- def on_search_down(self, item):
- self._search_provider.on_search_down()
-
- def on_search_up(self, item):
- self._search_provider.on_search_up()
-
def on_select_all(self, view):
self.update_selection(view, True)
diff --git a/app/ui/search.py b/app/ui/search.py
index bba8a75f..e283119d 100644
--- a/app/ui/search.py
+++ b/app/ui/search.py
@@ -1,31 +1,41 @@
""" This is helper module for search features """
+from app.commons import run_with_delay
class SearchProvider:
- def __init__(self, views, down_button, up_button):
+ def __init__(self, view, entry, down_button, up_button, columns=None):
self._paths = []
self._current_index = -1
self._max_indexes = 0
- self._views = views
+ self._view = view
+ self._entry = entry
self._up_button = up_button
self._down_button = down_button
+ self._columns = columns
+
+ entry.connect("changed", self.on_search)
+ self._down_button.connect("clicked", self.on_search_down)
+ self._up_button.connect("clicked", self.on_search_up)
def search(self, text):
self._current_index = -1
self._paths.clear()
- for view in self._views:
- model = view.get_model()
- selection = view.get_selection()
- selection.unselect_all()
- if not text:
- continue
+ model = self._view.get_model()
+ selection = self._view.get_selection()
+ if not selection:
+ return
- 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))
+ selection.unselect_all()
+ if not text:
+ return
+
+ text = text.upper()
+ for r in model:
+ data = [r[i] for i in self._columns] if self._columns else r[:]
+ if next((s for s in data if text in str(s).upper()), False):
+ path = r.path
+ selection.select_path(r.path)
+ self._paths.append(path)
self._max_indexes = len(self._paths) - 1
if self._max_indexes > 0:
@@ -34,16 +44,15 @@ class SearchProvider:
self.update_navigation_buttons()
def scroll_to(self, index):
- view, path = self._paths[index]
- view.scroll_to_cell(path, None)
+ self._view.scroll_to_cell(self._paths[index], None)
self.update_navigation_buttons()
- def on_search_down(self):
+ def on_search_down(self, button=None):
if self._current_index < self._max_indexes:
self._current_index += 1
self.scroll_to(self._current_index)
- def on_search_up(self):
+ def on_search_up(self, button=None):
if self._current_index > -1:
self._current_index -= 1
self.scroll_to(self._current_index)
@@ -52,6 +61,13 @@ class SearchProvider:
self._up_button.set_sensitive(self._current_index > 0)
self._down_button.set_sensitive(self._current_index < self._max_indexes)
+ @run_with_delay(1)
+ def on_search(self, entry):
+ self.search(entry.get_text())
+
+ def on_search_toggled(self, action, value=None):
+ self._entry.grab_focus() if action.get_active() else self._entry.set_text("")
+
if __name__ == "__main__":
pass