Package flumotion :: Package admin :: Package gtk :: Module dialogs
[hide private]

Source Code for Module flumotion.admin.gtk.dialogs

  1  # -*- Mode: Python; test-case-name: flumotion.test.test_dialogs -*- 
  2  # -*- coding: UTF-8 -*- 
  3  # vi:si:et:sw=4:sts=4:ts=4 
  4   
  5  # Flumotion - a streaming media server 
  6  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  7  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  8  # All rights reserved. 
  9  # 
 10  # This file may be distributed and/or modified under the terms of 
 11  # the GNU Lesser General Public License version 2.1 as published by 
 12  # the Free Software Foundation. 
 13  # This file is distributed without any warranty; without even the implied 
 14  # warranty of merchantability or fitness for a particular purpose. 
 15  # See "LICENSE.LGPL" in the source distribution for more information. 
 16  # 
 17  # Headers in this file shall remain intact. 
 18   
 19  """generic dialogs such as progress, error and about""" 
 20   
 21  import gettext 
 22  import os 
 23   
 24  import gobject 
 25  import gtk 
 26   
 27  from flumotion.configure import configure 
 28  from flumotion.common.errors import AlreadyConnectedError, \ 
 29       AlreadyConnectingError, ConnectionFailedError, \ 
 30       ConnectionRefusedError 
 31   
 32  __version__ = "$Rev$" 
 33  _ = gettext.gettext 
 34   
 35   
