Revision 699 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig/commonsdialog.py
commonsdialog.py | ||
---|---|---|
33 | 33 |
|
34 | 34 |
from javax.swing import JFileChooser |
35 | 35 |
from javax.swing.filechooser import FileNameExtensionFilter |
36 |
from java.lang import Throwable |
|
37 |
from java.io import File |
|
36 | 38 |
|
37 |
#from org.gvsig.app import ApplicationLocator
|
|
39 |
#from org.gvsig.app import ApplicationLocator |
|
38 | 40 |
|
39 | 41 |
from org.gvsig.andami.ui.mdiFrame import DefaultThreadSafeDialogs |
40 | 42 |
|
... | ... | |
76 | 78 |
""" |
77 | 79 |
DefaultThreadSafeDialogs(root).messageDialog(message, title, messageType) |
78 | 80 |
|
79 |
|
|
81 |
|
|
80 | 82 |
def inputbox(message, title="", messageType=IDEA, initialValue="", root=None): |
81 | 83 |
""" |
82 | 84 |
Shows a input dialog. |
83 | 85 |
:param message: text to present in the dialog |
84 | 86 |
:param title: title of the dialog |
85 | 87 |
:messageType: type of icon to use |
86 |
:initialValue: Initial value of the inputbox
|
|
88 |
:initialValue: Initial value of the inputbox |
|
87 | 89 |
""" |
88 |
return DefaultThreadSafeDialogs(root).inputDialog(message, title,
|
|
89 |
messageType, initialValue)
|
|
90 |
|
|
91 |
|
|
90 |
return DefaultThreadSafeDialogs(root).inputDialog(message, title, |
|
91 |
messageType, initialValue) |
|
92 |
|
|
93 |
|
|
92 | 94 |
def confirmDialog(message, title="", optionType=YES_NO, messageType=IDEA, root=None): |
93 | 95 |
""" |
94 | 96 |
Create a message dialog with options button |
95 | 97 |
:param message: text to present in the dialog |
96 | 98 |
:param title: title of the dialog |
97 | 99 |
:optionType: bottons to show |
98 |
:param messageType: type of icon to use.
|
|
100 |
:param messageType: type of icon to use. |
|
99 | 101 |
""" |
100 | 102 |
#0: yes/no option |
101 | 103 |
#1: yes/no/cancelar |
102 | 104 |
#2: accept/cancel |
103 |
return DefaultThreadSafeDialogs(None).confirmDialog(message, title,
|
|
104 |
optionType, messageType)
|
|
105 |
return DefaultThreadSafeDialogs(None).confirmDialog(message, title, |
|
106 |
optionType, messageType) |
|
105 | 107 |
|
106 |
def filechooser(option, title="", initialPath=None,
|
|
108 |
def filechooser(option, title="", initialPath=None, |
|
107 | 109 |
multiselection=False, filter = None, fileHidingEnabled=True, root=None): |
108 | 110 |
""" |
109 | 111 |
Allows configuration parameters to filechooser dialogs |
... | ... | |
114 | 116 |
:boolean multiselection: Allow select more than one object. |
115 | 117 |
:String[] filter: list of acepted extension files ("jpg", "png", "gif") |
116 | 118 |
:boolean fileHidingEnabled: True if hidden files are not displayed |
117 |
"""
|
|
119 |
""" |
|
118 | 120 |
# |
119 | 121 |
#Values for open files dialog |
120 | 122 |
dialogType = JFileChooser.OPEN_DIALOG |
121 | 123 |
selectionMode = FILES_ONLY |
122 |
|
|
124 |
|
|
123 | 125 |
if option == SAVE_FILE: |
124 | 126 |
dialogType = JFileChooser.SAVE_DIALOG |
125 | 127 |
elif option == OPEN_DIRECTORY: |
126 | 128 |
selectionMode = DIRECTORIES_ONLY |
127 | 129 |
|
128 | 130 |
initialPath = getJavaFile(initialPath) |
129 |
|
|
131 |
|
|
130 | 132 |
if filter: |
131 | 133 |
filter = FileNameExtensionFilter("Files", filter) |
132 |
|
|
133 |
return DefaultThreadSafeDialogs(root).showChooserDialog(
|
|
134 |
|
|
135 |
files = DefaultThreadSafeDialogs(root).showChooserDialog(
|
|
134 | 136 |
title, |
135 | 137 |
dialogType, |
136 | 138 |
selectionMode, |
... | ... | |
138 | 140 |
initialPath, |
139 | 141 |
filter, |
140 | 142 |
fileHidingEnabled) |
141 |
|
|
143 |
|
|
144 |
try: |
|
145 |
if files == None: |
|
146 |
return None |
|
147 |
elif len(files) <= 0: |
|
148 |
return None |
|
149 |
elif multiselection==False: |
|
150 |
jfile = files[0] |
|
151 |
if isinstance(jfile, File): |
|
152 |
return jfile.getAbsolutePath() |
|
153 |
elif jfile == None: |
|
154 |
return None |
|
155 |
else: |
|
156 |
raise Exception() |
|
157 |
elif multiselection==True: |
|
158 |
filePaths = [] |
|
159 |
for jfile in files: |
|
160 |
if isinstance(jfile, File): |
|
161 |
try: |
|
162 |
filePaths.append(jfile.getAbsolutePath()) |
|
163 |
except Throwable, ex: |
|
164 |
raise IOError(jfile) |
|
165 |
else: |
|
166 |
raise IOError("Not java.io.File type") |
|
167 |
return filePaths |
|
168 |
except Exception, ex: |
|
169 |
raise IOError(files) |
|
170 |
|
|
142 | 171 |
def openFileDialog(title='', initialPath=None, root=None): |
143 | 172 |
""" |
144 |
Shows a window dialog to choose one file.
|
|
173 |
Shows a window dialog to choose one file. |
|
145 | 174 |
:param title: Window title. Default '' |
146 | 175 |
:type title: string |
147 | 176 |
:param initialPath: Initial path to open in window dialog |
148 | 177 |
:type initialPath: string |
149 | 178 |
""" |
150 |
|
|
151 |
return DefaultThreadSafeDialogs(root).showOpenFileDialog(
|
|
152 |
title,
|
|
179 |
|
|
180 |
files = DefaultThreadSafeDialogs(root).showOpenFileDialog(
|
|
181 |
title, |
|
153 | 182 |
getJavaFile(initialPath)) |
154 | 183 |
|
184 |
if files==None: |
|
185 |
return None |
|
186 |
|
|
187 |
filePaths = [] |
|
188 |
for f in files: |
|
189 |
if isinstance(f, File): |
|
190 |
filePaths.append(f.getAbsolutePath()) |
|
191 |
else: |
|
192 |
raise IOError("Not java.io.File type") |
|
193 |
|
|
194 |
return filePaths |
|
195 |
|
|
196 |
|
|
155 | 197 |
def openFolderDialog(title='', initialPath=None, root=None): |
156 | 198 |
""" |
157 |
Shows a window dialog to choose one folder.
|
|
199 |
Shows a window dialog to choose one folder. |
|
158 | 200 |
:param title: Window title. Default '' |
159 | 201 |
:type title: string |
160 | 202 |
:param initialPath: Initial path to open in window dialog |
161 | 203 |
:type initialPath: string |
162 |
"""
|
|
163 |
|
|
164 |
return DefaultThreadSafeDialogs(None).showOpenDirectoryDialog(
|
|
165 |
title,
|
|
204 |
""" |
|
205 |
|
|
206 |
files = DefaultThreadSafeDialogs(None).showOpenDirectoryDialog(
|
|
207 |
title, |
|
166 | 208 |
getJavaFile(initialPath)) |
167 |
|
|
168 |
def saveFileDialog(title='', initialPath=None,root=None): |
|
209 |
|
|
210 |
if files==None: |
|
211 |
return None |
|
212 |
|
|
213 |
filePaths = [] |
|
214 |
for f in files: |
|
215 |
if isinstance(f, File): |
|
216 |
filePaths.append(f.getAbsolutePath()) |
|
217 |
else: |
|
218 |
raise IOError("Not java.io.File type") |
|
219 |
|
|
220 |
return filePaths |
|
221 |
|
|
222 |
|
|
223 |
def saveFileDialog(title='', initialPath=None, root=None): |
|
169 | 224 |
""" |
170 |
Shows a window dialog to choose one file.
|
|
225 |
Shows a window dialog to choose one file. |
|
171 | 226 |
:param title: Window title. Default '' |
172 | 227 |
:type title: string |
173 | 228 |
:param initialPath: Initial path to open in window dialog |
174 | 229 |
:type initialPath: string |
175 |
"""
|
|
176 |
|
|
177 |
return DefaultThreadSafeDialogs(root).showSaveFileDialog(
|
|
178 |
title,
|
|
230 |
""" |
|
231 |
|
|
232 |
files = DefaultThreadSafeDialogs(root).showSaveFileDialog(
|
|
233 |
title, |
|
179 | 234 |
getJavaFile(initialPath) |
180 | 235 |
) |
181 |
|
|
236 |
|
|
237 |
if files==None: |
|
238 |
return None |
|
239 |
|
|
240 |
filePaths = [] |
|
241 |
for f in files: |
|
242 |
if isinstance(f, File): |
|
243 |
filePaths.append(f.getAbsolutePath()) |
|
244 |
else: |
|
245 |
raise IOError("Not java.io.File type") |
|
246 |
|
|
247 |
return filePaths |
|
248 |
|
|
249 |
|
|
182 | 250 |
def getJavaFile(path): |
183 | 251 |
"""Returns a java File using parameter path. |
184 | 252 |
If path doesn't exists looks for user home folder and if can not find it, |
... | ... | |
208 | 276 |
return File(os.getcwd()) |
209 | 277 |
|
210 | 278 |
|
211 |
|
|
279 |
|
Also available in: Unified diff