Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/screencast_activity.py
blob: 4680c6db39e3f64c109fc772f254f625321857ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# -*- 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
"""

# Localization
from gettext import gettext as _

# Activity base class
from sugar.activity import activity

# Toolbar
from sugar.activity.activity import ActivityToolbox

# GTK
import gtk

# UI
import screencast_ui

# Process
#import screencast_process
import DesktopGrab

# GObject
import gobject

# OS
import os

# Bundlepath
from sugar.activity.activity import get_bundle_path

class ScreencastActivity(activity.Activity):
    """ Screencast Activity
    """

    # Attributes
    _ui = None
    #_process = None
    _outfile = None
    _state = None

    def __init__(self, handle):
        """ Constructor
        """

        # Call super class "Activity" constructor method
        super(ScreencastActivity, self).__init__(handle)

        # State
        self._state = "stop"

        # Out file
        self._outfile =  os.path.join( get_bundle_path(), "screencast.ogv" )

        # Build GUI
        self._ui = screencast_ui.ScreencastUI(self)
        self._ui.buildGUI()

        # Show GUI
        self._ui.showGUI()

        # Process
        self._process = DesktopGrab.DesktopGrab()
        self._process.connect('update', self.updateStatusbar)
        #self._process = screencast_process.ScreencastProcess()
        #self._process.connect('encode-start', self.startEncode)
        #self._process.connect('encode-finished', self.finishEncode)
        #self._process.connect('update-statusbar', self.updateStatusbar)

        # Connect UI signals
        self._ui.connect('record-button-clicked-signal', self.recordButtonClicked)
        self._ui.connect('stop-button-clicked-signal', self.stopButtonClicked)

    def recordButtonClicked(self, widget):
        """ Record button clicked event
        """
        self._ui.changeButtonsState("record")
        if self._ui.isSoundCheckActive():
            self._process.set_audio_enabled(True)
        else:
            self._process.set_audio_enabled(False)

        #self._process.runProcess(self._ui.getCurrentQuality(), self._ui.isSoundCheckActive(), self._outfile)
        self._process.set_audio_enabled(True)
        self._process.set_video_quality((800,600))

        self._process.record(self._outfile)
        self._state = "record"

    def stopButtonClicked(self, widget):
        """ Stop button clicked event
        """
        #self._ui.changeButtonsState("encode")
        self._ui.changeButtonsState("stop")
        #self._process.stopProcess()
        self._process.stop()
        self._state = "stop"

    def updateStatusbar(self, widget, text):
        """ Update status bar
        """
        self._ui.changeStatusbarText(text)

    #def startEncode(self,widget):
    #    """ Start encoding
    #    """
    #    self._ui.showProgressbar()
    #    self._state = "encode"
    #
    #def finishEncode(self,widget):
    #    """ Finish encoding
    #    """
    #    self._ui.changeButtonsState("stop")
    #    self._ui.hideProgressbar()
    #    self._state = "stop"
    #    self._ui.alert("Encode finished")
    #
    #
    #def updateStatusbar(self, widget, text, percentage):
    #    """ Update status bar
    #    """
    #    text = "Status: Encoding"
    #    self._ui.changeStatusbarText(text)
    #    self._ui.updateProgressbar(percentage)

    def write_file(self, filePath):
        """ Journal write file method
        """

        if os.path.exists(self._outfile) and self._state == "stop":
            self.metadata['mime_type'] = 'video/ogg'

            if self._jobject.metadata['title_set_by_user'] == '1':
                title = self.metadata['title']
            else:
                title = "My Screencast"

            cmd = "copy-to-journal %s -m video/ogg -t \"%s\"" % ( self._outfile, title )
            os.system(cmd)

    def can_close(self):
        """ Close before verification
        """

        if self._state == "stop":
            return True

        self._ui.alert("You need to finish current operation before quitting")
        return False