~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons/development_icon_get.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ##### BEGIN GPL LICENSE BLOCK #####
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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.
 
16
#
 
17
# ##### END GPL LICENSE BLOCK #####
 
18
 
 
19
# <pep8 compliant>
 
20
 
 
21
 
 
22
bl_info = {
 
23
    'name': 'Icons',
 
24
    'author': 'Crouch, N.tox, PKHG, Campbell Barton, Dany Lebel',
 
25
    'version': (1, 5, 1),
 
26
    "blender": (2, 5, 7),
 
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.5/'\
 
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'}
 
37
 
 
38
 
 
39
import bpy
 
40
 
 
41
 
 
42
def create_icon_list_all():
 
43
    icons = bpy.types.UILayout.bl_rna.functions['prop'].parameters['icon'].\
 
44
        enum_items.keys()
 
45
 
 
46
    icons.remove("NONE")
 
47
 
 
48
    return icons
 
49
 
 
50
 
 
51
def create_icon_list():
 
52
    icons = create_icon_list_all()
 
53
    search = bpy.context.scene.icon_props.search.lower()
 
54
 
 
55
    if search == "":
 
56
        pass
 
57
    else:
 
58
        icons = [key for key in icons if search in key.lower()]
 
59
 
 
60
    return icons
 
61
 
 
62
 
 
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()
 
69
 
 
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'}
 
74
 
 
75
 
 
76
class OBJECT_PT_icons(bpy.types.Panel):
 
77
    bl_space_type = "TEXT_EDITOR"
 
78
    bl_region_type = "UI"
 
79
    bl_label = "All icons"
 
80
 
 
81
    def __init__(self):
 
82
        self.amount = 10
 
83
        self.icon_list = create_icon_list()
 
84
 
 
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")
 
94
 
 
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
                emboss=False)
 
102
            # search buttons
 
103
            row = toprow.row(align=True)
 
104
            row.prop(props, "search", icon="VIEWZOOM")
 
105
            # scroll button
 
106
            row = toprow.row()
 
107
            row.active = props.bl_rna.scroll[1]['max'] > 1
 
108
            row.prop(props, "scroll")
 
109
 
 
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("")
 
123
 
 
124
        # expanded view
 
125
        else:
 
126
            # expand button
 
127
            toprow = box.row()
 
128
            toprow.prop(props, "expand", icon="TRIA_DOWN", icon_only=True,
 
129
                emboss=False)
 
130
            # search buttons
 
131
            row = toprow.row(align=True)
 
132
            row.prop(props, "search", icon="VIEWZOOM")
 
133
            # scroll button
 
134
            row = toprow.row()
 
135
            row.active = False
 
136
            row.prop(props, "scroll")
 
137
 
 
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("")
 
151
 
 
152
 
 
153
class CONSOLE_HT_icons(bpy.types.Header):
 
154
    bl_space_type = 'CONSOLE'
 
155
    _search_old = ""
 
156
 
 
157
    def __init__(self):
 
158
        self.amount = 10
 
159
        self.icon_list = create_icon_list()
 
160
 
 
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")
 
171
 
 
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")
 
183
 
 
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
 
193
 
 
194
 
 
195
def menu_func(self, context):
 
196
    self.layout.prop(bpy.context.scene.icon_props, 'console')
 
197
 
 
198
 
 
199
def register():
 
200
    global IconProps
 
201
 
 
202
    icons_total = len(create_icon_list_all())
 
203
    icons_per_row = 10
 
204
 
 
205
    class IconProps(bpy.types.PropertyGroup):
 
206
        """
 
207
        Fake module like class
 
208
        bpy.context.scene.icon_props
 
209
        """
 
210
        console = bpy.props.BoolProperty(name='Show System Icons',
 
211
            description='Display the Icons in the console header', default=False)
 
212
        expand = bpy.props.BoolProperty(default=False,
 
213
            description="Expand, to display all icons at once")
 
214
        search = bpy.props.StringProperty(default="",
 
215
            description="Search for icons by name")
 
216
        scroll = bpy.props.IntProperty(default=1, min=1,
 
217
            max=max(1, icons_total - icons_per_row + 1),
 
218
            description="Drag to scroll icons")
 
219
 
 
220
    bpy.utils.register_module(__name__)
 
221
    bpy.types.Scene.icon_props = bpy.props.PointerProperty(type=IconProps)
 
222
    bpy.types.CONSOLE_MT_console.append(menu_func)
 
223
 
 
224
 
 
225
def unregister():
 
226
    if bpy.context.scene.get('icon_props') != None:
 
227
        del bpy.context.scene['icon_props']
 
228
    try:
 
229
        del bpy.types.Scene.icon_props
 
230
        bpy.types.CONSOLE_MT_console.remove(menu_func)
 
231
    except:
 
232
        pass
 
233
    if __name__ == "__main__":
 
234
        # unregistering is only done automatically when run as addon
 
235
        bpy.utils.unregister_class(OBJECT_PT_icons)
 
236
        bpy.utils.unregister_class(CONSOLE_HT_icons)
 
237
 
 
238
    bpy.utils.unregister_module(__name__)
 
239
 
 
240
 
 
241
if __name__ == "__main__":
 
242
    register()