Skip to content

Commit

Permalink
Change icon code to allow imports from other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
greghope667 committed Jun 28, 2023
1 parent 327a818 commit e292cc0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions plover/gui_qt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e292cc0

Please sign in to comment.