~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to release/scripts/image_edit.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!BPY
2
2
"""
3
 
Name: 'Edit Externaly'
 
3
Name: 'Edit Externally'
4
4
Blender: 242a
5
5
Group: 'Image'
6
6
Tooltip: 'Open in an application for editing. (hold Shift to configure)'
9
9
__author__ = "Campbell Barton"
10
10
__url__ = ["blender", "blenderartists.org"]
11
11
__version__ = "1.0"
12
 
 
13
12
__bpydoc__ = """\
14
13
This script opens the current image in an external application for editing.
15
14
 
16
 
Useage:
 
15
Usage:
17
16
Choose an image for editing in the UV/Image view.
18
17
 
19
 
To configure the application to open the image with, hold Shift as you click on
20
 
this menu item.
21
 
 
22
 
For first time users try running the default application for your operating system.
23
 
If the application does not open you can type in the full path.
24
 
You can choose that the last entered application will be saved as a default.
25
 
 
26
 
* Note, default commants for opening an image are "start" for win32 and "open" for macos.
27
 
This will use the system default assosiated application.
 
18
To configure the application to open the image with, hold Shift as you
 
19
click on this menu item.
 
20
 
 
21
For first time users try running the default application for your
 
22
operating system.  If the application does not open you can type in
 
23
the full path.  You can choose that the last entered application will
 
24
be saved as a default.
 
25
 
 
26
* Note, default commants for opening an image are "start" for win32
 
27
and "open" for macos.  This will use the system default associated
 
28
application.
28
29
"""
29
30
 
30
31
# ***** BEGIN GPL LICENSE BLOCK *****
48
49
# ***** END GPL LICENCE BLOCK *****
49
50
# --------------------------------------------------------------------------
50
51
 
 
52
import Blender
 
53
from Blender import Image, sys, Draw, Registry
51
54
 
52
55
try:
53
 
        import os
 
56
        import subprocess
54
57
        import sys as py_sys
55
58
        platform = py_sys.platform
56
59
except:
57
 
        Draw.PupMenu('Error, python not installed')
58
 
        os=None
 
60
        Draw.PupMenu('Error: Recent version of Python not installed.')
 
61
        subprocess=None
59
62
 
60
 
import Blender
61
 
from Blender import Image, sys, Draw, Registry
 
63
def os_run(appstring, filename):
 
64
        '''
 
65
        Run the app, take into account different python versions etc
 
66
        looks like python 2.6 wants a list for 
 
67
        '''
 
68
        
 
69
        # evil trick, temp replace spaces so we can allow spaces in filenames
 
70
        # also allows multiple instances of %f
 
71
        appstring = appstring.replace(' ', '\t')
 
72
        appstring = appstring.replace('%f', filename)
 
73
        appstring = appstring.split('\t')
 
74
        
 
75
        print ' '.join(appstring)
 
76
        
 
77
        try: # only python 2.6 wants a list?
 
78
                p = subprocess.Popen(appstring)
 
79
        except:
 
80
                p = subprocess.Popen(' '.join(appstring))
 
81
        
62
82
 
63
83
def edit_extern(image=None):
64
84
        
66
86
                image = Image.GetCurrent()
67
87
        
68
88
        if not image: # Image is None
69
 
                Draw.PupMenu('ERROR: You must select an active Image.')
 
89
                Draw.PupMenu('ERROR: Please select active Image.')
70
90
                return
71
91
        if image.packed:
72
92
                Draw.PupMenu('ERROR: Image is packed, unpack before editing.')
94
114
        if new_text:
95
115
                pupblock.append('first time, set path.')
96
116
                if platform == 'win32':
97
 
                        appstring = 'start "" /B "%f"'
 
117
                        # Example of path to popular image editor... ;-)
 
118
                        # appstring = '"C:\\Program Files\\Adobe\\Photoshop CS\\photoshop.exe" "%f"'
 
119
                        # Have to add "cmd /c" to make sure we're using Windows shell.
 
120
                        appstring = 'cmd /c start "" /B "%f"'
98
121
                elif platform == 'darwin':
99
122
                        appstring = 'open "%f"'
100
123
                else:
101
 
                        appstring = 'gimp-remote "%f"'
 
124
                        appstring = 'gimp %f'
102
125
        
103
126
        appstring_but = Draw.Create(appstring)
104
127
        save_default_but = Draw.Create(0)
105
128
        
106
 
        pupblock.append(('editor: ', appstring_but, 0, 48, 'Path to application, %f will be replaced with the image path.'))
 
129
        pupblock.append(('editor: ', appstring_but, 0, 99, 'Path to application, %f will be replaced with the image path.'))
107
130
        pupblock.append(('Set Default', save_default_but, 'Store this path in the blender registry.'))
108
131
        
109
132
        # Only configure if Shift is held,
118
141
                Registry.SetKey('ExternalImageEditor', {'path':appstring}, True)
119
142
        
120
143
        if appstring.find('%f') == -1:
121
 
                Draw.PupMenu('ERROR: The comment you entered did not contain the filename ("%f")')
 
144
                Draw.PupMenu('ERROR: No filename specified! ("%f")')
122
145
                return
123
146
        
124
147
        # -------------------------------
125
148
        
126
 
        appstring = appstring.replace('%f', imageFileName)
127
 
        print '\tediting image with command "%s"' % appstring
128
 
        os.system(appstring)
 
149
        os_run(appstring, imageFileName)
 
150
 
129
151
 
130
152
 
131
153
def main():
132
154
        edit_extern()
133
155
        
134
156
 
135
 
if __name__ == '__main__' and os != None:
136
 
        main()
 
 
b'\\ No newline at end of file'
 
157
if __name__ == '__main__' and subprocess:
 
158
        main()