fix for error reading gzip'd x3d/vrml files
[blender-addons.git] / development_icon_get.py
blob927c218b880ee122ce05ba303dd9b5171f84b908
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': 'http://projects.blender.org/tracker/index.php?'\
35 'func=detail&aid=22011',
36 'category': 'Development'}
39 import bpy
42 def create_icon_list_all():
43 icons = bpy.types.UILayout.bl_rna.functions['prop'].parameters['icon'].\
44 enum_items.keys()
46 icons.remove("NONE")
48 return icons
51 def create_icon_list():
52 icons = create_icon_list_all()
53 search = bpy.context.scene.icon_props.search.lower()
55 if search == "":
56 pass
57 else:
58 icons = [key for key in icons if search in key.lower()]
60 return icons
63 class WM_OT_icon_info(bpy.types.Operator):
64 bl_idname = "wm.icon_info"
65 bl_label = "Icon Info"
66 bl_description = "Click to copy this icon name to the clipboard"
67 icon = bpy.props.StringProperty()
68 icon_scroll = bpy.props.IntProperty()
70 def invoke(self, context, event):
71 bpy.data.window_managers['WinMan'].clipboard = self.icon
72 self.report({'INFO'}, "Icon ID: %s" % self.icon)
73 return {'FINISHED'}
76 class OBJECT_PT_icons(bpy.types.Panel):
77 bl_space_type = "TEXT_EDITOR"
78 bl_region_type = "UI"
79 bl_label = "All icons"
81 def __init__(self):
82 self.amount = 10
83 self.icon_list = create_icon_list()
85 def draw(self, context):
86 props = context.scene.icon_props
87 # polling for updates
88 if props.search != CONSOLE_HT_icons._search_old:
89 self.icon_list = create_icon_list()
90 # adjusting max value of scroller
91 # IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
92 # max=max(1, len(self.icon_list) - self.amount + 1),
93 # description="Drag to scroll icons")
95 box = self.layout.box()
96 # scroll view
97 if not props.expand:
98 # expand button
99 toprow = box.row()
100 toprow.prop(props, "expand", icon="TRIA_RIGHT", icon_only=True,
101 text="", emboss=False) # icon_only broken?
102 # search buttons
103 row = toprow.row(align=True)
104 row.prop(props, "search", icon="VIEWZOOM", text="")
105 # scroll button
106 row = toprow.row()
107 row.active = props.bl_rna.scroll[1]['max'] > 1
108 row.prop(props, "scroll")
110 # icons
111 row = box.row(align=True)
112 if len(self.icon_list) == 0:
113 row.label("No icons found")
114 else:
115 for icon in self.icon_list[props.scroll - 1:
116 props.scroll - 1 + self.amount]:
117 row.operator("wm.icon_info", text=" ", icon=icon,
118 emboss=False).icon = icon
119 if len(self.icon_list) < self.amount:
120 for i in range(self.amount - len(self.icon_list) \
121 % self.amount):
122 row.label("")
124 # expanded view
125 else:
126 # expand button
127 toprow = box.row()
128 toprow.prop(props, "expand", icon="TRIA_DOWN", icon_only=True,
129 text="", emboss=False)
130 # search buttons
131 row = toprow.row(align=True)
132 row.prop(props, "search", icon="VIEWZOOM", text="")
133 # scroll button
134 row = toprow.row()
135 row.active = False
136 row.prop(props, "scroll")
138 # icons
139 col = box.column(align=True)
140 if len(self.icon_list) == 0:
141 col.label("No icons found")
142 else:
143 for i, icon in enumerate(self.icon_list):
144 if i % self.amount == 0:
145 row = col.row(align=True)
146 row.operator("wm.icon_info", text=" ", icon=icon,
147 emboss=False).icon = icon
148 for i in range(self.amount - len(self.icon_list) \
149 % self.amount):
150 row.label("")
153 class CONSOLE_HT_icons(bpy.types.Header):
154 bl_space_type = 'CONSOLE'
155 _search_old = ""
157 def __init__(self):
158 self.amount = 10
159 self.icon_list = create_icon_list()
161 def draw(self, context):
162 props = context.scene.icon_props
163 # polling for updates
164 if props.search != self.__class__._search_old:
165 self.__class__._search_old = props.search
166 self.icon_list = create_icon_list()
167 # adjusting max value of scroller
168 # IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
169 # max=max(1, len(self.icon_list) - self.amount + 1),
170 # description="Drag to scroll icons")
172 # scroll view
173 if props.console:
174 layout = self.layout
175 layout.separator()
176 # search buttons
177 row = layout.row()
178 row.prop(props, "search", icon="VIEWZOOM")
179 # scroll button
180 row = layout.row()
181 row.active = props.bl_rna.scroll[1]['max'] > 1
182 row.prop(props, "scroll")
184 # icons
185 row = layout.row(align=True)
186 if len(self.icon_list) == 0:
187 row.label("No icons found")
188 else:
189 for icon in self.icon_list[props.scroll - 1:
190 props.scroll - 1 + self.amount]:
191 row.operator("wm.icon_info", text="", icon=icon,
192 emboss=False).icon = icon
195 def menu_func(self, context):
196 self.layout.prop(bpy.context.scene.icon_props, 'console')
199 def register():
200 global IconProps
202 icons_total = len(create_icon_list_all())
203 icons_per_row = 10
205 class IconProps(bpy.types.PropertyGroup):
207 Fake module like class
208 bpy.context.scene.icon_props
210 console = bpy.props.BoolProperty(name='Show System Icons',
211 description='Display the Icons in the console header',
212 default=False)
213 expand = bpy.props.BoolProperty(name="Expand",
214 description="Expand, to display all icons at once",
215 default=False)
216 search = bpy.props.StringProperty(name="Search",
217 description="Search for icons by name",
218 default="")
219 scroll = bpy.props.IntProperty(name="Scroll",
220 description="Drag to scroll icons",
221 default=1, min=1, max=max(1, icons_total - icons_per_row + 1))
223 bpy.utils.register_module(__name__)
224 bpy.types.Scene.icon_props = bpy.props.PointerProperty(type=IconProps)
225 bpy.types.CONSOLE_MT_console.append(menu_func)
228 def unregister():
229 if bpy.context.scene.get('icon_props') != None:
230 del bpy.context.scene['icon_props']
231 try:
232 del bpy.types.Scene.icon_props
233 bpy.types.CONSOLE_MT_console.remove(menu_func)
234 except:
235 pass
236 if __name__ == "__main__":
237 # unregistering is only done automatically when run as addon
238 bpy.utils.unregister_class(OBJECT_PT_icons)
239 bpy.utils.unregister_class(CONSOLE_HT_icons)
241 bpy.utils.unregister_module(__name__)
244 if __name__ == "__main__":
245 register()