Show default icon

If no icon can be found for the row / properties box, flattool now defaults to the exec icon instead of having nothing
This commit is contained in:
heliguy
2023-09-02 21:36:28 -04:00
parent f6884c7886
commit 68c5621aa9
2 changed files with 23 additions and 32 deletions

View File

@@ -68,22 +68,11 @@ def show_properties_window(widget, index, window):
window.clipboard.set(to_copy)
properties_toast_overlay.add_toast(Adw.Toast.new(_("Copied {}").format(title)))
try:
icon_path = window.icon_theme.lookup_icon(window.host_flatpaks[index][2], None, 512, 1, window.get_direction(), 0).get_file().get_path()
except GLib.GError:
icon_path = None
if icon_path:
image = Gtk.Image.new_from_file(icon_path)
image.add_css_class("icon-dropshadow")
image.set_size_request(100, 100)
image.set_margin_top(12)
properties_box.append(image)
if "runtime" in window.host_flatpaks[index][12]:
image = Gtk.Image.new_from_icon_name("system-run-symbolic")
image.set_icon_size(Gtk.IconSize.LARGE)
image.set_margin_top(12)
properties_box.append(image)
image = window.find_app_icon(window.host_flatpaks[index][2])
image.add_css_class("icon-dropshadow")
image.set_margin_top(12)
image.set_pixel_size(100)
properties_box.append(image)
properties_list = Gtk.ListBox(selection_mode="none", margin_top=12, margin_bottom=12, margin_start=12, margin_end=12)
properties_list.add_css_class("boxed-list")

View File

@@ -355,6 +355,20 @@ class FlattoolGuiWindow(Adw.ApplicationWindow):
selected_host_flatpak_indexes = []
def find_app_icon(self, app_id):
try:
icon_path = self.icon_theme.lookup_icon(app_id, None, 512, 1, self.get_direction(), 0).get_file().get_path()
except GLib.GError:
icon_path = None
if icon_path:
image=Gtk.Image.new_from_file(icon_path)
image.set_icon_size(Gtk.IconSize.LARGE)
image.add_css_class("icon-dropshadow")
else:
image=Gtk.Image.new_from_icon_name("application-x-executable-symbolic")
image.set_icon_size(Gtk.IconSize.LARGE)
return(image)
def generate_list_of_flatpaks(self):
self.set_title(self.main_window_title)
self.batch_actions_enable(False)
@@ -382,23 +396,11 @@ class FlattoolGuiWindow(Adw.ApplicationWindow):
app_id = self.host_flatpaks[index][2]
app_ref = self.host_flatpaks[index][8]
flatpak_row = Adw.ActionRow(title=GLib.markup_escape_text(app_name), subtitle=app_ref)
image = None
try:
icon_path = self.icon_theme.lookup_icon(app_id, None, 512, 1, self.get_direction(), 0).get_file().get_path()
except GLib.GError:
icon_path = None
if icon_path:
image=Gtk.Image.new_from_file(icon_path)
image.set_icon_size(Gtk.IconSize.LARGE)
image.add_css_class("icon-dropshadow")
flatpak_row.add_prefix(image)
flatpak_row.add_prefix(self.find_app_icon(app_id))
if "runtime" in self.host_flatpaks[index][12]:
runtime_icon = Gtk.Image.new_from_icon_name("system-run-symbolic")
runtime_icon.set_icon_size(Gtk.IconSize.LARGE)
flatpak_row.add_prefix(runtime_icon)
if not self.show_runtimes:
flatpak_row.set_visible(False)
if (not self.show_runtimes) and "runtime" in self.host_flatpaks[index][12]:
continue
if os.path.exists(f"{self.user_data_path}{app_id}"):
has_data_icon = Gtk.Image.new_from_icon_name("paper-filled-symbolic")