From a76cdde2344873b2569ebd83e7031d5304b9217d Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Thu, 4 Jun 2020 14:51:52 -0300 Subject: [PATCH] [improvement][ui] rendering package icons with no full paths declared --- CHANGELOG.md | 1 + bauh/view/qt/apps_table.py | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dffcd08d..ffcf2416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - UI - not limiting the name filter size + - rendering package icons with no full paths declared - minor improvements - download clients parameters diff --git a/bauh/view/qt/apps_table.py b/bauh/view/qt/apps_table.py index 548a2fd8..aac1dec2 100644 --- a/bauh/view/qt/apps_table.py +++ b/bauh/view/qt/apps_table.py @@ -249,7 +249,7 @@ class AppsTable(QTableWidget): col_name = self.item(idx, 0) col_name.setIcon(icon_data['icon']) - if app.model.supports_disk_cache() and app.model.get_disk_icon_path(): + if app.model.supports_disk_cache() and app.model.get_disk_icon_path() and icon_data['bytes']: if not icon_was_cached or not os.path.exists(app.model.get_disk_icon_path()): self.window.manager.cache_to_disk(pkg=app.model, icon_bytes=icon_data['bytes'], only_icon=True) @@ -406,13 +406,21 @@ class AppsTable(QTableWidget): item.setText(name) icon_path = pkg.model.get_disk_icon_path() - if pkg.model.supports_disk_cache() and icon_path and os.path.isfile(icon_path): - with open(icon_path, 'rb') as f: - icon_bytes = f.read() - pixmap = QPixmap() - pixmap.loadFromData(icon_bytes) - icon = QIcon(pixmap) - self.icon_cache.add_non_existing(pkg.model.icon_url, {'icon': icon, 'bytes': icon_bytes}) + if pkg.model.supports_disk_cache() and icon_path: + if icon_path.startswith('/') and os.path.isfile(icon_path): + with open(icon_path, 'rb') as f: + icon_bytes = f.read() + pixmap = QPixmap() + pixmap.loadFromData(icon_bytes) + icon = QIcon(pixmap) + self.icon_cache.add_non_existing(pkg.model.icon_url, {'icon': icon, 'bytes': icon_bytes}) + else: + try: + icon = QIcon.fromTheme(icon_path) + self.icon_cache.add_non_existing(pkg.model.icon_url, {'icon': icon, 'bytes': None}) + + except: + icon = QIcon(pkg.model.get_default_icon_path()) elif not pkg.model.icon_url: icon = QIcon(pkg.model.get_default_icon_path())