Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/toolbars.py
blob: fb5406b1173e7b9ba64ff4f89863a9d8d96a125a (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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# toolbars.py
#
# Copyright 2012 S. Daniel Francis <francis@sugarlabs.org>,
#                Agustin Zubiaga <aguz@sugarlabs.org>
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import gobject
import gtk

from sugar.activity.widgets import StopButton
from sugar.activity.widgets import ToolbarButton
from sugar.activity.widgets import ActivityToolbarButton
from sugar.graphics.toolbarbox import ToolbarBox
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.radiotoolbutton import RadioToolButton

from gettext import gettext as _


class AnimateToolbarBox(ToolbarBox):

    def __init__(self, activity):
        super(AnimateToolbarBox, self).__init__()

        activity_button = ActivityToolbarButton(activity)
        self.toolbar.insert(activity_button, 0)

        separator = gtk.SeparatorToolItem()
        self.toolbar.insert(separator, -1)

        add_frame = ToolButton('list-add')
        add_frame.set_tooltip(_('Add a frame'))
        add_frame.connect('clicked', activity._add_frame)
        self.toolbar.insert(add_frame, -1)

        remove_frame = ToolButton('list-remove')
        remove_frame.set_tooltip(_('Remove the selected frame'))
        remove_frame.connect('clicked', activity._remove_frame)
        self.toolbar.insert(remove_frame, -1)

        separator = gtk.SeparatorToolItem()
        self.toolbar.insert(separator, -1)

        back_btn = ToolButton('media-seek-backward')
        back_btn.set_tooltip(_('Previous Frame'))
        back_btn.connect('clicked', activity._previous_frame)
        self.toolbar.insert(back_btn, -1)

        run_btn = ToolButton('media-playback-start')
        run_btn.set_tooltip(_('Run animation'))
        run_btn.connect('clicked', activity._run_pause_animation)
        self.toolbar.insert(run_btn, -1)

        next_btn = ToolButton('media-seek-forward')
        next_btn.set_tooltip(_('Next Frame'))
        next_btn.connect('clicked', activity._next_frame)
        self.toolbar.insert(next_btn, -1)

        separator = gtk.SeparatorToolItem()
        self.toolbar.insert(separator, -1)

        options_button = ToolbarButton(icon_name='preferences-system')
        options_toolbar = gtk.Toolbar()

        returnbutton = RadioToolButton(icon_name='media-playlist-repeat')
        returnbutton.set_tooltip(_('Repeat Mode'))
        returnbutton.set_active(True)
        returnbutton.connect('clicked', activity._set_return_mode)
        options_toolbar.insert(returnbutton, -1)

        normalmode = RadioToolButton(icon_name='normal-mode')
        normalmode.props.group = returnbutton
        normalmode.set_tooltip(_('Normal Mode'))
        normalmode.connect('clicked', activity._set_normal_mode)
        options_toolbar.insert(normalmode, -1)

        pingpong = RadioToolButton(icon_name='ping-pong')
        pingpong.props.group = returnbutton
        pingpong.set_tooltip(_('Ping Pong Mode'))
        pingpong.connect('clicked', activity._set_pingpong_mode)
        options_toolbar.insert(pingpong, -1)

        self.modes_buttons = [normalmode, returnbutton, pingpong]

        separator = gtk.SeparatorToolItem()
        options_toolbar.insert(separator, -1)

        toollabel = gtk.ToolItem()
        toollabel.add(gtk.Label(_('Frames per second:')))
        options_toolbar.insert(toollabel, -1)

        separator = gtk.SeparatorToolItem()
        separator.set_draw(False)
        options_toolbar.insert(separator, -1)

        toolspin = gtk.ToolItem()
        adjustment = gtk.Adjustment(2, 1, 24, 1, 1)
        self._fpsbutton = gtk.SpinButton(adjustment, 0, 0)
        self._fpsbutton.connect('value-changed', activity._fps_changed_cb)
        toolspin.add(self._fpsbutton)
        options_toolbar.insert(toolspin, -1)

        options_button.props.page = options_toolbar
        options_toolbar.show_all()

        self.toolbar.insert(options_button, -1)

        separator = gtk.SeparatorToolItem()
        self.toolbar.insert(separator, -1)

        fullscreen_btn = ToolButton('view-fullscreen')
        fullscreen_btn.set_tooltip(_('Fullscreen'))
        fullscreen_btn.connect('clicked', activity._view_fullscreen)

        self.toolbar.insert(fullscreen_btn, -1)

        separator = gtk.SeparatorToolItem()
        separator.set_expand(True)
        separator.set_draw(False)
        self.toolbar.insert(separator, -1)

        stopbtn = StopButton(activity)
        self.toolbar.insert(stopbtn, -1)

    def get_fps(self):
        return self._fpsbutton.get_value()

    def set_fps(self, fps):
        self._fpsbutton.set_value(fps)


class FramesToolbar(gtk.Toolbar):
    __gsignals__ = {'go-up': (gobject.SIGNAL_RUN_LAST,
                              gobject.TYPE_NONE,
                              tuple()),
                    'go-down': (gobject.SIGNAL_RUN_LAST,
                                gobject.TYPE_NONE,
                                tuple())}

    def __init__(self):
        super(FramesToolbar, self).__init__()

        move_up = ToolButton('go-up')
        move_up.set_tooltip(_('Move up'))
        move_up.connect('clicked', lambda w: self.emit('go-up'))
        self.insert(move_up, -1)

        move_down = ToolButton('go-down')
        move_down.set_tooltip(_('Move down'))
        move_down.connect('clicked', lambda w: self.emit('go-down'))
        self.insert(move_down, -1)

    def set_buttons_sensitive(self, widget, running):
        for button in self.get_children():
            button.set_sensitive(not running)