This patch is mainly for Marco, who plans to help me finish and clean
up the new activity launcher.  It's currently full of TODOs, comments,
temporary hacks, etc, but it's in a "nearly complete" state inasmuch
as it will run smoothly despite the partially unfinished and poorly
styled implementation.

Also, launchbox.py is a new file to be added to src/view/home/ in
addition to applying the patch, and of course you'll need to edit the
Makefile to include it as well.

Marco, take a peek at the various comments I've made; I look forward
to hearing your thoughts on the remainder.  It's looking good so far.

- Eben
diff --git a/src/model/shellmodel.py b/src/model/shellmodel.py
index 1834fcd..847136c 100644
--- a/src/model/shellmodel.py
+++ b/src/model/shellmodel.py
@@ -36,6 +36,7 @@ class ShellModel(gobject.GObject):
     ZOOM_FRIENDS = 1
     ZOOM_HOME = 2
     ZOOM_ACTIVITY = 3
+    ZOOM_LAUNCH = 4
 
     __gproperties__ = {
         'state'      : (int, None, None,
diff --git a/src/view/Shell.py b/src/view/Shell.py
index 2810c74..27a7123 100644
--- a/src/view/Shell.py
+++ b/src/view/Shell.py
@@ -151,16 +151,26 @@ class Shell(gobject.GObject):
         activityfactory.create(bundle_id, handle)
 
     def notify_launch(self, bundle_id, activity_id):
-        # Zoom to Home for launch feedback
-        self.set_zoom_level(shellmodel.ShellModel.ZOOM_HOME)
-
         home_model = self._model.get_home()
         home_model.notify_activity_launch(activity_id, bundle_id)
 
+        # Zoom in for launch feedback, except for Journal
+        if bundle_id != 'org.laptop.JournalActivity':
+            # TODO: How do I get the home_activity object properly?
+            home_activity = home_model._get_activity_by_id(activity_id)
+            self._home_window.do_activity_launch(home_activity.get_icon_path(),
+                                                 home_activity.get_icon_color())
+            self.set_zoom_level(shellmodel.ShellModel.ZOOM_LAUNCH)
+
+    # TODO: This never gets called...why?
     def notify_launch_failure(self, activity_id):
         home_model = self._model.get_home()
         home_model.notify_activity_launch_failed(activity_id)
 
+        # TODO: Add failure alert to launchbox; zoom home for now
+        print 'Launch Failure...returning to home zoom level'
+        self.set_zoom_level(shellmodel.ShellModel.ZOOM_HOME)
+
     def start_activity(self, activity_type):
         if activity_type in self._activities_starting:
             logging.debug("This activity is still launching.")
@@ -185,16 +195,26 @@ class Shell(gobject.GObject):
                 except dbus.DBusException, e:
                     logging.debug('Error raised by TakeScreenshot(): %s', e)
 
+    def set_launching_icon(self, icon_path, icon_color):
+        # There is a race condition here, if set_zoom_level gets called first
+        # We could call set_zoom_level(ZOOM_LAUNCH) within this function instead
+        zoom = self._model.get_zoom_level() < shellmodel.ShellModel.ZOOM_ACTIVITY
+        self._home_window.set_launching_icon(icon_path, icon_color, zoom)
+
     def set_zoom_level(self, level):
         if level == self._model.get_zoom_level():
             return
 
         self.take_activity_screenshot()
 
+        # TODO: We could check here to see if the selected activity is
+        # launching, and interpret ZOOM_LAUNCH if so.
         if level == shellmodel.ShellModel.ZOOM_ACTIVITY:
             if self._pending_host is not None:
                 self._pending_host.present()
             self._screen.toggle_showing_desktop(False)
+            self._model.set_zoom_level(level)
+            self._home_window.set_zoom_level(level)
         else:
             self._model.set_zoom_level(level)
             self._screen.toggle_showing_desktop(True)
diff --git a/src/view/frame/activitiestray.py b/src/view/frame/activitiestray.py
index f50a308..2b4cd72 100644
--- a/src/view/frame/activitiestray.py
+++ b/src/view/frame/activitiestray.py
@@ -43,6 +43,10 @@ class ActivityButton(RadioToolButton):
 
         self._home_activity = home_activity
 
+        # TODO: Clean up this temporary hack to access the info
+        self.icon_path = home_activity.get_icon_path()
+        self.icon_color = home_activity.get_icon_color()
+
         self._icon = PulsingIcon()
         self._icon.props.base_color = home_activity.get_icon_color()
         self._icon.props.pulse_color = \
@@ -68,23 +72,23 @@ class ActivityButton(RadioToolButton):
             self._notify_launching_hid = home_activity.connect('notify::launching',
                     self.__notify_launching_cb)
 
-            self._notif_icon = NotificationIcon()
-            self._notif_icon.props.xo_color = home_activity.get_icon_color()
-            if home_activity.get_icon_path():
-                self._notif_icon.props.icon_filename = home_activity.get_icon_path()
-            else:
-                self._notif_icon.props.icon_name = 'image-missing'
-            view.frame.frame.get_instance().add_notification(self._notif_icon)
+            #self._notif_icon = NotificationIcon()
+            #self._notif_icon.props.xo_color = home_activity.get_icon_color()
+            #if home_activity.get_icon_path():
+            #    self._notif_icon.props.icon_filename = home_activity.get_icon_path()
+            #else:
+            #    self._notif_icon.props.icon_name = 'image-missing'
+            #view.frame.frame.get_instance().add_notification(self._notif_icon)
         else:
             self._notify_launching_hid = None
             self._notif_icon = None
 
     def __notify_launching_cb(self, home_activity, pspec):
         if not home_activity.props.launching:
-            if self._notif_icon is not None:
-                frame = view.frame.frame.get_instance()
-                frame.remove_notification(self._notif_icon)
-                self._notif_icon = None
+            #if self._notif_icon is not None:
+            #    frame = view.frame.frame.get_instance()
+            #    frame.remove_notification(self._notif_icon)
+            #    self._notif_icon = None
             self._icon.props.pulsing = False
             home_activity.disconnect(self._notify_launching_hid)
 
@@ -209,6 +213,7 @@ class ActivitiesTray(HTray):
         self._buttons[home_activity.get_activity_id()] = button
         button.connect('clicked', self.__activity_clicked_cb, home_activity)
         button.show()
+        button.set_active(True)
 
     def __activity_removed_cb(self, home_model, home_activity):
         logging.debug('__activity_removed_cb: %r' % home_activity)
@@ -224,7 +229,13 @@ class ActivitiesTray(HTray):
     def __activity_clicked_cb(self, button, home_activity):
         if button.props.active:
             logging.debug('ActivitiesTray.__activity_clicked_cb')
-            home_activity.get_window().activate(1)
+            if home_activity.get_window() is not None:
+                home_activity.get_window().activate(1)
+            else:
+                logging.debug('ActivitiesTray: set launching icon')
+                shell = view.Shell.get_instance()
+                shell.set_launching_icon(button.icon_path, button.icon_color)
+                shell.set_zoom_level(shellmodel.get_instance().ZOOM_LAUNCH)
 
     def __invite_clicked_cb(self, icon, invite):
         self._invites.remove_invite(invite)
diff --git a/src/view/frame/zoomtoolbar.py b/src/view/frame/zoomtoolbar.py
index 946feac..9e1d2e6 100644
--- a/src/view/frame/zoomtoolbar.py
+++ b/src/view/frame/zoomtoolbar.py
@@ -64,6 +64,7 @@ class ZoomToolbar(gtk.Toolbar):
     def __level_clicked_cb(self, button, level):
         if not button.get_active():
             return
+        # TODO: switch to ZOOM_LAUNCH instead if selected activity is launching
         if shellmodel.get_instance().props.zoom_level != level:
             view.Shell.get_instance().set_zoom_level(level)
 
@@ -78,7 +79,8 @@ class ZoomToolbar(gtk.Toolbar):
             self._groups_button.props.active = True
         elif new_level == shellmodel.ShellModel.ZOOM_HOME:
             self._home_button.props.active = True
-        elif new_level == shellmodel.ShellModel.ZOOM_ACTIVITY:
+        elif new_level == shellmodel.ShellModel.ZOOM_ACTIVITY or \
+             new_level == shellmodel.ShellModel.ZOOM_LAUNCH:
             self._activity_button.props.active = True
         else:
             raise ValueError('Invalid zoom level: %r' % (new_level))
diff --git a/src/view/home/HomeWindow.py b/src/view/home/HomeWindow.py
index 9cb7c77..a9dd756 100644
--- a/src/view/home/HomeWindow.py
+++ b/src/view/home/HomeWindow.py
@@ -25,12 +25,14 @@ from view.home.MeshBox import MeshBox
 from view.home.HomeBox import HomeBox
 from view.home.FriendsBox import FriendsBox
 from view.home.transitionbox import TransitionBox
+from view.home.launchbox import LaunchBox
 from model.shellmodel import ShellModel
 
 _HOME_PAGE       = 0
 _FRIENDS_PAGE    = 1
 _MESH_PAGE       = 2
 _TRANSITION_PAGE = 3
+_LAUNCH_PAGE     = 4
 
 class HomeWindow(gtk.Window):
     def __init__(self):
@@ -65,6 +67,7 @@ class HomeWindow(gtk.Window):
         self._friends_box = FriendsBox()
         self._mesh_box = MeshBox()
         self._transition_box = TransitionBox()
+        self._launch_box = LaunchBox()
 
         self._activate_view()
         self._canvas.set_root(self._home_box)
@@ -111,11 +114,21 @@ class HomeWindow(gtk.Window):
         else:
             self._activate_view()
 
+    def do_activity_launch(self, icon_color, icon_path):
+        self._launch_box.set_icon(icon_color, icon_path, True)
+
+    def set_launching_icon(self, icon_path, icon_color, zoom):
+        self._launch_box.set_icon(icon_path, icon_color, zoom)
+
     def set_zoom_level(self, level):
         self._deactivate_view()
         self._level = level
         self._activate_view()
     
+        if level == ShellModel.ZOOM_LAUNCH:
+            self._canvas.set_root(self._launch_box)
+            return
+
         self._canvas.set_root(self._transition_box)
 
         if level == ShellModel.ZOOM_HOME:
@@ -124,9 +137,12 @@ class HomeWindow(gtk.Window):
             size = style.LARGE_ICON_SIZE
         elif level == ShellModel.ZOOM_MESH:
             size = style.STANDARD_ICON_SIZE
-            
-        self._transition_box.set_size(size)
-    
+        elif level == ShellModel.ZOOM_ACTIVITY:
+            size = style.XLARGE_ICON_SIZE
+ 
+        if size is not None:
+            self._transition_box.set_size(size)
+
     def _transition_completed_cb(self, transition_box):
         if self._level == ShellModel.ZOOM_HOME:
             self._canvas.set_root(self._home_box)
diff --git a/src/view/home/activitieslist.py b/src/view/home/activitieslist.py
index 3b4c9d2..e12e8f0 100644
--- a/src/view/home/activitieslist.py
+++ b/src/view/home/activitieslist.py
@@ -85,7 +85,8 @@ class ActivityEntry(hippo.CanvasBox, hippo.CanvasItem):
                 file_name=activity_info.icon,
                 stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
                 fill_color=style.COLOR_TRANSPARENT.get_svg())
-        self.icon.set_palette(ActivityPalette(self._activity_info))
+        self._palette = ActivityPalette(self._activity_info)
+        self.icon.set_palette(self._palette)
         self.icon.connect('hovering-changed',
                           self.__icon_hovering_changed_event_cb)
         self.icon.connect('button-release-event',
@@ -128,6 +129,9 @@ class ActivityEntry(hippo.CanvasBox, hippo.CanvasItem):
 
     def __icon_button_release_event_cb(self, icon, event):
         view.Shell.get_instance().start_activity(self._activity_info.bundle_id)
+        self.icon.props.stroke_color = style.COLOR_BUTTON_GREY.get_svg()
+        self.icon.props.fill_color = style.COLOR_TRANSPARENT.get_svg()
+        self._palette.hide()
 
     def get_bundle_id(self):
         return self._activity_info.bundle_id
diff --git a/src/view/home/activitiesring.py b/src/view/home/activitiesring.py
index 438874f..2dc8714 100644
--- a/src/view/home/activitiesring.py
+++ b/src/view/home/activitiesring.py
@@ -144,6 +144,9 @@ class ActivityIcon(CanvasIcon):
 
     def __button_release_event_cb(self, icon, event):
         view.Shell.get_instance().start_activity(self._activity_info.bundle_id)
+        self.props.stroke_color = style.COLOR_BUTTON_GREY.get_svg()
+        self.props.fill_color = style.COLOR_TRANSPARENT.get_svg()
+        self._palette.hide()
 
     def get_bundle_id(self):
         return self._activity_info.bundle_id
# Copyright (C) 2007, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import hippo
import gobject

from sugar.graphics import style
from sugar.graphics import animator
from sugar.graphics.xocolor import XoColor

from view.pulsingicon import CanvasPulsingIcon

class _Animation(animator.Animation):
    def __init__(self, icon, start_size, end_size):
        animator.Animation.__init__(self, 0.0, 1.0)

        self._icon = icon
        self.start_size = start_size
        self.end_size = end_size

    def next_frame(self, current):
        d = (self.end_size - self.start_size) * current
        self._icon.props.size = self.start_size + d

class _Layout(gobject.GObject,hippo.CanvasLayout):
    __gtype_name__ = 'SugarLaunchBoxLayout'
    def __init__(self):
        gobject.GObject.__init__(self)

    def do_set_box(self, box):
        self._box = box

    def do_get_height_request(self, for_width):
        return 0, 0

    def do_get_width_request(self):
        return 0, 0

    def do_allocate(self, x, y, width, height,
                    req_width, req_height, origin_changed):
        for child in self._box.get_layout_children():
            min_width, child_width = child.get_width_request()
            min_height, child_height = child.get_height_request(child_width)

            child.allocate(x + (width - child_width) / 2,
                           y + (height - child_height) / 2,
                           child_width, child_height, origin_changed)

class LaunchBox(hippo.CanvasBox):
    def __init__(self):
        hippo.CanvasBox.__init__(self, 
                                 background_color=style.COLOR_WHITE.get_int())

        self._layout = _Layout()
        self.set_layout(self._layout)

        self._activity_icon = CanvasPulsingIcon()
        self.append(self._activity_icon)

        self._activity_icon.props.base_color = \
            XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
                               style.COLOR_TRANSPARENT.get_svg()))

        # TODO: these defaults are just for testing
        self._activity_icon.props.icon_name = 'computer-xo'
        self._activity_icon.props.pulse_color = \
            XoColor('%s,%s' % (style.COLOR_BLACK.get_svg(),
                               style.COLOR_TEXT_FIELD_GREY.get_svg()))

        self._animator = animator.Animator(0.3)
        #self._animator.connect('completed', self._animation_completed_cb)

    #def _animation_completed_cb(self, anim):
    #    self.emit('completed')

    def set_icon(self, icon_path, color, zoom=False):
        self._activity_icon.props.file_name = icon_path
        self._activity_icon.props.pulse_color = color
        if zoom:
            self.zoom_in()

    def notify_launch_failure(self, activity_id):
        pass
        """
        This is super tricky.  As we use the same view for all 
        launching activities, we need a way to determine which of
        those activities have failed when switching to them with
        the above set_activity method.  We also need a notification
        and a badged icon, but that should occur in the method
        which calls this one, most likely.
        """

    def zoom_in(self):
        self._activity_icon.props.size = style.STANDARD_ICON_SIZE

        self._animator.remove_all()
        self._animator.add(_Animation(self._activity_icon,
                                      style.STANDARD_ICON_SIZE,
                                      style.XLARGE_ICON_SIZE))
        self._animator.start()
        
        # Kick of pulsing animation
        self._activity_icon.props.pulsing = True
_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar

Reply via email to