align columns (for multi-drag)
[blender-addons.git] / development_icon_get.py
blob24393554171ffc45ba2065a00d6834533e2ea89f
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 " "Console > Console Menu",
28 "warning": "",
29 "description": "Click an icon to display its name and "
30 "copy it to the clipboard",
31 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/"
32 "Py/Scripts/System/Display_All_Icons",
33 "category": "Development",
37 import bpy
40 def create_icon_list_all():
41 icons = bpy.types.UILayout.bl_rna.functions['prop'].parameters['icon'].\
42 enum_items.keys()
44 icons.remove("NONE")
46 return icons
49 def create_icon_list():
50 icons = create_icon_list_all()
51 search = bpy.context.scene.icon_props.search.lower()
53 if search == "":
54 pass
55 else:
56 icons = [key for key in icons if search in key.lower()]
58 return icons
61 class WM_OT_icon_info(bpy.types.Operator):
62 bl_idname = "wm.icon_info"
63 bl_label = "Icon Info"
64 bl_description = "Click to copy this icon name to the clipboard"
65 icon = bpy.props.StringProperty()
66 icon_scroll = bpy.props.IntProperty()
68 def invoke(self, context, event):
69 bpy.data.window_managers['WinMan'].clipboard = self.icon
70 self.report({'INFO'}, "Icon ID: %s" % self.icon)
71 return {'FINISHED'}
74 class OBJECT_PT_icons(bpy.types.Panel):
75 bl_space_type = "TEXT_EDITOR"
76 bl_region_type = "UI"
77 bl_label = "All icons"
79 def __init__(self):
80 self.amount = 10
81 self.icon_list = create_icon_list()
83 def draw(self, context):
84 props = context.scene.icon_props
85 # polling for updates
86 if props.search != CONSOLE_HT_icons._search_old:
87 self.icon_list = create_icon_list()
88 # adjusting max value of scroller
89 # IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
90 # max=max(1, len(self.icon_list) - self.amount + 1),
91 # description="Drag to scroll icons")
93 box = self.layout.box()
94 # scroll view
95 if not props.expand:
96 # expand button
97 toprow = box.row()
98 toprow.prop(props, "expand", icon="TRIA_RIGHT", icon_only=True,
99 text="", emboss=False) # icon_only broken?
100 # search buttons
101 row = toprow.row(align=True)
102 row.prop(props, "search", icon="VIEWZOOM", text="")
103 # scroll button
104 row = toprow.row()
105 row.active = props.bl_rna.scroll[1]['max'] > 1
106 row.prop(props, "scroll")
108 # icons
109 row = box.row(align=True)
110 if len(self.icon_list) == 0:
111 row.label("No icons found")
112 else:
113 for icon in self.icon_list[props.scroll - 1:
114 props.scroll - 1 + self.amount]:
115 row.operator("wm.icon_info", text=" ", icon=icon,
116 emboss=False).icon = icon
117 if len(self.icon_list) < self.amount:
118 for i in range(self.amount - len(self.icon_list) \
119 % self.amount):
120 row.label("")
122 # expanded view
123 else:
124 # expand button
125 toprow = box.row()
126 toprow.prop(props, "expand", icon="TRIA_DOWN", icon_only=True,
127 text="", emboss=False)
128 # search buttons
129 row = toprow.row(align=True)
130 row.prop(props, "search", icon="VIEWZOOM", text="")
131 # scroll button
132 row = toprow.row()
133 row.active = False
134 row.prop(props, "scroll")
136 # icons
137 col = box.column(align=True)
138 if len(self.icon_list) == 0:
139 col.label("No icons found")
140 else:
141 for i, icon in enumerate(self.icon_list):
142 if i % self.amount == 0:
143 row = col.row(align=True)
144 row.operator("wm.icon_info", text=" ", icon=icon,
145 emboss=False).icon = icon
146 for i in range(self.amount - len(self.icon_list) \
147 % self.amount):
148 row.label("")
151 class CONSOLE_HT_icons(bpy.types.Header):
152 bl_space_type = 'CONSOLE'
153 _search_old = ""
155 def __init__(self):
156 self.amount = 10
157 self.icon_list = create_icon_list()
159 def draw(self, context):
160 props = context.scene.icon_props
161 # polling for updates
162 if props.search != self.__class__._search_old:
163 self.__class__._search_old = props.search
164 self.icon_list = create_icon_list()
165 # adjusting max value of scroller
166 # IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
167 # max=max(1, len(self.icon_list) - self.amount + 1),
168 # description="Drag to scroll icons")
170 # scroll view
171 if props.console:
172 layout = self.layout
173 layout.separator()
174 # search buttons
175 row = layout.row()
176 row.prop(props, "search", icon="VIEWZOOM")
177 # scroll button
178 row = layout.row()
179 row.active = props.bl_rna.scroll[1]['max'] > 1
180 row.prop(props, "scroll")
182 # icons
183 row = layout.row(align=True)
184 if len(self.icon_list) == 0:
185 row.label("No icons found")
186 else:
187 for icon in self.icon_list[props.scroll - 1:
188 props.scroll - 1 + self.amount]:
189 row.operator("wm.icon_info", text="", icon=icon,
190 emboss=False).icon = icon
193 def menu_func(self, context):
194 self.layout.prop(bpy.context.scene.icon_props, 'console')
197 def register():
198 global IconProps
200 icons_total = len(create_icon_list_all())
201 icons_per_row = 10
203 class IconProps(bpy.types.PropertyGroup):
205 Fake module like class
206 bpy.context.scene.icon_props
208 console = bpy.props.BoolProperty(name='Show System Icons',
209 description='Display the Icons in the console header',
210 default=False)
211 expand = bpy.props.BoolProperty(name="Expand",
212 description="Expand, to display all icons at once",
213 default=False)
214 search = bpy.props.StringProperty(name="Search",
215 description="Search for icons by name",
216 default="")
217 scroll = bpy.props.IntProperty(name="Scroll",
218 description="Drag to scroll icons",
219 default=1, min=1, max=max(1, icons_total - icons_per_row + 1))
221 bpy.utils.register_module(__name__)
222 bpy.types.Scene.icon_props = bpy.props.PointerProperty(type=IconProps)
223 bpy.types.CONSOLE_MT_console.append(menu_func)
226 def unregister():
227 if bpy.context.scene.get('icon_props') != None:
228 del bpy.context.scene['icon_props']
229 try:
230 del bpy.types.Scene.icon_props
231 bpy.types.CONSOLE_MT_console.remove(menu_func)
232 except:
233 pass
234 if __name__ == "__main__":
235 # unregistering is only done automatically when run as addon
236 bpy.utils.unregister_class(OBJECT_PT_icons)
237 bpy.utils.unregister_class(CONSOLE_HT_icons)
239 bpy.utils.unregister_module(__name__)
242 if __name__ == "__main__":
243 register()