add kind labeling

This commit is contained in:
GloriousEggroll 2025-03-29 03:55:38 -06:00
parent 8ce6291bb6
commit 8de622614a
2 changed files with 73 additions and 4 deletions

View file

@ -33,7 +33,6 @@
# which have been modified and extended.
from typing import cast
import gi
gi.require_version("AppStream", "1.0")
gi.require_version("Flatpak", "1.0")
@ -62,6 +61,59 @@ class Match(IntEnum):
SUMMARY = 3
NONE = 4
class AppStreamComponentKind(IntEnum):
"""AppStream Component Kind enumeration."""
UNKNOWN = 0
"""Type invalid or not known."""
GENERIC = 1
"""A generic (= without specialized type) component."""
DESKTOP_APP = 2
"""An application with a .desktop-file."""
CONSOLE_APP = 3
"""A console application."""
WEB_APP = 4
"""A web application."""
SERVICE = 5
"""A system service launched by the init system."""
ADDON = 6
"""An extension of existing software, which does not run standalone."""
RUNTIME = 7
"""An application runtime platform."""
FONT = 8
"""A font."""
CODEC = 9
"""A multimedia codec."""
INPUT_METHOD = 10
"""An input-method provider."""
OPERATING_SYSTEM = 11
"""A computer operating system."""
FIRMWARE = 12
"""Firmware."""
DRIVER = 13
"""A driver."""
LOCALIZATION = 14
"""Software localization (usually l10n resources)."""
REPOSITORY = 15
"""A remote software or data source."""
ICON_THEME = 16
"""An icon theme following the XDG specification."""
class AppStreamPackage:
def __init__(self, comp: AppStream.Component, remote: Flatpak.Remote) -> None:
@ -108,9 +160,13 @@ class AppStreamPackage:
return None
@property
def kind(self) -> str:
return str(self.component.get_kind())
def kind(self):
kind = self.component.get_kind()
kind_str = str(kind)
for member in AppStreamComponentKind:
if member.name in kind_str:
return member.name
def _get_icon_url(self) -> str:
"""Get the remote icon URL from the component"""

15
main.py
View file

@ -606,6 +606,7 @@ class MainWindow(Gtk.Window):
def on_search_activate(self, searchentry):
"""Handle Enter key press in search"""
self.update_category_header("Search Results")
search_term = searchentry.get_text().lower()
if not search_term:
# Reset to showing all categories when search is empty
@ -702,7 +703,7 @@ class MainWindow(Gtk.Window):
break
if display_title == "":
# Fallback if category isn't found
display_title = category.capitalize()
display_title = category
self.category_header.set_label(display_title)
def create_applications_panel(self, title):
@ -1197,6 +1198,17 @@ class MainWindow(Gtk.Window):
title_label.set_yalign(0.5) # Use yalign instead of valign
title_label.set_hexpand(True)
# Add repository labels
kind_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
kind_box.set_spacing(4)
kind_box.set_halign(Gtk.Align.START)
kind_box.set_valign(Gtk.Align.START)
kind_label = Gtk.Label(label=details['kind'])
kind_label.get_style_context().add_class("item-repo-label")
kind_label.set_halign(Gtk.Align.START)
kind_box.pack_end(kind_label, False, False, 0)
# Add repository labels
repo_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
repo_box.set_spacing(4)
@ -1293,6 +1305,7 @@ class MainWindow(Gtk.Window):
# Add widgets to right box
right_box.pack_start(title_label, False, False, 0)
right_box.pack_start(kind_box, False, False, 0)
right_box.pack_start(repo_box, False, False, 0)
right_box.pack_start(desc_label, False, False, 0)
right_box.pack_start(buttons_box, False, True, 0)