From ab74d11827036a8c9b1d41ced316105e5950447a Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 30 Jan 2023 18:58:01 +0100 Subject: [PATCH] add fallback icons --- src/plugins/domain/raction.py | 4 ++-- src/plugins/openfileplugin.py | 1 + src/ui/bigtext/newhighlightingdialog.py | 8 ++++---- src/ui/icon.py | 5 ++++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/plugins/domain/raction.py b/src/plugins/domain/raction.py index e67a7f5..04f8636 100644 --- a/src/plugins/domain/raction.py +++ b/src/plugins/domain/raction.py @@ -80,8 +80,8 @@ class RAction(): action.setText(self.label) self._action = action if self.icon_from_theme: - action.setIcon(Icon.fromTheme(self.icon_from_theme)) - if self.icon_file: + action.setIcon(Icon.fromTheme(self.icon_from_theme, self.icon_file)) + elif self.icon_file: action.setIcon(Icon(self.icon_file)) if self.shortcut: action.setShortcut(self.shortcut) diff --git a/src/plugins/openfileplugin.py b/src/plugins/openfileplugin.py index e319709..f309514 100644 --- a/src/plugins/openfileplugin.py +++ b/src/plugins/openfileplugin.py @@ -23,6 +23,7 @@ class OpenFilePlugin(PluginBase): def _action_open_file(self) -> RAction: open_file = RAction(_("&Open..."), self._open_file_dialog, shortcut='Ctrl+O', + icon_from_theme="fileopen", icon_file="icons/myicons/select-file.svg") return open_file diff --git a/src/ui/bigtext/newhighlightingdialog.py b/src/ui/bigtext/newhighlightingdialog.py index 291828e..ef010bf 100644 --- a/src/ui/bigtext/newhighlightingdialog.py +++ b/src/ui/bigtext/newhighlightingdialog.py @@ -26,19 +26,19 @@ class NewHighlightingDialog(QDialog): self.layout = QGridLayout(self) row = 0 - btn_new = QPushButton(Icon("icons/myicons/list-add.svg"), _("New")) + btn_new = QPushButton(Icon.fromTheme("list-add", "icons/myicons/list-add.svg"), _("New")) btn_new.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) btn_new.pressed.connect(self._new_highlighter) - self.btn_delete = QPushButton(Icon("icons/myicons/list-remove.svg"), _("Remove")) + self.btn_delete = QPushButton(Icon.fromTheme("list-remove", "icons/myicons/list-remove.svg"), _("Remove")) self.btn_delete.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) self.btn_delete.pressed.connect(self._delete_selected_items) - self.btn_move_up = QPushButton(Icon("icons/myicons/go-up.svg"), _("Up")) + self.btn_move_up = QPushButton(Icon.fromTheme("go-up", "icons/myicons/go-up.svg"), _("Up")) self.btn_move_up.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) self.btn_move_up.pressed.connect(self._move_up) - self.btn_move_down = QPushButton(Icon("icons/myicons/go-down.svg"), _("Down")) + self.btn_move_down = QPushButton(Icon.fromTheme("go-down", "icons/myicons/go-down.svg"), _("Down")) self.btn_move_down.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)) self.btn_move_down.pressed.connect(self._move_down) diff --git a/src/ui/icon.py b/src/ui/icon.py index 48bb537..37ad29c 100644 --- a/src/ui/icon.py +++ b/src/ui/icon.py @@ -6,5 +6,8 @@ class Icon(QIcon): def __init__(self, file_name: str): super(Icon, self).__init__("%s" % Path(__file__).parent.parent.parent.joinpath(file_name).absolute()) - def fromTheme(icon_from_theme: str) -> QIcon: + @staticmethod + def fromTheme(icon_from_theme: str, fallback: str = None) -> QIcon: + if fallback: + return QIcon.fromTheme(icon_from_theme, Icon(fallback)) return QIcon.fromTheme(icon_from_theme)