-
Notifications
You must be signed in to change notification settings - Fork 10
/
toolbar.py
42 lines (36 loc) · 1.63 KB
/
toolbar.py
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
# Copyright (C) IBM Corporation 2008
#
# 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
from gi.repository import Gtk
from gi.repository import GObject
from sugar3.graphics.icon import Icon
import sugar3.graphics.style as style
class WidgetItem(Gtk.ToolItem):
def __init__(self, widget):
GObject.GObject.__init__(self)
self.add(widget)
widget.show()
class ButtonItem(Gtk.ToolButton):
def __init__(self, icon_name, size=Gtk.IconSize.SMALL_TOOLBAR, **kwargs):
GObject.GObject.__init__(self, **kwargs)
icon = Icon(icon_name=icon_name, pixel_size=size)
# The alignment is a hack to work around Gtk.ToolButton code
# that sets the icon_size when the icon_widget is a Gtk.Image
alignment = Gtk.Alignment.new(0.5, 0.5)
alignment.add(icon)
self.set_icon_widget(alignment)
if size == Gtk.IconSize.SMALL_TOOLBAR:
button_size = style.SMALL_ICON_SIZE + 8
self.set_size_request(button_size, button_size)