1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
23 "name": "Icon Viewer",
24 "description": "Click an icon to copy its name to the clipboard",
27 "blender": (2, 80, 0),
28 "location": "Search Menu > Icon Viewer, Text Editor > Properties",
29 "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6"
30 "/Py/Scripts/Development/Display_All_Icons",
31 "category": "Development"
36 from bpy
.props
import (
51 prefs
= bpy
.context
.preferences
.system
52 return prefs
.dpi
* prefs
.pixel_size
/ DPI
56 return bpy
.context
.preferences
.addons
[__name__
].preferences
60 def __init__(self
, is_popup
=False):
61 self
._filtered
_icons
= None
64 self
.selected_icon
= ""
65 self
.is_popup
= is_popup
72 def filter(self
, value
):
73 if self
._filter
== value
:
80 def filtered_icons(self
):
81 if self
._filtered
_icons
is None:
82 self
._filtered
_icons
= []
83 icon_filter
= self
._filter
.upper()
84 self
.filtered_icons
.clear()
87 icons
= bpy
.types
.UILayout
.bl_rna
.functions
[
88 "prop"].parameters
["icon"].enum_items
.keys()
90 if icon
== 'NONE' or \
91 icon_filter
and icon_filter
not in icon
or \
92 not pr
.show_brush_icons
and "BRUSH_" in icon
and \
93 icon
!= 'BRUSH_DATA' or \
94 not pr
.show_matcap_icons
and "MATCAP_" in icon
or \
95 not pr
.show_event_icons
and (
96 "EVENT_" in icon
or "MOUSE_" in icon
98 not pr
.show_colorset_icons
and "COLORSET_" in icon
:
100 self
._filtered
_icons
.append(icon
)
102 return self
._filtered
_icons
106 return len(self
.filtered_icons
)
109 if self
._filtered
_icons
is not None:
110 self
._filtered
_icons
.clear()
111 self
._filtered
_icons
= None
113 def draw(self
, layout
, num_cols
=0, icons
=None):
115 filtered_icons
= reversed(icons
)
117 filtered_icons
= self
.filtered_icons
119 column
= layout
.column(align
=True)
120 row
= column
.row(align
=True)
121 row
.alignment
= 'CENTER'
123 selected_icon
= self
.selected_icon
if self
.is_popup
else \
124 bpy
.context
.window_manager
.clipboard
126 for i
, icon
in enumerate(filtered_icons
):
128 IV_OT_icon_select
.bl_idname
, text
="",
129 icon
=icon
, emboss
=icon
== selected_icon
)
131 p
.force_copy_on_select
= not self
.is_popup
134 if col_idx
> num_cols
- 1:
138 if i
< len(filtered_icons
) - 1:
139 row
= column
.row(align
=True)
140 row
.alignment
= 'CENTER'
142 if col_idx
!= 0 and not icons
and i
>= num_cols
:
143 for _
in range(num_cols
- col_idx
):
144 row
.label(text
="", icon
='BLANK1')
146 if not filtered_icons
:
147 row
.label(text
="No icons were found")
150 class IV_Preferences(bpy
.types
.AddonPreferences
):
153 panel_icons
= Icons()
154 popup_icons
= Icons(is_popup
=True)
156 def update_icons(self
, context
):
157 self
.panel_icons
.update()
158 self
.popup_icons
.update()
160 def set_panel_filter(self
, value
):
161 self
.panel_icons
.filter = value
163 panel_filter
: StringProperty(
164 description
="Filter",
166 get
=lambda s
: s
.panel_icons
.filter,
167 set=set_panel_filter
,
168 options
={'TEXTEDIT_UPDATE'})
169 show_panel_icons
: BoolProperty(
171 description
="Show icons", default
=True)
172 show_history
: BoolProperty(
174 description
="Show history", default
=True)
175 show_brush_icons
: BoolProperty(
176 name
="Show Brush Icons",
177 description
="Show brush icons", default
=True,
179 show_matcap_icons
: BoolProperty(
180 name
="Show Matcap Icons",
181 description
="Show matcap icons", default
=True,
183 show_event_icons
: BoolProperty(
184 name
="Show Event Icons",
185 description
="Show event icons", default
=True,
187 show_colorset_icons
: BoolProperty(
188 name
="Show Colorset Icons",
189 description
="Show colorset icons", default
=True,
191 copy_on_select
: BoolProperty(
192 name
="Copy Icon On Click",
193 description
="Copy icon on click", default
=True)
194 close_on_select
: BoolProperty(
195 name
="Close Popup On Click",
197 "Close the popup on click.\n"
198 "Not supported by some windows (User Preferences, Render)"
201 auto_focus_filter
: BoolProperty(
202 name
="Auto Focus Input Field",
203 description
="Auto focus input field", default
=True)
204 show_panel
: BoolProperty(
206 description
="Show the panel in the Text Editor", default
=True)
207 show_header
: BoolProperty(
209 description
="Show the header in the Python Console",
212 def draw(self
, context
):
216 row
.operator(IV_OT_icons_show
.bl_idname
)
220 col
= row
.column(align
=True)
221 col
.label(text
="Icons:")
222 col
.prop(self
, "show_matcap_icons")
223 col
.prop(self
, "show_brush_icons")
224 col
.prop(self
, "show_colorset_icons")
225 col
.prop(self
, "show_event_icons")
227 col
.prop(self
, "show_history")
229 col
= row
.column(align
=True)
230 col
.label(text
="Popup:")
231 col
.prop(self
, "auto_focus_filter")
232 col
.prop(self
, "copy_on_select")
233 if self
.copy_on_select
:
234 col
.prop(self
, "close_on_select")
236 col
= row
.column(align
=True)
237 col
.label(text
="Panel:")
238 col
.prop(self
, "show_panel")
240 col
.prop(self
, "show_panel_icons")
243 col
.label(text
="Header:")
244 col
.prop(self
, "show_header")
247 class IV_PT_icons(bpy
.types
.Panel
):
248 bl_space_type
= "TEXT_EDITOR"
249 bl_region_type
= "UI"
250 bl_label
= "Icon Viewer"
251 bl_category
= "Icon Viewer"
255 wm
= bpy
.context
.window_manager
260 for a
in w
.screen
.areas
:
261 if a
.type == 'TEXT_EDITOR':
266 def draw(self
, context
):
268 row
= self
.layout
.row(align
=True)
269 if pr
.show_panel_icons
:
270 row
.prop(pr
, "panel_filter", text
="", icon
='VIEWZOOM')
272 row
.operator(IV_OT_icons_show
.bl_idname
)
274 IV_OT_panel_menu_call
.bl_idname
, text
="", icon
='COLLAPSEMENU')
276 _
, y0
= context
.region
.view2d
.region_to_view(0, 0)
277 _
, y1
= context
.region
.view2d
.region_to_view(0, 10)
278 region_scale
= 10 / abs(y0
- y1
)
282 (context
.region
.width
- PANEL_PADDING
) //
283 math
.ceil(ui_scale() * region_scale
* ICON_SIZE
))
286 if HISTORY
and pr
.show_history
:
287 col
= self
.layout
.column(align
=True)
288 pr
.panel_icons
.draw(col
.box(), num_cols
, HISTORY
)
290 if pr
.show_panel_icons
:
291 col
= col
or self
.layout
.column(align
=True)
292 pr
.panel_icons
.draw(col
.box(), num_cols
)
295 def poll(cls
, context
):
296 return prefs().show_panel
299 class IV_HT_icons(bpy
.types
.Header
):
300 bl_space_type
= 'CONSOLE'
302 def draw(self
, context
):
303 if not prefs().show_header
:
307 layout
.operator(IV_OT_icons_show
.bl_idname
)
310 class IV_OT_panel_menu_call(bpy
.types
.Operator
):
311 bl_idname
= "iv.panel_menu_call"
313 bl_description
= "Menu"
314 bl_options
= {'INTERNAL'}
316 def menu(self
, menu
, context
):
319 layout
.prop(pr
, "show_panel_icons")
320 layout
.prop(pr
, "show_history")
322 if not pr
.show_panel_icons
:
326 layout
.prop(pr
, "show_matcap_icons")
327 layout
.prop(pr
, "show_brush_icons")
328 layout
.prop(pr
, "show_colorset_icons")
329 layout
.prop(pr
, "show_event_icons")
331 def execute(self
, context
):
332 context
.window_manager
.popup_menu(self
.menu
, title
="Icon Viewer")
336 class IV_OT_icon_select(bpy
.types
.Operator
):
337 bl_idname
= "iv.icon_select"
339 bl_description
= "Select the icon"
340 bl_options
= {'INTERNAL'}
342 icon
: StringProperty()
343 force_copy_on_select
: BoolProperty()
345 def execute(self
, context
):
347 pr
.popup_icons
.selected_icon
= self
.icon
348 if pr
.copy_on_select
or self
.force_copy_on_select
:
349 context
.window_manager
.clipboard
= self
.icon
350 self
.report({'INFO'}, self
.icon
)
352 if pr
.close_on_select
and IV_OT_icons_show
.instance
:
353 IV_OT_icons_show
.instance
.close()
356 if self
.icon
in HISTORY
:
357 HISTORY
.remove(self
.icon
)
358 if len(HISTORY
) >= HISTORY_SIZE
:
360 HISTORY
.append(self
.icon
)
364 class IV_OT_icons_show(bpy
.types
.Operator
):
365 bl_idname
= "iv.icons_show"
366 bl_label
= "Icon Viewer"
367 bl_description
= "Icon viewer"
368 bl_property
= "filter_auto_focus"
372 def set_filter(self
, value
):
373 prefs().popup_icons
.filter = value
375 def set_selected_icon(self
, value
):
376 if IV_OT_icons_show
.instance
:
377 IV_OT_icons_show
.instance
.auto_focusable
= False
379 filter_auto_focus
: StringProperty(
380 description
="Filter",
381 get
=lambda s
: prefs().popup_icons
.filter,
383 options
={'TEXTEDIT_UPDATE', 'SKIP_SAVE'})
384 filter: StringProperty(
385 description
="Filter",
386 get
=lambda s
: prefs().popup_icons
.filter,
388 options
={'TEXTEDIT_UPDATE'})
389 selected_icon
: StringProperty(
390 description
="Selected Icon",
391 get
=lambda s
: prefs().popup_icons
.selected_icon
,
392 set=set_selected_icon
)
394 def get_num_cols(self
, num_icons
):
395 return round(1.3 * math
.sqrt(num_icons
))
397 def draw_header(self
, layout
):
399 header
= layout
.box()
400 header
= header
.split(factor
=0.75) if self
.selected_icon
else \
402 row
= header
.row(align
=True)
403 row
.prop(pr
, "show_matcap_icons", text
="", icon
='SHADING_RENDERED')
404 row
.prop(pr
, "show_brush_icons", text
="", icon
='BRUSH_DATA')
405 row
.prop(pr
, "show_colorset_icons", text
="", icon
='COLOR')
406 row
.prop(pr
, "show_event_icons", text
="", icon
='HAND')
410 pr
, "copy_on_select", text
="",
411 icon
='COPYDOWN', toggle
=True)
412 if pr
.copy_on_select
:
413 sub
= row
.row(align
=True)
414 if bpy
.context
.window
.screen
.name
== "temp":
417 pr
, "close_on_select", text
="",
418 icon
='RESTRICT_SELECT_OFF', toggle
=True)
420 pr
, "auto_focus_filter", text
="",
421 icon
='OUTLINER_DATA_FONT', toggle
=True)
424 if self
.auto_focusable
and pr
.auto_focus_filter
:
425 row
.prop(self
, "filter_auto_focus", text
="", icon
='VIEWZOOM')
427 row
.prop(self
, "filter", text
="", icon
='VIEWZOOM')
429 if self
.selected_icon
:
431 row
.prop(self
, "selected_icon", text
="", icon
=self
.selected_icon
)
433 def draw(self
, context
):
436 self
.draw_header(col
)
438 history_num_cols
= int(
439 (self
.width
- POPUP_PADDING
) / (ui_scale() * ICON_SIZE
))
441 self
.get_num_cols(len(pr
.popup_icons
.filtered_icons
)),
444 subcol
= col
.column(align
=True)
446 if HISTORY
and pr
.show_history
:
447 pr
.popup_icons
.draw(subcol
.box(), history_num_cols
, HISTORY
)
449 pr
.popup_icons
.draw(subcol
.box(), num_cols
)
452 bpy
.context
.window
.screen
= bpy
.context
.window
.screen
454 def check(self
, context
):
457 def cancel(self
, context
):
458 IV_OT_icons_show
.instance
= None
459 IV_PT_icons
.tag_redraw()
461 def execute(self
, context
):
462 if not IV_OT_icons_show
.instance
:
464 IV_OT_icons_show
.instance
= None
467 if self
.selected_icon
and not pr
.copy_on_select
:
468 context
.window_manager
.clipboard
= self
.selected_icon
469 self
.report({'INFO'}, self
.selected_icon
)
470 pr
.popup_icons
.selected_icon
= ""
472 IV_PT_icons
.tag_redraw()
475 def invoke(self
, context
, event
):
477 pr
.popup_icons
.selected_icon
= ""
478 pr
.popup_icons
.filter = ""
479 IV_OT_icons_show
.instance
= self
480 self
.auto_focusable
= True
482 num_cols
= self
.get_num_cols(len(pr
.popup_icons
.filtered_icons
))
484 ui_scale() * (num_cols
* ICON_SIZE
+ POPUP_PADDING
),
485 context
.window
.width
- WIN_PADDING
)
487 return context
.window_manager
.invoke_props_dialog(
488 self
, width
=self
.width
)
494 IV_OT_panel_menu_call
,
502 if bpy
.app
.background
:
506 bpy
.utils
.register_class(cls
)
510 if bpy
.app
.background
:
514 bpy
.utils
.unregister_class(cls
)