[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26973] trunk/blender/release/scripts/ui/ space_userpref.py: extension copying operator and fix in displaying extensions with no docstring

Campbell Barton ideasman42 at gmail.com
Tue Feb 16 20:22:37 CET 2010


Revision: 26973
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26973
Author:   campbellbarton
Date:     2010-02-16 20:22:37 +0100 (Tue, 16 Feb 2010)

Log Message:
-----------
extension copying operator and fix in displaying extensions with no docstring

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_userpref.py

Modified: trunk/blender/release/scripts/ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/ui/space_userpref.py	2010-02-16 19:02:32 UTC (rev 26972)
+++ trunk/blender/release/scripts/ui/space_userpref.py	2010-02-16 19:22:37 UTC (rev 26973)
@@ -171,6 +171,10 @@
             op.path = "keymap.py"
             op = layout.operator("wm.keyconfig_import", "Import Key Configuration...")
             op.path = "keymap.py"
+        elif userpref.active_section == 'EXTENSIONS':
+            layout.operator_context = 'INVOKE_DEFAULT'
+            op = layout.operator("wm.extension_install", "Install Extension...")
+            op.path = "*.py"
 
 
 class USERPREF_PT_tabs(bpy.types.Panel):
@@ -1384,7 +1388,10 @@
         for mod in self._extension_list():
             box = col.box()
             row = box.row()
-            row.label(text=mod.__doc__)
+            text = mod.__doc__
+            if not text:
+                text = mod.__name__
+            row.label(text=text)
             module_name = mod.__name__
             row.operator("wm.extension_disable" if module_name in used_ext else "wm.extension_enable").module = module_name
 
@@ -1443,6 +1450,55 @@
         return {'FINISHED'}
 
 
+class WM_OT_extension_install(bpy.types.Operator):
+    "Install an extension"
+    bl_idname = "wm.extension_install"
+    bl_label = "Install Extension"
+
+    module = StringProperty(name="Module", description="Module name of the extension to disable")
+    
+    path = StringProperty(name="File Path", description="File path to write file to")
+    filename = StringProperty(name="File Name", description="Name of the file")
+    directory = StringProperty(name="Directory", description="Directory of the file")
+    filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
+    filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
+
+    def execute(self, context):
+        import traceback
+        pyfile = self.properties.path
+
+        paths = bpy.utils.script_paths("extensions")
+        path_dest = os.path.join(paths[-1], os.path.basename(pyfile))
+
+        if os.path.exists(path_dest):
+            self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest)
+            return {'CANCELLED'}
+        
+        if os.path.exists(path_dest):
+            self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest)
+            return {'CANCELLED'}
+
+        try:
+            shutil.copyfile(pyfile, path_dest)
+        except:
+            traceback.print_exc()
+            return {'CANCELLED'}
+
+        # TODO, should not be a warning.
+        # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)
+        return {'FINISHED'}
+
+    def invoke(self, context, event):
+        paths = bpy.utils.script_paths("extensions")
+        if not paths:
+            self.report({'ERROR'}, "No 'extensions' path could be found in " + str(bpy.utils.script_paths()))
+            return {'CANCELLED'}
+        
+        wm = context.manager
+        wm.add_fileselect(self)
+        return {'RUNNING_MODAL'}
+
+
 class WM_OT_keyconfig_test(bpy.types.Operator):
     "Test keyconfig for conflicts"
     bl_idname = "wm.keyconfig_test"
@@ -1852,6 +1908,7 @@
     
     WM_OT_extension_enable,
     WM_OT_extension_disable,
+    WM_OT_extension_install,
 
     WM_OT_keyconfig_export,
     WM_OT_keyconfig_import,





More information about the Bf-blender-cvs mailing list