Commit 8874800c authored by Roman Alifanov's avatar Roman Alifanov

filters and search bar are now working!

parent 70f3e20d
......@@ -135,6 +135,8 @@ class ApplicationManager:
@Gtk.Template(resource_path='/ru/eepm/PlayGUI/window.ui')
class EepmPlayGuiWindow(Adw.ApplicationWindow):
__gtype_name__ = 'EepmPlayGuiWindow'
search_entry = Gtk.Template.Child()
search_dropdown = Gtk.Template.Child()
loading_spinner = Gtk.Template.Child()
choice_listbox = Gtk.Template.Child()
......@@ -144,6 +146,11 @@ class EepmPlayGuiWindow(Adw.ApplicationWindow):
super().__init__(**kwargs)
self.apply_button.connect("activated", self.on_apply_clicked)
self.search_entry.connect("search-changed", self.on_search_changed)
self.search_dropdown.connect("notify::selected", self.on_filter_changed)
self.choice_listbox.set_filter_func(self.listbox_filter_func)
self.loading_count = 0 # Track loading operations
self.load_applications()
......@@ -173,6 +180,7 @@ class EepmPlayGuiWindow(Adw.ApplicationWindow):
def update_ui(self):
self.show_loading_spinner() # Show loading again for installed apps
ApplicationManager.get_installed_applications(self.on_installed_apps_loaded)
self.choice_listbox.invalidate_filter()
def on_installed_apps_loaded(self, installed_apps, error=None):
if error:
......@@ -210,6 +218,35 @@ class EepmPlayGuiWindow(Adw.ApplicationWindow):
def on_checkbox_toggled(self, checkbox, app_name):
active = checkbox.get_active()
print(f"{app_name} {'установлен' if active else 'снят'}")
def on_search_changed(self, search_entry):
self.choice_listbox.invalidate_filter() # Обновление фильтра при изменении поиска
def on_filter_changed(self, dropdown, _pspec):
self.choice_listbox.invalidate_filter() # Обновление фильтра при изменении фильтра
def listbox_filter_func(self, row):
"""Функция фильтрации для GtkListBox, которая проверяет текст и состояние фильтра"""
search_text = self.search_entry.get_text().lower()
filter_option = self.search_dropdown.get_selected()
# Получение заголовка и подзаголовка строки
title = row.get_title().lower() if row.get_title() else ''
subtitle = row.get_subtitle().lower() if row.get_subtitle() else ''
# Проверка текста поиска (по имени или описанию)
matches_search = search_text in title or search_text in subtitle
# Проверка по фильтру: установлено/не установлено в системе
app_name = row.get_title() if row.get_title() else ''
is_installed = app_name in self.installed_apps
if filter_option == 1: # Installed
return matches_search and is_installed
elif filter_option == 2: # Uninstalled
return matches_search and not is_installed
else:
return matches_search # All
def on_apply_clicked(self, button):
self.show_loading_spinner() # Показать сообщение о загрузке перед выполнением команды
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment