[go: up one dir, main page]

Menu

[r3]: / trunk / src / dialogs.py  Maximize  Restore  History

Download this file

88 lines (78 with data), 3.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# dialogs.py
#
# Copyright 2009-2010 Sandro Mani <manisandro@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
# This file contains a variety of dialogs
import gtk
def question_dialog(primaryText,secondaryText=None,parent=None):
dialog=gtk.MessageDialog(parent, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, message_format=primaryText)
dialog.format_secondary_text(secondaryText)
dialog.set_default_response(gtk.RESPONSE_YES)
response=dialog.run()
dialog.destroy()
if response==gtk.RESPONSE_YES:
return True
else:
return False
def error_dialog(primaryText,secondaryText=None,parent=None):
dialog=gtk.MessageDialog(parent, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message_format=primaryText)
dialog.format_secondary_text(secondaryText)
dialog.run()
dialog.destroy()
def open_image(curdir=None,parent=None):
dialog=gtk.FileChooserDialog("Open Image...", parent, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
if curdir!=None:
dialog.set_current_folder(curdir)
dialog.set_default_response(gtk.RESPONSE_OK)
filter = gtk.FileFilter()
filter.set_name("Images")
filter.add_mime_type("image/png")
filter.add_mime_type("image/jpeg")
filter.add_mime_type("image/gif")
filter.add_mime_type("image/tif")
filter.add_pattern("*.png")
filter.add_pattern("*.jpg")
filter.add_pattern("*.gif")
filter.add_pattern("*.tif")
dialog.add_filter(filter)
response=dialog.run()
filename=dialog.get_filename()
dialog.destroy()
if response == gtk.RESPONSE_OK:
return filename
else:
return ""
def save_text(curdir,parent=None):
dialog = gtk.FileChooserDialog("Save Output...", parent, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))
if curdir!=None:
dialog.set_current_folder(curdir)
dialog.set_current_name("output.txt")
dialog.set_do_overwrite_confirmation(True)
filter = gtk.FileFilter()
filter.set_name("Text Files")
filter.add_pattern("*.txt")
dialog.add_filter(filter)
response = dialog.run()
filename=dialog.get_filename()
dialog.destroy()
if response == gtk.RESPONSE_OK:
return filename
else:
return ""