[Sugar-devel] [PATCH 2/2] Adding toolbars compatibility

Rafael Ortiz rafael at activitycentral.com
Mon May 30 20:04:38 EDT 2011


This patch adds toolbars compatibility for hello-world activity in order
to make this activity available for sugar-0.84 users.
---
 activity.py |   92 ++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/activity.py b/activity.py
index ea171dc..66f8464 100644
--- a/activity.py
+++ b/activity.py
@@ -23,63 +23,71 @@ import logging
 from gettext import gettext as _
 
 from sugar.activity import activity
-from sugar.graphics.toolbarbox import ToolbarBox
-from sugar.activity.widgets import ActivityButton
-from sugar.activity.widgets import ActivityToolbox
-from sugar.activity.widgets import TitleEntry
-from sugar.activity.widgets import StopButton
-from sugar.activity.widgets import ShareButton
-from sugar.activity.widgets import KeepButton
+
 
 class HelloWorldActivity(activity.Activity):
-    """HelloWorldActivity class as specified in activity.info"""
+    """HelloWorldActivity class as fspecified in activity.info"""
     """HelloWorldActivity clase como se specifica en activity.info"""
 
     def __init__(self, handle):
         """Set up the HelloWorld activity."""
         """Configurando la actividad HelloWorld."""
-        
+
         activity.Activity.__init__(self, handle)
 
         # We do not have collaboration features
         # Make the share option insensitive
         # No tenemos caracteristicas de colaboracion
-        # Deshabilitando la opcion de compartir 
+        # Deshabilitando la opcion de compartir
         self.max_participants = 1
 
-        # toolbar with the new toolbar redesign
-        # barra de herramientas con el nuevo diseño.
-
-        toolbar_box = ToolbarBox()
-
-        activity_button = ActivityButton(self)
-        toolbar_box.toolbar.insert(activity_button, 0)
-        activity_button.show()
-
-        title_entry = TitleEntry(self)
-        toolbar_box.toolbar.insert(title_entry, -1)
-        title_entry.show()
-
-        share_button = ShareButton(self)
-        toolbar_box.toolbar.insert(share_button, -1)
-        share_button.show()
-
-        keep_button = KeepButton(self)
-        toolbar_box.toolbar.insert(keep_button, -1)
-        keep_button.show()
+        # toolbar with the new toolbar redesign with old toolbar compatibility
+        # barra de herramientas con el nuevo diseno y compatibilidad con las viejas barras.
+        OLD_TOOLBAR = False
+        try:
+                from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
+                from sugar.activity.widgets import ActivityToolbarButton, StopButton, \
+                ShareButton, KeepButton, TitleEntry, ActivityButton
+
+        except ImportError:
+                OLD_TOOLBAR = True
+
+        if OLD_TOOLBAR:
+            from sugar.activity.activity import Activity, ActivityToolbox
+            toolbox = ActivityToolbox(self)
+            self.set_toolbox(toolbox)
+            toolbox.show()
+
+        else:
+                toolbar_box = ToolbarBox()
+                activity_button = ActivityButton(self)
+                toolbar_box.toolbar.insert(activity_button, 0)
+                activity_button.show()
+
+                title_entry = TitleEntry(self)
+                toolbar_box.toolbar.insert(title_entry, -1)
+                title_entry.show()
+
+                share_button = ShareButton(self)
+                toolbar_box.toolbar.insert(share_button, -1)
+                share_button.show()
+
+                keep_button = KeepButton(self)
+                toolbar_box.toolbar.insert(keep_button, -1)
+                keep_button.show()
         
-        separator = gtk.SeparatorToolItem()
-        separator.props.draw = False
-        separator.set_expand(True)
-        toolbar_box.toolbar.insert(separator, -1)
-        separator.show()
-
-        stop_button = StopButton(self)
-        toolbar_box.toolbar.insert(stop_button, -1)
-        stop_button.show()
-
-        self.set_toolbar_box(toolbar_box)
-        toolbar_box.show()
+                separator = gtk.SeparatorToolItem()
+                separator.props.draw = False
+                separator.set_expand(True)
+                toolbar_box.toolbar.insert(separator, -1)
+                separator.show()
+
+                stop_button = StopButton(self)
+                toolbar_box.toolbar.insert(stop_button, -1)
+                stop_button.show()
+
+                self.set_toolbar_box(toolbar_box)
+                toolbar_box.show()
 
         # Label with the text, make the string translatable.
         # Marca con el texto, haciendo la cadena traducible.
-- 
1.7.4.1



More information about the Sugar-devel mailing list