[Sugar-devel] [PATCH 1/2] Revert to original layout (<=v35) for Sugar <=0.84

Anish Mangal anish at sugarlabs.org
Mon Nov 1 07:36:22 EDT 2010


From: anishmangal2002 <anishmangal2002 at gmail.com>

Signed-off-by: Anish Mangal <anish at sugarlabs.org>
---
 pippy_app.py |  263 ++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 190 insertions(+), 73 deletions(-)

diff --git a/pippy_app.py b/pippy_app.py
index fc8aaaa..ed8ee24 100644
--- a/pippy_app.py
+++ b/pippy_app.py
@@ -34,8 +34,24 @@ from activity import ViewSourceActivity, TARGET_TYPE_TEXT
 from sugar.activity.activity import ActivityToolbox, \
      get_bundle_path, get_bundle_name
 from sugar.graphics import style
+
 from sugar.graphics.toolbutton import ToolButton
 
+_ORIGINAL_PIPPY_LAYOUT = False
+
+try:
+    # >= 0.86 toolbars
+    from sugar.graphics.toolbarbox import ToolbarButton, ToolbarBox
+    from sugar.activity.widgets import _create_activity_icon
+    from sugar.activity.widgets import ActivityButton, ActivityToolbar
+    from sugar.activity.widgets import TitleEntry
+    from sugar.activity.widgets import StopButton
+    from sugar.activity.widgets import ShareButton
+    from sugar.activity.widgets import KeepButton
+except ImportError:
+    # <= 0.84 toolbars
+    _ORIGINAL_PIPPY_LAYOUT = True
+
 import groupthink.sugar_tools
 import groupthink.gtk_tools
 
@@ -51,6 +67,20 @@ SIZE_Y = gtk.gdk.screen_height()
 
 groupthink_mimetype = 'pickle/groupthink-pippy'
 
+if _ORIGINAL_PIPPY_LAYOUT == False:
+    # modded ActivityToolbarButton which has its toolbar object public
+    class ActivityToolbarButton(ToolbarButton):
+
+        def __init__(self, activity, **kwargs):
+            self.toolbar = ActivityToolbar(activity, orientation_left=True)
+            self.toolbar.stop.hide()
+
+            ToolbarButton.__init__(self, page=self.toolbar, **kwargs)
+
+            icon = _create_activity_icon(activity.metadata)
+            self.set_icon_widget(icon)
+            icon.show()
+
 class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
     """Pippy Activity as specified in activity.info"""
     def early_setup(self):
@@ -61,79 +91,159 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
     def initialize_display(self):
         self._logger = logging.getLogger('pippy-activity')
 
