Update ErrorDialog usage and docstring
[wifi-radar.git] / wifiradar / gui / g2 / transients.py
blobbef95554cb00fdc54441eedc404c70952f85a2ea
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # gui/g2/transients.py - supporting dialogs for PyGTK UI
6 # Part of WiFi Radar: A utility for managing WiFi profiles on GNU/Linux.
8 # Copyright (C) 2004-2005 Ahmad Baitalmal <ahmad@baitalmal.com>
9 # Copyright (C) 2005 Nicolas Brouard <nicolas.brouard@mandrake.org>
10 # Copyright (C) 2005-2009 Brian Elliott Finley <brian@thefinleys.com>
11 # Copyright (C) 2006 David Decotigny <com.d2@free.fr>
12 # Copyright (C) 2006 Simon Gerber <gesimu@gmail.com>
13 # Copyright (C) 2006-2007 Joey Hurst <jhurst@lucubrate.org>
14 # Copyright (C) 2012 Anari Jalakas <anari.jalakas@gmail.com>
15 # Copyright (C) 2006, 2009 Ante Karamatic <ivoks@ubuntu.com>
16 # Copyright (C) 2009-2010,2014 Sean Robinson <seankrobinson@gmail.com>
17 # Copyright (C) 2010 Prokhor Shuchalov <p@shuchalov.ru>
19 # This program is free software; you can redistribute it and/or modify
20 # it under the terms of the GNU General Public License as published by
21 # the Free Software Foundation; version 2 of the License.
23 # This program is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 # GNU General Public License in LICENSE.GPL for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the Free Software
30 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 import gtk
34 import gobject
35 import logging
37 import wifiradar.misc as misc
39 # create a logger
40 logger = logging.getLogger(__name__)
43 class AboutDialog(gtk.AboutDialog, object):
44 """ Manage a GTK About Dialog.
45 """
46 def __init__(self):
47 """ Subclass GTK AboutDialog
49 Parameters:
51 nothing
53 Returns:
55 nothing
56 """
57 gtk.AboutDialog.__init__(self)
58 self.set_authors(["Ahmad Baitalmal <ahmad@baitalmal.com>",
59 "Brian Elliott Finley <brian@thefinleys.com>",
60 "Sean Robinson <seankrobinson@gmail.com>", "",
61 "Contributors", "Douglas Breault", "Nicolas Brouard",
62 "Jon Collette", "David Decotigny", "Simon Gerber",
63 "Joey Hurst", "Anari Jalakas", "Ante Karamatic",
64 "Richard Monk", "Kevin Otte", "Nathanael Rebsch",
65 "Andrea Scarpino", "Prokhor Shuchalov", "Patrick Winnertz"])
66 self.set_comments("WiFi connection manager")
67 self.set_copyright("Copyright 2004-2014 by various authors " + \
68 "and contributors\nCurrent Maintainer: " + \
69 "Sean Robinson <seankrobinson@gmail.com>")
70 self.set_documenters(["Gary Case"])
71 license = """
72 This program is free software; you can redistribute it and/or modify
73 it under the terms of the GNU General Public License as published by
74 the Free Software Foundation; either version 2 of the License, or
75 (at your option) any later version.
77 This program is distributed in the hope that it will be useful,
78 but WITHOUT ANY WARRANTY; without even the implied warranty of
79 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80 GNU General Public License for more details.
82 You should have received a copy of the GNU General Public License
83 along with this program; if not, write to the Free Software
84 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"""
85 self.set_license(license)
86 self.icon = gtk.gdk.pixbuf_new_from_file("pixmaps/wifi-radar.png")
87 self.set_logo(self.icon)
88 self.set_name("WiFi Radar")
89 self.set_version(misc.WIFI_RADAR_VERSION)
90 self.set_website("http://wifi-radar.tuxfamily.org/")
93 class ErrorDialog(gtk.MessageDialog, object):
94 """ Simple dialog to report an error to the user.
95 """
96 def __init__(self, parent, message):
97 """ Manage the complete life-cycle of an error message dialog.
98 """
99 gtk.MessageDialog.__init__(self, parent,
100 gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
101 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message)
102 self.run()
103 self.destroy()
106 class FileBrowseButton(gtk.Button, object):
107 """ Button to allow user to choose a file and put value into specified gtk.Entry.
109 def __init__(self, parent, entry):
110 """ Create a button to simulate a File/Open
112 Parameters:
114 'parent' -- gtk.Object -- Usually, the calling window.
116 'entry' -- gtk.Entry -- The text entry to update with user selection.
118 Returns:
120 FileBrowseButton instance
122 gtk.Button.__init__(self, "Browse", None)
123 self.entry = entry
124 self.browser_dialog = gtk.FileChooserDialog(None, parent,
125 gtk.FILE_CHOOSER_ACTION_OPEN,
126 (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
127 gtk.STOCK_OPEN, gtk.RESPONSE_OK), None)
128 self.connect("clicked", self.browse_files)
130 def browse_files(self, widget=None):
131 """ Show filechooser dialog and get user selection
133 Parameters:
135 'widget' -- gtk.Widget -- The widget sending the event.
137 Returns:
139 nothing
141 NOTES:
143 updates entry value
146 self.browser_dialog.set_filename(self.entry.get_text())
147 self.browser_dialog.run()
148 filename = self.browser_dialog.get_filename()
149 if filename:
150 self.entry.set_text(filename)
151 self.browser_dialog.destroy()
154 class StatusWindow(gtk.Dialog, object):
155 """ A simple class for putting up a "Please wait" dialog so the user
156 doesn't think we've forgotten about them. Implements the status interface.
158 def __init__(self, parent):
159 """ Create a new StatusWindow.
161 Parameters:
163 'parent' -- gtk.Object - Usually, the calling window.
165 Returns:
167 StatusWindow instance
169 NOTE:
171 Sample implementation of status interface. Status interface
172 requires .show(), .update_message(message), and .hide() methods.
174 gtk.Dialog.__init__(self, "Working", parent,
175 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)
176 self.icon = gtk.gdk.pixbuf_new_from_file("pixmaps/wifi-radar.png")
177 self.set_icon(self.icon)
178 self.lbl = gtk.Label("Please wait...")
179 self.bar = gtk.ProgressBar()
180 self.vbox.pack_start(self.lbl)
181 self.vbox.pack_start(self.bar)
182 self.cancel_button = self.add_button(gtk.STOCK_CANCEL, gtk.BUTTONS_CANCEL)
183 self.timer = None
185 def update_message(self, message):
186 """ Change the message displayed to the user.
188 Parameters:
190 'message' -- string - The message to show to the user.
192 Returns:
194 nothing
196 self.lbl.set_text(message)
198 def update_window(self):
199 """ Update the StatusWindow progress bar.
201 Parameters:
203 nothing
205 Returns:
207 True -- always return True
209 self.bar.pulse()
210 return True
212 def run(self):
213 """ Display and operate the StatusWindow.
215 Parameters:
217 nothing
219 Returns:
221 nothing
223 pass
225 def show(self):
226 """ Show all the widgets of the StatusWindow.
228 Parameters:
230 nothing
232 Returns:
234 nothing
236 self.show_all()
237 self.timer = gobject.timeout_add(250, self.update_window)
238 return False
240 def hide(self):
241 """ Hide all the widgets of the StatusWindow.
243 Parameters:
245 nothing
247 Returns:
249 nothing
251 if self.timer:
252 gobject.source_remove(self.timer)
253 self.timer = None
254 self.hide_all()
255 return False
257 def destroy(self):
258 """ Remove the StatusWindow.
260 Parameters:
262 nothing
264 Returns:
266 nothing
268 if self.timer:
269 gobject.source_remove(self.timer)
272 # Make so we can be imported
273 if __name__ == "__main__":
274 pass