Package flumotion :: Package wizard :: Module productionsteps
[hide private]

Source Code for Module flumotion.wizard.productionsteps

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008 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  import gettext 
 23   
 24  import gtk 
 25   
 26  from flumotion.common.errors import NoBundleError 
 27  from flumotion.common.i18n import N_ 
 28  from flumotion.ui.wizard import WizardStep 
 29   
 30  # Register components 
 31  from flumotion.common import componentui 
 32   
 33  __version__ = "$Rev: 6970 $" 
 34  # pychecker doesn't like the auto-generated widget attrs 
 35  # or the extra args we name in callbacks 
 36  __pychecker__ = 'no-classattr no-argsused' 
 37  _ = gettext.gettext 
 38   
 39   
40 -class LiveProductionStep(WizardStep):
41 name = 'Production' 42 title = _('Production') 43 section = _('Production') 44 icon = 'source.png' 45 gladeFile = 'production-wizard.glade' 46
47 - def __init__(self, wizard):
48 self._audioProducer = None 49 self._videoProducer = None 50 self._loadedSteps = None 51 WizardStep.__init__(self, wizard)
52 53 # Public API 54
55 - def hasAudio(self):
56 """Returns if audio will be used in the stream 57 created by the wizard. 58 59 @returns: if audio will be used 60 @rtype: bool 61 """ 62 return self.has_audio.get_active()
63
64 - def hasVideo(self):
65 """Returns if video will be used in the stream 66 created by the wizard. 67 68 @returns: if video will be used 69 @rtype: bool 70 """ 71 return self.has_video.get_active()
72
73 - def getAudioProducer(self):
74 """Returns the selected audio producer or None 75 @returns: producer or None 76 @rtype: L{flumotion.wizard.models.AudioProducer} 77 """ 78 if self.has_audio.get_active(): 79 return self._audioProducer
80
81 - def getVideoProducer(self):
82 """Returns the selected video producer or None 83 @returns: producer or None 84 @rtype: L{flumotion.wizard.models.VideoProducer} 85 """ 86 if self.has_video.get_active(): 87 return self._videoProducer
88
89 - def getVideoStep(self):
90 """Return the video step to be shown, given the currently 91 selected values in this step 92 @returns: video step 93 @rtype: a deferred returning a L{basesteps.VideoProducerStep} instance 94 """ 95 def stepLoaded(step): 96 if step is not None: 97 self._videoProducer = step.model 98 self.wizard.taskFinished() 99 return step
100 self.wizard.waitForTask('video producer step') 101 d = self._loadStep(self.video, 'video') 102 d.addCallback(stepLoaded) 103 return d
104
105 - def getAudioStep(self):
106 """Return the audio step to be shown, given the currently 107 selected values in this step 108 @returns: audio step 109 @rtype: a deferred returning a L{basesteps.AudioProducerStep} instance 110 """ 111 def stepLoaded(step): 112 if step is not None: 113 self._audioProducer = step.model 114 self.wizard.taskFinished() 115 return step
116 self.wizard.waitForTask('audio producer step') 117 d = self._loadStep(self.audio, 'audio') 118 d.addCallback(stepLoaded) 119 return d 120 121 # WizardStep 122
123 - def setup(self):
124 self.audio.data_type = object 125 self.video.data_type = object 126 # We want to save the audio/video attributes as 127 # componentType in the respective models 128 self.audio.model_attribute = 'componentType' 129 self.video.model_attribute = 'componentType' 130 131 tips = gtk.Tooltips() 132 tips.set_tip(self.has_video, _('If you want to stream video')) 133 tips.set_tip(self.has_audio, _('If you want to stream audio')) 134 135 self._populateCombos()
136
137 - def getNext(self):
138 if self.hasVideo(): 139 return self.getVideoStep() 140 elif self.hasAudio(): 141 return self.getAudioStep() 142 else: 143 raise AssertionError
144 145 # Private API 146
147 - def _populateCombos(self):
148 def gotEntries(entries, combo, default_type): 149 data = [] 150 default = None 151 for entry in entries: 152 if entry.componentType == default_type: 153 default = entry 154 continue 155 data.append((N_(entry.description), entry.componentType)) 156 assert default 157 data.insert(0, (N_(default.description), default.componentType)) 158 combo.prefill(data) 159 combo.set_sensitive(True)
160 161 for ctype, combo, default_type in [ 162 ('video-producer', self.video, 'videotest-producer'), 163 ('audio-producer', self.audio, 'audiotest-producer')]: 164 d = self.wizard.getWizardEntries( 165 wizardTypes=[ctype]) 166 d.addCallback(gotEntries, combo, default_type) 167 combo.prefill([('...', None)]) 168 combo.set_sensitive(False) 169 170 self.wizard.waitForTask('querying producers') 171 def done(_): 172 self.wizard.taskFinished() 173 self._loadedSteps = True 174 d.addCallback(done) 175
176 - def _loadPlugin(self, componentType, type):
177 def gotFactory(factory): 178 return factory(self.wizard)
179 180 def noBundle(failure): 181 failure.trap(NoBundleError) 182 183 d = self.wizard.getWizardEntry(componentType) 184 d.addCallback(gotFactory) 185 d.addErrback(noBundle) 186 187 return d 188
189 - def _loadStep(self, combo, type):
190 def pluginLoaded(plugin, entry): 191 # FIXME: verify that factory implements IProductionPlugin 192 step = plugin.getProductionStep(type) 193 return step
194 195 entry = combo.get_selected() 196 d = self._loadPlugin(entry, type) 197 d.addCallback(pluginLoaded, entry) 198 199 return d 200
201 - def _verify(self):
202 if not self._loadedSteps: 203 return 204 205 canContinue = self.hasAudio() or self.hasVideo() 206 self.wizard.blockNext(not canContinue)
207 208 # Callbacks 209
210 - def on_has_video__toggled(self, button):
211 self.video.set_sensitive(button.get_active()) 212 self._verify()
213
214 - def on_has_audio__toggled(self, button):
215 self.audio.set_sensitive(button.get_active()) 216 self._verify()
217
218 - def on_video__changed(self, button):
219 self._verify()
220
221 - def on_audio__changed(self, button):
222 self._verify()
223 224
225 -class SelectProducersStep(WizardStep):
226 name = 'Production' 227 title = _('Production') 228 section = _('Production') 229 icon = 'source.png' 230 gladeFile = 'select-producers-wizard.glade' 231
232 - def __init__(self, wizard):
233 self._audioProducer = None 234 self._videoProducer = None 235 self._loadedSteps = None 236 WizardStep.__init__(self, wizard)
237 238 # Public API 239
240 - def hasAudio(self):
241 """Returns if audio will be used in the stream 242 created by the wizard. 243 244 @returns: if audio will be used 245 @rtype: bool 246 """ 247 return self.has_audio.get_active()
248
249 - def hasVideo(self):
250 """Returns if video will be used in the stream 251 created by the wizard. 252 253 @returns: if video will be used 254 @rtype: bool 255 """ 256 return self.has_video.get_active()
257
258 - def getAudioProducer(self):
259 """Returns the selected audio producer or None 260 @returns: producer or None 261 @rtype: L{flumotion.wizard.models.AudioProducer} 262 """ 263 if self.has_audio.get_active(): 264 return self.audio.get_selected()
265
266 - def getVideoProducer(self):
267 """Returns the selected video producer or None 268 @returns: producer or None 269 @rtype: L{flumotion.wizard.models.VideoProducer} 270 """ 271 if self.has_video.get_active(): 272 return self.video.get_selected()
273
274 - def setVideoProducers(self, videoProducers):
275 self.video.prefill([(N_(vp.description), vp) for vp in videoProducers]) 276 self._updateWidgets()
277
278 - def setAudioProducers(self, audioProducers):
279 self.audio.prefill([(N_(vp.description), vp) for vp in audioProducers]) 280 self._updateWidgets()
281 282 # WizardStep 283
284 - def setup(self):
285 self.audio.data_type = object 286 self.video.data_type = object 287 # We want to save the audio/video attributes as 288 # componentType in the respective models 289 self.audio.model_attribute = 'componentType' 290 self.video.model_attribute = 'componentType' 291 292 tips = gtk.Tooltips() 293 tips.set_tip(self.has_video, _('If you want to stream video')) 294 tips.set_tip(self.has_audio, _('If you want to stream audio'))
295
296 - def getNext(self):
297 return None
298 299 # Private API 300
301 - def _updateWidgets(self):
302 # We can't call getAudio/VideoProducer here, since they 303 # depend on set_active() being enabled 304 hasAudio = bool(self.audio.get_model_strings()) 305 hasVideo = bool(self.video.get_model_strings()) 306 hasBoth = hasVideo and hasAudio 307 self.has_video.set_active(hasVideo) 308 self.has_audio.set_active(hasAudio) 309 self.audio.set_property('visible', hasAudio) 310 self.video.set_property('visible', hasVideo) 311 self.has_audio.set_property('visible', hasBoth) 312 self.has_video.set_property('visible', hasBoth)
313
314 - def _verify(self):
315 canContinue = self.hasAudio() or self.hasVideo() 316 self.wizard.blockNext(not canContinue)
317 318 # Callbacks 319
320 - def on_has_video__toggled(self, button):
321 self.video.set_sensitive(button.get_active()) 322 self._verify()
323
324 - def on_has_audio__toggled(self, button):
325 self.audio.set_sensitive(button.get_active()) 326 self._verify()
327
328 - def on_video__changed(self, button):
329 self._verify()
330
331 - def on_audio__changed(self, button):
332 self._verify()
333