-        # Top toolbar with share and close buttons:
-        toolbox = ActivityToolbox(self)
-        activity_toolbar = toolbox.get_activity_toolbar()
-        # add 'make bundle' entry to 'keep' palette.
-        palette = toolbox.get_activity_toolbar().keep.get_palette()
-        # XXX: should clear out old palette entries?
-        from sugar.graphics.menuitem import MenuItem
-        from sugar.graphics.icon import Icon
-        menu_item = MenuItem(_('As Pippy Document'))
-        menu_item.set_image(Icon(file=('%s/activity/activity-icon.svg' % get_bundle_path()), icon_size=gtk.ICON_SIZE_MENU))
-        menu_item.connect('activate', self.keepbutton_cb)
-        palette.menu.append(menu_item)
-        menu_item.show()
-        menu_item = MenuItem(_('As Activity Bundle'))
-        menu_item.set_image(Icon(file=('%s/activity/activity-default.svg' % get_bundle_path()), icon_size=gtk.ICON_SIZE_MENU))
-        menu_item.connect('activate', self.makebutton_cb)
-        palette.menu.append(menu_item)
-        menu_item.show()
-
-        # The "go" button
-        goicon_bw = gtk.Image()
-        goicon_bw.set_from_file("%s/icons/run_bw.svg" % os.getcwd())
-        goicon_color = gtk.Image()
-        goicon_color.set_from_file("%s/icons/run_color.svg" % os.getcwd())
-        gobutton = ToolButton(label=_("_Run!"))
-        gobutton.props.accelerator = _('<alt>r')
-        gobutton.set_icon_widget(goicon_bw)
-        gobutton.set_tooltip("Run")
-        gobutton.connect('clicked', self.flash_cb, dict({'bw':goicon_bw,
-            'color':goicon_color}))
-        gobutton.connect('clicked', self.gobutton_cb)
-        activity_toolbar.insert(gobutton, 2)
-
-        # The "stop" button
-        stopicon_bw = gtk.Image()
-        stopicon_bw.set_from_file("%s/icons/stopit_bw.svg" % os.getcwd())
-        stopicon_color = gtk.Image()
-        stopicon_color.set_from_file("%s/icons/stopit_color.svg" % os.getcwd())
-        stopbutton = ToolButton(label=_("_Stop"))
-        stopbutton.props.accelerator = _('<alt>s')
-        stopbutton.set_icon_widget(stopicon_bw)
-        stopbutton.connect('clicked', self.flash_cb, dict({'bw':stopicon_bw,
-            'color':stopicon_color}))
-        stopbutton.connect('clicked', self.stopbutton_cb)
-        stopbutton.set_tooltip("Stop Running")
-        activity_toolbar.insert(stopbutton, 3)
-
-        # The "clear" button
-        clearicon_bw = gtk.Image()
-        clearicon_bw.set_from_file("%s/icons/eraser_bw.svg" % os.getcwd())
-        clearicon_color = gtk.Image()
-        clearicon_color.set_from_file("%s/icons/eraser_color.svg" % os.getcwd())
-        clearbutton = ToolButton(label=_("_Clear"))
-        clearbutton.props.accelerator = _('<alt>c')
-        clearbutton.set_icon_widget(clearicon_bw)
-        clearbutton.connect('clicked', self.clearbutton_cb)
-        clearbutton.connect('clicked', self.flash_cb, dict({'bw':clearicon_bw,
-            'color':clearicon_color}))
-        clearbutton.set_tooltip("Clear")
-        activity_toolbar.insert(clearbutton, 4)
-
-        # A vertical toolbar separator
-        separator = gtk.SeparatorToolItem()
-        separator.set_draw(True)
-        activity_toolbar.insert(separator, 5)
-        activity_toolbar.show_all()
-
-        self.set_toolbox(toolbox)
-        toolbox.show()
+        # A homogeneous table used for packing buttons so that they
+        # resize without any pains
+        self._table = gtk.Table()
+        self._table.set_homogeneous(True)
+
+        if not _ORIGINAL_PIPPY_LAYOUT:
+            # >= 0.86 toolbars
+            toolbar_box = ToolbarBox()
+            activity_button = ActivityToolbarButton(self)
+            toolbar_box.toolbar.insert(activity_button, 0)
+
+            separator = gtk.SeparatorToolItem()
+            toolbar_box.toolbar.insert(separator, -1)
+
+            # The "go" button
+            goicon_bw = gtk.Image()
+            goicon_bw.set_from_file("%s/icons/run_bw.svg" % os.getcwd())
+            goicon_color = gtk.Image()
+            goicon_color.set_from_file("%s/icons/run_color.svg" % os.getcwd())
+            gobutton = ToolButton(label=_("_Run!"))
+            gobutton.props.accelerator = _('<alt>r')
+            gobutton.set_icon_widget(goicon_bw)
+            gobutton.set_tooltip("Run")
+            gobutton.connect('clicked', self.flash_cb, dict({'bw':goicon_bw,
+                'color':goicon_color}))
+            gobutton.connect('clicked', self.gobutton_cb)
+            toolbar_box.toolbar.insert(gobutton, -1)
+            gobutton.show()
+
+            # The "stop" button
+            stopicon_bw = gtk.Image()
+            stopicon_bw.set_from_file("%s/icons/stopit_bw.svg" % os.getcwd())
+            stopicon_color = gtk.Image()
+            stopicon_color.set_from_file("%s/icons/stopit_color.svg" % os.getcwd())
+            stopbutton = ToolButton(label=_("_Stop"))
+            stopbutton.props.accelerator = _('<alt>s')
+            stopbutton.set_icon_widget(stopicon_bw)
+            stopbutton.connect('clicked', self.flash_cb, dict({'bw':stopicon_bw,
+                'color':stopicon_color}))
+            stopbutton.connect('clicked', self.stopbutton_cb)
+            stopbutton.set_tooltip("Stop Running")
+            toolbar_box.toolbar.insert(stopbutton, -1)
+            stopbutton.show()
+
+            # The "clear" button
+            clearicon_bw = gtk.Image()
+            clearicon_bw.set_from_file("%s/icons/eraser_bw.svg" % os.getcwd())
+            clearicon_color = gtk.Image()
+            clearicon_color.set_from_file("%s/icons/eraser_color.svg" % os.getcwd())
+            clearbutton = ToolButton(label=_("_Clear"))
+            clearbutton.props.accelerator = _('<alt>c')
+            clearbutton.set_icon_widget(clearicon_bw)
+            clearbutton.connect('clicked', self.flash_cb, dict({'bw':clearicon_bw,
+                'color':clearicon_color}))
+            clearbutton.connect('clicked', self.clearbutton_cb)
+            clearbutton.set_tooltip("Clear")
+            toolbar_box.toolbar.insert(clearbutton, -1)
+            clearbutton.show()
+
+            # add 'make bundle' entry to 'keep' palette.
+            palette = activity_button.toolbar.keep.get_palette()
+            # XXX: should clear out old palette entries?
+            from sugar.graphics.menuitem import MenuItem
+            from sugar.graphics.icon import Icon
+            menu_item = MenuItem(_('As Pippy Document'))
+            menu_item.set_image(Icon(file=('%s/activity/activity-icon.svg' % get_bundle_path()), icon_size=gtk.ICON_SIZE_MENU))
+            menu_item.connect('activate', self.keepbutton_cb)
+            palette.menu.append(menu_item)
+            menu_item.show()
+            menu_item = MenuItem(_('As Activity Bundle'))
+            menu_item.set_image(Icon(file=('%s/activity/activity-default.svg' % get_bundle_path()), icon_size=gtk.ICON_SIZE_MENU))
+            menu_item.connect('activate', self.makebutton_cb)
+            palette.menu.append(menu_item)
+            menu_item.show()
+
+            separator = gtk.SeparatorToolItem()
+            separator.props.draw = False
+            separator.set_expand(True)
+            toolbar_box.toolbar.insert(separator, -1)
+
+            stop = StopButton(self)
+            toolbar_box.toolbar.insert(stop, -1)
+            self.set_toolbox(toolbar_box)
+            toolbar_box.show()
+
+        else:
+            # <= 0.84 toolbars
+            # Top toolbar with share and close buttons:
+            toolbox = ActivityToolbox(self)
+            # add 'make bundle' entry to 'keep' palette.
+            palette = toolbox.get_activity_toolbar().keep.get_palette()
+            # XXX: should clear out old palette entries?
+            from sugar.graphics.menuitem import MenuItem
+            from sugar.graphics.icon import Icon
+            menu_item = MenuItem(_('As Pippy Document'))
+            menu_item.set_image(Icon(file=('%s/activity/activity-icon.svg' % get_bundle_path()), icon_size=gtk.ICON_SIZE_MENU))
+            menu_item.connect('activate', self.keepbutton_cb)
+            palette.menu.append(menu_item)
+            menu_item.show()
+            menu_item = MenuItem(_('As Activity Bundle'))
+            menu_item.set_image(Icon(file=('%s/activity/activity-default.svg' % get_bundle_path()), icon_size=gtk.ICON_SIZE_MENU))
+            menu_item.connect('activate', self.makebutton_cb)
+            palette.menu.append(menu_item)
+            menu_item.show()
+
+            # The "go" button
+            goicon_bw = gtk.Image()
+            goicon_bw.set_from_file("%s/icons/run_bw.svg" % os.getcwd())
+            goicon_color = gtk.Image()
+            goicon_color.set_from_file("%s/icons/run_color.svg" % os.getcwd())
+            gobutton = gtk.Button(label=_("_Run!"))
+            gobutton.set_image(goicon_bw)
+            gobutton.connect('clicked', self.flash_cb, dict({'bw':goicon_bw,
+                'color':goicon_color}))
+            gobutton.connect('clicked', self.gobutton_cb)
+            self._table.attach(gobutton, 0, 2, 0, 1)
+
+            # The "clear" button
+            clearicon_bw = gtk.Image()
+            clearicon_bw.set_from_file("%s/icons/eraser_bw.svg" % os.getcwd())
+            clearicon_color = gtk.Image()
+            clearicon_color.set_from_file("%s/icons/eraser_color.svg" % os.getcwd())
+            clearbutton = gtk.Button(label=_("_Clear!"))
+            clearbutton.set_image(clearicon_bw)
+            clearbutton.connect('clicked', self.flash_cb, dict({'bw':clearicon_bw,
+                'color':clearicon_color}))
+            clearbutton.connect('clicked', self.clearbutton_cb)
+            self._table.attach(clearbutton, 2, 3, 0, 1)
+
+            # The "stop" button
+            stopicon_bw = gtk.Image()
+            stopicon_bw.set_from_file("%s/icons/stopit_bw.svg" % os.getcwd())
+            stopicon_color = gtk.Image()
+            stopicon_color.set_from_file("%s/icons/stopit_color.svg" % os.getcwd())
+            stopbutton = gtk.Button(label=_("_Stop!"))
+            stopbutton.set_image(stopicon_bw)
+            stopbutton.connect('clicked', self.flash_cb, dict({'bw':stopicon_bw,
+                'color':stopicon_color}))
+            stopbutton.connect('clicked', self.stopbutton_cb)
+            self._table.attach(stopbutton, 3, 4, 0, 1)
+
+            self.set_toolbox(toolbox)
+            toolbox.show()
+            activity_toolbar = toolbox.get_activity_toolbar()
+            activity_toolbar.share.props.visible = False
 
         # Main layout.
         self.hpane = gtk.HPaned()
         self.vpane = gtk.VPaned()
