Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting.app / trunk / org.gvsig.scripting.app / org.gvsig.scripting.app.extension / src / main / resources / scripting / lib / commonsdialog.py @ 386

History | View | Annotate | Download (5.03 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
__docformat__ = 'plaintext'
30

    
31

    
32

    
33

    
34
from javax.swing import JOptionPane, JFileChooser
35

    
36

    
37
from org.gvsig.app import ApplicationLocator      
38

    
39
#org.gvsig.andami.ui.mdiframe.DefaultThreadSafeDialogs
40
from org.gvsig.andami.ui.mdiFrame import DefaultThreadSafeDialogs
41

    
42
application = ApplicationLocator.getManager()
43

    
44
# -*- coding: utf-8 -*-
45
#
46
# File: commonsdialog.py
47
#
48
# Copyright (c) 2011 by Model Driven Development sl and Antonio Carrasco Valero
49
#
50
# GNU General Public License (GPL)
51
#
52
# This program is free software; you can redistribute it and/or
53
# modify it under the terms of the GNU General Public License
54
# as published by the Free Software Foundation; either version 2
55
# of the License, or (at your option) any later version.
56
#
57
# This program is distributed in the hope that it will be useful,
58
# but WITHOUT ANY WARRANTY; without even the implied warranty of
59
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60
# GNU General Public License for more details.
61
#
62
# You should have received a copy of the GNU General Public License
63
# along with this program; if not, write to the Free Software
64
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
65
# 02110-1301, USA.
66
#
67
#
68

    
69
__author__ = """Antonio Carrasco Valero
70
Model Driven Development sl and Antonio Carrasco Valero
71
<carrasco@modeldd.org>
72
Victor Acevedo Royer <vacevedor@gmail.com>"""
73
__docformat__ = 'plaintext'
74

    
75

    
76

    
77

    
78
from javax.swing import JOptionPane, JFileChooser
79

    
80
#====================================
81
# SWING
82

    
83
# messageType options
84
FORBIDEN = 0
85
IDEA= 1
86
WARNING= 2
87
QUESTION= 3
88

    
89
# Confirmdialog Options
90
YES_NO = 0
91
YES_NO_CANCEL = 1
92
ACEPT_CANCEL = 2
93

    
94
def msgbox(message, title="", messageType=1):
95
  """
96
  Create a message dialog with ok button only
97
  
98
    :param message: text to present in the dialog
99
    :param title: title of the dialog
100
    :param messageType: type of icon to use.
101
  
102
  """
103
  DefaultThreadSafeDialogs().messageDialog(message, title, messageType)
104

    
105
   
106
def inputbox(message, title="", messageType=1, initialValue=""):
107
  """
108
  Show a input dialog.
109

110
     :param message: text to present in the dialog
111
     :param title: title of the dialog
112
     :messageType: type of icon to use
113
     :initialValue: Initial value of the inputbox
114
  
115
  """
116
  return DefaultThreadSafeDialogs().inputDialog(message, title, messageType, initialValue) 
117
  
118
  
119
def confirmDialog(message, title="", optionType=0, messageType=1):
120
  """
121
  Create a message dialog with options button
122
  
123
    :param message: text to present in the dialog
124
    :param title: title of the dialog
125
    :optionType: bottons to show
126
    :param messageType: type of icon to use.
127
  
128
  """
129
  #0 : si/no option
130
  #1: si/no/cancelar
131
  #2: aceptar/cancelar
132
  return DefaultThreadSafeDialogs().confirmDialog(message,title, optionType, messageType) 
133

    
134
def filechooser(option, title=""):
135

    
136
  if option == "openFile":
137
    return openFileDialog(title)
138
  elif option == "openFolder":
139
    return openFolderDialog(title)
140
  elif option == "saveFile":
141
    return saveFileDialog(title)
142
  return None
143

    
144
def openFileDialog(title=None):
145
  #fc = JFileChooser()
146
  fc = DefaultThreadSafeDialogs().createComponent(JFileChooser)
147
  #createComponentWithParams
148
  if title!=None:
149
    fc.setDialogTitle(title)
150
  fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES)
151
  val = fc.showOpenDialog(None)
152
  if val == JFileChooser.APPROVE_OPTION:
153
    return fc.getSelectedFile().getAbsolutePath()
154
   
155
  return None
156

    
157
def openFolderDialog(title=None):
158
  fc = DefaultThreadSafeDialogs().createComponent(JFileChooser)
159
  #fc = JFileChooser()
160
  if title!=None:
161
    fc.setDialogTitle(title)
162
  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
163
  val = fc.showOpenDialog(None)
164
  if val == JFileChooser.APPROVE_OPTION:
165
    return fc.getSelectedFile().getAbsolutePath()
166
  return None
167

    
168
def saveFileDialog(title=None):
169
  #fc = JFileChooser()
170
  fc = DefaultThreadSafeDialogs().createComponent(JFileChooser)
171
  if title!=None:
172
    fc.setDialogTitle(title)
173
  fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES)
174
  val = fc.showSaveDialog(None)
175
  if val == JFileChooser.APPROVE_OPTION:
176
    return fc.getSelectedFile().getAbsolutePath()
177
  return None