[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24757] trunk/blender/release/scripts: - hide members of bpy from dir() and autocomp.
Campbell Barton
ideasman42 at gmail.com
Sun Nov 22 12:23:19 CET 2009
Revision: 24757
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24757
Author: campbellbarton
Date: 2009-11-22 12:23:19 +0100 (Sun, 22 Nov 2009)
Log Message:
-----------
- hide members of bpy from dir() and autocomp.
- path functions bpy.utils.script_paths(), bpy.utils_preset_paths(subdir)
- further simplified presets, use a generic draw function for preset menus and define the preset subdir and operator in the class
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy/__init__.py
trunk/blender/release/scripts/modules/bpy/utils.py
trunk/blender/release/scripts/modules/bpy_types.py
trunk/blender/release/scripts/ui/properties_material.py
trunk/blender/release/scripts/ui/properties_physics_cloth.py
trunk/blender/release/scripts/ui/properties_render.py
trunk/blender/release/scripts/ui/space_text.py
Modified: trunk/blender/release/scripts/modules/bpy/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/__init__.py 2009-11-22 11:15:38 UTC (rev 24756)
+++ trunk/blender/release/scripts/modules/bpy/__init__.py 2009-11-22 11:23:19 UTC (rev 24757)
@@ -25,21 +25,15 @@
# python modules
from bpy import utils
-from bpy import ops as ops_module
+from bpy import ops as _ops_module
+
# fake operator module
-ops = ops_module.ops_fake_module
+ops = _ops_module.ops_fake_module
-# load all scripts
-import os
-import sys
-
-# a bit nasty but this prevents help() and input() from locking blender
-# Ideally we could have some way for the console to replace sys.stdin but
-# python would lock blender while waiting for a return value, not easy :|
-sys.stdin = None
-
def load_scripts(reload_scripts=False):
+ import os
+ import sys
import traceback
def test_import(module_name):
@@ -49,34 +43,44 @@
traceback.print_exc()
return None
- base_path = os.path.join(os.path.dirname(__file__), "..", "..")
- base_path = os.path.normpath(base_path) # clean
+ for base_path in utils.script_paths():
+ print(base_path)
+ for path_subdir in ("ui", "op", "io"):
+ path = os.path.join(base_path, path_subdir)
+ sys.path.insert(0, path)
+ for f in sorted(os.listdir(path)):
+ if f.endswith(".py"):
+ # python module
+ mod = test_import(f[0:-3])
+ elif "." not in f:
+ # python package
+ mod = test_import(f)
+ else:
+ mod = None
- for path_subdir in ("ui", "op", "io"):
- path = os.path.join(base_path, path_subdir)
- sys.path.insert(0, path)
- for f in sorted(os.listdir(path)):
- if f.endswith(".py"):
- # python module
- mod = test_import(f[0:-3])
- elif "." not in f:
- # python package
- mod = test_import(f)
- else:
- mod = None
+ if reload_scripts and mod:
+ print("Reloading:", mod)
+ reload(mod)
- if reload_scripts and mod:
- print("Reloading:", mod)
- reload(mod)
+def _main():
+ # a bit nasty but this prevents help() and input() from locking blender
+ # Ideally we could have some way for the console to replace sys.stdin but
+ # python would lock blender while waiting for a return value, not easy :|
+ import sys
+ sys.stdin = None
-if "-d" in sys.argv and False: # Enable this to measure startup speed
- import cProfile
- cProfile.run('import bpy; bpy.load_scripts()', 'blender.prof')
+ if "-d" in sys.argv and False: # Enable this to measure startup speed
+ import cProfile
+ cProfile.run('import bpy; bpy.load_scripts()', 'blender.prof')
- import pstats
- p = pstats.Stats('blender.prof')
- p.sort_stats('cumulative').print_stats(100)
+ import pstats
+ p = pstats.Stats('blender.prof')
+ p.sort_stats('cumulative').print_stats(100)
-else:
- load_scripts()
+ else:
+ load_scripts()
+
+_main()
+
+
Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py 2009-11-22 11:15:38 UTC (rev 24756)
+++ trunk/blender/release/scripts/modules/bpy/utils.py 2009-11-22 11:23:19 UTC (rev 24757)
@@ -25,3 +25,27 @@
return path
+# base scripts
+_scripts = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)
+_scripts = (os.path.normpath(_scripts), )
+
+def script_paths(*args):
+ if not args:
+ return _scripts
+
+ subdir = os.path.join(*args)
+ script_paths = []
+ for path in _scripts:
+ script_paths.append(os.path.join(path, subdir))
+
+ return script_paths
+
+
+_presets = os.path.join(_scripts[0], "presets") # FIXME - multiple paths
+
+def preset_paths(subdir):
+ '''
+ Returns a list of paths for a spesific preset.
+ '''
+
+ return (os.path.join(_presets, subdir), )
Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py 2009-11-22 11:15:38 UTC (rev 24756)
+++ trunk/blender/release/scripts/modules/bpy_types.py 2009-11-22 11:23:19 UTC (rev 24757)
@@ -110,7 +110,7 @@
class Menu(StructRNA):
- def path_menu(self, searchpath, operator):
+ def path_menu(self, searchpaths, operator):
layout = self.layout
# hard coded to set the operators 'path' to the filename.
@@ -133,12 +133,24 @@
layout = self.layout
- for f in sorted(os.listdir(searchpath)):
+ # collect paths
+ files = []
+ for path in searchpaths:
+ files.extend([(f, os.path.join(path, f)) for f in os.listdir(path)])
+ files.sort()
+
+ for f, path in files:
+
if f.startswith("."):
continue
- path = os.path.join(searchpath, f)
- path = os.path.normpath(path)
layout.item_stringO(operator, "path", path, text=path_to_name(f))
-
+
+ def draw_preset(self, context):
+ '''Define these on the subclass
+ - preset_operator
+ - preset_subdir
+ '''
+ import bpy
+ self.path_menu(bpy.utils.preset_paths(self.preset_subdir), self.preset_operator)
Modified: trunk/blender/release/scripts/ui/properties_material.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_material.py 2009-11-22 11:15:38 UTC (rev 24756)
+++ trunk/blender/release/scripts/ui/properties_material.py 2009-11-22 11:23:19 UTC (rev 24757)
@@ -37,13 +37,11 @@
class MATERIAL_MT_sss_presets(bpy.types.Menu):
bl_label = "SSS Presets"
+ preset_subdir = "sss"
+ preset_operator = "script.python_file_run"
+ draw = bpy.types.Menu.draw_preset
- def draw(self, context):
- import os
- template_dir = os.path.join(os.path.dirname(__file__), os.path.pardir, "presets", "sss")
- self.path_menu(template_dir, "script.python_file_run")
-
class MaterialButtonsPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
Modified: trunk/blender/release/scripts/ui/properties_physics_cloth.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_physics_cloth.py 2009-11-22 11:15:38 UTC (rev 24756)
+++ trunk/blender/release/scripts/ui/properties_physics_cloth.py 2009-11-22 11:23:19 UTC (rev 24757)
@@ -35,13 +35,11 @@
Creates the menu items by scanning scripts/templates
'''
bl_label = "Cloth Presets"
+ preset_subdir = "cloth"
+ preset_operator = "script.python_file_run"
+ draw = bpy.types.Menu.draw_preset
- def draw(self, context):
- import os
- template_dir = os.path.join(os.path.dirname(__file__), os.path.pardir, "presets", "cloth")
- self.path_menu(template_dir, "script.python_file_run")
-
class PhysicButtonsPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
Modified: trunk/blender/release/scripts/ui/properties_render.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_render.py 2009-11-22 11:15:38 UTC (rev 24756)
+++ trunk/blender/release/scripts/ui/properties_render.py 2009-11-22 11:23:19 UTC (rev 24757)
@@ -23,17 +23,12 @@
class RENDER_MT_presets(bpy.types.Menu):
- '''
- Creates the menu items by scanning scripts/templates
- '''
bl_label = "Render Presets"
+ preset_subdir = "render"
+ preset_operator = "script.python_file_run"
+ draw = bpy.types.Menu.draw_preset
- def draw(self, context):
- import os
- template_dir = os.path.join(os.path.dirname(__file__), os.path.pardir, "presets", "render")
- self.path_menu(template_dir, "script.python_file_run")
-
class RenderButtonsPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
Modified: trunk/blender/release/scripts/ui/space_text.py
===================================================================
--- trunk/blender/release/scripts/ui/space_text.py 2009-11-22 11:15:38 UTC (rev 24756)
+++ trunk/blender/release/scripts/ui/space_text.py 2009-11-22 11:23:19 UTC (rev 24757)
@@ -158,14 +158,6 @@
layout.itemO("text.properties", icon='ICON_MENU_PANEL')
-
-
- #ifndef DISABLE_PYTHON
- # XXX layout.column()
- # XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
- # XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
- #endif
-
layout.itemM("TEXT_MT_templates")
@@ -177,8 +169,7 @@
def draw(self, context):
import os
- template_dir = os.path.join(os.path.dirname(__file__), os.path.pardir, "templates")
- self.path_menu(template_dir, "text.open")
+ self.path_menu(bpy.utils.script_paths("templates"), "text.open")
class TEXT_MT_edit_view(bpy.types.Menu):
More information about the Bf-blender-cvs
mailing list