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  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  from flumotion.common.pygobject import gsignal 
 23  from flumotion.common import pygobject 
 24   
 25   
 26  import gtk 
 27  import gobject 
 28   
29 -class ProgressDialog(gtk.Dialog):
30 - def __init__(self, title, message, parent = None):
31 gtk.Dialog.__init__(self, title, parent, 32 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) 33 34 35 self.label = gtk.Label(message) 36 self.vbox.pack_start(self.label, True, True, 6) 37 self.bar = gtk.ProgressBar() 38 self.vbox.pack_end(self.bar, True, True, 6) 39 self.active = False 40 self._timeout_id = None 41 42 self.connect('destroy', self._destroy_cb)
43
44 - def start(self):
45 "Show the dialog and start pulsating." 46 self.active = True 47 self.show_all() 48 self.bar.pulse() 49 self._timeout_id = gobject.timeout_add(200, self._pulse)
50
51 - def stop(self):
52 "Remove the dialog and stop pulsating." 53 self.active = False 54 if self._timeout_id: 55 gobject.source_remove(self._timeout_id) 56 self._timeout_id = None
57
58 - def message(self, message):
59 "Set the message on the dialog." 60 self.label.set_text(message)
61
62 - def _pulse(self):
63 if not self.active: 64 # we were disabled, so stop pulsating 65 return False 66 self.bar.pulse() 67 return True
68
69 - def _destroy_cb(self, widget):
70 self.stop()
71
72 -class ErrorDialog(gtk.MessageDialog):
73 - def __init__(self, message, parent=None, close_on_response=True, 74 secondary_text=None):
75 gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL, 76 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message) 77 b = self.action_area.get_children()[0] 78 b.set_name('ok_button') 79 self.message = message 80 if close_on_response: 81 self.connect("response", lambda self, response: self.hide()) 82 83 # GTK 2.4 does not have format_secondary_text 84 if not hasattr(self, 'format_secondary_text'): 85 self.format_secondary_text = self._format_secondary_text_backport 86 87 if secondary_text: 88 self.format_secondary_text(secondary_text)
89
90 - def _format_secondary_text_backport(self, secondary_text):
91 self.set_markup('<span weight="bold" size="larger">%s</span>' 92 '\n\n%s' % (self.message, secondary_text))
93
94 - def run(self):
95 # can't run a recursive mainloop, because that mucks with 96 # twisted's reactor. 97 from twisted.internet import defer 98 deferred = defer.Deferred() 99 def callback(_, response, deferred): 100 self.destroy() 101 deferred.callback(None)
102 self.connect('response', callback, deferred) 103 self.show() 104 return deferred
105
106 -def connection_refused_message(host, parent=None):
107 d = ErrorDialog('Connection refused', parent, True, 108 '"%s" refused your connection.\n' 109 'Check your user name and password and try again.' 110 % host) 111 return d.run()
112
113 -def connection_failed_message(message, parent=None):
114 d = ErrorDialog('Connection failed', parent, True, message) 115 return d.run()
116
117 -class PropertyChangeDialog(gtk.Dialog):
118 """ 119 I am a dialog to get and set GStreamer element properties on a component. 120 """ 121 122 gsignal('set', str, str, object) 123 gsignal('get', str, str) 124 125 RESPONSE_FETCH = 0 126
127 - def __init__(self, name, parent):
128 title = "Change element property on '%s'" % name 129 gtk.Dialog.__init__(self, title, parent, 130 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) 131 self.connect('response', self.response_cb) 132 self._close = self.add_button('Close', gtk.RESPONSE_CLOSE) 133 self._set = self.add_button('Set', gtk.RESPONSE_APPLY) 134 self._fetch = self.add_button('Fetch current', self.RESPONSE_FETCH) 135 136 hbox = gtk.HBox() 137 hbox.show() 138 139 label = gtk.Label('Element') 140 label.show() 141 hbox.pack_start(label, False, False) 142 self.element_combo = gtk.ComboBox() 143 self.element_entry = gtk.Entry() 144 self.element_entry.show() 145 hbox.pack_start(self.element_entry, False, False) 146 147 label = gtk.Label('Property') 148 label.show() 149 hbox.pack_start(label, False, False) 150 self.property_entry = gtk.Entry() 151 self.property_entry.show() 152 hbox.pack_start(self.property_entry, False, False) 153 154 label = gtk.Label('Value') 155 label.show() 156 hbox.pack_start(label, False, False) 157 self.value_entry = gtk.Entry() 158 self.value_entry.show() 159 hbox.pack_start(self.value_entry, False, False) 160 161 self.vbox.pack_start(hbox)
162
163 - def response_cb(self, dialog, response):
164 if response == gtk.RESPONSE_APPLY: 165 self.emit('set', self.element_entry.get_text(), 166 self.property_entry.get_text(), 167 self.value_entry.get_text()) 168 elif response == self.RESPONSE_FETCH: 169 self.emit('get', self.element_entry.get_text(), 170 self.property_entry.get_text()) 171 elif response == gtk.RESPONSE_CLOSE: 172 dialog.hide()
173
174 - def update_value_entry(self, value):
175 self.value_entry.set_text(str(value))
176 177 pygobject.type_register(PropertyChangeDialog) 178