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: 7079 $" 
 37  _ = gettext.gettext 
 38   
 39   
40 -class ProgressDialog(gtk.Dialog):
41 - def __init__(self, title, message, parent = None):
42 gtk.Dialog.__init__(self, title, parent, 43 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) 44 45 46 self.label = gtk.Label(message) 47 self.vbox.pack_start(self.label, True, True, 6) 48 self.label.show() 49 self.bar = gtk.ProgressBar() 50 self.bar.show() 51 self.vbox.pack_end(self.bar, True, True, 6) 52 self.active = False 53 self._timeout_id = None 54 55 self.connect('destroy', self._destroy_cb)
56
57 - def start(self):
58 "Show the dialog and start pulsating." 59 self.active = True 60 self.show() 61 self.bar.pulse() 62 self._timeout_id = gobject.timeout_add(200, self._pulse)
63
64 - def stop(self):
65 "Remove the dialog and stop pulsating." 66 self.active = False 67 if self._timeout_id: 68 gobject.source_remove(self._timeout_id) 69 self._timeout_id = None
70
71 - def message(self, message):
72 "Set the message on the dialog." 73 self.label.set_text(message)
74
75 - def _pulse(self):
76 if not self.active: 77 # we were disabled, so stop pulsating 78 return False 79 self.bar.pulse() 80 return True
81
82 - def _destroy_cb(self, widget):
83 self.stop()
84 85
86 -class ErrorDialog(gtk.MessageDialog):
87 - def __init__(self, message, parent=None, close_on_response=True, 88 secondary_text=None):
89 gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL, 90 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message) 91 b = self.action_area.get_children()[0] 92 b.set_name('ok_button') 93 self.message = message 94 if close_on_response: 95 self.connect("response", lambda self, response: self.hide()) 96 97 # GTK 2.4 does not have format_secondary_text 98 if not hasattr(self, 'format_secondary_text'): 99 self.format_secondary_text = self._format_secondary_text_backport 100 101 if secondary_text: 102 self.format_secondary_text(secondary_text)
103
104 - def _format_secondary_text_backport(self, secondary_text):
105 self.set_markup('<span weight="bold" size="larger">%s</span>' 106 '\n\n%s' % (self.message, secondary_text))
107
108 - def run(self):
109 # can't run a recursive mainloop, because that mucks with 110 # twisted's reactor. 111 from twisted.internet import defer 112 deferred = defer.Deferred() 113 def callback(_, response, deferred): 114 self.destroy() 115 deferred.callback(None)
116 self.connect('response', callback, deferred) 117 self.show() 118 return deferred
119 120
121 -class AboutDialog(gtk.Dialog):
122 - def __init__(self, parent=None):
123 gtk.Dialog.__init__(self, _('About Flumotion'), parent, 124 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, 125 (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) 126 self.set_has_separator(False) 127 self.set_resizable(False) 128 self.set_border_width(12) 129 self.vbox.set_spacing(6) 130 131 image = gtk.Image() 132 self.vbox.pack_start(image) 133 image.set_from_file(os.path.join(configure.imagedir, 'fluendo.png')) 134 image.show() 135 136 version = gtk.Label( 137 '<span size="xx-large"><b>Flumotion %s</b></span>' % 138 configure.version) 139 version.set_selectable(True) 140 self.vbox.pack_start(version) 141 version.set_use_markup(True) 142 version.show() 143 144 text = _('Flumotion is a streaming media server.\n\n' 145 '© 2004, 2005, 2006, 2007, 2008 Fluendo S.L.') 146 authors = ( 147 'Johan Dahlin', 148 'Pedro Gracia Fajardo', 149 'Arek Korbik', 150 'Jordi Massaguer Pla', 151 'Zaheer Abbas Merali', 152 'Sébastien Merle', 153 'Mike Smith', 154 'Wim Taymans', 155 'Thomas Vander Stichele', 156 'Andy Wingo', 157 ) 158 text += '\n\n<small>' + _('Authors') + ':\n' 159 for author in authors: 160 text += ' %s\n' % author 161 text += '</small>' 162 info = gtk.Label(text) 163 self.vbox.pack_start(info) 164 info.set_use_markup(True) 165 info.set_selectable(True) 166 info.set_justify(gtk.JUSTIFY_FILL) 167 info.set_line_wrap(True) 168 info.show()
169
170 -def showConnectionErrorDialog(failure, info, parent=None):
171 if failure.check(ConnectionRefusedError): 172 title = _('Connection refused') 173 message = ( 174 _('"%s" refused your connection.\n' 175 'Check your user name and password and try again.') 176 % (info.host,)) 177 elif failure.check(ConnectionFailedError): 178 title = _('Connection failed') 179 message = (_("Connection to manager on %s failed (%s).") 180 % (str(info), str(failure))) 181 elif failure.check(AlreadyConnectedError, 182 AlreadyConnectingError): 183 title =_('Already connected to %s') % (info,) 184 message = _("You cannot connect twice to the same manager. Try " 185 "disconnecting first.") 186 else: 187 raise AssertionError(failure) 188 189 dialog = ErrorDialog(title, parent, True, message) 190 return dialog.run()
191