From 5e2529456fb1502dcb5e30ee8559bf409204d47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Fri, 20 Dec 2019 13:52:29 -0300 Subject: [PATCH] [icon] notifications and panel favor the system's default --- CHANGELOG.md | 1 + bauh/app.py | 4 +++- bauh/view/qt/window.py | 4 ++-- bauh/view/util/util.py | 21 ++++++++++++++++++--- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12532f2d..6b96da46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ updates: 1) Icon paths defined in **~/.config/bauh/config.yml** 2) Icons from the system with the following names: `bauh_tray_default` and `bauh_tray_updates` 3) Own packaged icons +- Now bauh considers the default system icon for the notifications and panel. If there is none, then it will use its own. - AppImage: - cleaning the downloaded database files when **--reset** is passed as parameter - environment variables **BAUH_APPIMAGE_DB_UPDATER** and **BAUH_APPIMAGE_DB_UPDATER_TIME** dropped in favor of the new configuration file located at **~/.config/bauh/appimage.yml** diff --git a/bauh/app.py b/bauh/app.py index 7c2085c2..28bdce9b 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -69,7 +69,8 @@ def main(): app = QApplication(sys.argv) app.setApplicationName(__app_name__) app.setApplicationVersion(__version__) - app.setWindowIcon(QIcon(resource.get_path('img/logo.svg'))) + app_icon = util.get_default_icon()[1] + app.setWindowIcon(app_icon) if local_config['ui']['style']: app.setStyle(str(local_config['ui']['style'])) @@ -84,6 +85,7 @@ def main(): config=local_config, context=context, http_client=http_client, + icon=app_icon, logger=logger) if args.tray: diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 0009ff73..3fcf0af8 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -51,7 +51,7 @@ class ManageWindow(QWidget): signal_table_update = pyqtSignal() def __init__(self, i18n: I18n, icon_cache: MemoryCache, manager: SoftwareManager, screen_size, config: dict, - context: ApplicationContext, http_client: HttpClient, logger: logging.Logger, tray_icon=None): + context: ApplicationContext, http_client: HttpClient, logger: logging.Logger, icon: QIcon, tray_icon=None): super(ManageWindow, self).__init__() self.i18n = i18n self.logger = logger @@ -68,7 +68,7 @@ class ManageWindow(QWidget): self.context = context self.http_client = http_client - self.icon_app = QIcon(resource.get_path('img/logo.svg')) + self.icon_app = icon self.resize(ManageWindow.__BASE_HEIGHT__, ManageWindow.__BASE_HEIGHT__) self.setWindowIcon(self.icon_app) diff --git a/bauh/view/util/util.py b/bauh/view/util/util.py index 77e90cb8..0fc006c2 100644 --- a/bauh/view/util/util.py +++ b/bauh/view/util/util.py @@ -3,9 +3,10 @@ import shutil import subprocess import sys import traceback -from typing import List +from typing import List, Tuple from PyQt5.QtCore import QCoreApplication +from PyQt5.QtGui import QIcon from colorama import Fore from bauh import __app_name__ @@ -15,8 +16,22 @@ from bauh.commons.system import run_cmd from bauh.view.util import resource -def notify_user(msg: str, icon_path: str = resource.get_path('img/logo.svg')): - os.system("notify-send -a {} {} '{}'".format(__app_name__, "-i {}".format(icon_path) if icon_path else '', msg)) +def notify_user(msg: str, icon_path: str = None): + icon_id = icon_path + + if not icon_id: + icon_id = get_default_icon()[0] + + os.system("notify-send -a {} {} '{}'".format(__app_name__, "-i {}".format(icon_id) if icon_id else '', msg)) + + +def get_default_icon() -> Tuple[str, QIcon]: + system_icon = QIcon.fromTheme(__app_name__) + if not system_icon.isNull(): + return system_icon.name(), system_icon + else: + path = resource.get_path('img/logo.svg') + return path, QIcon(path) def restart_app(show_panel: bool):