[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1240] contrib/py/scripts/addons/ system_icon_get.py: Major update (version 1.4.0)

Bart Crouch bartius.crouch at gmail.com
Mon Dec 6 15:16:12 CET 2010


Revision: 1240
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1240
Author:   crouch
Date:     2010-12-06 15:16:12 +0100 (Mon, 06 Dec 2010)

Log Message:
-----------
Major update (version 1.4.0)

- Moved from properties window to text-editor
- Implemented scroller (displaying all icons at once is optional)
- Copy icon name to clipboard when pressed
- Layout improved
- Pep-8 compliant

Special thanks to Dany Lebel

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-12-06 08:27:35 UTC (rev 1239)
+++ contrib/py/scripts/addons/system_icon_get.py	2010-12-06 14:16:12 UTC (rev 1240)
@@ -21,56 +21,107 @@
 
 bl_addon_info = {
     'name': 'Icons',
-    'author': 'Crouch, N.tox, PKHG',
-    'version': (1, 3, 1),
-    'blender': (2, 5, 5),
-    'api': 32738,
-    'location': 'Properties window > Object tab',
+    'author': 'Crouch, N.tox, PKHG, Campbell Barton, Dany Lebel',
+    'version': (1, 4, 0),
+    'blender': (2, 5, 6),
+    'api': 33479,
+    'location': 'Text window > Properties panel (ctrl+F)',
     'warning': '',
-    'description': 'Creates a panel displaying all icons and their names.',
+    'description': 'Click an icon to display its name and copy it '\
+        'to the clipboard',
     'wiki_url': '',
-    'tracker_url': '',
+    'tracker_url': 'http://projects.blender.org/tracker/index.php?'\
+        'func=detail&aid=22011&group_id=153&atid=468',
     'category': 'System'}
 
 
 import bpy
-import urllib.request
 
+
+class IconProps(bpy.types.IDPropertyGroup):
+    """
+    Fake module like class
+    bpy.context.scene.icon_props
+    """
+    pass
+
+
 class WM_OT_icon_info(bpy.types.Operator):
     bl_label = "Icon Info"
     icon = bpy.props.StringProperty()
-
+    icon_scroll = bpy.props.IntProperty()
+    
     def invoke(self, context, event):
-        self.report({'INFO'}, "Icon ID: '%s'" % self.icon)
+        bpy.data.window_managers['WinMan'].clipboard = self.icon
+        self.report({'INFO'}, "Icon ID: %s" % self.icon)
         return {'FINISHED'}
 
 
 class OBJECT_PT_icons(bpy.types.Panel):
-    bl_space_type = "PROPERTIES"
-    bl_region_type = "WINDOW"
-    bl_context = "object"
+    bl_space_type = "TEXT_EDITOR"
+    bl_region_type = "UI"
     bl_label = "All icons"
-
+    
     @staticmethod
     def _icon_list():
-        return sorted(bpy.types.UILayout.bl_rna.functions['prop'].parameters['icon'].items.keys())
-
+        list = sorted(bpy.types.UILayout.bl_rna.functions['prop'].\
+            parameters['icon'].items.keys())
+        list.remove("BLENDER") # hack for icon that messes up layout
+        return list
+    
+    @staticmethod
+    def _amount():
+        return 10
+    
     def draw(self, context):
-        amount = 10
-        cols = []
-        layout = self.layout
-        split = layout.split(percentage=1.0 / amount)
+        split = self.layout.split(percentage=0.05)
+        
+        # scroll view
+        if not context.scene.icon_props.expand:
+            split.prop(context.scene.icon_props, "expand",
+                icon="TRIA_RIGHT", icon_only=True, emboss=False)
+            split.prop(context.scene.icon_props, "scroll", slider=True)
+            
+            row = self.layout.row(align=True)
+            for icon in self._icon_list()[context.scene.icon_props.scroll-1:
+            context.scene.icon_props.scroll-1+self._amount()]:
+                row.operator("wm.icon_info", text="", icon=icon).icon = icon
+        
+        # expanded view
+        else:
+            split.prop(context.scene.icon_props, "expand",
+                icon="TRIA_DOWN", icon_only=True, emboss=False)
+            row = split.row()
+            row.active = False
+            row.prop(context.scene.icon_props, "scroll", slider=True)
+            
+            col = self.layout.column(align=True)
+            for i, icon in enumerate(self._icon_list()):
+                if i % self._amount() == 0:
+                    row = col.row(align=True)
+                row.operator("wm.icon_info", text="", icon=icon).icon = icon
 
-        for i, icon in enumerate(self._icon_list()):
-            if i < amount:
-                cols.append(split.column())
 
-            col = cols[i % amount].row()
-            col.operator("wm.icon_info", text="", icon=icon).icon = icon
+def register():
+    icons_total = len(bpy.types.OBJECT_PT_icons._icon_list())
+    icons_per_row = bpy.types.OBJECT_PT_icons._amount()
+    
+    bpy.types.Scene.icon_props = bpy.props.PointerProperty(type = IconProps)
+    IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
+        max=icons_total - icons_per_row + 1,
+        description="Drag to scroll icons")
+    IconProps.expand = bpy.props.BoolProperty(default=False,
+        description="Expand, to display all icons at once")
 
 
-def register():
-    pass
+def unregister():
+    if bpy.context.scene.get('icon_props') != None:
+        del bpy.context.scene['icon_props']
+    try:
+        del bpy.types.Scene.icon_props
+    except:
+        pass
 
-def unregister():
-    pass
+
+if __name__ == "__main__":
+    register()




More information about the Bf-extensions-cvs mailing list