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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# frames_tray.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 gtk
import gobject
from sugar.graphics import style
from sugar.graphics.tray import HTray
from sugar.graphics.radiotoolbutton import RadioToolButton
class FramesTray(HTray):
__gsignals__ = {"current-frame-changed": (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_INT,))}
def __init__(self):
HTray.__init__(self)
self._group = None
self.set_size_request(-1, style.LARGE_ICON_SIZE + 10)
self.show()
def add_frame(self, pixbuf):
item = FrameWidget(pixbuf)
if not self._group:
self._group = item
else:
item.set_group(self._group)
self.add_item(item)
item.connect('toggled', self._frame_selected)
def get_selected_frame(self):
for button in self.get_children():
if button.get_active():
return button
def remove_selected_frame(self):
button = self.get_selected_frame()
self.remove_item(button)
del(button)
def remove_frame(self):
return
def select_frame(self, index):
self.get_children()[index].set_active(True)
def _frame_selected(self, widget):
if widget.get_active():
index = self.get_children().index(widget)
self.emit('current-frame-changed', index)
class FrameWidget(RadioToolButton):
def __init__(self, pixbuf):
super(FrameWidget, self).__init__()
width = pixbuf.get_width()
height = pixbuf.get_height()
preview_pixbuf = pixbuf.scale_simple(style.LARGE_ICON_SIZE *
width / height,
style.LARGE_ICON_SIZE,
gtk.gdk.INTERP_TILES)
image = gtk.image_new_from_pixbuf(preview_pixbuf)
self.set_icon_widget(image)
image.show()
self.show()
|