[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25556] trunk/blender: replace dynamic_menu.py with Menu classmethods much less complicated.
Campbell Barton
ideasman42 at gmail.com
Fri Dec 25 23:16:20 CET 2009
Revision: 25556
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25556
Author: campbellbarton
Date: 2009-12-25 23:16:19 +0100 (Fri, 25 Dec 2009)
Log Message:
-----------
replace dynamic_menu.py with Menu classmethods much less complicated.
access append/prepend eg.
bpy.types.INFO_MT_file_import.append(lambda self, context: self.layout.operator("import_some.format"))
Modified Paths:
--------------
trunk/blender/release/scripts/io/export_3ds.py
trunk/blender/release/scripts/io/export_fbx.py
trunk/blender/release/scripts/io/export_mdd.py
trunk/blender/release/scripts/io/export_obj.py
trunk/blender/release/scripts/io/export_ply.py
trunk/blender/release/scripts/io/export_x3d.py
trunk/blender/release/scripts/io/import_anim_bvh.py
trunk/blender/release/scripts/io/import_scene_3ds.py
trunk/blender/release/scripts/io/import_scene_obj.py
trunk/blender/release/scripts/modules/bpy_types.py
trunk/blender/release/scripts/op/add_armature_human.py
trunk/blender/release/scripts/op/add_mesh_torus.py
trunk/blender/release/scripts/op/mesh_skin.py
trunk/blender/release/scripts/op/uvcalc_follow_active.py
trunk/blender/release/scripts/op/uvcalc_smart_project.py
trunk/blender/release/scripts/templates/operator.py
trunk/blender/release/scripts/ui/properties_data_armature_rigify.py
trunk/blender/release/scripts/ui/space_info.py
trunk/blender/release/scripts/ui/space_view3d.py
trunk/blender/source/blender/python/sphinx_doc_gen.py
Removed Paths:
-------------
trunk/blender/release/scripts/modules/dynamic_menu.py
Modified: trunk/blender/release/scripts/io/export_3ds.py
===================================================================
--- trunk/blender/release/scripts/io/export_3ds.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/export_3ds.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -1139,10 +1139,8 @@
bpy.types.register(Export3DS)
# Add to a menu
-import dynamic_menu
-
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".3ds")
self.layout.operator(Export3DS.bl_idname, text="Autodesk 3DS...").path = default_path
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+bpy.types.INFO_MT_file_export.append(menu_func)
Modified: trunk/blender/release/scripts/io/export_fbx.py
===================================================================
--- trunk/blender/release/scripts/io/export_fbx.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/export_fbx.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -3462,13 +3462,9 @@
# SMALL or COSMETICAL
# - find a way to get blender version, and put it in bpy.util?, old was Blender.Get('version')
-
-# Add to a menu
-import dynamic_menu
-
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".fbx")
self.layout.operator(ExportFBX.bl_idname, text="Autodesk FBX...").path = default_path
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+menu_item = bpy.types.INFO_MT_file_export.append(menu_func)
Modified: trunk/blender/release/scripts/io/export_mdd.py
===================================================================
--- trunk/blender/release/scripts/io/export_mdd.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/export_mdd.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -183,14 +183,11 @@
bpy.types.register(ExportMDD)
# Add to a menu
-import dynamic_menu
-
-
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".mdd")
self.layout.operator(ExportMDD.bl_idname, text="Vertex Keyframe Animation (.mdd)...").path = default_path
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+bpy.types.INFO_MT_file_export.append(menu_func)
if __name__ == '__main__':
bpy.ops.export.mdd(path="/tmp/test.mdd")
Modified: trunk/blender/release/scripts/io/export_obj.py
===================================================================
--- trunk/blender/release/scripts/io/export_obj.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/export_obj.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -987,19 +987,13 @@
wm.add_fileselect(self)
return {'RUNNING_MODAL'}
-
-
-
-
bpy.types.register(ExportOBJ)
-import dynamic_menu
-
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".obj")
self.layout.operator(ExportOBJ.bl_idname, text="Wavefront (.obj)...").path = default_path
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+menu_item = bpy.types.INFO_MT_file_export.append(menu_func)
if __name__ == "__main__":
bpy.ops.EXPORT_OT_obj(filename="/tmp/test.obj")
Modified: trunk/blender/release/scripts/io/export_ply.py
===================================================================
--- trunk/blender/release/scripts/io/export_ply.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/export_ply.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -318,14 +318,11 @@
bpy.types.register(ExportPLY)
-import dynamic_menu
-
-
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".ply")
self.layout.operator(ExportPLY.bl_idname, text="Stanford (.ply)...").path = default_path
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+bpy.types.INFO_MT_file_export.append(menu_func)
if __name__ == "__main__":
bpy.ops.export.ply(path="/tmp/test.ply")
Modified: trunk/blender/release/scripts/io/export_x3d.py
===================================================================
--- trunk/blender/release/scripts/io/export_x3d.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/export_x3d.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -1242,13 +1242,12 @@
bpy.types.register(ExportX3D)
-import dynamic_menu
def menu_func(self, context):
default_path = bpy.data.filename.replace(".blend", ".x3d")
self.layout.operator(ExportX3D.bl_idname, text="X3D Extensible 3D (.x3d)...").path = default_path
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+bpy.types.INFO_MT_file_export.append(menu_func)
# NOTES
# - blender version is hardcoded
Modified: trunk/blender/release/scripts/io/import_anim_bvh.py
===================================================================
--- trunk/blender/release/scripts/io/import_anim_bvh.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/import_anim_bvh.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -897,7 +897,5 @@
bpy.types.register(BvhImporter)
-
-import dynamic_menu
menu_func = lambda self, context: self.layout.operator(BvhImporter.bl_idname, text="Motion Capture (.bvh)...")
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_import, menu_func)
+bpy.types.INFO_MT_file_import.append(menu_func)
Modified: trunk/blender/release/scripts/io/import_scene_3ds.py
===================================================================
--- trunk/blender/release/scripts/io/import_scene_3ds.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/import_scene_3ds.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -1168,10 +1168,9 @@
bpy.types.register(IMPORT_OT_autodesk_3ds)
-import dynamic_menu
menu_func = lambda self, context: self.layout.operator(IMPORT_OT_autodesk_3ds.bl_idname, text="3D Studio (.3ds)...")
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_import, menu_func)
+bpy.types.INFO_MT_file_import.append(menu_func)
# NOTES:
-# why add 1 extra vertex? and remove it when done?
+# why add 1 extra vertex? and remove it when done? - "Answer - eekadoodle - would need to re-order UV's without this since face order isnt always what we give blender, BMesh will solve :D"
# disabled scaling to size, this requires exposing bb (easy) and understanding how it works (needs some time)
Modified: trunk/blender/release/scripts/io/import_scene_obj.py
===================================================================
--- trunk/blender/release/scripts/io/import_scene_obj.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/io/import_scene_obj.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -1627,9 +1627,8 @@
bpy.types.register(IMPORT_OT_obj)
-import dynamic_menu
menu_func = lambda self, context: self.layout.operator(IMPORT_OT_obj.bl_idname, text="Wavefront (.obj)...")
-menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_import, menu_func)
+menu_item = bpy.types.INFO_MT_file_import.append(menu_func)
# NOTES (all line numbers refer to 2.4x import_obj.py, not this file)
Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/modules/bpy_types.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -379,7 +379,33 @@
class Menu(StructRNA):
__slots__ = ()
+
+ @classmethod
+ def _dyn_menu_initialize(cls):
+ draw_funcs = getattr(cls.draw, "_draw_funcs", None)
+ if draw_funcs is None:
+ def draw_ls(*args):
+ for func in draw_ls._draw_funcs:
+ func(*args)
+
+ draw_funcs = draw_ls._draw_funcs = [cls.draw]
+ cls.draw = draw_ls
+
+ return draw_funcs
+
+ @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.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)
+
def path_menu(self, searchpaths, operator):
layout = self.layout
# hard coded to set the operators 'path' to the filename.
@@ -410,3 +436,4 @@
"""
import bpy
self.path_menu(bpy.utils.preset_paths(self.preset_subdir), self.preset_operator)
+
Deleted: trunk/blender/release/scripts/modules/dynamic_menu.py
===================================================================
--- trunk/blender/release/scripts/modules/dynamic_menu.py 2009-12-25 20:52:05 UTC (rev 25555)
+++ trunk/blender/release/scripts/modules/dynamic_menu.py 2009-12-25 22:16:19 UTC (rev 25556)
@@ -1,118 +0,0 @@
-# ##### 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# <pep8 compliant>
-
-import bpy
-
-
-def collect_baseclasses(_class, bases):
-
- if _class is type or _class is object:
- return bases
-
- bases.append(_class)
- for _superclass in _class.__bases__:
- collect_baseclasses(_superclass, bases)
-
- return bases
-
-
-def collect_subclasses(_class, subs):
-
- if _class is type or _class is object:
- return subs
-
- subs.append(_class)
- for _subclass in _class.__subclasses__():
- collect_subclasses(_subclass, subs)
-
- return subs
-
-
-class DynMenu(bpy.types.Menu):
-
- def draw(self, context):
- '''
- This is a draw function that is used to call all subclasses draw functions
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list