From e292cc014d27673e40c89fafd32f64082332a48f Mon Sep 17 00:00:00 2001 From: Greg Hope Date: Wed, 28 Jun 2023 15:23:54 +0100 Subject: [PATCH] Change icon code to allow imports from other modules --- plover/gui_qt/utils.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/plover/gui_qt/utils.py b/plover/gui_qt/utils.py index 667967046..763c6b4f0 100644 --- a/plover/gui_qt/utils.py +++ b/plover/gui_qt/utils.py @@ -44,15 +44,20 @@ def ToolBar(*action_list): return toolbar -def Icon(resource: str): +def Icon(resource): icon = QIcon() + package = "plover.gui_qt.resources" - if resource.startswith(":/"): - resource = resource[2:] - with importlib.resources.path("plover.gui_qt.resources", resource) as f_path: - icon.addPixmap(QPixmap(str(f_path))) - else: - icon.addPixmap(QPixmap(resource)) + if type(resource) is tuple: + package = resource[0] + resource = resource[1] + + if type(resource) is str: + if resource.startswith(":/"): + resource = resource[2:] + + with importlib.resources.path(package, resource) as f_path: + icon.addPixmap(QPixmap(str(f_path))) return icon