1 # SPDX-License-Identifier: GPL-2.0-or-later
6 "description": "Click an icon to copy its name to the clipboard",
10 "location": "Text Editor > Dev Tab > Icon Viewer",
11 "doc_url": "{BLENDER_MANUAL_URL}/addons/development/icon_viewer.html",
12 "category": "Development",
17 from bpy
.props
import (
32 prefs
= bpy
.context
.preferences
.system
33 return prefs
.dpi
/ DPI
37 return bpy
.context
.preferences
.addons
[__name__
].preferences
41 def __init__(self
, is_popup
=False):
42 self
._filtered
_icons
= None
45 self
.selected_icon
= ""
46 self
.is_popup
= is_popup
53 def filter(self
, value
):
54 if self
._filter
== value
:
61 def filtered_icons(self
):
62 if self
._filtered
_icons
is None:
63 self
._filtered
_icons
= []
64 icon_filter
= self
._filter
.upper()
65 self
.filtered_icons
.clear()
68 icons
= bpy
.types
.UILayout
.bl_rna
.functions
[
69 "prop"].parameters
["icon"].enum_items
.keys()
71 if icon
== 'NONE' or \
72 icon_filter
and icon_filter
not in icon
or \
73 not pr
.show_brush_icons
and "BRUSH_" in icon
and \
74 icon
!= 'BRUSH_DATA' or \
75 not pr
.show_matcap_icons
and "MATCAP_" in icon
or \
76 not pr
.show_event_icons
and (
77 "EVENT_" in icon
or "MOUSE_" in icon
79 not pr
.show_colorset_icons
and "COLORSET_" in icon
:
81 self
._filtered
_icons
.append(icon
)
83 return self
._filtered
_icons
87 return len(self
.filtered_icons
)
90 if self
._filtered
_icons
is not None:
91 self
._filtered
_icons
.clear()
92 self
._filtered
_icons
= None
94 def draw(self
, layout
, num_cols
=0, icons
=None):
96 filtered_icons
= reversed(icons
)
98 filtered_icons
= self
.filtered_icons
100 column
= layout
.column(align
=True)
101 row
= column
.row(align
=True)
102 row
.alignment
= 'CENTER'
104 selected_icon
= self
.selected_icon
if self
.is_popup
else \
105 bpy
.context
.window_manager
.clipboard
107 for i
, icon
in enumerate(filtered_icons
):
109 IV_OT_icon_select
.bl_idname
, text
="",
110 icon
=icon
, emboss
=icon
== selected_icon
)
112 p
.force_copy_on_select
= not self
.is_popup
115 if col_idx
> num_cols
- 1:
119 if i
< len(filtered_icons
) - 1:
120 row
= column
.row(align
=True)
121 row
.alignment
= 'CENTER'
123 if col_idx
!= 0 and not icons
and i
>= num_cols
:
124 for _
in range(num_cols
- col_idx
):
125 row
.label(text
="", icon
='BLANK1')
127 if not filtered_icons
:
128 row
.label(text
="No icons were found")
131 class IV_Preferences(bpy
.types
.AddonPreferences
):
134 panel_icons
= Icons()
135 popup_icons
= Icons(is_popup
=True)
137 def update_icons(self
, context
):
138 self
.panel_icons
.update()
139 self
.popup_icons
.update()
141 def set_panel_filter(self
, value
):
142 self
.panel_icons
.filter = value
144 panel_filter
: StringProperty(
145 description
="Filter",
147 get
=lambda s
: s
.panel_icons
.filter,
148 set=set_panel_filter
,
149 options
={'TEXTEDIT_UPDATE'})
150 show_panel_icons
: BoolProperty(
152 description
="Show icons", default
=True)
153 show_history
: BoolProperty(
155 description
="Show history", default
=True)
156 show_brush_icons
: BoolProperty(
157 name
="Show Brush Icons",
158 description
="Show brush icons", default
=True,
160 show_matcap_icons
: BoolProperty(
161 name
="Show Matcap Icons",
162 description
="Show matcap icons", default
=True,
164 show_event_icons
: BoolProperty(
165 name
="Show Event Icons",
166 description
="Show event icons", default
=True,
168 show_colorset_icons
: BoolProperty(
169 name
="Show Colorset Icons",
170 description
="Show colorset icons", default
=True,
172 copy_on_select
: BoolProperty(
173 name
="Copy Icon On Click",
174 description
="Copy icon on click", default
=True)
175 close_on_select
: BoolProperty(
176 name
="Close Popup On Click",
178 "Close the popup on click.\n"
179 "Not supported by some windows (User Preferences, Render)"
182 auto_focus_filter
: BoolProperty(
183 name
="Auto Focus Input Field",
184 description
="Auto focus input field", default
=True)
185 show_panel
: BoolProperty(
187 description
="Show the panel in the Text Editor", default
=True)
188 show_header
: BoolProperty(
190 description
="Show the header in the Python Console",
193 def draw(self
, context
):
197 row
.operator(IV_OT_icons_show
.bl_idname
)
201 col
= row
.column(align
=True)
202 col
.label(text
="Icons:")
203 col
.prop(self
, "show_matcap_icons")
204 col
.prop(self
, "show_brush_icons")
205 col
.prop(self
, "show_colorset_icons")
206 col
.prop(self
, "show_event_icons")
208 col
.prop(self
, "show_history")
210 col
= row
.column(align
=True)
211 col
.label(text
="Popup:")
212 col
.prop(self
, "auto_focus_filter")
213 col
.prop(self
, "copy_on_select")
214 if self
.copy_on_select
:
215 col
.prop(self
, "close_on_select")
217 col
= row
.column(align
=True)
218 col
.label(text
="Panel:")
219 col
.prop(self
, "show_panel")
221 col
.prop(self
, "show_panel_icons")
224 col
.label(text
="Header:")
225 col
.prop(self
, "show_header")
228 class IV_PT_icons(bpy
.types
.Panel
):
229 bl_space_type
= "TEXT_EDITOR"
230 bl_region_type
= "UI"
231 bl_label
= "Icon Viewer"
233 bl_options
= {'DEFAULT_CLOSED'}
237 wm
= bpy
.context
.window_manager
242 for a
in w
.screen
.areas
:
243 if a
.type == 'TEXT_EDITOR':
248 def draw(self
, context
):
250 row
= self
.layout
.row(align
=True)
251 if pr
.show_panel_icons
:
252 row
.prop(pr
, "panel_filter", text
="", icon
='VIEWZOOM')
254 row
.operator(IV_OT_icons_show
.bl_idname
)
256 IV_OT_panel_menu_call
.bl_idname
, text
="", icon
='COLLAPSEMENU')
258 _
, y0
= context
.region
.view2d
.region_to_view(0, 0)
259 _
, y1
= context
.region
.view2d
.region_to_view(0, 10)
260 region_scale
= 10 / abs(y0
- y1
)
264 (context
.region
.width
- PANEL_PADDING
) //
265 math
.ceil(ui_scale() * region_scale
* ICON_SIZE
))
268 if HISTORY
and pr
.show_history
:
269 col
= self
.layout
.column(align
=True)
270 pr
.panel_icons
.draw(col
.box(), num_cols
, HISTORY
)
272 if pr
.show_panel_icons
:
273 col
= col
or self
.layout
.column(align
=True)
274 pr
.panel_icons
.draw(col
.box(), num_cols
)
277 def poll(cls
, context
):
278 return prefs().show_panel
281 class IV_OT_panel_menu_call(bpy
.types
.Operator
):
282 bl_idname
= "iv.panel_menu_call"
284 bl_description
= "Menu"
285 bl_options
= {'INTERNAL'}
287 def menu(self
, menu
, context
):
290 layout
.prop(pr
, "show_panel_icons")
291 layout
.prop(pr
, "show_history")
293 if not pr
.show_panel_icons
:
297 layout
.prop(pr
, "show_matcap_icons")
298 layout
.prop(pr
, "show_brush_icons")
299 layout
.prop(pr
, "show_colorset_icons")
300 layout
.prop(pr
, "show_event_icons")
302 def execute(self
, context
):
303 context
.window_manager
.popup_menu(self
.menu
, title
="Icon Viewer")
307 class IV_OT_icon_select(bpy
.types
.Operator
):
308 bl_idname
= "iv.icon_select"
310 bl_description
= "Select the icon"
311 bl_options
= {'INTERNAL'}
313 icon
: StringProperty()
314 force_copy_on_select
: BoolProperty()
316 def execute(self
, context
):
318 pr
.popup_icons
.selected_icon
= self
.icon
319 if pr
.copy_on_select
or self
.force_copy_on_select
:
320 context
.window_manager
.clipboard
= self
.icon
321 self
.report({'INFO'}, self
.icon
)
323 if pr
.close_on_select
and IV_OT_icons_show
.instance
:
324 IV_OT_icons_show
.instance
.close()
327 if self
.icon
in HISTORY
:
328 HISTORY
.remove(self
.icon
)
329 if len(HISTORY
) >= HISTORY_SIZE
:
331 HISTORY
.append(self
.icon
)
335 class IV_OT_icons_show(bpy
.types
.Operator
):
336 bl_idname
= "iv.icons_show"
337 bl_label
= "Icon Viewer"
338 bl_description
= "Icon viewer"
339 bl_property
= "filter_auto_focus"
343 def set_filter(self
, value
):
344 prefs().popup_icons
.filter = value
346 def set_selected_icon(self
, value
):
347 if IV_OT_icons_show
.instance
:
348 IV_OT_icons_show
.instance
.auto_focusable
= False
350 filter_auto_focus
: StringProperty(
351 description
="Filter",
352 get
=lambda s
: prefs().popup_icons
.filter,
354 options
={'TEXTEDIT_UPDATE', 'SKIP_SAVE'})
355 filter: StringProperty(
356 description
="Filter",
357 get
=lambda s
: prefs().popup_icons
.filter,
359 options
={'TEXTEDIT_UPDATE'})
360 selected_icon
: StringProperty(
361 description
="Selected Icon",
362 get
=lambda s
: prefs().popup_icons
.selected_icon
,
363 set=set_selected_icon
)
365 def get_num_cols(self
, num_icons
):
366 return round(1.3 * math
.sqrt(num_icons
))
368 def draw_header(self
, layout
):
370 header
= layout
.box()
371 header
= header
.split(factor
=0.75) if self
.selected_icon
else \
373 row
= header
.row(align
=True)
374 row
.prop(pr
, "show_matcap_icons", text
="", icon
='SHADING_RENDERED')
375 row
.prop(pr
, "show_brush_icons", text
="", icon
='BRUSH_DATA')
376 row
.prop(pr
, "show_colorset_icons", text
="", icon
='COLOR')
377 row
.prop(pr
, "show_event_icons", text
="", icon
='HAND')
381 pr
, "copy_on_select", text
="",
382 icon
='COPYDOWN', toggle
=True)
383 if pr
.copy_on_select
:
384 sub
= row
.row(align
=True)
385 if bpy
.context
.window
.screen
.name
== "temp":
388 pr
, "close_on_select", text
="",
389 icon
='RESTRICT_SELECT_OFF', toggle
=True)
391 pr
, "auto_focus_filter", text
="",
392 icon
='OUTLINER_DATA_FONT', toggle
=True)
395 if self
.auto_focusable
and pr
.auto_focus_filter
:
396 row
.prop(self
, "filter_auto_focus", text
="", icon
='VIEWZOOM')
398 row
.prop(self
, "filter", text
="", icon
='VIEWZOOM')
400 if self
.selected_icon
:
402 row
.prop(self
, "selected_icon", text
="", icon
=self
.selected_icon
)
404 def draw(self
, context
):
407 self
.draw_header(col
)
409 history_num_cols
= int(
410 (self
.width
- POPUP_PADDING
) / (ui_scale() * ICON_SIZE
))
412 self
.get_num_cols(len(pr
.popup_icons
.filtered_icons
)),
415 subcol
= col
.column(align
=True)
417 if HISTORY
and pr
.show_history
:
418 pr
.popup_icons
.draw(subcol
.box(), history_num_cols
, HISTORY
)
420 pr
.popup_icons
.draw(subcol
.box(), num_cols
)
423 bpy
.context
.window
.screen
= bpy
.context
.window
.screen
425 def check(self
, context
):
428 def cancel(self
, context
):
429 IV_OT_icons_show
.instance
= None
430 IV_PT_icons
.tag_redraw()
432 def execute(self
, context
):
433 if not IV_OT_icons_show
.instance
:
435 IV_OT_icons_show
.instance
= None
438 if self
.selected_icon
and not pr
.copy_on_select
:
439 context
.window_manager
.clipboard
= self
.selected_icon
440 self
.report({'INFO'}, self
.selected_icon
)
441 pr
.popup_icons
.selected_icon
= ""
443 IV_PT_icons
.tag_redraw()
446 def invoke(self
, context
, event
):
448 pr
.popup_icons
.selected_icon
= ""
449 pr
.popup_icons
.filter = ""
450 IV_OT_icons_show
.instance
= self
451 self
.auto_focusable
= True
453 num_cols
= self
.get_num_cols(len(pr
.popup_icons
.filtered_icons
))
454 self
.width
= int(min(
455 ui_scale() * (num_cols
* ICON_SIZE
+ POPUP_PADDING
),
456 context
.window
.width
- WIN_PADDING
))
458 return context
.window_manager
.invoke_props_dialog(
459 self
, width
=self
.width
)
461 def draw_console_header(self
, context
):
462 if not prefs().show_header
:
464 self
.layout
.operator(IV_OT_icons_show
.bl_idname
)
468 IV_OT_panel_menu_call
,
476 if bpy
.app
.background
:
480 bpy
.utils
.register_class(cls
)
482 bpy
.types
.CONSOLE_HT_header
.append(draw_console_header
)
486 if bpy
.app
.background
:
489 bpy
.types
.CONSOLE_HT_header
.remove(draw_console_header
)
492 bpy
.utils
.unregister_class(cls
)