diff options
Diffstat (limited to 'pippy_app.py')
-rw-r--r-- | pippy_app.py | 320 |
1 files changed, 0 insertions, 320 deletions
diff --git a/pippy_app.py b/pippy_app.py deleted file mode 100644 index ea05c7a..0000000 --- a/pippy_app.py +++ /dev/null @@ -1,320 +0,0 @@ -# Copyright 2008 Chris Ball. -# -# 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.""" -from gettext import gettext as _ -from dbus.service import method, signal as dbus_signal -import fcntl -import gobject -import gtk -import logging -import os -import popen2 -import re -import shutil -import signal -import sys - -from activity import ViewSourceActivity -from sugar.activity.activity import ActivityToolbox, \ - get_bundle_path, get_bundle_name -from sugar.graphics.alert import NotifyAlert -from sugar.graphics.combobox import ComboBox - -SERVICE = "org.laptop.Screencast" -IFACE = SERVICE -PATH = "/org/laptop/Screencast" - -OUTFILE = "/tmp/recordmydesktop.ogv" - -class ScreencastActivity(ViewSourceActivity): - """Screencast Activity as specified in activity.info""" - def __init__(self, handle): - """Set up the Screencast activity.""" - super(ScreencastActivity, self).__init__(handle) - self._logger = logging.getLogger('screencast-activity') - self.timed_id2 = None - - from sugar.graphics.menuitem import MenuItem - from sugar.graphics.icon import Icon - - # Main layout. Record button, stop button, label. - hbox = gtk.HBox() - vbox = gtk.VBox() - - # Toolbar. - toolbox = ActivityToolbox(self) - activity_toolbar = toolbox.get_activity_toolbar() - activity_toolbar.remove(activity_toolbar.share) - activity_toolbar.share = None - activity_toolbar.remove(activity_toolbar.keep) - activity_toolbar.keep = None - self.set_toolbox(toolbox) - toolbox.show() - - # Recording buttons. - self.record = gtk.Button("Record") - self.record.connect("clicked", self.record_cb) - self.record.set_size_request(150, 150) - recimage = gtk.Image() - recimage.set_from_icon_name("media-record", -1) - self.record.set_image(recimage) - self.stop = gtk.Button("Stop") - self.stop.connect("clicked", self.stop_cb) - self.stop.set_size_request(150, 150) - self.stop.set_sensitive(False) - stopimage = gtk.Image() - stopimage.set_from_icon_name("media-playback-stop", -1) - self.stop.set_image(stopimage) - - # Record sound checkbox and quality selector - hbox2 = gtk.HBox(spacing=50) - self.audiocheckbox = gtk.CheckButton(label="record sound") - self.audiocheckbox.set_active(True) - hbox2.add(self.audiocheckbox) - 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) - - hbox2.add(self.qualitycombo) - options = gtk.Alignment(0.5, 0, 0, 0) - options.add(hbox2) - - # Status label. - self.status = gtk.Label(_("Status: Stopped")) - hbox.pack_start(self.record, expand=False, padding=40) - hbox.pack_start(self.stop, expand=False, padding=40) - - # Encoding progress bar - self.progressbar=gtk.ProgressBar(adjustment=None) - self.progressbar.set_fraction(0) - self.progressbar.set_text("0% complete") - - valign = gtk.Alignment(0.5, 0.4, 0, 0) - valign.add(vbox) - vbox.pack_end(self.progressbar, expand=True, padding=20) - vbox.pack_end(self.status, expand=True, padding=40) - vbox.pack_end(hbox, expand=True, fill=False) - vbox.pack_end(options, expand=True, padding=40) - - self.set_canvas(valign) - self.show_all() - self.progressbar.hide() - - def write_file (self, file_path): - print "Saving file to %s" % file_path - self.metadata['mime_type'] = 'video/ogg' - #try: - # shutil.copy(OUTFILE, file_path) - - #except IOError, e: - # print "unable to save to outfile: %s" % e - - - # FIXME: This fails in /tmp. - # that comment by probably cjb - # I have no idea why it was saving to filepath - #added copy-to-journal in check_status_cb - #error msgs are OK probably just no video processed - #Tony Forster - - #try: - - # os.remove(OUTFILE) - #except OSError, e: - # print "unable to remove outfile: %s" % e - - def can_close(self): - if self.status.get_text().startswith("Status: Stopped"): - return True - else: - self.alert("You need to finish operation before quitting.", self.status.get_text()) - - def alert(self, title, text=None): - alert = NotifyAlert(timeout=10) - alert.props.title = title - alert.props.msg = text - self.add_alert(alert) - alert.connect('response', self.alert_cancel_cb) - alert.show() - - def alert_cancel_cb(self, alert, response_id): - self.remove_alert(alert) - - def record_cb(self, record): - self.stop.set_sensitive(True) - self.record.set_sensitive(False) - self.audiocheckbox.set_sensitive(False) - self.qualitycombo.set_sensitive(False) - execargs = ["./recordmydesktop", "--no-frame", "--overwrite"] - if not self.audiocheckbox.get_active(): - execargs.append("--no-sound") - if self.qualitycombo.get_active()==0: - execargs.append("-v_quality") # in later versions seems to be --v_quality instead - execargs.append("0") - elif self.qualitycombo.get_active()==1: - execargs.append("-v_quality") # in later versions seems to be --v_quality instead - execargs.append("31") - execargs.append("-o") - execargs.append(OUTFILE) - self.childp = popen2.Popen3(execargs, "t", 0) - flags = fcntl.fcntl(self.childp.childerr, fcntl.F_GETFL) - fcntl.fcntl(self.childp.childerr, fcntl.F_SETFL, flags|os.O_NONBLOCK) - flags = fcntl.fcntl(self.childp.fromchild, fcntl.F_GETFL) - fcntl.fcntl(self.childp.fromchild, fcntl.F_SETFL, flags|os.O_NONBLOCK) - self.timed_id = gobject.timeout_add(1000, self.check_status_cb) - self.status.set_text("Status: Recording") - - def stop_cb(self, stop): - exitret = os.waitpid(self.childp.pid, os.WNOHANG) - if exitret[0] == 0: - os.kill(self.childp.pid, signal.SIGTERM) - self.stop.set_sensitive(False) - - def update_counter(self): - self.progressbar.show() - while True: - try: - strstdout=self.childp.fromchild.read() - self.counter_fraction=float(re.search("[0-9][0-9]?[0-9]?", strstdout).group()) - percentage=self.counter_fraction/100.0 - if percentage>1.0: - percentage=1.0 - #print "PORCENTAJE %s " % str(percentage) - self.progressbar.set_fraction(percentage) - self.progressbar.set_text("%d%%"%int(percentage*100)+' complete') - except IOError: - gtk.main_iteration(block=False) - except AttributeError: - break - except: - print "Unexpected error:", sys.exc_info()[0] - print "Unexpected error:", sys.exc_info()[1] - break - - def check_status_cb(self): - if self.childp.pid: - exitret = os.waitpid(self.childp.pid, os.WNOHANG) - if exitret[0] != 0: - # The recording process exited - self.status.set_text("Status: Stopped") - if self.timed_id2: - gobject.source_remove(self.timed_id2) - self.timed_id2 = None - self.progressbar.hide() - self.alert("Success:", "Saved recording to journal") - self.progressbar.set_fraction(0) - self.progressbar.set_text('0% complete') - self.record.set_sensitive(True) - self.audiocheckbox.set_sensitive(True) - self.qualitycombo.set_sensitive(True) - if self._jobject.metadata['title_set_by_user'] == '1': - title = self.metadata['title'] - else: - title = "My Screencast" - os.system("copy-to-journal /tmp/recordmydesktop.ogv -m video/ogg -t \"%s\""% title) - return False - else: - # Maybe we have new stderr. - while True: - try: - err_line = self.childp.childerr.readline() - if err_line.startswith("STATE:ENCODING"): - if not self.timed_id2: - self.timed_id2=gobject.timeout_add(300,self.update_counter) - self.status.set_text("Status: Encoding, please wait") - except: - break - return True - -############# TEMPLATES AND INLINE FILES ############## -ACTIVITY_INFO_TEMPLATE = """ -[Activity] -name = %(title)s -bundle_id = %(bundle_id)s -service_name = %(bundle_id)s -class = %(class)s -icon = activity-icon -activity_version = %(version)d -mime_types = %(mime_types)s -show_launcher = yes -%(extra_info)s -""" - -PIPPY_ICON = \ -"""<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [ - <!ENTITY stroke_color "#010101"> - <!ENTITY fill_color "#FFFFFF"> -]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="activity-pippy"> - <path d="M28.497,48.507 c5.988,0,14.88-2.838,14.88-11.185c0-9.285-7.743-10.143-10.954-11.083c-3.549-0.799-5.913-1.914-6.055-3.455 c-0.243-2.642,1.158-3.671,3.946-3.671c0,0,6.632,3.664,12.266,0.74c1.588-0.823,4.432-4.668,4.432-7.32 c0-2.653-9.181-5.719-11.967-5.719c-2.788,0-5.159,3.847-5.159,3.847c-5.574,0-11.149,5.306-11.149,10.612 c0,5.305,5.333,9.455,11.707,10.612c2.963,0.469,5.441,2.22,4.878,5.438c-0.457,2.613-2.995,5.306-8.361,5.306 c-4.252,0-13.3-0.219-14.745-4.079c-0.929-2.486,0.168-5.205,1.562-5.205l-0.027-0.16c-1.42-0.158-5.548,0.16-5.548,5.465 C8.202,45.452,17.347,48.507,28.497,48.507z" fill="&fill_color;" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5"/> - <path d="M42.579,19.854c-2.623-0.287-6.611-2-7.467-5.022" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-width="3"/> - <circle cx="35.805" cy="10.96" fill="&stroke_color;" r="1.676"/> -</g></svg><!-- " --> -""" - -PIPPY_DEFAULT_ICON = \ -"""<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [ - <!ENTITY stroke_color "#010101"> - <!ENTITY fill_color "#FFFFFF"> -]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" - viewBox="0 0 55 55" width="55px" x="0px" y="0px" xml:space="preserve" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" -><g display="block" id="activity-icon"><path - d="M 28.497,48.507 C 34.485,48.507 43.377,45.669 43.377,37.322 C 43.377,32.6795 41.44125,30.14375 39.104125,28.651125 C 36.767,27.1585 38.482419,26.816027 39.758087,25.662766 C 39.42248,24.275242 37.206195,22.826987 36.262179,21.037968 C 34.005473,20.582994 27.526,19.113 30.314,19.113 C 30.314,19.113 36.946,22.777 42.58,19.853 C 44.168,19.03 47.012,15.185 47.012,12.533 C 47.012,9.88 37.831,6.814 35.045,6.814 C 32.257,6.814 29.886,10.661 29.886,10.661 C 24.312,10.661 12.043878,16.258005 12.043878,21.564005 C 12.043878,24.216505 16.585399,30.069973 19.144694,33.736352 C 22.438716,38.455279 27.257,31.3065 30.444,31.885 C 33.407,32.354 35.885,34.105 35.322,37.323 C 34.865,39.936 32.327,42.629 26.961,42.629 C 22.709,42.629 13.661,42.41 12.216,38.55 C 11.287,36.064 12.384,33.345 13.778,33.345 L 13.751,33.185 C 12.331,33.027 8.203,33.345 8.203,38.65 C 8.202,45.452 17.347,48.507 28.497,48.507 z " - fill="&fill_color;" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5" /> - <path d="M42.579,19.854c-2.623-0.287-6.611-2-7.467-5.022" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-width="3"/> - <circle cx="35.805" cy="10.96" fill="&stroke_color;" r="1.676"/> -</g></svg><!-- " --> -""" - -############# ACTIVITY META-INFORMATION ############### -# this is used by Screencast to generate a bundle for itself. - -def pippy_activity_version(): - """Returns the version number of the generated activity bundle.""" - return 1 -def pippy_activity_extra_files(): - """Returns a map of 'extra' files which should be included in the - generated activity bundle.""" - # Cheat here and generate the map from the fs contents. - extra = {} - bp = get_bundle_path() - for d in [ 'po', 'data' ]: # everybody gets library already - for root, dirs, files in os.walk(os.path.join(bp, d)): - for name in files: - fn = os.path.join(root, name).replace(bp+'/', '') - extra[fn] = open(os.path.join(root, name), 'r').read() - extra['activity/activity-default.svg'] = PIPPY_DEFAULT_ICON - return extra -def pippy_activity_news(): - """Return the NEWS file for this activity.""" - # Cheat again. - return open(os.path.join(get_bundle_path(), 'NEWS')).read() -def pippy_activity_icon(): - """Return an SVG document specifying the icon for this activity.""" - return PIPPY_ICON -def pippy_activity_class(): - """Return the class which should be started to run this activity.""" - return 'pippy_app.ScreencastActivity' -def pippy_activity_bundle_id(): - """Return the bundle_id for the generated activity.""" - return 'org.laptop.Screencast' -def pippy_activity_mime_types(): - """Return the mime types handled by the generated activity, as a list.""" - return None |