36 -def exceptionHandler(exctype, value, tb):
37 """ 38 Opens a dialog showing an exception in a nice dialog allowing 39 the users to report it directly to trac. 40 41 @param exctype : The class of the catched exception. 42 @type exctype : type 43 @param value : The exception itself. 44 @type value : exctype 45 @param tb : Contains the full traceback information. 46 @type tb : traceback 47 """ 48 if exctype is KeyboardInterrupt: 49 return 50 51 from flumotion.extern.exceptiondialog import ExceptionDialog 52 dialog = ExceptionDialog((exctype, value, tb)) 53 response = dialog.run() 54 if response != ExceptionDialog.RESPONSE_BUG: 55 dialog.destroy() 56 return 57 58 from flumotion.common.bugreporter import BugReporter 59 br = BugReporter() 60 br.submit(dialog.getFilenames(), 61 dialog.getDescription(), 62 dialog.getSummary()) 63 dialog.destroy()
64 65
66 -class ProgressDialog(gtk.Dialog):
67
68 - def __init__(self, title, message, parent = None):
69 gtk.Dialog.__init__(self, title, parent, 70 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) 71 72 73 self.label = gtk.Label(message) 74 self.vbox.pack_start(self.label, True, True, 6) 75 self.label.show() 76 self.bar = gtk.ProgressBar() 77 self.bar.show() 78 self.vbox.pack_end(self.bar, True, True, 6) 79 self.active = False 80 self._timeout_id = None 81 82 self.connect('destroy', self._destroy_cb)
83
84 - def start(self):
85 "Show the dialog and start pulsating." 86 self.active = True 87 self.show() 88 self.bar.pulse() 89 self._timeout_id = gobject.timeout_add(200, self._pulse)
90
91 - def stop(self):
92 "Remove the dialog and stop pulsating." 93 self.active = False 94 if self._timeout_id: 95 gobject.source_remove(self._timeout_id) 96 self._timeout_id = None
97
98 - def message(self, message):
99 "Set the message on the dialog." 100 self.label.set_text(message)
101
102 - def _pulse(self):
103 if not self.active: 104 # we were disabled, so stop pulsating 105 return False 106 self.bar.pulse() 107 return True
108
109 - def _destroy_cb(self, widget):
110 self.stop()
111 112
113 -class ErrorDialog(gtk.MessageDialog):
114
115 - def __init__(self, message, parent=None, close_on_response=True, 116 secondary_text=None):
117 gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL, 118 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message) 119 b = self.action_area.get_children()[0] 120 b.set_name('ok_button') 121 self.message = message 122 if close_on_response: 123 self.connect("response", lambda self, response: self.hide()) 124 125 # GTK 2.4 does not have format_secondary_text 126 if not hasattr(self, 'format_secondary_text'): 127 self.format_secondary_text = self._format_secondary_text_backport 128 129 if secondary_text: 130 self.format_secondary_text(secondary_text)
131
132 - def _format_secondary_text_backport(self, secondary_text):
133 self.set_markup('<span weight="bold" size="larger">%s</span>' 134 '\n\n%s' % (self.message, secondary_text))
135
136 - def run(self):
137 # can't run a recursive mainloop, because that mucks with 138 # twisted's reactor. 139 from twisted.internet import defer 140 deferred = defer.Deferred() 141 142 def callback(_, response, deferred): 143 self.destroy() 144 deferred.callback(None)
145 self.connect('response', callback, deferred) 146 self.show() 147 return deferred
148 149
150 -class AboutDialog(gtk.Dialog):
151
152 - def __init__(self, parent=None):
153 gtk.Dialog.__init__(self, _('About Flumotion'), parent, 154 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, 155 (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) 156 self.set_has_separator(False) 157 self.set_resizable(False) 158 self.set_border_width(12) 159 self.vbox.set_spacing(6) 160 161 image = gtk.Image() 162 self.vbox.pack_start(image) 163 image.set_from_file(os.path.join(configure.imagedir, 'flumotion.png')) 164 image.show() 165 166 version = gtk.Label( 167 '<span size="xx-large"><b>Flumotion %s</b></span>' % 168 configure.version) 169 version.set_selectable(True) 170 self.vbox.pack_start(version) 171 version.set_use_markup(True) 172 version.show() 173 174 text = _('Flumotion is a streaming media server.\n\n' 175 '© 2004, 2005, 2006, 2007, 2008 Fluendo S.L.') 176 authors = ( 177 'Johan Dahlin', 178 'Alvin Delagon', 179 'David Gay i Tello', 180 'Pedro Gracia Fajardo', 181 'Aitor Guevara Escalante', 182 'Arek Korbik', 183 'Marek Kowalski', 184 'Julien Le Goff', 185 'Marc-André Lureau', 186 'Xavier Martinez', 187 'Jordi Massaguer Pla', 188 'Andoni Morales Alastruey', 189 'Zaheer Abbas Merali', 190 'Sébastien Merle', 191 'Thodoris Paschidis', 192 'Xavier Queralt Mateu', 193 'Guillaume Quintard', 194 'Josep Joan "Pepe" Ribas', 195 'Mike Smith', 196 'Guillem Solà', 197 'Wim Taymans', 198 'Jan Urbański', 199 'Thomas Vander Stichele', 200 'Andy Wingo', 201 ) 202 text += '\n\n<small>' + _('Authors') + ':\n' 203 for author in authors: 204 text += ' %s\n' % author 205 text += '</small>' 206 info = gtk.Label(text) 207 self.vbox.pack_start(info) 208 info.set_use_markup(True) 209 info.set_selectable(True) 210 info.set_justify(gtk.JUSTIFY_FILL) 211 info.set_line_wrap(True) 212 info.show()
213 214 215 try: 216 from flumotion.admin.gtk import about 217 AboutDialog = about.GtkAboutDialog 218 except AttributeError: 219 pass 220 221
222 -def showConnectionErrorDialog(failure, info, parent=None):
223 if failure.check(ConnectionRefusedError): 224 title = _('Connection Refused') 225 message = ( 226 _('"%s" refused your connection.\n' 227 'Check your user name and password and try again.') 228 % (info.host, )) 229 elif failure.check(ConnectionFailedError): 230 title = _('Connection Failed') 231 message = (_("Connection to manager on %s failed (%s).") 232 % (str(info), str(failure.getErrorMessage()))) 233 elif failure.check(AlreadyConnectedError, 234 AlreadyConnectingError): 235 title =_('Already Connected to %s') % (info, ) 236 message = _("You cannot connect twice to the same manager. Try " 237 "disconnecting first.") 238 else: 239 raise AssertionError(failure) 240 241 dialog = ErrorDialog(title, parent, True, message) 242 return dialog.run()
243