[Sugar-devel] [PATCH sugar] Add toolbar to the TransitionBox

Gonzalo Odiard gonzalo at laptop.org
Mon Aug 27 10:40:26 EDT 2012


Can't you use the ViewToolbar in the last patch from erikos?

from jarabe.desktop.viewtoolbar import ViewToolbar

Gonzalo



On Mon, Aug 27, 2012 at 11:29 AM, Manuel Quiñones <manuq at laptop.org> wrote:

> With the new frame behaviour the toolbar was appearing and
> disappearing while the transition took place.  this patch adds a
> toolbar in the transition box with a fake search entry, that is set
> editable=False to prevent issues.
>
> Signed-off-by: Manuel Quiñones <manuq at laptop.org>
> ---
>  src/jarabe/desktop/transitionbox.py | 75
> +++++++++++++++++++++++++++++++++++--
>  1 file changed, 71 insertions(+), 4 deletions(-)
>
> diff --git a/src/jarabe/desktop/transitionbox.py
> b/src/jarabe/desktop/transitionbox.py
> index 54a70de..62764d7 100644
> --- a/src/jarabe/desktop/transitionbox.py
> +++ b/src/jarabe/desktop/transitionbox.py
> @@ -14,10 +14,12 @@
>  # along with this program; if not, write to the Free Software
>  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
>  USA
>
> +import gtk
>  import gobject
>
>  from sugar.graphics import style
>  from sugar.graphics import animator
> +from sugar.graphics import iconentry
>
>  from jarabe.model.buddy import get_owner_instance
>  from jarabe.view.buddyicon import BuddyIcon
> @@ -36,7 +38,63 @@ class _Animation(animator.Animation):
>          self._icon.props.pixel_size = int(self.start_size + d)
>
>
> -class TransitionBox(BuddyIcon):
> +class ViewToolbar(gtk.Toolbar):
> +    def __init__(self):
> +        gtk.Toolbar.__init__(self)
> +
> +        separator = gtk.SeparatorToolItem()
> +        separator.props.draw = False
> +        separator.set_size_request(style.GRID_CELL_SIZE,
> +                                   style.GRID_CELL_SIZE)
> +        self.insert(separator, -1)
> +        separator.show()
> +
> +        tool_item = gtk.ToolItem()
> +        self.insert(tool_item, -1)
> +        tool_item.show()
> +
> +        self.search_entry = iconentry.IconEntry()
> +        self.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
> +                                             'system-search')
> +        self.search_entry.set_width_chars(25)
> +        self.search_entry.props.editable = False
> +        tool_item.add(self.search_entry)
> +        self.search_entry.show()
> +
> +
> +class ViewContainer(gtk.HBox):
> +    def __init__(self, owner_icon):
> +        gtk.Container.__init__(self)
> +        self._owner_icon = owner_icon
> +        self.add(self._owner_icon)
> +        self._owner_icon.show()
> +        self.connect('size-allocate', self.__on_size_allocate)
> +
> +    def __on_size_allocate(self, widget, allocation):
> +        owner_width, owner_height = self._owner_icon.size_request()
> +        height = allocation.height + allocation.y
> +        width = allocation.width
> +
> +        # Find vertical center point of screen
> +        y = height / 2
> +
> +        # This container may be offset from the top by a certain amount
> +        # (e.g. for a toolbar at the top of the screen). Adjust the
> +        # center-point for that
> +        y -= allocation.y
> +
> +        # Now subtract half of the owner height. This gives us the y
> +        # coordinate for the top of the owner icon.
> +        y -= owner_height / 2
> +
> +        # calculate x coordinate and create allocation
> +        x = (width - owner_width) / 2
> +        owner_icon_allocation = gtk.gdk.Rectangle(x, allocation.y + y,
> +                                                  owner_width,
> owner_height)
> +        self._owner_icon.size_allocate(owner_icon_allocation)
> +
> +
> +class TransitionBox(gtk.VBox):
>      __gtype_name__ = 'SugarTransitionBox'
>
>      __gsignals__ = {
> @@ -44,8 +102,17 @@ class TransitionBox(BuddyIcon):
>      }
>
>      def __init__(self):
> -        BuddyIcon.__init__(self, buddy=get_owner_instance(),
> -                           pixel_size=style.XLARGE_ICON_SIZE)
> +        gtk.VBox.__init__(self)
> +
> +        self._toolbar = ViewToolbar()
> +        self.pack_start(self._toolbar, expand=False)
> +        self._toolbar.show()
> +
> +        self._owner_icon = BuddyIcon(buddy=get_owner_instance(),
> +                                     pixel_size=style.XLARGE_ICON_SIZE)
> +        view_container = ViewContainer(self._owner_icon)
> +        self.add(view_container)
> +        view_container.show()
>
>          self._animator = animator.Animator(0.3)
>          self._animator.connect('completed', self._animation_completed_cb)
> @@ -55,5 +122,5 @@ class TransitionBox(BuddyIcon):
>
>      def start_transition(self, start_size, end_size):
>          self._animator.remove_all()
> -        self._animator.add(_Animation(self, start_size, end_size))
> +        self._animator.add(_Animation(self._owner_icon, start_size,
> end_size))
>          self._animator.start()
> --
> 1.7.11.4
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20120827/11472d5e/attachment-0001.html>


More information about the Sugar-devel mailing list