[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26081] trunk/blender/release/scripts/ modules/bpy_types.py: append/ prepend class methods for the header and panels ( previously only worked for menus)

Campbell Barton ideasman42 at gmail.com
Mon Jan 18 17:47:26 CET 2010


Revision: 26081
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26081
Author:   campbellbarton
Date:     2010-01-18 17:47:26 +0100 (Mon, 18 Jan 2010)

Log Message:
-----------
append/prepend class methods for the header and panels (previously only worked for menus)

Example of adding a button to the view header;

 def draw_custom(self, context): self.layout.operator("some.operator")
 bpy.types.VIEW3D_HT_header.append(draw_custom)

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy_types.py

Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py	2010-01-18 16:31:33 UTC (rev 26080)
+++ trunk/blender/release/scripts/modules/bpy_types.py	2010-01-18 16:47:26 UTC (rev 26081)
@@ -436,11 +436,11 @@
         return ops.macro_define(self, opname)
 
 
-class Menu(StructRNA):
+class _GenericUI:
     __slots__ = ()
 
     @classmethod
-    def _dyn_menu_initialize(cls):
+    def _dyn_ui_initialize(cls):
         draw_funcs = getattr(cls.draw, "_draw_funcs", None)
 
         if draw_funcs is None:
@@ -457,15 +457,27 @@
     @classmethod
     def append(cls, draw_func):
         """Prepend an draw function to this menu, takes the same arguments as the menus draw function."""
-        draw_funcs = cls._dyn_menu_initialize()
+        draw_funcs = cls._dyn_ui_initialize()
         draw_funcs.append(draw_func)
 
     @classmethod
     def prepend(cls, draw_func):
         """Prepend a draw function to this menu, takes the same arguments as the menus draw function."""
-        draw_funcs = cls._dyn_menu_initialize()
-        draw_funcs.insert(0, draw_func)
+        draw_funcs = cls._dyn_ui_initialize()
+        draw_funcs.insert(0, draw_func)    
 
+
+class Panel(StructRNA, _GenericUI):
+    __slots__ = ()
+
+
+class Header(StructRNA, _GenericUI):
+    __slots__ = ()
+
+
+class Menu(StructRNA, _GenericUI):
+    __slots__ = ()
+
     def path_menu(self, searchpaths, operator):
         layout = self.layout
         # hard coded to set the operators 'path' to the filename.





More information about the Bf-blender-cvs mailing list