[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1146] contrib/py/scripts/addons/ system_icon_get.py: Updated for Blender 2.55.

Bart Crouch bartius.crouch at gmail.com
Mon Nov 8 13:48:34 CET 2010


Revision: 1146
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1146
Author:   crouch
Date:     2010-11-08 13:48:34 +0100 (Mon, 08 Nov 2010)

Log Message:
-----------
Updated for Blender 2.55.
Old Contrib version was already lagging behind several versions from what was available on BlenderArtists.

Modified Paths:
--------------
    contrib/py/scripts/addons/system_icon_get.py

Modified: contrib/py/scripts/addons/system_icon_get.py
===================================================================
--- contrib/py/scripts/addons/system_icon_get.py	2010-11-08 10:45:48 UTC (rev 1145)
+++ contrib/py/scripts/addons/system_icon_get.py	2010-11-08 12:48:34 UTC (rev 1146)
@@ -1,67 +1,78 @@
-# ***** BEGIN GPL LICENSE BLOCK *****
+# ##### BEGIN GPL LICENSE BLOCK #####
 #
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
-# GNU General Public License for more details.
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-# ***** END GPL LICENCE BLOCK *****
-# retrieving the masterlist with all icon names
+# ##### END GPL LICENSE BLOCK #####
 
+# <pep8 compliant>
+
+
 bl_addon_info = {
-    "name": "Display All Icons",
-    "author": "",
-    "version": (0,3),
-    "blender": (2, 5, 3),
-    "api": 32411,
-    "location": "Object > Properties",
-    "description": "Fetch Icons from internet * display",
-    "warning": "",
-    "wiki_url": 'http://wiki.blender.org/index.php/Extensions:2.5/Py/' \
-        'Scripts/',
-    "tracker_url": "https://projects.blender.org/tracker/index.php?" \
-        "func==detail&aid=22011&group_id=153&atid=468",
-    "category": "System"}
+    'name': 'Icons',
+    'author': 'Crouch, N.tox, PKHG',
+    'version': (1, 3, 1),
+    'blender': (2, 5, 5),
+    'api': 32738,
+    'location': 'Properties window > Object tab',
+    'warning': '',
+    'description': 'Creates a panel displaying all icons and their names.',
+    'wiki_url': '',
+    'tracker_url': '',
+    'category': 'System'}
 
+
 import bpy
-try:
-    import urllib.request
-    file = urllib.request.urlopen('https://svn.blender.org/svnroot/bf-blender/trunk/blender/source/blender/editors/include/UI_icons.h')
-except:
-    print("Couldn't find the urllib module or was unable to connect to the internet")
-    file = False
-if file:
-    lines = str(file.read()).split('\\n')
-else:
-    lines = []
+import urllib.request
 
-# get the icon names of existing non-blank icons
-icons = []
-for l in lines:
-    if l[:9] == 'DEF_ICON(':
-        n = l.strip().split('(')[1].split(')')[0]
-        if n[:10] != 'ICON_BLANK':
-            icons.append(n[5:])
 
+# create list with all icon names
+def createIcons():
+    # retrieving the masterlist with all icon names
+    try:
+        file = urllib.request.urlopen('https://svn.blender.org/svnroot/'\
+        'bf-blender/trunk/blender/source/blender/editors/include/UI_icons.h')
+    except:
+        print("Couldn't find the urllib module or was unable to connect to"\
+        " the internet")
+        file = ''
+    # get the icon names of existing non-blank icons
+    icons = [str(l)[11:(-4 if l[-2]==b')' else (l.index(b')')+2))] for l in \
+        file if ( (l[:9]==b'DEF_ICON(') and (l[9:19]!=b'ICON_BLANK') )]
+    icons.sort()
+    return icons
+
+
 # create custom operator for each icon
-def printdoc_invoke(self, context, event):
-    print(self.bl_description)
-    return{'FINISHED'}
-for i in icons:
-    c = type(i,(bpy.types.Operator,),dict(bl_idname="ICONDISPLAY_OT_"+i, bl_label="ICONDISPLAY_OT_"+i, bl_description=i))
-    setattr(c, 'invoke', printdoc_invoke)
-    bpy.types.register(c)
+def createOperators(icons):
+    for i in icons:
+        class custom_op(bpy.types.Operator):
+            bl_idname = "ICONDISPLAY_OT_"+i
+            bl_label = "ICONDISPLAY_OT_"+i
+            bl_description = i
+        
+            def invoke(self, context, event):
+                print(self.bl_description)
+                return {'FINISHED'}
 
+
+# main function that calls subroutines
+def main():
+    icons = createIcons()
+    createOperators(icons)
+
+
 # draw the panel with the icons
 class OBJECT_PT_icons(bpy.types.Panel):
     bl_space_type = "PROPERTIES"
@@ -69,26 +80,28 @@
     bl_context = "object"
     bl_label = "All icons"
     
+    icons = createIcons()
+    
     def draw(self, context):
         amount = 10
         cols = []
         layout = self.layout
         split = layout.split(percentage=1.0/amount)
-        for i in range(amount):
-            cols.append(split.column())
-        for i in range(len(icons)):
+        for i,icon in enumerate(self.icons):
+            if i<amount: cols.append(split.column())
             col = cols[i%amount].row()
             try:
-                col.operator("icondisplay."+icons[i], text="", icon=icons[i])
+                col.operator("icondisplay."+icon, text="", icon=icon)
             except:
-                col.operator("icondisplay."+icons[i], text="new")
+                col.operator("icondisplay."+icon, text="new")
 
-###################################
+
+main()
+
+
 def register():
     pass
 
+
 def unregister():
-    pass
-
-if __name__ == "__main__":
-    register()
+    pass
\ No newline at end of file




More information about the Bf-extensions-cvs mailing list