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