Package flumotion :: Package component :: Package producers :: Package looper :: Module wizard_gtk
[hide private]

Source Code for Module flumotion.component.producers.looper.wizard_gtk

  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,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 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.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  import gettext 
 19  import os 
 20   
 21  import gobject 
 22  import gtk 
 23   
 24  from zope.interface import implements 
 25   
 26  from flumotion.common import messages 
 27  from flumotion.common.i18n import N_, gettexter 
 28  from flumotion.admin.gtk.basesteps import AudioProducerStep, VideoProducerStep 
 29  from flumotion.admin.assistant.interfaces import IProducerPlugin 
 30  from flumotion.admin.assistant.models import AudioProducer, VideoProducer, \ 
 31       AudioEncoder, VideoEncoder, VideoConverter 
 32  from flumotion.ui.fileselector import FileSelectorDialog 
 33   
 34  __pychecker__ = 'no-returnvalues' 
 35  __version__ = "$Rev: 6583 $" 
 36  _ = gettext.gettext 
 37  T_ = gettexter('flumotion') 
 38   
 39   
40 -class LoopProducer(AudioProducer, VideoProducer):
41 componentType = 'loop-producer' 42
43 - def __init__(self):
44 super(LoopProducer, self).__init__() 45 self.properties.location = None 46 self.properties.framerate = 5.0 47 self.properties.width = 320 48 self.properties.height = 240
49
50 - def getFeederName(self, component):
51 if isinstance(component, AudioEncoder): 52 return 'audio' 53 elif isinstance(component, (VideoEncoder, VideoConverter)): 54 return 'video' 55 else: 56 raise AssertionError
57 58
59 -class _LoopCommon:
60 icon = 'looper.png' 61 componentType = 'filesrc' 62 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 63 'wizard.glade') 64 65 _mimetype = 'application/ogg' 66 _audio_required = True 67 _video_required = True 68
69 - def __init__(self):
70 self._idleId = -1 71 self._blockNext = {}
72
73 - def workerChanged(self, worker):
74 self.model.worker = worker 75 self._runChecks()
76
77 - def setup(self):
78 return
79
80 - def _runChecks(self):
81 self._runFileCheck(self.model.properties.location, 'location')
82
83 - def _runFileCheck(self, location, id):
84 self._blockNext[id] = True 85 if location is None or location == '': 86 self._verify() 87 return 88 self.wizard.waitForTask('looper location check') 89 90 def checkFileFinished(result): 91 validFile, properties = result 92 if not validFile: 93 message = messages.Warning(T_(N_( 94 "'%s' is not a valid file, " 95 "or is not readable on worker '%s'.") 96 % (location, self.worker))) 97 message.id = 'looper-'+id+'-check' 98 self.wizard.add_msg(message) 99 else: 100 self._updateFileProperties(properties) 101 self.wizard.clear_msg('looper-'+id+'-check') 102 self._blockNext[id] = False 103 self.wizard.taskFinished() 104 self._verify()
105 d = self.runInWorker('flumotion.worker.checks.check', 106 'checkMediaFile', 107 location, 108 self._mimetype, 109 self._audio_required, 110 self._video_required) 111 d.addCallback(checkFileFinished)
112
113 - def _abortScheduledCheck(self):
114 if self._idleId != -1: 115 gobject.source_remove(self._idleId) 116 self._idleId = -1
117
118 - def _scheduleCheck(self, checkToRun, data, id):
119 self._abortScheduledCheck() 120 self._idleId = gobject.timeout_add(300, checkToRun, data, id)
121
122 - def _clearMessage(self, id):
123 self.wizard.clear_msg('looper-'+id+'-check') 124 self._blockNext[id] = False
125
126 - def _verify(self):
127 self.wizard.blockNext(reduce(lambda x, y: x or y, 128 self._blockNext.values(), 129 False))
130
131 - def _showFileSelector(self, response_cb, location):
132 133 def deleteEvent(fs, event): 134 pass
135 136 fs = FileSelectorDialog(self.wizard.window, 137 self.wizard.getAdminModel()) 138 139 fs.connect('response', response_cb) 140 fs.connect('delete-event', deleteEvent) 141 fs.selector.setWorkerName(self.model.worker) 142 fs.selector.setOnlyDirectoriesMode(False) 143 if location: 144 directory = os.path.dirname(location) 145 else: 146 directory = '/' 147 fs.selector.setDirectory(directory) 148 fs.show_all() 149
150 - def _updateFileProperties(self, props):
151 pass
152
153 - def on_browse_clicked(self, button):
154 155 def response(fs, response): 156 fs.hide() 157 if response == gtk.RESPONSE_OK: 158 self.model.properties.location = fs.getFilename() 159 self._proxy.update('location') 160 self._clearMessage('location') 161 self._runFileCheck(self.model.properties.location, 'location')
162 163 self._showFileSelector(response, 164 self.model.properties.location) 165
166 - def on_location_changed(self, entry):
167 self._scheduleCheck(self._runFileCheck, 168 entry.get_text(), 169 'location')
170 171
172 -class LoopVideoStep(_LoopCommon, VideoProducerStep):
173 title = _('Loop Video') 174 name = 'Loop Video' 175
176 - def __init__(self, wizard, model):
177 VideoProducerStep.__init__(self, wizard, model) 178 _LoopCommon.__init__(self)
179
180 - def setup(self):
181 self._audio_required = False 182 self.location.data_type = str 183 self.width.data_type = int 184 self.height.data_type = int 185 self.framerate.data_type = float 186 self._proxy = self.add_proxy(self.model.properties, 187 ['width', 'height', 188 'framerate', 'location'])
189
190 - def _updateFileProperties(self, props):
191 self.model.properties.width = props.get('width', 192 self.model.properties.width) 193 self.model.properties.height = props.get('height', 194 self.model.properties.height) 195 self.model.properties.framerate = props.get('framerate', 196 self.model.properties.framerate) 197 self._proxy.update('width') 198 self._proxy.update('height') 199 self._proxy.update('framerate')
200 201
202 -class LoopAudioStep(_LoopCommon, AudioProducerStep):
203 name = 'Loop audio' 204 title = _('Loop audio') 205
206 - def __init__(self, wizard, model):
207 AudioProducerStep.__init__(self, wizard, model) 208 _LoopCommon.__init__(self)
209
210 - def setup(self):
211 self._video_required = False 212 self.location.data_type = str 213 self._proxy = self.add_proxy(self.model.properties, ['location']) 214 self.video.hide() 215 videoProducer = self.wizard.getStep('Production').getVideoProducer() 216 if not videoProducer or videoProducer.componentType != 'loop-producer': 217 self.location_box.set_sensitive(True) 218 else: 219 self.location.set_text(videoProducer.properties.location) 220 self.location_box.set_sensitive(False)
221
222 - def getNext(self):
223 return None
224 225
226 -class LoopWizardPlugin(object):
227 implements(IProducerPlugin) 228
229 - def __init__(self, wizard):
230 self.wizard = wizard
231
232 - def getProductionStep(self, type):
233 if type == 'audio': 234 return LoopAudioStep(self.wizard, LoopProducer()) 235 elif type == 'video': 236 return LoopVideoStep(self.wizard, LoopProducer())
237