+        # Vbox for vertically placing the gtksourceview and old pippy
+        # layout buttons (if needed)
+        self._vbox = gtk.VBox()
+        self._vbox.set_size_request(0, int(SIZE_Y * 0.5))
 
         # The sidebar.
         self.sidebar = gtk.VBox()
@@ -191,7 +301,6 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
 
         # The GTK source view window
         self.text_view = gtksourceview2.View(text_buffer)
-        self.text_view.set_size_request(0, int(SIZE_Y * 0.5))
         self.text_view.set_editable(True)
         self.text_view.set_cursor_visible(True)
         self.text_view.set_show_line_numbers(True)
@@ -211,7 +320,9 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
         codesw.set_policy(gtk.POLICY_AUTOMATIC,
                       gtk.POLICY_AUTOMATIC)
         codesw.add(self.text_view)
-        self.vpane.add1(codesw)
+        self._vbox.pack_start(codesw)
+        self._vbox.pack_start(self._table, expand=False, fill=False)
+        self.vpane.add1(self._vbox)
 
         # An hbox to hold the vte window and its scrollbar.
         outbox = gtk.HBox()
@@ -263,12 +374,18 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
         self.text_view.grab_focus()
 
     def timer_cb(self, button, icons):
-        button.set_icon_widget(icons['bw'])
+        if not _ORIGINAL_PIPPY_LAYOUT:
+            button.set_icon_widget(icons['bw'])
+        else:
+            button.set_image(icons['bw'])
         button.show_all()
         return False
 
     def flash_cb(self, button, icons):
-        button.set_icon_widget(icons['color'])
+        if not _ORIGINAL_PIPPY_LAYOUT:
+            button.set_icon_widget(icons['color'])
+        else:
+            button.set_image(icons['color'])
         button.show_all()
         gobject.timeout_add(400, self.timer_cb, button, icons)
 
-- 
1.7.2.3



More information about the Sugar-devel mailing list