8000
Skip to content

Add support for custom icons by id in blender - #55

Merged
hannesdelbeke merged 7 commits into
hannesdelbeke:mainfrom
hasielhassan:main
Aug 2, 2023
Merged

Add support for custom icons by id in blender#55
hannesdelbeke merged 7 commits into
hannesdelbeke:mainfrom
hasielhassan:main

Conversation

@hasielhassan
Copy link
Copy Markdown
Contributor

On Blender apart from the existing icons which can be referenced by name, they can also be custom ones created which can be referenced by id

from bpy.utils import previews    
icons = previews.new()

icon = icons.load(
    name="icon_name"), 
    path="/custom/icon/path.png", 
    path_type='IMAGE'
)
icon_value = icon.icon_id

This changes validates the menu icon data type and properly attempts to set it by the correct argument

So when setting up the menu items, we can have a full file path as the icon key value

This is a simplified implementation that leaves the handling of the icons to the dev configuring the menus, particularly if its needed to reuse icons in other places too, but we can also include the full icon setup and check if the icon value is a file path and in such case create the icon and use it directly, open for suggestions

:)

@hannesdelbeke
hannesdelbeke commented Aug 1, 2023
Copy link
Copy Markdown
Owner

this looks great. will have a think how to best implement this.
Your suggestion of icon value is a file path is a good one

@hannesdelbeke
Copy link
Copy Markdown
Owner

this does create a warning.
it seems it can be ignored but would be nice if we could correctly handle this.

Exception ignored in: <function ImagePreviewCollection.__del__ at 0x000001FD01FA6680>
Traceback (most recent call last):
  File "C:\Users\hanne\Downloads\Blender_Launcher_v1.14.1_Windows_x64\stable\blender-3.2.0+stable.e05e1e369187\3.2\scripts\modules\bpy\utils\previews.py", line 66, in __del__
    raise ResourceWarning(
ResourceWarning: <ImagePreviewCollection id=0x1fd064c7650[1], <super: <class 'ImagePreviewCollection'>, <ImagePreviewCollection object>>>: left open, remove with 'bpy.utils.previews.remove()'
focus_object_changed <PySide2.QtWidgets.QMainWindow(0x1fd013a7890) at 0x000001FD019EDEC0>

@hannesdelbeke
Copy link
Copy Markdown
Owner

used the blender docs to fix the warning https://docs.blender.org/api/current/bpy.utils.previews.html#module-bpy.utils.previews
also added a sample to test with pyblish-lite icon

@hannesdelbeke
hannesdelbeke merged commit 314ccf8 into hannesdelbeke:main Aug 2, 2023
@hasielhassan
Copy link
Copy Markdown
Contributor Author

Wow, this si awesome, thank you for the merge! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0