image editor user preference.

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.
This commit is contained in:
Campbell Barton 2010-03-07 09:23:57 +00:00
parent 3ad1bfa69e
commit b237dc3af5
5 changed files with 37 additions and 17 deletions

@ -19,8 +19,24 @@
# <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'}

@ -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

@ -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="")

@ -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;

@ -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");