Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ImageViewerToolbar.py
blob: c0ade2dc1ee95e64b73a7037e0289f8fc3409199 (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
# Based on read-activity/readtoolbar.py
# Copyright (C) 2006, Red Hat, Inc.
#
# 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

import logging
from gettext import gettext as _
import re

import pango
import gobject
import gtk

from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.menuitem import MenuItem
from sugar.graphics import iconentry
from sugar.activity import activity


class ViewToolbar(gtk.Toolbar):
    __gtype_name__ = 'ViewToolbar'

    __gsignals__ = {
        'go-fullscreen': (gobject.SIGNAL_RUN_FIRST,
                          gobject.TYPE_NONE,
                          ([]))
    }

    def __init__(self, view):
        gtk.Toolbar.__init__(self)

        self._view = view
            
        self._zoom_out = ToolButton('zoom-out')
        self._zoom_out.set_tooltip(_('Zoom out'))
        self._zoom_out.connect('clicked', self._zoom_out_cb)
        self.insert(self._zoom_out, -1)
        self._zoom_out.show()

        self._zoom_in = ToolButton('zoom-in')
        self._zoom_in.set_tooltip(_('Zoom in'))
        self._zoom_in.connect('clicked', self._zoom_in_cb)
        self.insert(self._zoom_in, -1)
        self._zoom_in.show()

        self._zoom_tofit = ToolButton('zoom-best-fit')
        self._zoom_tofit.set_tooltip(_('Fit to window'))
        self._zoom_tofit.connect('clicked', self._zoom_tofit_cb)
        self.insert(self._zoom_tofit, -1)
        self._zoom_tofit.show()
        
        self._zoom_original = ToolButton('zoom-original')
        self._zoom_original.set_tooltip(_('Original size'))
        self._zoom_original.connect('clicked', self._zoom_original_cb)
        self.insert(self._zoom_original, -1)
        self._zoom_original.show()

        spacer = gtk.SeparatorToolItem()
        spacer.props.draw = False
        self.insert(spacer, -1)
        spacer.show()

        self._rotate_anticlockwise = ToolButton('rotate_anticlockwise')
        self._rotate_anticlockwise.set_tooltip(_('Rotate anticlockwise'))
        self._rotate_anticlockwise.connect('clicked', self._rotate_anticlockwise_cb)
        self.insert(self._rotate_anticlockwise, -1)
        self._rotate_anticlockwise.show()

        self._rotate_clockwise = ToolButton('rotate_clockwise')
        self._rotate_clockwise.set_tooltip(_('Rotate clockwise'))
        self._rotate_clockwise.connect('clicked', self._rotate_clockwise_cb)
        self.insert(self._rotate_clockwise, -1)
        self._rotate_clockwise.show()
        
        spacer = gtk.SeparatorToolItem()
        spacer.props.draw = False
        self.insert(spacer, -1)
        spacer.show()

        self._fullscreen = ToolButton('view-fullscreen')
        self._fullscreen.set_tooltip(_('Fullscreen'))
        self._fullscreen.connect('clicked', self._fullscreen_cb)
        self.insert(self._fullscreen, -1)
        self._fullscreen.show()


    def _zoom_in_cb(self, button):
        self._zoom_in.set_sensitive(self._view.zoom_in())
        self._zoom_out.set_sensitive(True)

    def _zoom_out_cb(self, button):
        self._zoom_out.set_sensitive(self._view.zoom_out())
        self._zoom_in.set_sensitive(True)

    def _zoom_tofit_cb(self, button):
        zoom = self._view.calculate_optimal_zoom()
        self._view.set_zoom(zoom)
        
    def _zoom_original_cb(self, button):
        self._view.set_zoom(1)

    def _rotate_anticlockwise_cb(self, button):
        angle = self._view.get_property('angle')
        self._view.set_angle(angle + 90)
        
    def _rotate_clockwise_cb(self, button):
        angle = self._view.get_property('angle')
        if angle == 0:
            angle = 360

        self._view.set_angle(angle - 90)        
    
    def _fullscreen_cb(self, button):
        self.emit('go-fullscreen')