Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ScreencastActivity.py
blob: 6b7543bedc9b9394ae9b6d535339dc74505d2af6 (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
# -*- coding: utf-8 -*-

# Copyright 2008 Chris Ball.
# Copyright 2012 Activity Central, Inc., Rafael Ortiz - rafael@activitycentral.com
# Copyright 2012 Activity Central, Inc., Ariel Calzada - ariel@activitycentral.com
# Copyright 2012 Activity Central, Inc., Flavio Danesse - flavio@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 3 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, see <http://www.gnu.org/licenses/>.

# Activity base class
from sugar.activity import activity

# User interface
import sc_ui

# Gstreamer interface
import sc_gst

# os
import os

# bundlepath
from sugar.activity.activity import get_activity_root

# datetime for journal entry name
import datetime

# i18n
import i18n

class ScreencastActivity(activity.Activity):

    # Attributes
    _state = None
    _ui = None
    _gst = None
    _videofile = None

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

        # User interface object
        self._ui = sc_ui.ScreencastUserInterface(self)

        # Set video file
        directory = os.path.join(get_activity_root(), "data")
        if not os.path.exists(directory):
            os.makedir(directory)

        self._videofile =  os.path.join( directory, "screencast.ogg" )

        # Gstreamer interface object
        self._gst = sc_gst.ScreencastGstreamer(self, self._videofile)

        # State
        self._state = "stopped"

        # Connect user interface signals
        self._ui.connect('recordbutton-clicked', self.recordbuttonClicked)
        self._ui.connect('stopbutton-clicked', self.stopbuttonClicked)

        # Connect gstreamer interface signals
        self._gst.connect('update-info', self.updateInfo)

        # Show user interface
        self._ui.showInterface()

    def recordbuttonClicked(self, widget):
        """ Record button clicked
        """
        self._state = "recording"
        self._ui.changeButtonsState(self._state)
        self._gst.start(self._ui.getRecordSoundOption())

    def stopbuttonClicked(self, widget):
        """ Stop button clicked
        """
        self._state = "stopped"
        self._ui.changeButtonsState(self._state)
        self._gst.stop()

    def updateInfo(self, widget, videosize, videolength):
        """ Update info
        """
        self._ui.refreshLabelRecordText(videosize, videolength)

    def write_file(self, filePath):
        """ Send file to journal
        """

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

            if self._jobject.metadata['title_set_by_user'] == '1':
                title = self.metadata['title']
            else:
                title = "My Screencast video " + datetime.datetime.now().strftime("%Y%m%d%H%M%s")

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

    def can_close(self):
        """ Close hook
        """
        if self._state == "stopped":
            return True

        self._ui.alert(i18n.I18N_EXIT_ALERT)
        return False

    def flush_events(self):
        """ Wait for graphics events finish
        """
        gtk.gdk.threads_enter()
        while gtk.events_pending():
            gtk.main_iteration(True)
        gtk.gdk.flush()
        gtk.gdk.threads_leave()