Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/screencast_ui.py
blob: 2290dff90f5f18360d159fb4a07fea0c88c7c591 (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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)