Show arrows only when the icons does not fit.
This commit is contained in:
parent
7fcc23b4c8
commit
c742cff64d
@ -22,7 +22,14 @@ from sugar.graphics.toolbutton import ToolButton
|
|||||||
from sugar.graphics.icon import Icon
|
from sugar.graphics.icon import Icon
|
||||||
|
|
||||||
class _TrayViewport(gtk.Viewport):
|
class _TrayViewport(gtk.Viewport):
|
||||||
|
__gproperties__ = {
|
||||||
|
'can-scroll' : (bool, None, None, False,
|
||||||
|
gobject.PARAM_READABLE),
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self._can_scroll = False
|
||||||
|
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
self.set_shadow_type(gtk.SHADOW_NONE)
|
self.set_shadow_type(gtk.SHADOW_NONE)
|
||||||
@ -32,6 +39,8 @@ class _TrayViewport(gtk.Viewport):
|
|||||||
self.add(self.traybar)
|
self.add(self.traybar)
|
||||||
self.traybar.show()
|
self.traybar.show()
|
||||||
|
|
||||||
|
self.connect('size_allocate', self._size_allocate_cb)
|
||||||
|
|
||||||
def scroll_right(self):
|
def scroll_right(self):
|
||||||
adj = self.get_hadjustment()
|
adj = self.get_hadjustment()
|
||||||
new_value = adj.value + self.allocation.width
|
new_value = adj.value + self.allocation.width
|
||||||
@ -42,6 +51,21 @@ class _TrayViewport(gtk.Viewport):
|
|||||||
new_value = adj.value - self.allocation.width
|
new_value = adj.value - self.allocation.width
|
||||||
adj.value = max(adj.lower, new_value)
|
adj.value = max(adj.lower, new_value)
|
||||||
|
|
||||||
|
def do_get_property(self, pspec):
|
||||||
|
if pspec.name == 'can-scroll':
|
||||||
|
return self._can_scroll
|
||||||
|
|
||||||
|
def _size_allocate_cb(self, viewport, allocation):
|
||||||
|
bar_requisition = self.traybar.get_child_requisition()
|
||||||
|
if bar_requisition[0] < allocation.width:
|
||||||
|
can_scroll = False
|
||||||
|
else:
|
||||||
|
can_scroll = True
|
||||||
|
|
||||||
|
if can_scroll != self._can_scroll:
|
||||||
|
self._can_scroll = can_scroll
|
||||||
|
self.notify('can-scroll')
|
||||||
|
|
||||||
class HTray(gtk.HBox):
|
class HTray(gtk.HBox):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
gobject.GObject.__init__(self, **kwargs)
|
gobject.GObject.__init__(self, **kwargs)
|
||||||
@ -55,9 +79,10 @@ class HTray(gtk.HBox):
|
|||||||
icon.show()
|
icon.show()
|
||||||
|
|
||||||
self.pack_start(self._scroll_left, False)
|
self.pack_start(self._scroll_left, False)
|
||||||
self._scroll_left.show()
|
|
||||||
|
|
||||||
self._viewport = _TrayViewport()
|
self._viewport = _TrayViewport()
|
||||||
|
self._viewport.connect('notify::can-scroll',
|
||||||
|
self._viewport_can_scroll_changed_cb)
|
||||||
self.pack_start(self._viewport)
|
self.pack_start(self._viewport)
|
||||||
self._viewport.show()
|
self._viewport.show()
|
||||||
|
|
||||||
@ -70,6 +95,10 @@ class HTray(gtk.HBox):
|
|||||||
icon.show()
|
icon.show()
|
||||||
|
|
||||||
self.pack_start(self._scroll_right, False)
|
self.pack_start(self._scroll_right, False)
|
||||||
|
|
||||||
|
def _viewport_can_scroll_changed_cb(self, viewport, pspec):
|
||||||
|
if self._viewport.props.can_scroll:
|
||||||
|
self._scroll_left.show()
|
||||||
self._scroll_right.show()
|
self._scroll_right.show()
|
||||||
|
|
||||||
def _scroll_left_cb(self, button):
|
def _scroll_left_cb(self, button):
|
||||||
|
@ -41,6 +41,15 @@ for i in range(0, 100):
|
|||||||
tray.add_item(button)
|
tray.add_item(button)
|
||||||
button.show()
|
button.show()
|
||||||
|
|
||||||
|
tray = HTray()
|
||||||
|
box.pack_start(tray, False)
|
||||||
|
tray.show()
|
||||||
|
|
||||||
|
for i in range(0, 10):
|
||||||
|
button = TrayButton(icon_name=theme_icons[i])
|
||||||
|
tray.add_item(button)
|
||||||
|
button.show()
|
||||||
|
|
||||||
test.pack_start(box)
|
test.pack_start(box)
|
||||||
box.show()
|
box.show()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user