[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27605] branches/render25/release/scripts: operator & menu item in the image editor to edit an image externally.

Campbell Barton ideasman42 at gmail.com
Thu Mar 18 18:21:52 CET 2010


Revision: 27605
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27605
Author:   campbellbarton
Date:     2010-03-18 18:21:52 +0100 (Thu, 18 Mar 2010)

Log Message:
-----------
operator & menu item in the image editor to edit an image externally.

Modified Paths:
--------------
    branches/render25/release/scripts/op/image.py
    branches/render25/release/scripts/ui/space_image.py

Modified: branches/render25/release/scripts/op/image.py
===================================================================
--- branches/render25/release/scripts/op/image.py	2010-03-18 17:05:17 UTC (rev 27604)
+++ branches/render25/release/scripts/op/image.py	2010-03-18 17:21:52 UTC (rev 27605)
@@ -19,32 +19,65 @@
 # <pep8 compliant>
 
 import bpy
+from bpy.props import StringProperty
 
+class EditExternally(bpy.types.Operator):
+    '''Edit image in an external application'''
+    bl_idname = "image.external_edit"
+    bl_label = "Image Edit Externally"
+    bl_options = {'REGISTER'}
 
-def image_editor_guess(context):
-    import platform
-    system = platform.system()
-    
-    image_editor = context.user_preferences.filepaths.image_editor
+    path = StringProperty(name="File Path", description="Path to an image file", maxlen= 1024, default= "")
 
-    # use image editor in the preferences when available.
-    if not image_editor:
-        if system == 'Windows':
-            image_editor = ["start"] # not tested!
-        elif system == 'Darwin':
-            image_editor = ["open"]
+    def _editor_guess(self, context):
+        import platform
+        system = platform.system()
+
+        image_editor = context.user_preferences.filepaths.image_editor
+
+        # use image editor in the preferences when available.
+        if not image_editor:
+            if system == 'Windows':
+                image_editor = ["start"] # not tested!
+            elif system == 'Darwin':
+                image_editor = ["open"]
+            else:
+                image_editor = ["gimp"]
         else:
-            image_editor = ["gimp"]
-    else:
-        if system == 'Darwin':
-            # blender file selector treats .app as a folder
-            # and will include a trailing backslash, so we strip it.
-            image_editor.rstrip('\\')
-            image_editor = ["open", "-a", image_editor]
+            if system == 'Darwin':
+                # blender file selector treats .app as a folder
+                # and will include a trailing backslash, so we strip it.
+                image_editor.rstrip('\\')
+                image_editor = ["open", "-a", image_editor]
 
-    return image_editor
+        return image_editor
 
+    def execute(self, context):
+        import subprocess
+        path = self.properties.path
+        image_editor = self._editor_guess(context)
 
+        cmd = []
+        cmd.extend(image_editor)
+        cmd.append(bpy.utils.expandpath(path))
+
+        subprocess.Popen(cmd)
+
+        return {'FINISHED'}
+
+    def invoke(self, context, event):
+        try:
+            path = context.space_data.image.filename
+        except:
+            self.report({'ERROR'}, "Image not found on disk")
+            return {'CANCELLED'}
+
+        self.properties.path = path
+        self.execute(context)
+        
+        return {'FINISHED'}
+
+
 class SaveDirty(bpy.types.Operator):
     '''Select object matching a naming pattern'''
     bl_idname = "image.save_dirty"
@@ -79,7 +112,6 @@
         import subprocess
 
         EXT = "png" # could be made an option but for now ok
-        image_editor = image_editor_guess(context)
 
         for image in bpy.data.images:
             image.tag = True
@@ -124,12 +156,8 @@
         image_new.file_format = 'PNG'
         image_new.save()
 
-        cmd = []
-        cmd.extend(image_editor)
-        cmd.append(bpy.utils.expandpath(filename_final))
+        bpy.ops.image.external_edit(path=filename_final)
 
-        subprocess.Popen(cmd)
-
         return {'FINISHED'}
 
 
@@ -155,6 +183,7 @@
 
 
 classes = [
+    EditExternally,
     SaveDirty,
     ProjectEdit,
     ProjectApply]

Modified: branches/render25/release/scripts/ui/space_image.py
===================================================================
--- branches/render25/release/scripts/ui/space_image.py	2010-03-18 17:05:17 UTC (rev 27604)
+++ branches/render25/release/scripts/ui/space_image.py	2010-03-18 17:21:52 UTC (rev 27605)
@@ -115,6 +115,8 @@
             if ima.source == 'SEQUENCE':
                 layout.operator("image.save_sequence")
 
+            layout.operator("image.external_edit", "Edit Externally")
+
             if not show_render:
                 layout.separator()
 





More information about the Bf-blender-cvs mailing list