add basic search functionality

This commit is contained in:
GloriousEggroll 2025-03-25 00:07:14 -06:00
parent edeedff2f6
commit fcba871050
2 changed files with 13 additions and 8 deletions

View file

@ -469,11 +469,13 @@ class AppstreamSearcher:
self.collection_results = [] # Initialize empty list self.collection_results = [] # Initialize empty list
self.installed_results = [] # Initialize empty list self.installed_results = [] # Initialize empty list
self.updates_results = [] # Initialize empty list self.updates_results = [] # Initialize empty list
self.all_apps = [] # Initialize empty list
total_categories = sum(len(categories) for categories in self.category_groups.values()) total_categories = sum(len(categories) for categories in self.category_groups.values())
current_category = 0 current_category = 0
# Search for each app in local repositories # Search for each app in local repositories
searcher = get_reposearcher(system, refresh) searcher = get_reposearcher(system, refresh)
self.all_apps = searcher.get_all_apps()
json_path = "collections_data.json" json_path = "collections_data.json"
search_result = [] search_result = []
@ -559,7 +561,7 @@ class AppstreamSearcher:
except (IOError, json.JSONDecodeError) as e: except (IOError, json.JSONDecodeError) as e:
print(f"Error loading collections data: {str(e)}") print(f"Error loading collections data: {str(e)}")
# make sure to reset these to empty before refreshing. # make sure to reset these to empty before refreshing.
return self.category_results, self.collection_results, self.installed_results, self.updates_results return self.category_results, self.collection_results, self.installed_results, self.updates_results, self.all_apps
def install_flatpak(app: AppStreamPackage, repo_name=None, system=False) -> tuple[bool, str]: def install_flatpak(app: AppStreamPackage, repo_name=None, system=False) -> tuple[bool, str]:
""" """

17
main.py
View file

@ -14,6 +14,7 @@ class MainWindow(Gtk.Window):
super().__init__() super().__init__()
# Store search results as an instance variable # Store search results as an instance variable
self.all_apps = []
self.category_results = [] # Initialize empty list self.category_results = [] # Initialize empty list
self.collection_results = [] # Initialize empty list self.collection_results = [] # Initialize empty list
self.installed_results = [] # Initialize empty list self.installed_results = [] # Initialize empty list
@ -207,11 +208,12 @@ class MainWindow(Gtk.Window):
# Define thread target function # Define thread target function
def refresh_target(): def refresh_target():
try: try:
category_results, collection_results, installed_results, updates_results = searcher.retrieve_metadata(self.system_mode) category_results, collection_results, installed_results, updates_results, all_apps = searcher.retrieve_metadata(self.system_mode)
self.category_results = category_results self.category_results = category_results
self.collection_results = collection_results self.collection_results = collection_results
self.installed_results = installed_results self.installed_results = installed_results
self.updates_results = updates_results self.updates_results = updates_results
self.all_apps = all_apps
except Exception as e: except Exception as e:
message_type = Gtk.MessageType.ERROR message_type = Gtk.MessageType.ERROR
dialog = Gtk.MessageDialog( dialog = Gtk.MessageDialog(
@ -432,6 +434,11 @@ class MainWindow(Gtk.Window):
def on_search_changed(self, searchentry): def on_search_changed(self, searchentry):
"""Handle search text changes""" """Handle search text changes"""
pass # Don't perform search on every keystroke
def on_search_activate(self, searchentry):
"""Handle Enter key press in search"""
search_term = searchentry.get_text().lower() search_term = searchentry.get_text().lower()
if not search_term: if not search_term:
# Reset to showing all categories when search is empty # Reset to showing all categories when search is empty
@ -454,10 +461,6 @@ class MainWindow(Gtk.Window):
# Show search results # Show search results
self.show_search_results(filtered_apps) self.show_search_results(filtered_apps)
def on_search_activate(self, searchentry):
"""Handle Enter key press in search"""
self.on_search_changed(searchentry)
def show_search_results(self, apps): def show_search_results(self, apps):
"""Display search results in the right panel""" """Display search results in the right panel"""
# Clear existing content # Clear existing content
@ -467,8 +470,8 @@ class MainWindow(Gtk.Window):
# Display each application # Display each application
for app in apps: for app in apps:
details = app.get_details() details = app.get_details()
is_installed = details['id'] in installed_package_ids is_installed = details['id'] in self.installed_results
is_updatable = details['id'] in updatable_package_ids is_updatable = details['id'] in self.updates_results
# Create application container # Create application container
app_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) app_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)