Here's my second pass at the launcher patch. This version changes
little in the actual behavior of the code, but substantially cleans up
the code itself. I pulled all of the "pending_activity" code out,
simplifying the model a good deal, as we no longer need it with the
new Home design. I also re-factored the flow of the launch (and
launch failed) notifications, unifying so that everything occurs first
in the model which then sends signals to the view, rather than having
the view call the model in some cases and vice versa, which led to
inconsistencies.
These changes also made the calls to notify_launch in the shell
cleaner, passing the home_activity object instead of several other
parameters, which in turn cleaned up the call stack for
setting/changing the launching activity icon. I'm much more satisfied
here.
The main problem that remains is that the launching activity feedback
is still mostly maintained within the view. The model remains
unchanged from before. We need to clean this up so that a launching
activity (which doesn't yet have a window) can still be considered
active in the model, so that the view always properly reflects the
model instead of tiptoeing around it to achieve the launching feedback
effect.
Thoughts on how to best achieve this goal are welcomed, as it gets a
bit more intimate with the window management business that I'm
unfamiliar with.
- Eben
On Thu, Apr 17, 2008 at 1:19 AM, Eben Eliason <[EMAIL PROTECTED]> wrote:
> 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/homemodel.py b/src/model/homemodel.py
index 8de989c..97f0772 100644
--- a/src/model/homemodel.py
+++ b/src/model/homemodel.py
@@ -42,7 +42,13 @@ class HomeModel(gobject.GObject):
'activity-added': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
- 'activity-started': (gobject.SIGNAL_RUN_FIRST,
+ 'activity-started': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ([gobject.TYPE_PYOBJECT])),
+ 'activity-launched': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ([gobject.TYPE_PYOBJECT])),
+ 'activity-launch-failed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'activity-removed': (gobject.SIGNAL_RUN_FIRST,
@@ -51,9 +57,6 @@ class HomeModel(gobject.GObject):
'active-activity-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
- 'pending-activity-changed': (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ([gobject.TYPE_PYOBJECT]))
}
def __init__(self):
@@ -61,7 +64,6 @@ class HomeModel(gobject.GObject):
self._activities = []
self._active_activity = None
- self._pending_activity = None
screen = wnck.screen_get_default()
screen.connect('window-opened', self._window_opened_cb)
@@ -78,7 +80,7 @@ class HomeModel(gobject.GObject):
def get_previous_activity(self):
activities = self._get_activities_with_window()
- i = activities.index(self._pending_activity)
+ i = activities.index(self._active_activity)
if len(activities) == 0:
return None
elif i - 1 >= 0:
@@ -88,7 +90,7 @@ class HomeModel(gobject.GObject):
def get_next_activity(self):
activities = self._get_activities_with_window()
- i = activities.index(self._pending_activity)
+ i = activities.index(self._active_activity)
if len(activities) == 0:
return None
elif i + 1 < len(activities):
@@ -96,25 +98,6 @@ class HomeModel(gobject.GObject):
else:
return activities[0]
- def get_pending_activity(self):
- """Returns the activity that would be seen in the Activity zoom level
-
- In the Home (or Neighborhood or Groups) zoom level, this
- indicates the activity that would become active if the user
- switched to the Activity zoom level. (In the Activity zoom
- level, this just returns the currently-active activity.)
- Unlike get_active_activity(), this never returns None as long
- as there is any activity running.
- """
- return self._pending_activity
-
- def _set_pending_activity(self, home_activity):
- if self._pending_activity == home_activity:
- return
-
- self._pending_activity = home_activity
- self.emit('pending-activity-changed', self._pending_activity)
-
def get_active_activity(self):
"""Returns the activity that the user is currently working in
@@ -183,8 +166,8 @@ class HomeModel(gobject.GObject):
home_activity.props.launching = False
self.emit('activity-started', home_activity)
- if self._pending_activity is None:
- self._set_pending_activity(home_activity)
+ if self._active_activity is None:
+ self._set_active_activity(home_activity)
def _window_closed_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
@@ -219,7 +202,6 @@ class HomeModel(gobject.GObject):
activity = self._get_activity_by_xid(window.get_xid())
if activity is not None:
- self._set_pending_activity(activity)
self._set_active_activity(activity)
def _add_activity(self, home_activity):
@@ -227,21 +209,19 @@ class HomeModel(gobject.GObject):
self.emit('activity-added', home_activity)
def _remove_activity(self, home_activity):
- if home_activity == self._active_activity:
- self._set_active_activity(None)
- if home_activity == self._pending_activity:
- # Figure out the new _pending_activity
+ if home_activity == self._active_activity:
+ # Figure out the new _active_activity
windows = wnck.screen_get_default().get_windows_stacked()
windows.reverse()
for window in windows:
new_activity = self._get_activity_by_xid(window.get_xid())
if new_activity is not None:
- self._set_pending_activity(new_activity)
+ self._set_active_activity(new_activity)
break
else:
logging.error('No activities are running')
- self._set_pending_activity(None)
+ self._set_active_activity(None)
self.emit('activity-removed', home_activity)
self._activities.remove(home_activity)
@@ -253,11 +233,11 @@ class HomeModel(gobject.GObject):
else:
logging.error('Model for window %d does not exist.' % xid)
- def notify_activity_launch(self, activity_id, service_name):
+ def notify_launch(self, bundle_id, activity_id):
registry = activity.get_registry()
- activity_info = registry.get_activity(service_name)
+ activity_info = registry.get_activity(bundle_id)
if not activity_info:
- raise ValueError("Activity service name '%s' was not found in the bundle registry." % service_name)
+ raise ValueError("Activity service name '%s' was not found in the bundle registry." % bundle_id)
home_activity = HomeActivity(activity_info, activity_id)
home_activity.props.launching = True
self._add_activity(home_activity)
@@ -266,7 +246,9 @@ class HomeModel(gobject.GObject):
# Now just check whether an activity has a window after ~90sec
gobject.timeout_add(90000, self._check_activity_launched, activity_id)
- def notify_activity_launch_failed(self, activity_id):
+ self.emit('activity-launched', home_activity)
+
+ def notify_launch_failure(self, activity_id):
home_activity = self._get_activity_by_id(activity_id)
if home_activity:
logging.debug("Activity %s (%s) launch failed" % \
@@ -276,10 +258,12 @@ class HomeModel(gobject.GObject):
else:
logging.error('Model for activity id %s does not exist.' % activity_id)
+ self.emit('activity-launch-failed', home_activity)
+
def _check_activity_launched(self, activity_id):
home_activity = self._get_activity_by_id(activity_id)
if home_activity and home_activity.props.launching:
logging.debug('Activity %s still launching, assuming it failed...',
activity_id)
- self.notify_activity_launch_failed(activity_id)
+ self.notify_launch_failure(activity_id)
return False
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/shellservice.py b/src/shellservice.py
index add49d8..e05f85d 100644
--- a/src/shellservice.py
+++ b/src/shellservice.py
@@ -79,12 +79,12 @@ class ShellService(dbus.service.Object):
@dbus.service.method(_DBUS_SHELL_IFACE,
in_signature="ss", out_signature="")
def NotifyLaunch(self, bundle_id, activity_id):
- self._shell.notify_launch(bundle_id, activity_id)
+ self._home_model.notify_launch(bundle_id, activity_id)
@dbus.service.method(_DBUS_SHELL_IFACE,
in_signature="s", out_signature="")
def NotifyLaunchFailure(self, activity_id):
- self._shell.notify_launch_failure(activity_id)
+ self._home_model.notify_launch_failure(activity_id)
@dbus.service.signal(_DBUS_OWNER_IFACE, signature="s")
def ColorChanged(self, color):
diff --git a/src/view/Shell.py b/src/view/Shell.py
index 2810c74..1866cbd 100644
--- a/src/view/Shell.py
+++ b/src/view/Shell.py
@@ -56,7 +56,6 @@ class Shell(gobject.GObject):
self._hosts = {}
self._screen = wnck.screen_get_default()
self._current_host = None
- self._pending_host = None
self._screen_rotation = 0
self._key_handler = KeyHandler()
@@ -68,11 +67,12 @@ class Shell(gobject.GObject):
home_model = self._model.get_home()
home_model.connect('activity-started', self._activity_started_cb)
+ home_model.connect('activity-launched', self._activity_launched_cb)
+ home_model.connect('activity-launch-failed',
+ self._activity_launch_failed_cb)
home_model.connect('activity-removed', self._activity_removed_cb)
home_model.connect('active-activity-changed',
self._active_activity_changed_cb)
- home_model.connect('pending-activity-changed',
- self._pending_activity_changed_cb)
gobject.idle_add(self._start_journal_idle)
@@ -101,6 +101,16 @@ class Shell(gobject.GObject):
if home_activity.get_type() in self._activities_starting:
self._activities_starting.remove(home_activity.get_type())
+ def _activity_launched_cb(self, home_model, home_activity):
+ # Zoom in for launch feedback, except for Journal
+ if home_activity.get_type() != 'org.laptop.JournalActivity':
+ self._home_window.set_launching_activity(home_activity)
+ self.set_zoom_level(shellmodel.ShellModel.ZOOM_LAUNCH)
+
+ def _activity_launch_failed_cb(self, home_model, home_activity):
+ # TODO: Add failure alert; just zoom home for now
+ self.set_zoom_level(shellmodel.ShellModel.ZOOM_HOME)
+
def _activity_removed_cb(self, home_model, home_activity):
if home_activity.get_type() in self._activities_starting:
self._activities_starting.remove(home_activity.get_type())
@@ -120,12 +130,6 @@ class Shell(gobject.GObject):
self._current_host = host
- def _pending_activity_changed_cb(self, home_model, home_activity):
- if home_activity:
- self._pending_host = self._hosts[home_activity.get_xid()]
- else:
- self._pending_host = None
-
def get_model(self):
return self._model
@@ -150,17 +154,6 @@ class Shell(gobject.GObject):
handle = ActivityHandle(activity_id)
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)
-
- def notify_launch_failure(self, activity_id):
- home_model = self._model.get_home()
- home_model.notify_activity_launch_failed(activity_id)
-
def start_activity(self, activity_type):
if activity_type in self._activities_starting:
logging.debug("This activity is still launching.")
@@ -185,16 +178,25 @@ class Shell(gobject.GObject):
except dbus.DBusException, e:
logging.debug('Error raised by TakeScreenshot(): %s', e)
+ def set_launching_activity(self, home_activity):
+ zoom = self._model.get_zoom_level() < shellmodel.ShellModel.ZOOM_ACTIVITY
+ self._home_window.set_launching_activity(home_activity, zoom)
+ self.set_zoom_level(shellmodel.ShellModel.ZOOM_LAUNCH)
+
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()
+ if self._current_host is not None:
+ self._current_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..6968245 100644
--- a/src/view/frame/activitiestray.py
+++ b/src/view/frame/activitiestray.py
@@ -68,23 +68,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)
@@ -189,7 +189,7 @@ class ActivitiesTray(HTray):
self._home_model = shellmodel.get_instance().get_home()
self._home_model.connect('activity-added', self.__activity_added_cb)
self._home_model.connect('activity-removed', self.__activity_removed_cb)
- self._home_model.connect('pending-activity-changed', self.__activity_changed_cb)
+ self._home_model.connect('active-activity-changed', self.__activity_changed_cb)
self._invites = shellmodel.get_instance().get_invites()
for invite in self._invites:
@@ -209,6 +209,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 +225,11 @@ 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:
+ shell = view.Shell.get_instance()
+ shell.set_launching_activity(home_activity)
def __invite_clicked_cb(self, icon, invite):
self._invites.remove_invite(invite)
diff --git a/src/view/frame/friendstray.py b/src/view/frame/friendstray.py
index 8b45409..c813d97 100644
--- a/src/view/frame/friendstray.py
+++ b/src/view/frame/friendstray.py
@@ -55,8 +55,8 @@ class FriendsTray(VTray):
self._pservice.get_activities_async(reply_handler=self._get_activities_cb)
home_model = shellmodel.get_instance().get_home()
- home_model.connect('pending-activity-changed',
- self._pending_activity_changed_cb)
+ home_model.connect('active-activity-changed',
+ self._active_activity_changed_cb)
def _get_activities_cb(self, list):
for activity in list:
@@ -118,8 +118,8 @@ class FriendsTray(VTray):
self._left_hid = activity_ps.connect(
'buddy-left', self.__buddy_left_cb)
- def _pending_activity_changed_cb(self, home_model, home_activity):
- if home_activity is None:
+ def _active_activity_changed_cb(self, home_model, home_activity):
+ if home_activity is None:
return
activity_id = home_activity.get_activity_id()
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..d2819df 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_activity(icon_color, icon_path, True)
+
+ def set_launching_activity(self, home_activity, zoom=True):
+ self._launch_box.set_activity(home_activity, 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..c1d4ce8 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
@@ -159,16 +162,16 @@ class CurrentActivityIcon(CanvasIcon, hippo.CanvasItem):
CanvasIcon.__init__(self, cache=True)
self._home_model = shellmodel.get_instance().get_home()
- if self._home_model.get_pending_activity() is not None:
- self._update(self._home_model.get_pending_activity())
+ if self._home_model.get_active_activity() is not None:
+ self._update(self._home_model.get_active_activity())
- self._home_model.connect('pending-activity-changed',
- self.__pending_activity_changed_cb)
+ self._home_model.connect('active-activity-changed',
+ self.__active_activity_changed_cb)
self.connect('button-release-event', self.__button_release_event_cb)
def __button_release_event_cb(self, icon, event):
- self._home_model.get_pending_activity().get_window().activate(1)
+ self._home_model.get_active_activity().get_window().activate(1)
def _update(self, home_activity):
_logger.debug('CurrentActivityIcon._update')
@@ -182,7 +185,7 @@ class CurrentActivityIcon(CanvasIcon, hippo.CanvasItem):
palette = CurrentActivityPalette(home_activity)
self.set_palette(palette)
- def __pending_activity_changed_cb(self, home_model, home_activity):
+ def __active_activity_changed_cb(self, home_model, home_activity):
self._update(home_activity)
class RingLayout(gobject.GObject, hippo.CanvasLayout):
diff --git a/src/view/home/launchbox.py b/src/view/home/launchbox.py
index 4b94ee2..c26e689 100644
--- a/src/view/home/launchbox.py
+++ b/src/view/home/launchbox.py
@@ -86,9 +86,9 @@ class LaunchBox(hippo.CanvasBox):
#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
+ def set_activity(self, home_activity, zoom=False):
+ self._activity_icon.props.file_name = home_activity.get_icon_path()
+ self._activity_icon.props.pulse_color = home_activity.get_icon_color()
if zoom:
self.zoom_in()
# 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_activity(self, home_activity, zoom=False):
self._activity_icon.props.file_name = home_activity.get_icon_path()
self._activity_icon.props.pulse_color = home_activity.get_icon_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