[Sugar-devel] [PATCH] Change toolbar to enable the use in Sugar < 0.86

James Cameron quozl at laptop.org
Tue Nov 2 20:39:49 EDT 2010


Reviewed-by: James Cameron <quozl at laptop.org>

On Tue, Nov 02, 2010 at 10:07:21AM -0300, godiard at sugarlabs.org wrote:
> From: Gonzalo Odiard <godiard at sugarlabs.org>
> 

No commit message body, but the subject said it well.

> -        activity_toolbar.insert(gobutton, 2)
> +        activity_toolbar.insert(gobutton, -1 if OLD_TOOLBAR else 2)

I'd like to see this factored out into a function.  Here's what I mean:


diff --git a/pippy_app.py b/pippy_app.py
index fc8aaaa..01a6020 100644
--- a/pippy_app.py
+++ b/pippy_app.py
@@ -45,6 +45,12 @@ PYTHON_PREFIX="""#!/usr/bin/python
 # -*- coding: utf-8 -*-
 """
 
+OLD_TOOLBAR = False
+try:
+    from sugar.graphics.toolbarbox import ToolbarBox
+except ImportError:
+    OLD_TOOLBAR = True
+
 # get screen sizes
 SIZE_X = gtk.gdk.screen_width()
 SIZE_Y = gtk.gdk.screen_height()
@@ -80,6 +86,13 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
         palette.menu.append(menu_item)
         menu_item.show()
 
+	if OLD_TOOLBAR:
+	    activity_toolbar = gtk.Toolbar()
+	    toolbox.add_toolbar('Pippy',activity_toolbar)
+	    toolbox.set_current_toolbar(1)
+        def pos(x):
+            return -1 if OLD_TOOLBAR else x
+
         # The "go" button
         goicon_bw = gtk.Image()
         goicon_bw.set_from_file("%s/icons/run_bw.svg" % os.getcwd())
@@ -92,7 +105,7 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
         gobutton.connect('clicked', self.flash_cb, dict({'bw':goicon_bw,
             'color':goicon_color}))
         gobutton.connect('clicked', self.gobutton_cb)
-        activity_toolbar.insert(gobutton, 2)
+        activity_toolbar.insert(gobutton, pos(2))
 
         # The "stop" button
         stopicon_bw = gtk.Image()
@@ -106,7 +119,7 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
             'color':stopicon_color}))
         stopbutton.connect('clicked', self.stopbutton_cb)
         stopbutton.set_tooltip("Stop Running")
-        activity_toolbar.insert(stopbutton, 3)
+        activity_toolbar.insert(stopbutton, pos(3))
 
         # The "clear" button
         clearicon_bw = gtk.Image()
@@ -120,12 +133,12 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
         clearbutton.connect('clicked', self.flash_cb, dict({'bw':clearicon_bw,
             'color':clearicon_color}))
         clearbutton.set_tooltip("Clear")
-        activity_toolbar.insert(clearbutton, 4)
+        activity_toolbar.insert(clearbutton, pos(4))
 
         # A vertical toolbar separator
         separator = gtk.SeparatorToolItem()
         separator.set_draw(True)
-        activity_toolbar.insert(separator, 5)
+        activity_toolbar.insert(separator, pos(5))
         activity_toolbar.show_all()
 
         self.set_toolbox(toolbox)

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list