gvsig-scripting / org.gvsig.scripting.app / trunk / org.gvsig.scripting.app / org.gvsig.scripting.app.extension / src / main / resources / scripting / lib / commonsdialog.py @ 419
History | View | Annotate | Download (3.69 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
#
|
3 |
# File: commonsdialog.py
|
4 |
#
|
5 |
# Copyright (c) 2011 by Model Driven Development sl and Antonio Carrasco Valero
|
6 |
#
|
7 |
# GNU General Public License (GPL)
|
8 |
#
|
9 |
# This program is free software; you can redistribute it and/or
|
10 |
# modify it under the terms of the GNU General Public License
|
11 |
# as published by the Free Software Foundation; either version 2
|
12 |
# of the License, or (at your option) any later version.
|
13 |
#
|
14 |
# This program is distributed in the hope that it will be useful,
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
# GNU General Public License for more details.
|
18 |
#
|
19 |
# You should have received a copy of the GNU General Public License
|
20 |
# along with this program; if not, write to the Free Software
|
21 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
22 |
# 02110-1301, USA.
|
23 |
#
|
24 |
#
|
25 |
|
26 |
__author__ = """Antonio Carrasco Valero
|
27 |
Model Driven Development sl and Antonio Carrasco Valero
|
28 |
<carrasco@modeldd.org>
|
29 |
Victor Acevedo Royer <vacevedo@gvsig.com> <vacevedor@gmail.com>
|
30 |
"""
|
31 |
__docformat__ = 'plaintext'
|
32 |
|
33 |
|
34 |
from javax.swing import JOptionPane, JFileChooser |
35 |
|
36 |
|
37 |
from org.gvsig.app import ApplicationLocator |
38 |
|
39 |
from org.gvsig.andami.ui.mdiFrame import DefaultThreadSafeDialogs |
40 |
|
41 |
#====================================
|
42 |
# SWING
|
43 |
|
44 |
# messageType options
|
45 |
FORBIDEN = 0
|
46 |
IDEA= 1
|
47 |
WARNING= 2
|
48 |
QUESTION= 3
|
49 |
|
50 |
# Confirmdialog optionType Options
|
51 |
YES_NO = 0
|
52 |
YES_NO_CANCEL = 1
|
53 |
ACEPT_CANCEL = 2
|
54 |
|
55 |
def msgbox(message, title="", messageType=IDEA): |
56 |
"""
|
57 |
Create a message dialog with ok button only
|
58 |
|
59 |
:param message: text to present in the dialog
|
60 |
:param title: title of the dialog
|
61 |
:param messageType: type of icon to use.
|
62 |
|
63 |
"""
|
64 |
DefaultThreadSafeDialogs().messageDialog(message, title, messageType) |
65 |
|
66 |
|
67 |
def inputbox(message, title="", messageType=IDEA, initialValue=""): |
68 |
"""
|
69 |
Show a input dialog.
|
70 |
|
71 |
:param message: text to present in the dialog
|
72 |
:param title: title of the dialog
|
73 |
:messageType: type of icon to use
|
74 |
:initialValue: Initial value of the inputbox
|
75 |
|
76 |
"""
|
77 |
return DefaultThreadSafeDialogs().inputDialog(message, title, messageType, initialValue)
|
78 |
|
79 |
|
80 |
def confirmDialog(message, title="", optionType=YES_NO, messageType=IDEA): |
81 |
"""
|
82 |
Create a message dialog with options button
|
83 |
|
84 |
:param message: text to present in the dialog
|
85 |
:param title: title of the dialog
|
86 |
:optionType: bottons to show
|
87 |
:param messageType: type of icon to use.
|
88 |
|
89 |
"""
|
90 |
#0 : si/no option
|
91 |
#1: si/no/cancelar
|
92 |
#2: aceptar/cancelar
|
93 |
return DefaultThreadSafeDialogs().confirmDialog(message,title, optionType, messageType)
|
94 |
|
95 |
def filechooser(option, title=""): |
96 |
|
97 |
if option == "openFile": |
98 |
return openFileDialog(title)
|
99 |
elif option == "openFolder": |
100 |
return openFolderDialog(title)
|
101 |
elif option == "saveFile": |
102 |
return saveFileDialog(title)
|
103 |
return None |
104 |
|
105 |
def openFileDialog(title=None): |
106 |
fc = JFileChooser() |
107 |
if title!=None: |
108 |
fc.setDialogTitle(title) |
109 |
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES) |
110 |
val = fc.showOpenDialog(None)
|
111 |
if val == JFileChooser.APPROVE_OPTION:
|
112 |
return fc.getSelectedFile().getAbsolutePath()
|
113 |
|
114 |
return None |
115 |
|
116 |
def openFolderDialog(title=None): |
117 |
fc = JFileChooser() |
118 |
if title!=None: |
119 |
fc.setDialogTitle(title) |
120 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) |
121 |
val = fc.showOpenDialog(None)
|
122 |
if val == JFileChooser.APPROVE_OPTION:
|
123 |
return fc.getSelectedFile().getAbsolutePath()
|
124 |
return None |
125 |
|
126 |
def saveFileDialog(title=None): |
127 |
fc = JFileChooser() |
128 |
if title!=None: |
129 |
fc.setDialogTitle(title) |
130 |
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES) |
131 |
val = fc.showSaveDialog(None)
|
132 |
if val == JFileChooser.APPROVE_OPTION:
|
133 |
return fc.getSelectedFile().getAbsolutePath()
|
134 |
return None |