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 | 355 | jjdelcerro | # -*- 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 | 399 | vacevedo | <carrasco@modeldd.org>
|
29 | Victor Acevedo Royer <vacevedo@gvsig.com> <vacevedor@gmail.com>
|
||
30 | """
|
||
31 | 355 | jjdelcerro | __docformat__ = 'plaintext'
|
32 | |||
33 | |||
34 | from javax.swing import JOptionPane, JFileChooser |
||
35 | |||
36 | 362 | vacevedo | |
37 | from org.gvsig.app import ApplicationLocator |
||
38 | |||
39 | from org.gvsig.andami.ui.mdiFrame import DefaultThreadSafeDialogs |
||
40 | |||
41 | 355 | jjdelcerro | #====================================
|
42 | # SWING
|
||
43 | |||
44 | 372 | vacevedo | # messageType options
|
45 | 381 | vacevedo | FORBIDEN = 0
|
46 | IDEA= 1
|
||
47 | WARNING= 2
|
||
48 | QUESTION= 3
|
||
49 | 372 | vacevedo | |
50 | 399 | vacevedo | # Confirmdialog optionType Options
|
51 | 381 | vacevedo | YES_NO = 0
|
52 | YES_NO_CANCEL = 1
|
||
53 | ACEPT_CANCEL = 2
|
||
54 | 372 | vacevedo | |
55 | 399 | vacevedo | def msgbox(message, title="", messageType=IDEA): |
56 | 362 | vacevedo | """
|
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 | 355 | jjdelcerro | |
66 | 362 | vacevedo | |
67 | 399 | vacevedo | def inputbox(message, title="", messageType=IDEA, initialValue=""): |
68 | 362 | vacevedo | """
|
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 | 399 | vacevedo | def confirmDialog(message, title="", optionType=YES_NO, messageType=IDEA): |
81 | 362 | vacevedo | """
|
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 | 355 | jjdelcerro | def openFileDialog(title=None): |
106 | 399 | vacevedo | fc = JFileChooser() |
107 | 355 | jjdelcerro | 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 | 362 | vacevedo | |
114 | 355 | jjdelcerro | return None |
115 | |||
116 | def openFolderDialog(title=None): |
||
117 | 399 | vacevedo | fc = JFileChooser() |
118 | 355 | jjdelcerro | 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 | 399 | vacevedo | fc = JFileChooser() |
128 | 355 | jjdelcerro | 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 |