2007-08-27 21:28:20 +02:00
|
|
|
# Copyright (C) 2007, One Laptop Per Child
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library 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
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
|
2008-10-28 14:19:01 +01:00
|
|
|
"""
|
|
|
|
STABLE.
|
|
|
|
"""
|
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
from gi.repository import GObject
|
|
|
|
from gi.repository import Gtk
|
2012-11-01 13:24:45 +01:00
|
|
|
from gi.repository import Gdk
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2011-10-29 10:44:18 +02:00
|
|
|
from sugar3.graphics import style
|
|
|
|
from sugar3.graphics.palette import ToolInvoker
|
|
|
|
from sugar3.graphics.toolbutton import ToolButton
|
|
|
|
from sugar3.graphics.icon import Icon
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
_PREVIOUS_PAGE = 0
|
|
|
|
_NEXT_PAGE = 1
|
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
class _TrayViewport(Gtk.Viewport):
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2007-08-27 22:10:18 +02:00
|
|
|
__gproperties__ = {
|
2011-11-15 19:29:07 +01:00
|
|
|
'scrollable': (bool, None, None, False, GObject.PARAM_READABLE),
|
|
|
|
'can-scroll-prev': (bool, None, None, False, GObject.PARAM_READABLE),
|
|
|
|
'can-scroll-next': (bool, None, None, False, GObject.PARAM_READABLE),
|
2007-08-27 22:10:18 +02:00
|
|
|
}
|
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
def __init__(self, orientation):
|
|
|
|
self.orientation = orientation
|
2007-12-23 20:42:20 +01:00
|
|
|
self._scrollable = False
|
|
|
|
self._can_scroll_next = False
|
|
|
|
self._can_scroll_prev = False
|
2007-08-27 22:10:18 +02:00
|
|
|
|
2012-11-28 22:47:24 +01:00
|
|
|
Gtk.Viewport.__init__(self)
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
self.set_shadow_type(Gtk.ShadowType.NONE)
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
self.traybar = Gtk.Toolbar()
|
2007-08-30 14:29:52 +02:00
|
|
|
self.traybar.set_orientation(orientation)
|
2007-08-27 21:28:20 +02:00
|
|
|
self.traybar.set_show_arrow(False)
|
|
|
|
self.add(self.traybar)
|
|
|
|
self.traybar.show()
|
|
|
|
|
2007-08-27 22:10:18 +02:00
|
|
|
self.connect('size_allocate', self._size_allocate_cb)
|
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
if self.orientation == Gtk.Orientation.HORIZONTAL:
|
2007-12-23 20:42:20 +01:00
|
|
|
adj = self.get_hadjustment()
|
|
|
|
else:
|
|
|
|
adj = self.get_vadjustment()
|
|
|
|
adj.connect('changed', self._adjustment_changed_cb)
|
|
|
|
adj.connect('value-changed', self._adjustment_changed_cb)
|
2009-08-25 19:55:48 +02:00
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
def scroll(self, direction):
|
|
|
|
if direction == _PREVIOUS_PAGE:
|
|
|
|
self._scroll_previous()
|
|
|
|
elif direction == _NEXT_PAGE:
|
|
|
|
self._scroll_next()
|
|
|
|
|
2008-06-20 14:46:27 +02:00
|
|
|
def scroll_to_item(self, item):
|
|
|
|
"""This function scrolls the viewport so that item will be visible."""
|
|
|
|
assert item in self.traybar.get_children()
|
|
|
|
|
|
|
|
# Get the allocation, and make sure that it is visible
|
2011-12-15 02:23:18 +01:00
|
|
|
allocation = item.get_allocation()
|
2011-11-15 19:29:07 +01:00
|
|
|
if self.orientation == Gtk.Orientation.HORIZONTAL:
|
2008-06-20 14:46:27 +02:00
|
|
|
adj = self.get_hadjustment()
|
2011-12-15 02:23:18 +01:00
|
|
|
start = allocation.x
|
|
|
|
stop = allocation.x + allocation.width
|
2008-06-20 14:46:27 +02:00
|
|
|
else:
|
|
|
|
adj = self.get_vadjustment()
|
2011-12-15 02:23:18 +01:00
|
|
|
start = allocation.y
|
|
|
|
stop = allocation.y + allocation.height
|
2008-06-20 14:46:27 +02:00
|
|
|
|
2011-11-15 21:32:03 +01:00
|
|
|
if start < adj.get_value():
|
|
|
|
adj.set_value(start)
|
|
|
|
elif stop > adj.get_value() + adj.get_page_size():
|
|
|
|
adj.set_value(stop - adj.get_page_size())
|
2008-06-20 14:46:27 +02:00
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
def _scroll_next(self):
|
2008-04-19 01:10:48 +02:00
|
|
|
allocation = self.get_allocation()
|
2011-11-15 19:29:07 +01:00
|
|
|
if self.orientation == Gtk.Orientation.HORIZONTAL:
|
2007-08-30 14:29:52 +02:00
|
|
|
adj = self.get_hadjustment()
|
2011-11-15 21:32:03 +01:00
|
|
|
new_value = adj.get_value() + allocation.width
|
|
|
|
adj.set_value(min(new_value, adj.get_upper() - allocation.width))
|
2007-08-30 14:29:52 +02:00
|
|
|
else:
|
|
|
|
adj = self.get_vadjustment()
|
2011-11-15 21:32:03 +01:00
|
|
|
new_value = adj.get_value() + allocation.height
|
|
|
|
adj.set_value(min(new_value, adj.get_upper() - allocation.height))
|
2007-08-30 14:29:52 +02:00
|
|
|
|
|
|
|
def _scroll_previous(self):
|
2008-04-19 01:10:48 +02:00
|
|
|
allocation = self.get_allocation()
|
2011-11-15 19:29:07 +01:00
|
|
|
if self.orientation == Gtk.Orientation.HORIZONTAL:
|
2007-08-30 14:29:52 +02:00
|
|
|
adj = self.get_hadjustment()
|
2011-11-15 21:32:03 +01:00
|
|
|
new_value = adj.get_value() - allocation.width
|
|
|
|
adj.set_value(max(adj.get_lower(), new_value))
|
2007-08-30 14:29:52 +02:00
|
|
|
else:
|
|
|
|
adj = self.get_vadjustment()
|
2011-11-15 21:32:03 +01:00
|
|
|
new_value = adj.get_value() - allocation.height
|
|
|
|
adj.set_value(max(adj.get_lower(), new_value))
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2011-12-15 02:23:18 +01:00
|
|
|
def do_get_preferred_width(self):
|
2011-11-15 19:29:07 +01:00
|
|
|
if self.orientation == Gtk.Orientation.HORIZONTAL:
|
2012-05-04 14:52:25 +02:00
|
|
|
min_width, nat_width = Gtk.Viewport.do_get_preferred_width(self)
|
|
|
|
return 0, nat_width
|
2011-12-15 02:23:18 +01:00
|
|
|
child_minimum, child_natural = self.get_child().get_preferred_size()
|
|
|
|
return child_minimum.width, child_natural.width
|
|
|
|
|
|
|
|
def do_get_preferred_height(self):
|
|
|
|
if self.orientation != Gtk.Orientation.HORIZONTAL:
|
2012-05-04 14:52:25 +02:00
|
|
|
min_height, nat_height = Gtk.Viewport.do_get_preferred_height(self)
|
|
|
|
return 0, nat_height
|
2011-12-15 02:23:18 +01:00
|
|
|
child_minimum, child_natural = self.get_child().get_preferred_size()
|
|
|
|
return child_minimum.height, child_natural.height
|
2007-08-29 14:04:46 +02:00
|
|
|
|
2007-08-27 22:10:18 +02:00
|
|
|
def do_get_property(self, pspec):
|
2007-12-23 20:42:20 +01:00
|
|
|
if pspec.name == 'scrollable':
|
|
|
|
return self._scrollable
|
|
|
|
elif pspec.name == 'can-scroll-next':
|
|
|
|
return self._can_scroll_next
|
|
|
|
elif pspec.name == 'can-scroll-prev':
|
|
|
|
return self._can_scroll_prev
|
2007-08-27 22:10:18 +02:00
|
|
|
|
|
|
|
def _size_allocate_cb(self, viewport, allocation):
|
2012-12-04 21:40:26 +01:00
|
|
|
if allocation.width == 1 and allocation.height == 1:
|
|
|
|
# HACK: the first time this callback is called 'width' and
|
|
|
|
# 'height' are 1 so we mark the Viewport as scrollable and
|
|
|
|
# we show the Prev / Next buttons
|
|
|
|
return
|
|
|
|
|
2011-10-30 12:01:34 +01:00
|
|
|
bar_minimum, bar_natural = self.traybar.get_preferred_size()
|
2012-11-28 22:47:24 +01:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
if self.orientation == Gtk.Orientation.HORIZONTAL:
|
2011-10-30 12:01:34 +01:00
|
|
|
scrollable = bar_minimum.width > allocation.width
|
2007-08-27 22:10:18 +02:00
|
|
|
else:
|
2011-10-30 12:01:34 +01:00
|
|
|
scrollable = bar_minimum.height > allocation.height
|
2007-08-27 22:10:18 +02:00
|
|
|
|
2007-12-23 20:42:20 +01:00
|
|
|
if scrollable != self._scrollable:
|
|
|
|
self._scrollable = scrollable
|
|
|
|
self.notify('scrollable')
|
2007-08-27 22:10:18 +02:00
|
|
|
|
2007-12-23 20:42:20 +01:00
|
|
|
def _adjustment_changed_cb(self, adjustment):
|
2011-11-15 21:32:03 +01:00
|
|
|
if adjustment.get_value() <= adjustment.get_lower():
|
2007-12-23 20:42:20 +01:00
|
|
|
can_scroll_prev = False
|
|
|
|
else:
|
|
|
|
can_scroll_prev = True
|
|
|
|
|
2011-11-15 21:32:03 +01:00
|
|
|
if adjustment.get_value() + adjustment.get_page_size() >= \
|
|
|
|
adjustment.get_upper():
|
2007-12-23 20:42:20 +01:00
|
|
|
can_scroll_next = False
|
|
|
|
else:
|
|
|
|
can_scroll_next = True
|
|
|
|
|
|
|
|
if can_scroll_prev != self._can_scroll_prev:
|
|
|
|
self._can_scroll_prev = can_scroll_prev
|
|
|
|
self.notify('can-scroll-prev')
|
2007-08-29 14:04:46 +02:00
|
|
|
|
2007-12-23 20:42:20 +01:00
|
|
|
if can_scroll_next != self._can_scroll_next:
|
|
|
|
self._can_scroll_next = can_scroll_next
|
|
|
|
self.notify('can-scroll-next')
|
|
|
|
|
|
|
|
|
|
|
|
class _TrayScrollButton(ToolButton):
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2012-11-28 22:47:24 +01:00
|
|
|
__gtype_name__ = 'SugarTrayScrollButton'
|
|
|
|
|
2007-12-23 20:42:20 +01:00
|
|
|
def __init__(self, icon_name, scroll_direction):
|
|
|
|
ToolButton.__init__(self)
|
2007-08-30 14:29:52 +02:00
|
|
|
self._viewport = None
|
|
|
|
|
|
|
|
self._scroll_direction = scroll_direction
|
|
|
|
|
2007-08-29 14:04:46 +02:00
|
|
|
self.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE)
|
|
|
|
|
2010-10-15 20:36:38 +02:00
|
|
|
self.icon = Icon(icon_name=icon_name,
|
2015-06-29 17:12:58 +02:00
|
|
|
pixel_size=style.SMALL_ICON_SIZE)
|
2011-11-15 19:29:07 +01:00
|
|
|
# The alignment is a hack to work around Gtk.ToolButton code
|
|
|
|
# that sets the icon_size when the icon_widget is a Gtk.Image
|
2011-10-30 14:54:53 +01:00
|
|
|
alignment = Gtk.Alignment(xalign=0.5, yalign=0.5)
|
2007-12-23 20:42:20 +01:00
|
|
|
alignment.add(self.icon)
|
|
|
|
self.set_icon_widget(alignment)
|
|
|
|
alignment.show_all()
|
2007-08-29 14:04:46 +02:00
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
self.connect('clicked', self._clicked_cb)
|
|
|
|
|
|
|
|
def set_viewport(self, viewport):
|
|
|
|
self._viewport = viewport
|
2007-12-23 20:42:20 +01:00
|
|
|
self._viewport.connect('notify::scrollable',
|
|
|
|
self._viewport_scrollable_changed_cb)
|
|
|
|
|
|
|
|
if self._scroll_direction == _PREVIOUS_PAGE:
|
|
|
|
self._viewport.connect('notify::can-scroll-prev',
|
|
|
|
self._viewport_can_scroll_dir_changed_cb)
|
|
|
|
self.set_sensitive(self._viewport.props.can_scroll_prev)
|
|
|
|
else:
|
|
|
|
self._viewport.connect('notify::can-scroll-next',
|
|
|
|
self._viewport_can_scroll_dir_changed_cb)
|
|
|
|
self.set_sensitive(self._viewport.props.can_scroll_next)
|
|
|
|
|
|
|
|
def _viewport_scrollable_changed_cb(self, viewport, pspec):
|
|
|
|
self.props.visible = self._viewport.props.scrollable
|
|
|
|
|
|
|
|
def _viewport_can_scroll_dir_changed_cb(self, viewport, pspec):
|
|
|
|
if self._scroll_direction == _PREVIOUS_PAGE:
|
|
|
|
sensitive = self._viewport.props.can_scroll_prev
|
|
|
|
else:
|
|
|
|
sensitive = self._viewport.props.can_scroll_next
|
2007-08-30 14:29:52 +02:00
|
|
|
|
2007-12-23 20:42:20 +01:00
|
|
|
self.set_sensitive(sensitive)
|
2007-08-30 14:29:52 +02:00
|
|
|
|
|
|
|
def _clicked_cb(self, button):
|
|
|
|
self._viewport.scroll(self._scroll_direction)
|
|
|
|
|
|
|
|
viewport = property(fset=set_viewport)
|
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2008-07-04 15:49:33 +02:00
|
|
|
ALIGN_TO_START = 0
|
|
|
|
ALIGN_TO_END = 1
|
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2012-11-28 22:47:24 +01:00
|
|
|
class HTray(Gtk.EventBox):
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2008-10-18 23:08:13 +02:00
|
|
|
__gtype_name__ = 'SugarHTray'
|
|
|
|
|
|
|
|
__gproperties__ = {
|
2009-08-25 21:12:40 +02:00
|
|
|
'align': (int, None, None, 0, 1, ALIGN_TO_START,
|
2013-05-18 04:27:04 +02:00
|
|
|
GObject.PARAM_READWRITE |
|
|
|
|
GObject.PARAM_CONSTRUCT_ONLY),
|
2011-11-15 19:29:07 +01:00
|
|
|
'drag-active': (bool, None, None, False, GObject.PARAM_READWRITE),
|
2008-10-18 23:08:13 +02:00
|
|
|
}
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2007-08-27 21:28:20 +02:00
|
|
|
def __init__(self, **kwargs):
|
2008-10-18 23:08:13 +02:00
|
|
|
self._drag_active = False
|
|
|
|
self.align = ALIGN_TO_START
|
|
|
|
|
2012-11-28 22:47:24 +01:00
|
|
|
Gtk.EventBox.__init__(self, **kwargs)
|
|
|
|
|
|
|
|
self._box = Gtk.HBox()
|
|
|
|
self.add(self._box)
|
|
|
|
self._box.show()
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
scroll_left = _TrayScrollButton('go-left', _PREVIOUS_PAGE)
|
2012-11-28 22:47:24 +01:00
|
|
|
self._box.pack_start(scroll_left, False, False, 0)
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
self._viewport = _TrayViewport(Gtk.Orientation.HORIZONTAL)
|
2012-11-28 22:47:24 +01:00
|
|
|
self._box.pack_start(self._viewport, True, True, 0)
|
2007-08-27 21:28:20 +02:00
|
|
|
self._viewport.show()
|
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
scroll_right = _TrayScrollButton('go-right', _NEXT_PAGE)
|
2012-11-28 22:47:24 +01:00
|
|
|
self._box.pack_start(scroll_right, False, False, 0)
|
2007-08-27 22:10:18 +02:00
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
scroll_left.viewport = self._viewport
|
|
|
|
scroll_right.viewport = self._viewport
|
|
|
|
|
2008-07-04 15:49:33 +02:00
|
|
|
if self.align == ALIGN_TO_END:
|
2011-11-15 19:29:07 +01:00
|
|
|
spacer = Gtk.SeparatorToolItem()
|
2008-07-04 15:49:33 +02:00
|
|
|
spacer.set_size_request(0, 0)
|
|
|
|
spacer.props.draw = False
|
|
|
|
spacer.set_expand(True)
|
|
|
|
self._viewport.traybar.insert(spacer, 0)
|
|
|
|
spacer.show()
|
|
|
|
|
2008-10-18 23:08:13 +02:00
|
|
|
def do_set_property(self, pspec, value):
|
|
|
|
if pspec.name == 'align':
|
|
|
|
self.align = value
|
|
|
|
elif pspec.name == 'drag-active':
|
|
|
|
self._set_drag_active(value)
|
|
|
|
else:
|
|
|
|
raise AssertionError
|
|
|
|
|
|
|
|
def do_get_property(self, pspec):
|
|
|
|
if pspec.name == 'align':
|
|
|
|
return self.align
|
|
|
|
elif pspec.name == 'drag-active':
|
|
|
|
return self._drag_active
|
|
|
|
else:
|
|
|
|
raise AssertionError
|
|
|
|
|
|
|
|
def _set_drag_active(self, active):
|
|
|
|
if self._drag_active != active:
|
|
|
|
self._drag_active = active
|
|
|
|
if self._drag_active:
|
2013-05-18 04:27:04 +02:00
|
|
|
self._viewport.traybar.modify_bg(
|
|
|
|
Gtk.StateType.NORMAL,
|
|
|
|
style.COLOR_BLACK.get_gdk_color())
|
2008-10-18 23:08:13 +02:00
|
|
|
else:
|
2011-11-15 19:29:07 +01:00
|
|
|
self._viewport.traybar.modify_bg(Gtk.StateType.NORMAL, None)
|
2008-07-04 15:49:33 +02:00
|
|
|
|
2007-09-03 01:48:03 +02:00
|
|
|
def get_children(self):
|
2008-07-04 15:49:33 +02:00
|
|
|
children = self._viewport.traybar.get_children()[:]
|
|
|
|
if self.align == ALIGN_TO_END:
|
|
|
|
children = children[1:]
|
|
|
|
return children
|
2007-09-03 01:48:03 +02:00
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
def add_item(self, item, index=-1):
|
2008-07-04 15:49:33 +02:00
|
|
|
if self.align == ALIGN_TO_END and index > -1:
|
|
|
|
index += 1
|
2007-08-30 14:29:52 +02:00
|
|
|
self._viewport.traybar.insert(item, index)
|
|
|
|
|
|
|
|
def remove_item(self, item):
|
|
|
|
self._viewport.traybar.remove(item)
|
|
|
|
|
|
|
|
def get_item_index(self, item):
|
2008-07-04 15:49:33 +02:00
|
|
|
index = self._viewport.traybar.get_item_index(item)
|
|
|
|
if self.align == ALIGN_TO_END:
|
|
|
|
index -= 1
|
|
|
|
return index
|
2007-08-30 14:29:52 +02:00
|
|
|
|
2008-06-20 14:46:27 +02:00
|
|
|
def scroll_to_item(self, item):
|
|
|
|
self._viewport.scroll_to_item(item)
|
2015-12-31 12:53:47 +01:00
|
|
|
if hasattr(HTray, 'set_css_name'):
|
|
|
|
HTray.set_css_name('htray')
|
2008-06-20 14:46:27 +02:00
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2012-11-28 22:47:24 +01:00
|
|
|
class VTray(Gtk.EventBox):
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2008-10-18 23:08:13 +02:00
|
|
|
__gtype_name__ = 'SugarVTray'
|
|
|
|
|
|
|
|
__gproperties__ = {
|
2009-08-25 21:12:40 +02:00
|
|
|
'align': (int, None, None, 0, 1, ALIGN_TO_START,
|
2013-05-18 04:27:04 +02:00
|
|
|
GObject.PARAM_READWRITE | GObject.PARAM_CONSTRUCT_ONLY),
|
2011-11-15 19:29:07 +01:00
|
|
|
'drag-active': (bool, None, None, False, GObject.PARAM_READWRITE),
|
2008-10-18 23:08:13 +02:00
|
|
|
}
|
|
|
|
|
2007-08-30 14:29:52 +02:00
|
|
|
def __init__(self, **kwargs):
|
2008-10-18 23:08:13 +02:00
|
|
|
self._drag_active = False
|
|
|
|
self.align = ALIGN_TO_START
|
|
|
|
|
2012-11-28 22:47:24 +01:00
|
|
|
Gtk.EventBox.__init__(self, **kwargs)
|
|
|
|
|
|
|
|
self._box = Gtk.VBox()
|
|
|
|
self.add(self._box)
|
|
|
|
self._box.show()
|
2007-08-30 14:29:52 +02:00
|
|
|
|
2008-10-18 23:11:11 +02:00
|
|
|
scroll_up = _TrayScrollButton('go-up', _PREVIOUS_PAGE)
|
2012-11-28 22:47:24 +01:00
|
|
|
self._box.pack_start(scroll_up, False, False, 0)
|
2007-08-30 14:29:52 +02:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
self._viewport = _TrayViewport(Gtk.Orientation.VERTICAL)
|
2012-11-28 22:47:24 +01:00
|
|
|
self._box.pack_start(self._viewport, True, True, 0)
|
2007-08-30 14:29:52 +02:00
|
|
|
self._viewport.show()
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2008-10-18 23:11:11 +02:00
|
|
|
scroll_down = _TrayScrollButton('go-down', _NEXT_PAGE)
|
2012-11-28 22:47:24 +01:00
|
|
|
self._box.pack_start(scroll_down, False, False, 0)
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2008-10-18 23:11:11 +02:00
|
|
|
scroll_up.viewport = self._viewport
|
|
|
|
scroll_down.viewport = self._viewport
|
2007-08-27 21:28:20 +02:00
|
|
|
|
2008-07-04 15:49:33 +02:00
|
|
|
if self.align == ALIGN_TO_END:
|
2011-11-15 19:29:07 +01:00
|
|
|
spacer = Gtk.SeparatorToolItem()
|
2008-07-04 15:49:33 +02:00
|
|
|
spacer.set_size_request(0, 0)
|
|
|
|
spacer.props.draw = False
|
|
|
|
spacer.set_expand(True)
|
|
|
|
self._viewport.traybar.insert(spacer, 0)
|
|
|
|
spacer.show()
|
|
|
|
|
2008-10-18 23:08:13 +02:00
|
|
|
def do_set_property(self, pspec, value):
|
|
|
|
if pspec.name == 'align':
|
|
|
|
self.align = value
|
|
|
|
elif pspec.name == 'drag-active':
|
|
|
|
self._set_drag_active(value)
|
|
|
|
else:
|
|
|
|
raise AssertionError
|
|
|
|
|
|
|
|
def do_get_property(self, pspec):
|
|
|
|
if pspec.name == 'align':
|
|
|
|
return self.align
|
|
|
|
elif pspec.name == 'drag-active':
|
|
|
|
return self._drag_active
|
|
|
|
else:
|
|
|
|
raise AssertionError
|
|
|
|
|
|
|
|
def _set_drag_active(self, active):
|
|
|
|
if self._drag_active != active:
|
|
|
|
self._drag_active = active
|
|
|
|
if self._drag_active:
|
2013-05-18 04:27:04 +02:00
|
|
|
self._viewport.traybar.modify_bg(
|
|
|
|
Gtk.StateType.NORMAL,
|
|
|
|
style.COLOR_BLACK.get_gdk_color())
|
2008-10-18 23:08:13 +02:00
|
|
|
else:
|
2011-11-15 19:29:07 +01:00
|
|
|
self._viewport.traybar.modify_bg(Gtk.StateType.NORMAL, None)
|
2008-07-04 15:49:33 +02:00
|
|
|
|
2007-09-03 01:48:03 +02:00
|
|
|
def get_children(self):
|
2008-07-04 15:49:33 +02:00
|
|
|
children = self._viewport.traybar.get_children()[:]
|
|
|
|
if self.align == ALIGN_TO_END:
|
|
|
|
children = children[1:]
|
|
|
|
return children
|
2007-09-03 01:48:03 +02:00
|
|
|
|
2007-08-27 21:28:20 +02:00
|
|
|
def add_item(self, item, index=-1):
|
2008-07-04 15:49:33 +02:00
|
|
|
if self.align == ALIGN_TO_END and index > -1:
|
|
|
|
index += 1
|
2007-08-27 21:28:20 +02:00
|
|
|
self._viewport.traybar.insert(item, index)
|
|
|
|
|
2007-08-29 14:08:12 +02:00
|
|
|
def remove_item(self, item):
|
2007-08-27 21:28:20 +02:00
|
|
|
self._viewport.traybar.remove(item)
|
|
|
|
|
2007-08-28 14:15:51 +02:00
|
|
|
def get_item_index(self, item):
|
2008-07-04 15:49:33 +02:00
|
|
|
index = self._viewport.traybar.get_item_index(item)
|
|
|
|
if self.align == ALIGN_TO_END:
|
|
|
|
index -= 1
|
|
|
|
return index
|
2007-08-28 14:15:51 +02:00
|
|
|
|
2008-06-20 14:46:27 +02:00
|
|
|
def scroll_to_item(self, item):
|
|
|
|
self._viewport.scroll_to_item(item)
|
2015-12-31 12:53:47 +01:00
|
|
|
if hasattr(VTray, 'set_css_name'):
|
|
|
|
VTray.set_css_name('VTray')
|
2008-06-20 14:46:27 +02:00
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2007-08-27 21:28:20 +02:00
|
|
|
class TrayButton(ToolButton):
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2007-08-27 21:28:20 +02:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
ToolButton.__init__(self, **kwargs)
|
2007-09-03 01:48:03 +02:00
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
class _IconWidget(Gtk.EventBox):
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2010-10-15 21:14:59 +02:00
|
|
|
__gtype_name__ = 'SugarTrayIconWidget'
|
2007-09-05 13:55:18 +02:00
|
|
|
|
2007-09-03 01:48:03 +02:00
|
|
|
def __init__(self, icon_name=None, xo_color=None):
|
2012-11-28 22:47:24 +01:00
|
|
|
Gtk.EventBox.__init__(self)
|
2007-09-05 13:55:18 +02:00
|
|
|
|
|
|
|
self.set_app_paintable(True)
|
2012-11-01 13:24:45 +01:00
|
|
|
self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
|
|
|
|
Gdk.EventMask.TOUCH_MASK |
|
|
|
|
Gdk.EventMask.BUTTON_RELEASE_MASK)
|
2007-09-03 01:48:03 +02:00
|
|
|
|
2008-02-25 12:36:58 +01:00
|
|
|
self._icon = Icon(icon_name=icon_name, xo_color=xo_color,
|
2015-06-29 17:12:58 +02:00
|
|
|
pixel_size=style.STANDARD_ICON_SIZE)
|
2008-02-25 12:36:58 +01:00
|
|
|
self.add(self._icon)
|
|
|
|
self._icon.show()
|
2007-09-03 01:48:03 +02:00
|
|
|
|
2012-08-23 05:40:10 +02:00
|
|
|
def do_draw(self, cr):
|
2011-11-15 21:32:03 +01:00
|
|
|
palette = self.get_parent().palette
|
2012-12-10 18:22:57 +01:00
|
|
|
|
|
|
|
if palette and palette.is_up():
|
|
|
|
allocation = self.get_allocation()
|
|
|
|
# draw a black background, has been done by the engine before
|
|
|
|
cr.set_source_rgb(0, 0, 0)
|
|
|
|
cr.rectangle(0, 0, allocation.width, allocation.height)
|
|
|
|
cr.paint()
|
|
|
|
|
|
|
|
Gtk.EventBox.do_draw(self, cr)
|
|
|
|
|
2008-05-23 18:00:47 +02:00
|
|
|
if palette and palette.is_up():
|
|
|
|
invoker = palette.props.invoker
|
2012-08-23 05:40:10 +02:00
|
|
|
invoker.draw_rectangle(cr, palette)
|
2007-09-05 13:55:18 +02:00
|
|
|
|
2012-12-10 18:22:57 +01:00
|
|
|
return False
|
2007-09-03 01:48:03 +02:00
|
|
|
|
2008-02-25 12:36:58 +01:00
|
|
|
def get_icon(self):
|
|
|
|
return self._icon
|
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
class TrayIcon(Gtk.ToolItem):
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2010-10-15 21:14:59 +02:00
|
|
|
__gtype_name__ = 'SugarTrayIcon'
|
2007-09-05 13:55:18 +02:00
|
|
|
|
|
|
|
def __init__(self, icon_name=None, xo_color=None):
|
2011-11-15 19:29:07 +01:00
|
|
|
Gtk.ToolItem.__init__(self)
|
2007-09-05 13:55:18 +02:00
|
|
|
|
|
|
|
self._icon_widget = _IconWidget(icon_name, xo_color)
|
|
|
|
self.add(self._icon_widget)
|
|
|
|
self._icon_widget.show()
|
|
|
|
|
2008-05-23 18:00:47 +02:00
|
|
|
self._palette_invoker = ToolInvoker(self)
|
|
|
|
|
2007-09-05 13:55:18 +02:00
|
|
|
self.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE)
|
|
|
|
|
2008-09-18 14:12:18 +02:00
|
|
|
self.connect('destroy', self.__destroy_cb)
|
|
|
|
|
|
|
|
def __destroy_cb(self, icon):
|
|
|
|
if self._palette_invoker is not None:
|
|
|
|
self._palette_invoker.detach()
|
|
|
|
|
2008-05-23 18:00:47 +02:00
|
|
|
def create_palette(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_palette(self):
|
|
|
|
return self._palette_invoker.palette
|
|
|
|
|
2007-09-05 13:55:18 +02:00
|
|
|
def set_palette(self, palette):
|
2008-05-23 18:00:47 +02:00
|
|
|
self._palette_invoker.palette = palette
|
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
palette = GObject.property(
|
2008-05-23 18:00:47 +02:00
|
|
|
type=object, setter=set_palette, getter=get_palette)
|
|
|
|
|
|
|
|
def get_palette_invoker(self):
|
|
|
|
return self._palette_invoker
|
2009-08-25 19:55:48 +02:00
|
|
|
|
2008-05-23 18:00:47 +02:00
|
|
|
def set_palette_invoker(self, palette_invoker):
|
|
|
|
self._palette_invoker.detach()
|
|
|
|
self._palette_invoker = palette_invoker
|
2007-09-03 01:48:03 +02:00
|
|
|
|
2011-11-15 19:29:07 +01:00
|
|
|
palette_invoker = GObject.property(
|
2008-05-23 18:00:47 +02:00
|
|
|
type=object, setter=set_palette_invoker, getter=get_palette_invoker)
|
2007-09-05 13:55:18 +02:00
|
|
|
|
2008-02-25 12:36:58 +01:00
|
|
|
def get_icon(self):
|
|
|
|
return self._icon_widget.get_icon()
|
2008-03-01 17:39:22 +01:00
|
|
|
icon = property(get_icon, None)
|