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 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  from gettext import gettext as _ 
 24  import os 
 25   
 26  import gtk 
 27  import gobject 
 28   
 29  from flumotion.configure import configure 
 30  from flumotion.common.pygobject import gsignal 
 31  from flumotion.common import pygobject 
 32   
 33   
34 -class ProgressDialog(gtk.Dialog):
35 - def __init__(self, title, message, parent = None):
36 gtk.Dialog.__init__(self, title, parent, 37 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) 38 39 40 self.label = gtk.Label(message) 41 self.vbox.pack_start(self.label, True, True, 6) 42 self.label.show() 43 self.bar = gtk.ProgressBar() 44 self.bar.show() 45 self.vbox.pack_end(self.bar, True, True, 6) 46 self.active = False 47 self._timeout_id = None 48 49 self.connect('destroy', self._destroy_cb)
50
51 - def start(self):
52 "Show the dialog and start pulsating." 53 self.active = True 54 self.show() 55 self.bar.pulse() 56 self._timeout_id = gobject.timeout_add(200, self._pulse)
57
58 - def stop(self):
59 "Remove the dialog and stop pulsating." 60 self.active = False 61 if self._timeout_id: 62 gobject.source_remove(self._timeout_id) 63 self._timeout_id = None
64
65 - def message(self, message):
66 "Set the message on the dialog." 67 self.label.set_text(message)
68
69 - def _pulse(self):
70 if not self.active: 71 # we were disabled, so stop pulsating 72 return False 73 self.bar.pulse() 74 return True
75
76 - def _destroy_cb(self, widget):
77 self.stop()
78
79 -class ErrorDialog(gtk.MessageDialog):
80 - def __init__(self, message, parent=None, close_on_response=True, 81 secondary_text=None):
82 gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL, 83 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message) 84 b = self.action_area.get_children()[0] 85 b.set_name('ok_button') 86 self.message = message 87 if close_on_response: 88 self.connect("response", lambda self, response: self.hide()) 89 90 # GTK 2.4 does not have format_secondary_text 91 if not hasattr(self, 'format_secondary_text'): 92 self.format_secondary_text = self._format_secondary_text_backport 93 94 if secondary_text: 95 self.format_secondary_text(secondary_text)
96
97 - def _format_secondary_text_backport(self, secondary_text):
98 self.set_markup('<span weight="bold" size="larger">%s</span>' 99 '\n\n%s' % (self.message, secondary_text))
100
101 - def run(self):
102 # can't run a recursive mainloop, because that mucks with 103 # twisted's reactor. 104 from twisted.internet import defer 105 deferred = defer.Deferred() 106 def callback(_, response, deferred): 107 self.destroy() 108 deferred.callback(None)
109 self.connect('response', callback, deferred) 110 self.show() 111 return deferred
112
113 -def connection_refused_message(host, parent=None):
114 d = ErrorDialog('Connection refused', parent, True, 115 '"%s" refused your connection.\n' 116 'Check your user name and password and try again.' 117 % host) 118 return d.run()
119
120 -def connection_failed_message(info, debug, parent=None):
121 message = (_("Connection to manager on %s failed (%s).") 122 % (str(info), debug)) 123 d = ErrorDialog('Connection failed', parent, True, message) 124 return d.run()
125
126 -def already_connected_message(info, parent=None):
127 d = ErrorDialog('Already connected to %s' % info, parent, True, 128 "Seek your satisfaction via existing routes.") 129 return d.run()
130
131 -class PropertyChangeDialog(gtk.Dialog):
132 """ 133 I am a dialog to get and set GStreamer element properties on a component. 134 """ 135 136 gsignal('set', str, str, object) 137 gsignal('get', str, str) 138 139 RESPONSE_FETCH = 0 140
141 - def __init__(self, name, parent):
142 title = "Change element property on '%s'" % name 143 gtk.Dialog.__init__(self, title, parent, 144 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) 145 self.connect('response', self.response_cb) 146 self._close = self.add_button('Close', gtk.RESPONSE_CLOSE) 147 self._set = self.add_button('Set', gtk.RESPONSE_APPLY) 148 self._fetch = self.add_button('Fetch current', self.RESPONSE_FETCH) 149 150 hbox = gtk.HBox() 151 hbox.show() 152 153 label = gtk.Label('Element') 154 label.show() 155 hbox.pack_start(label, False, False) 156 self.element_combo = gtk.ComboBox() 157 self.element_entry = gtk.Entry() 158 self.element_entry.show() 159 hbox.pack_start(self.element_entry, False, False) 160 161 label = gtk.Label('Property') 162 label.show() 163 hbox.pack_start(label, False, False) 164 self.property_entry = gtk.Entry() 165 self.property_entry.show() 166 hbox.pack_start(self.property_entry, False, False) 167 168 label = gtk.Label('Value') 169 label.show() 170 hbox.pack_start(label, False, False) 171 self.value_entry = gtk.Entry() 172 self.value_entry.show() 173 hbox.pack_start(self.value_entry, False, False) 174 175 self.vbox.pack_start(hbox)
176
177 - def response_cb(self, dialog, response):
178 if response == gtk.RESPONSE_APPLY: 179 self.emit('set', self.element_entry.get_text(), 180 self.property_entry.get_text(), 181 self.value_entry.get_text()) 182 elif response == self.RESPONSE_FETCH: 183 self.emit('get', self.element_entry.get_text(), 184 self.property_entry.get_text()) 185 elif response == gtk.RESPONSE_CLOSE: 186 dialog.hide()
187
188 - def update_value_entry(self, value):
189 self.value_entry.set_text(str(value))
190 191 pygobject.type_register(PropertyChangeDialog) 192
193 -class AboutDialog(gtk.Dialog):
194 - def __init__(self, parent=None):
195 gtk.Dialog.__init__(self, _('About Flumotion'), parent, 196 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, 197 (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) 198 self.set_has_separator(False) 199 self.set_resizable(False) 200 self.set_border_width(12) 201 self.vbox.set_spacing(6) 202 203 image = gtk.Image() 204 self.vbox.pack_start(image) 205 image.set_from_file(os.path.join(configure.imagedir, 'fluendo.png')) 206 image.show() 207 208 version = gtk.Label( 209 '<span size="xx-large"><b>Flumotion %s</b></span>' % 210 configure.version) 211 version.set_selectable(True) 212 self.vbox.pack_start(version) 213 version.set_use_markup(True) 214 version.show() 215 216 text = _('Flumotion is a streaming media server.\n\n' 217 '© 2004, 2005, 2006, 2007 Fluendo S.L.') 218 authors = ( 219 'Johan Dahlin', 220 'Arek Korbik', 221 'Zaheer Abbas Merali', 222 'Sébastien Merle', 223 'Mike Smith', 224 'Wim Taymans', 225 'Thomas Vander Stichele', 226 'Andy Wingo', 227 ) 228 text += '\n\n<small>' + _('Authors') + ':\n' 229 for author in authors: 230 text += ' %s\n' % author 231 text += '</small>' 232 info = gtk.Label(text) 233 self.vbox.pack_start(info) 234 info.set_use_markup(True) 235 info.set_selectable(True) 236 info.set_justify(gtk.JUSTIFY_FILL) 237 info.set_line_wrap(True) 238 info.show()
239