2006-01-26 22:47:31 +00:00
|
|
|
#!BPY
|
|
|
|
"""
|
2008-11-07 15:16:30 +00:00
|
|
|
Name: 'Edit Externally'
|
2006-09-15 10:21:25 +00:00
|
|
|
Blender: 242a
|
2006-07-28 02:38:02 +00:00
|
|
|
Group: 'Image'
|
2006-09-15 10:21:25 +00:00
|
|
|
Tooltip: 'Open in an application for editing. (hold Shift to configure)'
|
2006-01-26 22:47:31 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Campbell Barton"
|
2008-04-23 14:04:05 +00:00
|
|
|
__url__ = ["blender", "blenderartists.org"]
|
2006-01-26 22:47:31 +00:00
|
|
|
__version__ = "1.0"
|
|
|
|
__bpydoc__ = """\
|
|
|
|
This script opens the current image in an external application for editing.
|
|
|
|
|
2008-11-07 15:16:30 +00:00
|
|
|
Usage:
|
2006-01-26 22:47:31 +00:00
|
|
|
Choose an image for editing in the UV/Image view.
|
2006-09-15 10:21:25 +00:00
|
|
|
|
2008-11-07 15:16:30 +00:00
|
|
|
To configure the application to open the image with, hold Shift as you
|
|
|
|
click on this menu item.
|
2006-09-15 10:21:25 +00:00
|
|
|
|
2008-11-07 15:16:30 +00:00
|
|
|
For first time users try running the default application for your
|
|
|
|
operating system. If the application does not open you can type in
|
|
|
|
the full path. You can choose that the last entered application will
|
|
|
|
be saved as a default.
|
2006-01-26 22:47:31 +00:00
|
|
|
|
2008-11-07 15:16:30 +00:00
|
|
|
* Note, default commants for opening an image are "start" for win32
|
|
|
|
and "open" for macos. This will use the system default associated
|
|
|
|
application.
|
2006-01-26 22:47:31 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
2007-02-14 01:03:32 +00:00
|
|
|
# Script copyright (C) Campbell J Barton 2006
|
|
|
|
#
|
2006-01-26 22:47:31 +00:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ***** END GPL LICENCE BLOCK *****
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
2008-11-07 15:16:30 +00:00
|
|
|
import Blender
|
|
|
|
from Blender import Image, sys, Draw, Registry
|
2006-01-26 22:47:31 +00:00
|
|
|
|
|
|
|
try:
|
2008-11-07 15:16:30 +00:00
|
|
|
import subprocess
|
2006-01-26 22:47:31 +00:00
|
|
|
import sys as py_sys
|
|
|
|
platform = py_sys.platform
|
|
|
|
except:
|
2008-11-07 15:16:30 +00:00
|
|
|
Draw.PupMenu('Error: Recent version of Python not installed.')
|
|
|
|
subprocess=None
|
2006-01-26 22:47:31 +00:00
|
|
|
|
2008-11-11 08:21:09 +00:00
|
|
|
def os_run(appstring, filename):
|
|
|
|
'''
|
|
|
|
Run the app, take into account different python versions etc
|
|
|
|
looks like python 2.6 wants a list for
|
|
|
|
'''
|
|
|
|
|
|
|
|
# evil trick, temp replace spaces so we can allow spaces in filenames
|
|
|
|
# also allows multiple instances of %f
|
|
|
|
appstring = appstring.replace(' ', '\t')
|
|
|
|
appstring = appstring.replace('%f', filename)
|
|
|
|
appstring = appstring.split('\t')
|
|
|
|
|
|
|
|
print ' '.join(appstring)
|
|
|
|
|
|
|
|
try: # only python 2.6 wants a list?
|
|
|
|
p = subprocess.Popen(appstring)
|
|
|
|
except:
|
|
|
|
p = subprocess.Popen(' '.join(appstring))
|
|
|
|
|
|
|
|
|
2006-11-26 18:40:04 +00:00
|
|
|
def edit_extern(image=None):
|
|
|
|
|
|
|
|
if not image:
|
|
|
|
image = Image.GetCurrent()
|
|
|
|
|
2006-01-26 22:47:31 +00:00
|
|
|
if not image: # Image is None
|
2008-11-07 15:16:30 +00:00
|
|
|
Draw.PupMenu('ERROR: Please select active Image.')
|
2006-01-26 22:47:31 +00:00
|
|
|
return
|
2006-05-16 01:41:54 +00:00
|
|
|
if image.packed:
|
|
|
|
Draw.PupMenu('ERROR: Image is packed, unpack before editing.')
|
|
|
|
return
|
|
|
|
|
2006-01-26 22:47:31 +00:00
|
|
|
imageFileName = sys.expandpath( image.filename )
|
|
|
|
|
2006-05-16 01:41:54 +00:00
|
|
|
if not sys.exists(imageFileName):
|
|
|
|
Draw.PupMenu('ERROR: Image path does not exist.')
|
|
|
|
return
|
|
|
|
|
2006-01-26 22:47:31 +00:00
|
|
|
pupblock = [imageFileName.split('/')[-1].split('\\')[-1]]
|
|
|
|
|
2006-05-16 01:41:54 +00:00
|
|
|
new_text= False
|
2006-01-26 22:47:31 +00:00
|
|
|
try:
|
|
|
|
appstring = Registry.GetKey('ExternalImageEditor', True)
|
|
|
|
appstring = appstring['path']
|
2006-05-16 01:41:54 +00:00
|
|
|
|
|
|
|
# for ZanQdo if he removed the path from the textbox totaly. ;) - Cam
|
|
|
|
if not appstring or appstring.find('%f')==-1:
|
|
|
|
new_text= True
|
2006-01-26 22:47:31 +00:00
|
|
|
except:
|
2006-05-16 01:41:54 +00:00
|
|
|
new_text= True
|
|
|
|
|
|
|
|
if new_text:
|
2006-01-26 22:47:31 +00:00
|
|
|
pupblock.append('first time, set path.')
|
|
|
|
if platform == 'win32':
|
2008-11-07 15:16:30 +00:00
|
|
|
# Example of path to popular image editor... ;-)
|
|
|
|
# appstring = '"C:\\Program Files\\Adobe\\Photoshop CS\\photoshop.exe" "%f"'
|
|
|
|
# Have to add "cmd /c" to make sure we're using Windows shell.
|
|
|
|
appstring = 'cmd /c start "" /B "%f"'
|
2006-01-26 22:47:31 +00:00
|
|
|
elif platform == 'darwin':
|
|
|
|
appstring = 'open "%f"'
|
|
|
|
else:
|
2008-11-11 08:21:09 +00:00
|
|
|
appstring = 'gimp %f'
|
2006-01-26 22:47:31 +00:00
|
|
|
|
|
|
|
appstring_but = Draw.Create(appstring)
|
2006-05-16 01:41:54 +00:00
|
|
|
save_default_but = Draw.Create(0)
|
2006-01-26 22:47:31 +00:00
|
|
|
|
2008-11-07 15:16:30 +00:00
|
|
|
pupblock.append(('editor: ', appstring_but, 0, 99, 'Path to application, %f will be replaced with the image path.'))
|
2006-05-16 01:41:54 +00:00
|
|
|
pupblock.append(('Set Default', save_default_but, 'Store this path in the blender registry.'))
|
2006-01-26 22:47:31 +00:00
|
|
|
|
2006-09-15 10:21:25 +00:00
|
|
|
# Only configure if Shift is held,
|
|
|
|
if Blender.Window.GetKeyQualifiers() & Blender.Window.Qual.SHIFT:
|
|
|
|
if not Draw.PupBlock('External Image Editor...', pupblock):
|
|
|
|
return
|
2006-01-26 22:47:31 +00:00
|
|
|
|
|
|
|
appstring = appstring_but.val
|
2006-05-16 01:41:54 +00:00
|
|
|
save_default= save_default_but.val
|
|
|
|
|
|
|
|
if save_default:
|
|
|
|
Registry.SetKey('ExternalImageEditor', {'path':appstring}, True)
|
2006-01-26 22:47:31 +00:00
|
|
|
|
2006-05-16 01:41:54 +00:00
|
|
|
if appstring.find('%f') == -1:
|
2008-11-07 15:16:30 +00:00
|
|
|
Draw.PupMenu('ERROR: No filename specified! ("%f")')
|
2006-05-16 01:41:54 +00:00
|
|
|
return
|
2006-01-26 22:47:31 +00:00
|
|
|
|
|
|
|
# -------------------------------
|
|
|
|
|
2008-11-11 08:21:09 +00:00
|
|
|
os_run(appstring, imageFileName)
|
|
|
|
|
2006-01-26 22:47:31 +00:00
|
|
|
|
2006-11-26 18:40:04 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
edit_extern()
|
|
|
|
|
|
|
|
|
2008-11-07 15:16:30 +00:00
|
|
|
if __name__ == '__main__' and subprocess:
|
|
|
|
main()
|