From ed57ea74b09395e23edceec969a6b87697e76d4b Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Mon, 01 Jun 2009 15:03:49 +0000 Subject: Hide photo/video tabs if camera doesn't exist #847 #848 --- diff --git a/gfx/stub.png b/gfx/stub.png new file mode 100644 index 0000000..42e593f --- /dev/null +++ b/gfx/stub.png Binary files differ diff --git a/glive.py b/glive.py index 99d6b7a..d681d44 100644 --- a/glive.py +++ b/glive.py @@ -33,7 +33,7 @@ gobject.threads_init() import logging logger = logging.getLogger('record:glive.py') -from sugar.activity.activity import get_activity_root +from sugar.activity.activity import get_activity_root, get_bundle_path from instance import Instance from constants import Constants @@ -52,8 +52,20 @@ OGG_TRAITS = { 1: { 'width': 400, 'height': 300, 'quality': 16 }, 2: { 'width': 640, 'height': 480, 'quality': 32 } } +THUMB_STUB = gtk.gdk.pixbuf_new_from_file( + os.path.join(get_bundle_path(), 'gfx', 'stub.png')) + +def _does_camera_present(): + v4l2src = gst.element_factory_make('v4l2src') + return v4l2src.props.device_name is not None + +camera_presents = _does_camera_present() + class Glive: def play(self): + if not camera_presents: + return + logger.debug('play') if not self.play_pipe: @@ -71,7 +83,7 @@ class Glive: '! %s' \ % (self.src_str, self.play_str)) self.valve = self.play_pipe.get_by_name('valve') - + def message_cb(bus, message): if message.type == gst.MESSAGE_ERROR: err, debug = message.parse_error() @@ -109,6 +121,9 @@ class Glive: self._switch_pipe(self.play_pipe) def thumb_play(self, use_fallback=False): + if not camera_presents: + return + if not self.fallback and not use_fallback: # use xv to scale video self.play() @@ -148,6 +163,9 @@ class Glive: self.pipeline.set_state(gst.STATE_NULL) def takePhoto(self, after_photo_cb=None): + if not camera_presents: + return + logger.debug('takePhoto') if not self.photo: @@ -201,6 +219,9 @@ class Glive: self._switch_pipe(self.play_pipe) def startRecordingVideo(self, quality): + if not camera_presents: + return + logger.debug('startRecordingVideo quality=%s' % quality) if not self.video_pipe or quality != self.ogg_quality: @@ -246,6 +267,9 @@ class Glive: self.takePhoto(process_cb) def stopRecordingVideo(self): + if not camera_presents: + return + logger.debug('stopRecordingVideo') self._switch_pipe(self.play_pipe) @@ -317,20 +341,27 @@ class Glive: def startRecordingAudio(self): logger.debug('startRecordingAudio') - # XXX re-create pipe every time + # XXX re-create pipe every time # to supress gst glitches during the second invoking if True: - self.audio_pipe = gst.parse_launch( \ - '%s ' \ - '! queue ' \ - '! %s ' \ + audio_pipe = \ 'alsasrc ' \ '! queue ' \ '! audioconvert ' \ '! vorbisenc name=vorbisenc ' \ '! oggmux ' \ '! filesink location=%s ' \ - % (self.src_str, self.play_str, TMP_OGG)) + % TMP_OGG + + if camera_presents: + self.audio_pipe = gst.parse_launch( \ + '%s ' \ + '! queue ' \ + '! %s ' \ + '%s ' \ + % (self.src_str, self.play_str, audio_pipe)) + else: + self.audio_pipe = gst.parse_launch(audio_pipe) def message_cb(bus, message, self): if message.type == gst.MESSAGE_ERROR: @@ -352,8 +383,11 @@ class Glive: self.pixbuf = pixbuf self._switch_pipe(self.audio_pipe) - # take photo first - self.takePhoto(process_cb) + if camera_presents: + # take photo first + self.takePhoto(process_cb) + else: + process_cb(self, THUMB_STUB) def stopRecordingAudio( self ): logger.debug('stopRecordingAudio') @@ -399,6 +433,9 @@ class Glive: self.mux_pipe = None self.audio_pipe = None + self.src_str = 'fakesrc' + self.play_str = 'fakesink' + self.fallback = False # XXX since sugar doesn't control capture volumes (see #800) diff --git a/ui.py b/ui.py index 73812d3..05fc34e 100644 --- a/ui.py +++ b/ui.py @@ -52,6 +52,7 @@ from p5 import P5 from p5_button import P5Button from p5_button import Polygon from p5_button import Button +import glive from glive import LiveVideoWindow from gplay import PlayVideoWindow from recorded import Recorded @@ -133,17 +134,30 @@ class UI: #this includes the default sharing tab self.toolbox = activity.ActivityToolbox(self.ca) self.ca.set_toolbox(self.toolbox) - self.photoToolbar = PhotoToolbar() - self.photoToolbar.set_sensitive( False ) - self.toolbox.add_toolbar( Constants.istrPhoto, self.photoToolbar ) - self.videoToolbar = VideoToolbar() - self.videoToolbar.set_sensitive( False ) - self.toolbox.add_toolbar( Constants.istrVideo, self.videoToolbar ) + + if glive.camera_presents: + self.photoToolbar = PhotoToolbar() + self.photoToolbar.set_sensitive( False ) + self.toolbox.add_toolbar( Constants.istrPhoto, self.photoToolbar ) + + self.videoToolbar = VideoToolbar() + self.videoToolbar.set_sensitive( False ) + self.toolbox.add_toolbar( Constants.istrVideo, self.videoToolbar ) + + self.tbars = { Constants.MODE_PHOTO: 1, + Constants.MODE_VIDEO: 2, + Constants.MODE_AUDIO: 3 } + else: + self.photoToolbar = None + self.videoToolbar = None + self.tbars = { Constants.MODE_AUDIO: 1 } + self.ca.m.MODE = Constants.MODE_AUDIO + self.audioToolbar = AudioToolbar() self.audioToolbar.set_sensitive( False ) self.toolbox.add_toolbar( Constants.istrAudio, self.audioToolbar ) - self.tbars = {Constants.MODE_PHOTO:self.photoToolbar,Constants.MODE_VIDEO:self.videoToolbar,Constants.MODE_AUDIO:self.audioToolbar} - self.toolbox.set_current_toolbar(self.ca.m.MODE+1) + + self.toolbox.set_current_toolbar(self.tbars[self.ca.m.MODE]) self.toolbox.remove(self.toolbox._separator) #taken directly from toolbox.py b/c I don't know how to mod the hongry hippo @@ -164,19 +178,33 @@ class UI: def serialize(self): data = {} - data['photo_timer'] = self.photoToolbar.timerCb.combo.get_active() - data['video_timer'] = self.videoToolbar.timerCb.combo.get_active() - data['video_duration'] = self.videoToolbar.durCb.combo.get_active() - data['video_quality'] = self.videoToolbar.quality.combo.get_active() + + if self.photoToolbar: + data['photo_timer'] = self.photoToolbar.timerCb.combo.get_active() + + if self.videoToolbar: + data['video_timer'] = self.videoToolbar.timerCb.combo.get_active() + data['video_duration'] = self.videoToolbar.durCb.combo.get_active() + data['video_quality'] = self.videoToolbar.quality.combo.get_active() + data['audio_timer'] = self.audioToolbar.timerCb.combo.get_active() data['audio_duration'] = self.audioToolbar.durCb.combo.get_active() + return data def deserialize(self, data): - self.photoToolbar.timerCb.combo.set_active(data.get('photo_timer', 0)) - self.videoToolbar.timerCb.combo.set_active(data.get('video_timer', 0)) - self.videoToolbar.durCb.combo.set_active(data.get('video_duration', 0)) - self.videoToolbar.quality.combo.set_active(data.get('video_quality', 0)) + if self.photoToolbar: + self.photoToolbar.timerCb.combo.set_active( + data.get('photo_timer', 0)) + + if self.videoToolbar: + self.videoToolbar.timerCb.combo.set_active( + data.get('video_timer', 0)) + self.videoToolbar.durCb.combo.set_active( + data.get('video_duration', 0)) + self.videoToolbar.quality.combo.set_active( + data.get('video_quality', 0)) + self.audioToolbar.timerCb.combo.set_active(data.get('audio_timer', 0)) self.audioToolbar.durCb.combo.set_active(data.get('audio_duration')) @@ -364,8 +392,10 @@ class UI: self.resetWidgetFadeTimer() self.showLiveVideoTags() - self.photoToolbar.set_sensitive( True ) - self.videoToolbar.set_sensitive( True ) + if self.photoToolbar: + self.photoToolbar.set_sensitive( True ) + if self.videoToolbar: + self.videoToolbar.set_sensitive( True ) self.audioToolbar.set_sensitive( True ) #initialize the app with the default thumbs @@ -508,14 +538,19 @@ class UI: def _toolbarChangeCb( self, tbox, num ): if (num != 0) and (self.ca.m.RECORDING or self.ca.m.UPDATING): - self.toolbox.set_current_toolbar( self.ca.m.MODE+1 ) + self.toolbox.set_current_toolbar(self.tbars[self.ca.m.MODE]) else: - num = num - 1 #offset the default activity tab - if (num == Constants.MODE_PHOTO) and (self.ca.m.MODE != Constants.MODE_PHOTO): + mode = [mode for mode, i in self.tbars.items() if i == num] + if not mode: + return + if (mode[0] == Constants.MODE_PHOTO) and \ + (self.ca.m.MODE != Constants.MODE_PHOTO): self.ca.m.doPhotoMode() - elif(num == Constants.MODE_VIDEO) and (self.ca.m.MODE != Constants.MODE_VIDEO): + elif(mode == Constants.MODE_VIDEO) and \ + (self.ca.m.MODE != Constants.MODE_VIDEO): self.ca.m.doVideoMode() - elif(num == Constants.MODE_AUDIO) and (self.ca.m.MODE != Constants.MODE_AUDIO): + elif(mode == Constants.MODE_AUDIO) and \ + (self.ca.m.MODE != Constants.MODE_AUDIO): self.ca.m.doAudioMode() @@ -798,8 +833,11 @@ class UI: def updateButtonSensitivities( self ): switchStuff = ((not self.ca.m.UPDATING) and (not self.ca.m.RECORDING)) - self.photoToolbar.set_sensitive( switchStuff ) - self.videoToolbar.set_sensitive( switchStuff ) + + if self.photoToolbar: + self.photoToolbar.set_sensitive( switchStuff ) + if self.videoToolbar: + self.videoToolbar.set_sensitive( switchStuff ) self.audioToolbar.set_sensitive( switchStuff ) if (not self.COUNTINGDOWN): -- cgit v0.9.1