append/prepend class methods for the header and panels (previously only worked for...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 18 Jan 2010 16:47:26 +0000 (16:47 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 18 Jan 2010 16:47:26 +0000 (16:47 +0000)
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)

release/scripts/modules/bpy_types.py

index 731757668bdc59680b5527a8a58225e8b8107221..a1278f4f7cda89161ef846b81029e252c283cc6c 100644 (file)
@@ -436,11 +436,11 @@ class Macro(StructRNA, metaclass=OrderedMeta):
         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,14 +457,26 @@ class Menu(StructRNA):
     @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