Remove workaround for uuid, resolved with the Python3.4x and MSVC2013 move.
[blender-addons.git] / development_icon_get.py
blobef5f8f30ce2ee0886b34f9f1e4b43e1c5388d170
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 #####
19 # <pep8 compliant>
22 bl_info = {
23 'name': 'Icons',
24 'author': 'Crouch, N.tox, PKHG, Campbell Barton, Dany Lebel',
25 'version': (1, 5, 2),
26 "blender": (2, 57, 0),
27 'location': 'Text Editor > Properties or '\
28 'Console > Console Menu',
29 'warning': '',
30 'description': 'Click an icon to display its name and copy it '\
31 'to the clipboard',
32 'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.6/'\
33 'Py/Scripts/System/Display_All_Icons',
34 'tracker_url': 'https://developer.blender.org/T22011',
35 'category': 'Development'}
38 import bpy
41 def create_icon_list_all():
42 icons = bpy.types.UILayout.bl_rna.functions['prop'].parameters['icon'].\
43 enum_items.keys()
45 icons.remove("NONE")
47 return icons
50 def create_icon_list():
51 icons = create_icon_list_all()
52 search = bpy.context.scene.icon_props.search.lower()
54 if search == "":
55 pass
56 else:
57 icons = [key for key in icons if search in key.lower()]
59 return icons
62 class WM_OT_icon_info(bpy.types.Operator):
63 bl_idname = "wm.icon_info"
64 bl_label = "Icon Info"
65 bl_description = "Click to copy this icon name to the clipboard"
66 icon = bpy.props.StringProperty()
67 icon_scroll = bpy.props.IntProperty()
69 def invoke(self, context, event):
70 bpy.data.window_managers['WinMan'].clipboard = self.icon
71 self.report({'INFO'}, "Icon ID: %s" % self.icon)
72 return {'FINISHED'}
75 class OBJECT_PT_icons(bpy.types.Panel):
76 bl_space_type = "TEXT_EDITOR"
77 bl_region_type = "UI"
78 bl_label = "All icons"
80 def __init__(self):
81 self.amount = 10
82 self.icon_list = create_icon_list()
84 def draw(self, context):
85 props = context.scene.icon_props
86 # polling for updates
87 if props.search != CONSOLE_HT_icons._search_old:
88 self.icon_list = create_icon_list()
89 # adjusting max value of scroller
90 # IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
91 # max=max(1, len(self.icon_list) - self.amount + 1),
92 # description="Drag to scroll icons")
94 box = self.layout.box()
95 # scroll view
96 if not props.expand:
97 # expand button
98 toprow = box.row()
99 toprow.prop(props, "expand", icon="TRIA_RIGHT", icon_only=True,
100 text="", emboss=False) # icon_only broken?
101 # search buttons
102 row = toprow.row(align=True)
103 row.prop(props, "search", icon="VIEWZOOM", text="")
104 # scroll button
105 row = toprow.row()
106 row.active = props.bl_rna.scroll[1]['max'] > 1
107 row.prop(props, "scroll")
109 # icons
110 row = box.row(align=True)
111 if len(self.icon_list) == 0:
112 row.label("No icons found")
113 else:
114 for icon in self.icon_list[props.scroll - 1:
115 props.scroll - 1 + self.amount]:
116 row.operator("wm.icon_info", text=" ", icon=icon,
117 emboss=False).icon = icon
118 if len(self.icon_list) < self.amount:
119 for i in range(self.amount - len(self.icon_list) \
120 % self.amount):
121 row.label("")
123 # expanded view
124 else:
125 # expand button
126 toprow = box.row()
127 toprow.prop(props, "expand", icon="TRIA_DOWN", icon_only=True,
128 text="", emboss=False)
129 # search buttons
130 row = toprow.row(align=True)
131 row.prop(props, "search", icon="VIEWZOOM", text="")
132 # scroll button
133 row = toprow.row()
134 row.active = False
135 row.prop(props, "scroll")
137 # icons
138 col = box.column(align=True)
139 if len(self.icon_list) == 0:
140 col.label("No icons found")
141 else:
142 for i, icon in enumerate(self.icon_list):
143 if i % self.amount == 0:
144 row = col.row(align=True)
145 row.operator("wm.icon_info", text=" ", icon=icon,
146 emboss=False).icon = icon
147 for i in range(self.amount - len(self.icon_list) \
148 % self.amount):
149 row.label("")
152 class CONSOLE_HT_icons(bpy.types.Header):
153 bl_space_type = 'CONSOLE'
154 _search_old = ""
156 def __init__(self):
157 self.amount = 10
158 self.icon_list = create_icon_list()
160 def draw(self, context):
161 props = context.scene.icon_props
162 # polling for updates
163 if props.search != self.__class__._search_old:
164 self.__class__._search_old = props.search
165 self.icon_list = create_icon_list()
166 # adjusting max value of scroller
167 # IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
168 # max=max(1, len(self.icon_list) - self.amount + 1),
169 # description="Drag to scroll icons")
171 # scroll view
172 if props.console:
173 layout = self.layout
174 layout.separator()
175 # search buttons
176 row = layout.row()
177 row.prop(props, "search", icon="VIEWZOOM")
178 # scroll button
179 row = layout.row()
180 row.active = props.bl_rna.scroll[1]['max'] > 1
181 row.prop(props, "scroll")
183 # icons
184 row = layout.row(align=True)
185 if len(self.icon_list) == 0:
186 row.label("No icons found")
187 else:
188 for icon in self.icon_list[props.scroll - 1:
189 props.scroll - 1 + self.amount]:
190 row.operator("wm.icon_info", text="", icon=icon,
191 emboss=False).icon = icon
194 def menu_func(self, context):
195 self.layout.prop(bpy.context.scene.icon_props, 'console')
198 def register():
199 global IconProps
201 icons_total = len(create_icon_list_all())
202 icons_per_row = 10
204 class IconProps(bpy.types.PropertyGroup):
206 Fake module like class
207 bpy.context.scene.icon_props
209 console = bpy.props.BoolProperty(name='Show System Icons',
210 description='Display the Icons in the console header',
211 default=False)
212 expand = bpy.props.BoolProperty(name="Expand",
213 description="Expand, to display all icons at once",
214 default=False)
215 search = bpy.props.StringProperty(name="Search",
216 description="Search for icons by name",
217 default="")
218 scroll = bpy.props.IntProperty(name="Scroll",
219 description="Drag to scroll icons",
220 default=1, min=1, max=max(1, icons_total - icons_per_row + 1))
222 bpy.utils.register_module(__name__)
223 bpy.types.Scene.icon_props = bpy.props.PointerProperty(type=IconProps)
224 bpy.types.CONSOLE_MT_console.append(menu_func)
227 def unregister():
228 if bpy.context.scene.get('icon_props') != None:
229 del bpy.context.scene['icon_props']
230 try:
231 del bpy.types.Scene.icon_props
232 bpy.types.CONSOLE_MT_console.remove(menu_func)
233 except:
234 pass
235 if __name__ == "__main__":
236 # unregistering is only done automatically when run as addon
237 bpy.utils.unregister_class(OBJECT_PT_icons)
238 bpy.utils.unregister_class(CONSOLE_HT_icons)
240 bpy.utils.unregister_module(__name__)
243 if __name__ == "__main__":
244 register()