image editor user preference.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 7 Mar 2010 09:23:57 +0000 (09:23 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 7 Mar 2010 09:23:57 +0000 (09:23 +0000)
image.py has a function image_editor_guess(), please test on windows and mac. (using 'startfile' and 'open')
this is only used when the image editor is not set.

release/scripts/op/image.py
release/scripts/op/screen_play_rendered_anim.py
release/scripts/ui/space_userpref.py
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c

index 469982c0c5ecbc830690c673b239fb6c1140cd72..ccb9a07c2420354c1139d52a38f6fe175c722895 100644 (file)
 # <pep8 compliant>
 
 import bpy
-import sys as py_sys
-platform = py_sys.platform
+
+
+def image_editor_guess(context):
+    image_editor = context.user_preferences.filepaths.image_editor
+
+    # use image editor in the preferences when available.
+    if not image_editor:
+        import platform
+        system = platform.system()
+
+        if system == 'Windows':
+            image_editor = "startfile" # not tested!
+        elif system == 'Darwin':
+            image_editor = "open"
+        else:
+            image_editor = "gimp"
+
+    return image_editor
 
 
 class SaveDirty(bpy.types.Operator):
@@ -44,25 +60,21 @@ class SaveDirty(bpy.types.Operator):
         return {'FINISHED'}
 
 
-_proj_hack = [""]
 class ProjectEdit(bpy.types.Operator):
     '''Select object matching a naming pattern'''
     bl_idname = "image.project_edit"
     bl_label = "Project Edit"
     bl_options = {'REGISTER'}
+    
+    _proj_hack = [""]
 
     def execute(self, context):
         import os
         import subprocess
 
         EXT = "tga" # until we have a way to save as another format!
-        if platform == 'win32':
-            EDITOR = "C:\\Program Files\\GIMP-2.7\\bin\\gimp-2.7.exe"
-        elif platform == 'darwin':
-            EDITOR = "open"
-        else:
-            EDITOR = "gimp" # until we have a way to set a default image edior            
-        
+        image_editor = image_editor_guess(context)
+
         for image in bpy.data.images:
             image.tag = True
 
@@ -99,12 +111,12 @@ class ProjectEdit(bpy.types.Operator):
             i += 1
         
         image_new.name = os.path.basename(filename_final)
-        _proj_hack[0] = image_new.name
+        ProjectEdit._proj_hack[0] = image_new.name
         
         image_new.filename_raw = filename_final # TODO, filename raw is crummy
         image_new.save()
         
-        subprocess.Popen([EDITOR, bpy.utils.expandpath(filename_final)])
+        subprocess.Popen([image_editor, bpy.utils.expandpath(filename_final)])
         
         return {'FINISHED'}
 
@@ -116,10 +128,10 @@ class ProjectApply(bpy.types.Operator):
     bl_options = {'REGISTER'}
 
     def execute(self, context):
-        image_name = _proj_hack[0] # TODO, deal with this nicer
+        image_name = ProjectEdit._proj_hack[0] # TODO, deal with this nicer
 
         try:
-            image = bpy.data.images[_proj_hack[0]]
+            image = bpy.data.images[image_name]
         except KeyError:
             self.report({'ERROR'}, "Could not find image '%s'" % image_name)
             return {'CANCELLED'}
index aa2b25fc77ba2aa5820524721b994e65bb131307..3fdb0b8e084abbb6922066c06a250fe8885f423b 100644 (file)
@@ -30,13 +30,14 @@ import os
 
 def guess_player_path(preset):
     import platform
+    system = platform.system()
 
     if preset == 'BLENDER24':
         player_path = "blender"
 
-        if platform.system() == 'Darwin':
+        if system == 'Darwin':
             test_path = "/Applications/blender 2.49.app/Contents/MacOS/blender"
-        elif platform.system() == 'Windows':
+        elif system == 'Windows':
             test_path = "/Program Files/Blender Foundation/Blender/blender.exe"
 
             if os.path.exists(test_path):
@@ -45,7 +46,7 @@ def guess_player_path(preset):
     elif preset == 'DJV':
         player_path = "djv_view"
 
-        if platform.system() == 'Darwin':
+        if system == 'Darwin':
             test_path = '/Applications/djv-0.8.2.app/Contents/Resources/bin/djv_view'
             if os.path.exists(test_path):
                 player_path = test_path
index ed8349924276f9725044216c1a25f38dc5eec7d4..6e8fa8d1a28e8b026cd69efc591b963f5c55f5c3 100644 (file)
@@ -1004,6 +1004,7 @@ class USERPREF_PT_file(bpy.types.Panel):
         sub.label(text="Scripts:")
         sub.label(text="Sounds:")
         sub.label(text="Temp:")
+        sub.label(text="Image Editor:")
         sub.label(text="Animation Player:")
 
         sub = col1.column()
@@ -1015,6 +1016,7 @@ class USERPREF_PT_file(bpy.types.Panel):
         sub.prop(paths, "python_scripts_directory", text="")
         sub.prop(paths, "sounds_directory", text="")
         sub.prop(paths, "temporary_directory", text="")
+        sub.prop(paths, "image_editor", text="")
         subsplit = sub.split(percentage=0.3)
         subsplit.prop(paths, "animation_player_preset", text="")
         subsplit.prop(paths, "animation_player", text="")
index 8a41c2da071bae1c117358ce528a752333e38f7e..24d7837b6ed215f43f24892b29e20d8578d4b557 100644 (file)
@@ -297,6 +297,7 @@ typedef struct UserDef {
        char plugseqdir[160];
        char pythondir[160];
        char sounddir[160];
+       char image_editor[240]; // FILE_MAX length
        char anim_player[240];  // FILE_MAX length
        int anim_player_preset;
        
index 0e8dae480a3a24a250d52585cc1387f6eecb1b01..2b4a8aad255b12d29867415b6572fab0c10ffcad 100644 (file)
@@ -2624,6 +2624,10 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna)
        prop= RNA_def_property(srna, "temporary_directory", PROP_STRING, PROP_DIRPATH);
        RNA_def_property_string_sdna(prop, NULL, "tempdir");
        RNA_def_property_ui_text(prop, "Temporary Directory", "The directory for storing temporary save files");
+
+       prop= RNA_def_property(srna, "image_editor", PROP_STRING, PROP_DIRPATH);
+       RNA_def_property_string_sdna(prop, NULL, "image_editor");
+       RNA_def_property_ui_text(prop, "Image Editor", "Path to an image editor");
        
        prop= RNA_def_property(srna, "animation_player", PROP_STRING, PROP_DIRPATH);
        RNA_def_property_string_sdna(prop, NULL, "anim_player");