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

Source Code for Module flumotion.component.producers.webcam.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) 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  import os 
 24   
 25  from zope.interface import implements 
 26   
 27  from flumotion.common import errors 
 28  from flumotion.common.fraction import fractionAsString 
 29  from flumotion.common.i18n import N_, gettexter 
 30  from flumotion.common.messages import Info 
 31  # FIXME: make pychecker able to suppress shadowed builtins like these 
 32  # at the defining site, not caller site 
 33  # P2.4 
 34  __pychecker__ = 'no-shadowbuiltin' 
 35  from flumotion.common.python import sorted 
 36  __pychecker__ = '' 
 37  from flumotion.wizard.basesteps import VideoProducerStep 
 38  from flumotion.wizard.interfaces import IProducerPlugin 
 39  from flumotion.wizard.models import VideoProducer 
 40   
 41  __version__ = "$Rev: 7097 $" 
 42  _ = gettext.gettext 
 43  T_ = gettexter() 
 44   
 45   
46 -class WebcamProducer(VideoProducer):
47 componentType = 'webcam-producer' 48
49 - def __init__(self):
50 super(WebcamProducer, self).__init__() 51 52 self.properties.device = '/dev/video0'
53 54
55 -class WebcamStep(VideoProducerStep):
56 name = 'Webcam' 57 title = _('Webcam') 58 icon = 'webcam.png' 59 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 60 'wizard.glade') 61 componentType = 'video4linux' 62
63 - def __init__(self, wizard, model):
64 VideoProducerStep.__init__(self, wizard, model) 65 self._inSetup = False 66 # _sizes is probed, not set from the UI 67 self._sizes = None
68 69 # WizardStep 70
71 - def setup(self):
72 self._inSetup = True 73 self.device.data_type = str 74 self.framerate.data_type = object 75 76 self.device.prefill(['/dev/video0', 77 '/dev/video1', 78 '/dev/video2', 79 '/dev/video3']) 80 81 self.add_proxy(self.model.properties,['device']) 82 83 self._inSetup = False
84
85 - def workerChanged(self, worker):
86 self.model.worker = worker 87 self._clear() 88 self._runChecks()
89 90 # Private 91
92 - def _clear(self):
93 # Clear is called: 94 # - when changing a worker 95 # - after probing a device, if none found 96 self.size.set_sensitive(False) 97 self.framerate.set_sensitive(False) 98 self.label_name.set_label("")
99
100 - def _runChecks(self):
101 if self._inSetup: 102 return None 103 104 self.wizard.waitForTask('webcam checks') 105 106 device = self.device.get_selected() 107 msg = Info(T_( 108 N_("Probing the webcam. This can take a while...")), 109 mid='webcam-check') 110 self.wizard.add_msg(msg) 111 d = self.runInWorker('flumotion.worker.checks.video', 'checkWebcam', 112 device, mid='webcam-check') 113 114 def errRemoteRunFailure(failure): 115 failure.trap(errors.RemoteRunFailure) 116 self.debug('a RemoteRunFailure happened') 117 self._clear() 118 self.wizard.taskFinished(blockNext=True)
119 120 def errRemoteRunError(failure): 121 failure.trap(errors.RemoteRunError) 122 self.debug('a RemoteRunError happened') 123 self._clear() 124 self.wizard.taskFinished(blockNext=True)
125 126 def deviceFound(result): 127 if not result: 128 self.debug('no device %s' % device) 129 self._clear() 130 self.wizard.taskFinished(blockNext=True) 131 return None 132 133 deviceName, factoryName, sizes = result 134 self.model.properties.element_factory = factoryName 135 self._populateSizes(sizes) 136 self.wizard.clear_msg('webcam-check') 137 self.label_name.set_label(deviceName) 138 self.wizard.taskFinished() 139 self.size.set_sensitive(True) 140 self.framerate.set_sensitive(True) 141 142 d.addCallback(deviceFound) 143 d.addErrback(errRemoteRunFailure) 144 d.addErrback(errRemoteRunError) 145
146 - def _populateSizes(self, sizes):
147 # Set sizes before populating the values, since 148 # it trigger size_changed which depends on this 149 # to be set 150 self._sizes = sizes 151 152 values = [] 153 for w, h in sorted(sizes.keys(), reverse=True): 154 values.append(['%d x %d' % (w, h), (w, h)]) 155 self.size.prefill(values)
156
157 - def _populateFramerates(self, size):
158 values = [] 159 for d in self._sizes[size]: 160 num, denom = d['framerate'] 161 values.append(('%.2f fps' % (1.0*num/denom), d)) 162 self.framerate.prefill(values)
163
164 - def _updateSize(self):
165 size = self.size.get_selected() 166 if size: 167 self._populateFramerates(size) 168 width, height = size 169 else: 170 self.warning('something bad happened: no height/width selected?') 171 width, height = 320, 240 172 173 self.model.properties.width = width 174 self.model.properties.height = height
175
176 - def _updateFramerate(self):
177 if self._inSetup: 178 return None 179 180 framerate = self.framerate.get_selected() 181 if framerate: 182 num, denom = framerate['framerate'] 183 mime = framerate['mime'] 184 format = framerate.get('format', None) 185 else: 186 self.warning('something bad happened: no framerate selected?') 187 num, denom = 15, 2 188 mime = 'video/x-raw-yuv' 189 format = None 190 191 self.model.properties.mime = mime 192 self.model.properties.framerate = fractionAsString((num, denom)) 193 if format: 194 self.model.properties.format = format
195 196 # Callbacks 197
198 - def on_device_changed(self, combo):
199 self._runChecks()
200
201 - def on_size_changed(self, combo):
202 self._updateSize()
203
204 - def on_framerate_changed(self, combo):
205 self._updateFramerate()
206 207
208 -class WebcamWizardPlugin(object):
209 implements(IProducerPlugin)
210 - def __init__(self, wizard):
211 self.wizard = wizard 212 self.model = WebcamProducer()
213
214 - def getProductionStep(self, type):
215 return WebcamStep(self.wizard, self.model)
216