Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/slideview.py
blob: c98339574a4f039905e7a507872c6d4b1d8c1a32 (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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2012 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 St, Fifth Floor, Boston, MA  02110-1301  USA


from gi.repository import Gtk
from sugar3.graphics import style
from sugar3.graphics.icon import Icon


class SlideView(Gtk.EventBox):

    def __init__(self, activity):
        Gtk.EventBox.__init__(self)

        self._area = Gtk.DrawingArea()
        self._area.connect('draw', self._area_draw_cb)

        self._boxes = []
        self._current_box = None

        prev_btn = Gtk.EventBox()
        prev_btn.connect('button-press-event', self._prev_slide)
        self._prev_icon = Icon(pixel_size=100)
        self._prev_icon.props.icon_name = 'go-previous'
        prev_btn.add(self._prev_icon)

        next_btn = Gtk.EventBox()
        next_btn.connect('button-press-event', self._next_slide)
        self._next_icon = Icon(pixel_size=100)
        self._next_icon.props.icon_name = 'go-next'
        next_btn.add(self._next_icon)

        hbox = Gtk.Box()
        hbox.set_border_width(10)
        hbox.pack_start(prev_btn, True, False, 0)
        hbox.pack_start(self._area, False, False, 0)
        hbox.pack_end(next_btn, True, False, 0)

        self.add(hbox)

        self.show_all()

    def _area_draw_cb(self, widget, context):
        if self._current_box is None:
            return

        box = self._boxes[self._current_box]
        self._area.set_size_request(box.width + 1, box.height + 1)

        context.move_to(box.width - style.zoom(40),
                        box.height + style.zoom(25))
        context.set_font_size(style.zoom(20))
        context.show_text('%s/%s' % (self._current_box + 1,
                                     str(len(self._boxes))))

        if self._current_box == len(self._boxes) - 1:
            self._next_icon.set_fill_color(style.COLOR_BUTTON_GREY.get_html())
        else:
            self._next_icon.set_fill_color(None)

        if self._current_box == 0:
            self._prev_icon.set_fill_color(style.COLOR_BUTTON_GREY.get_html())
        else:
            self._prev_icon.set_fill_color(None)

        box.draw_in_context(context)

    def set_boxes(self, boxes):
        # Discard the title box
        self._boxes = boxes[1:]

    def set_current_box(self, box):
        self._current_box = box
        self._area.queue_draw()

    def _next_slide(self, widget, event):
        self._current_box += 1
        if self._current_box > len(self._boxes) - 1:
            self._current_box -= 1
        self._area.queue_draw()

    def _prev_slide(self, widget, event):
        self._current_box -= 1
        if self._current_box < 0:
            self._current_box += 1
        self._area.queue_draw()

    def key_press_cb(self, widget, event):
        if event.keyval == 65361:
            self._prev_slide(None, None)

        elif event.keyval == 65363:
            self._next_slide(None, None)