Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2007-08-27 20:10:18 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2007-08-27 20:10:18 (GMT)
commitc742cff64dde66ca7d8f2f68b1c41a023640d154 (patch)
tree72ad12290357e2702dbf9e1c7b4afe55b3cb9d9b
parent7fcc23b4c8c36b28f2e17904c1a64244fdd553b6 (diff)
Show arrows only when the icons does not fit.
-rw-r--r--sugar/graphics/tray.py33
-rw-r--r--tests/graphics/tray.py9
2 files changed, 40 insertions, 2 deletions
diff --git a/sugar/graphics/tray.py b/sugar/graphics/tray.py
index bfc4ad1..cf646a6 100644
--- a/sugar/graphics/tray.py
+++ b/sugar/graphics/tray.py
@@ -22,7 +22,14 @@ from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.icon import Icon
class _TrayViewport(gtk.Viewport):
+ __gproperties__ = {
+ 'can-scroll' : (bool, None, None, False,
+ gobject.PARAM_READABLE),
+ }
+
def __init__(self):
+ self._can_scroll = False
+
gobject.GObject.__init__(self)
self.set_shadow_type(gtk.SHADOW_NONE)
@@ -32,6 +39,8 @@ class _TrayViewport(gtk.Viewport):
self.add(self.traybar)
self.traybar.show()
+ self.connect('size_allocate', self._size_allocate_cb)
+
def scroll_right(self):
adj = self.get_hadjustment()
new_value = adj.value + self.allocation.width
@@ -42,6 +51,21 @@ class _TrayViewport(gtk.Viewport):
new_value = adj.value - self.allocation.width
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):
def __init__(self, **kwargs):
gobject.GObject.__init__(self, **kwargs)
@@ -55,9 +79,10 @@ class HTray(gtk.HBox):
icon.show()
self.pack_start(self._scroll_left, False)
- self._scroll_left.show()
self._viewport = _TrayViewport()
+ self._viewport.connect('notify::can-scroll',
+ self._viewport_can_scroll_changed_cb)
self.pack_start(self._viewport)
self._viewport.show()
@@ -70,7 +95,11 @@ class HTray(gtk.HBox):
icon.show()
self.pack_start(self._scroll_right, False)
- self._scroll_right.show()
+
+ def _viewport_can_scroll_changed_cb(self, viewport, pspec):
+ if self._viewport.props.can_scroll:
+ self._scroll_left.show()
+ self._scroll_right.show()
def _scroll_left_cb(self, button):
self._viewport.scroll_left()
diff --git a/tests/graphics/tray.py b/tests/graphics/tray.py
index 8088fde..9bbf0b2 100644
--- a/tests/graphics/tray.py
+++ b/tests/graphics/tray.py
@@ -41,6 +41,15 @@ for i in range(0, 100):
tray.add_item(button)
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)
box.show()