diff options
Diffstat (limited to 'screencast_ui.py')
-rw-r--r-- | screencast_ui.py | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/screencast_ui.py b/screencast_ui.py new file mode 100644 index 0000000..2290dff --- /dev/null +++ b/screencast_ui.py @@ -0,0 +1,260 @@ +# -*- coding: utf-8 -*- + +# Copyright 2012 Ariel Calzada - ariel@activitycentral.com +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +""" +Screencast Activity: An activity for producing XO tutorials. +Based on http://git.sugarlabs.org/screencast +UI Component +""" + +# Toolbar +from sugar.activity.activity import ActivityToolbox + +# GTK +import gtk + +# Sugar graphics widget +from sugar.graphics.combobox import ComboBox + +# GObject used for subclassing and finally for managing signals +import gobject + +# Alert popup +from sugar.graphics.alert import NotifyAlert + +class ScreencastUI(gobject.GObject): + """ Screencast UI + """ + + # Attributes + _activity = None + _toolbar = None + _toolbox = None + _mainbox = None + _buttonsbox = None + _recordButton = None + _stopButton = None + _soundandquality = None + _soundCheck = None + _qualityCombo = None + _mainboxAlign = None + _statusbar = None + _progressbar = None + + # Custom signals + __gsignals__ = { + 'record-button-clicked-signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()), + 'stop-button-clicked-signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()), + } + + def __init__(self, activity): + """ Constructor + """ + super(ScreencastUI, self).__init__() + + self._activity = activity + + def buildGUI(self): + """ Build GUI + """ + + # Toolbar + self.buildToolbar() + + # Sound checkbox and quality combobox + self.buildSoundAndQuality() + + # Buttons + self.buildButtons() + + # Buttons + self.buildButtons() + + # Progress bar + self.buildProgressBar() + + # Status bar + self.buildStatusBar() + + # we do not have collaboration features + # make the share option insensitive + self.max_participants = 1 + + # Add items to mainbox + self._mainbox = gtk.VBox() + self._mainbox.pack_start(self._soundandquality, expand=True, fill=False, padding=20) + self._mainbox.pack_start(self._buttonsbox, expand=True, fill=False, padding=20) + self._mainbox.pack_start(self._progressbar, expand=True, fill=False, padding=20) + self._mainbox.pack_start(self._statusbar, expand=True, fill=False, padding=20) + + # Align mainbox + self._mainboxAlign = gtk.Alignment(0.5, 0.5, 0, 0) + self._mainboxAlign.add(self._mainbox) + + # Set canvas with box alignment + self._activity.set_canvas(self._mainboxAlign) + + def buildToolbar(self): + """ Build GUI Toolbar + """ + self._toolbox = ActivityToolbox(self._activity) + self._toolbar = self._toolbox.get_activity_toolbar() + + # Remove share button + self._toolbar.remove(self._toolbar.share) + self._toolbar.share = None + + self._activity.set_toolbox(self._toolbox) + + def buildSoundAndQuality(self): + """ Build sound checkbox and quality combobox + """ + self._soundandquality = gtk.HBox(spacing=50) + + self._soundCheck = gtk.CheckButton(label="Record sound") + self._soundCheck.set_active(True) + self._soundandquality.add(self._soundCheck) + + self._qualityCombo = ComboBox() + self._qualityCombo.append_item("0", " High quality video") + self._qualityCombo.append_item("1", " Medium quality video") + self._qualityCombo.append_item("2", " Low quality video") + self._qualityCombo.set_active(2) + self._soundandquality.add(self._qualityCombo) + + def buildButtons(self): + """ Build record and stop buttons + """ + + # Record button + self._recordButton = gtk.Button("Record") + self._recordButton.connect("clicked", self.recordButtonClicked) + self._recordButton.set_size_request(150, 150) + recordButtonIcon = gtk.Image() + recordButtonIcon.set_from_icon_name("media-record", -1) + self._recordButton.set_image(recordButtonIcon) + + # Stop button + self._stopButton = gtk.Button("Stop") + self._stopButton.connect("clicked", self.stopButtonClicked) + self._stopButton.set_size_request(150, 150) + self._stopButton.set_sensitive(False) + stopButtonIcon = gtk.Image() + stopButtonIcon.set_from_icon_name("media-playback-stop", -1) + self._stopButton.set_image(stopButtonIcon) + + # Buttons hbox + self._buttonsbox = gtk.HBox() + self._buttonsbox.pack_start(self._recordButton, expand=False, padding=40) + self._buttonsbox.pack_start(self._stopButton, expand=False, padding=40) + + def showGUI(self): + """ Show GUI + """ + self._activity.show_all() + self._progressbar.hide() + + def recordButtonClicked(self, widget): + """ Clicked event handler for record button + """ + self.emit('record-button-clicked-signal') + + def stopButtonClicked(self, widget): + """ Clicked event handler for stop button + """ + self.emit('stop-button-clicked-signal') + + def changeButtonsState(self, activate="record"): + """ Change sensitive property for the buttons + """ + if activate == "record": + self._recordButton.set_sensitive(False) + self._soundCheck.set_sensitive(False) + self._qualityCombo.set_sensitive(False) + self._stopButton.set_sensitive(True) + self._statusbar.set_text("Status: Recording") + elif activate == "encode": + self._stopButton.set_sensitive(False) + self._recordButton.set_sensitive(False) + self._soundCheck.set_sensitive(False) + self._qualityCombo.set_sensitive(False) + self._statusbar.set_text("Status: Encoding") + else: + self._stopButton.set_sensitive(False) + self._recordButton.set_sensitive(True) + self._soundCheck.set_sensitive(True) + self._qualityCombo.set_sensitive(True) + self._statusbar.set_text("Status: Stopped") + + def isSoundCheckActive(self): + """ Sound checked + """ + return self._soundCheck.get_active() + + def getCurrentQuality(self): + """ Get current video quality + """ + return self._qualityCombo.get_active() + + def buildProgressBar(self): + """ Progress bar + """ + self._progressbar = gtk.ProgressBar(adjustment=None) + self._progressbar.set_fraction(0) + self._progressbar.set_text("0% complete") + + def buildStatusBar(self): + """ Status bar + """ + self._statusbar = gtk.Label("Status: Stopped") + + def changeStatusbarText(self, text): + """ Change text of statusbar + """ + self._statusbar.set_text(text) + + def showProgressbar(self): + """ Show the progressbar + """ + self._progressbar.show() + + def hideProgressbar(self): + """ Hide the progressbar + """ + self._progressbar.hide() + + def updateProgressbar(self, percentage): + """ Update percentage value + """ + self._progressbar.set_fraction(percentage/100.0) + self._progressbar.set_text("%d%%"%int(percentage)+' complete') + + def alert(self, title, text=None): + """ Alert popup + """ + alert = NotifyAlert(timeout=10) + alert.props.title = title + alert.props.msg = text + self._activity.add_alert(alert) + alert.connect('response', self.alert_cancel_cb) + alert.show() + + def alert_cancel_cb(self, alert, response_id): + """ Destroy alert popup + """ + self._activity.remove_alert(alert) |