Ticket #1447: 0001-Display-error-message-when-activity-fails-to-launch.patch

File 0001-Display-error-message-when-activity-fails-to-launch.patch, 6.5 KB (added by wadeb, 15 years ago)
  • src/jarabe/model/shell.py

    From 8b581435ab8b4f591b7f03aaaa7e78384ee7f763 Mon Sep 17 00:00:00 2001
    From: Wade Brainerd <wadetb@gmail.com>
    Date: Tue, 29 Sep 2009 08:46:02 -0400
    Subject: [PATCH] Display error message when activity fails to launch.
    
    Added new NotifyActivityEnded DBus method to the shell, which is called by the activityfactory when an
    activity's process ends.  If the activity is still launching, this triggers a notify-launch-failed signal.
    When the signal is received, the launcher window now displays a simple error message with a Close button.
    
    Also corrected a minor bug in ShellModel.notify_launch_failed.
    ---
     src/jarabe/model/shell.py   |   18 ++++++++++++++++--
     src/jarabe/view/launcher.py |   43 ++++++++++++++++++++++++++++++++++++++++---
     src/jarabe/view/service.py  |    5 +++++
     3 files changed, 61 insertions(+), 5 deletions(-)
    
    diff --git a/src/jarabe/model/shell.py b/src/jarabe/model/shell.py
    index ef2268d..3b87fce 100644
    a b class ShellModel(gobject.GObject): 
    572572                home_activity.get_type())
    573573            home_activity.props.launching = False
    574574            self._remove_activity(home_activity)
     575            self.emit('launch-failed', home_activity)
    575576        else:
    576577            logging.error('Model for activity id %s does not exist.',
    577578                activity_id)
    578579
    579         self.emit('launch-failed', home_activity)
    580 
     580    def notify_activity_ended(self, activity_id):
     581        home_activity = self.get_activity_by_id(activity_id)
     582        if home_activity:
     583            if home_activity.props.launching:
     584                logging.debug('Activity %s (%s) ended while still launching, '\
     585                              'assuming it failed.', activity_id,
     586                              home_activity.get_type())
     587                self.notify_launch_failed(activity_id)
     588            else:
     589                logging.debug("Activity %s ended", activity_id)
     590                self._remove_activity(home_activity)
     591        else:
     592            # The activity may have already been removed when its window closed.
     593            pass
     594   
    581595    def _check_activity_launched(self, activity_id):
    582596        home_activity = self.get_activity_by_id(activity_id)
    583597
  • src/jarabe/view/launcher.py

    diff --git a/src/jarabe/view/launcher.py b/src/jarabe/view/launcher.py
    index d4b9967..1e9f38a 100644
    a b  
    1515# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1616
    1717import logging
     18from gettext import gettext as _
    1819
    1920import gtk
    2021import hippo
    2122import gobject
    2223
    2324from sugar import wm
     25from sugar.presence import presenceservice
    2426from sugar.graphics import style
    2527from sugar.graphics import animator
    2628from sugar.graphics.xocolor import XoColor
     29from sugar.graphics.icon import Icon
    2730
    2831from jarabe.model import shell
    2932from jarabe.view.pulsingicon import CanvasPulsingIcon
    class LaunchWindow(gtk.Window): 
    6669    def __size_changed_cb(self, screen):
    6770        self._update_size()
    6871
     72    def show_failed(self, home_activity):
     73        self._box.show_failed(home_activity)
     74
    6975class LaunchBox(hippo.CanvasBox):
    7076    def __init__(self, activity_id, icon_path, icon_color):
    7177        gobject.GObject.__init__(self, orientation=hippo.ORIENTATION_VERTICAL)
    7278
     79        self.props.spacing = style.DEFAULT_SPACING
     80        self.props.yalign = hippo.ALIGNMENT_CENTER
     81
    7382        self._activity_id = activity_id
    7483        self._activity_icon = CanvasPulsingIcon(
    7584            file_name=icon_path,
    7685            pulse_color=icon_color,
    7786            background_color=style.COLOR_WHITE.get_gdk_color())
    78         self.append(self._activity_icon, hippo.PACK_EXPAND)
     87        self.append(self._activity_icon)
    7988
    8089        # FIXME support non-xo colors in CanvasPulsingIcon
    8190        self._activity_icon.props.base_color = \
    class LaunchBox(hippo.CanvasBox): 
    110119        else:
    111120            self._activity_icon.props.paused = True
    112121
     122    def show_failed(self, home_activity):
     123        logging.debug("Displaying failure message on launcher")
     124
     125        self._activity_icon.props.pulsing = False
     126        self._animator.stop()
     127
     128        text = hippo.CanvasText(text=_('%s failed to start.') % \
     129                                home_activity.get_activity_name(),
     130                                xalign=hippo.ALIGNMENT_CENTER,
     131                                font_desc=style.FONT_BOLD.get_pango_desc(),
     132                                color = style.COLOR_BUTTON_GREY.get_int())
     133        self.append(text)
     134
     135        button = gtk.Button(label=_('Close'))
     136        button.connect('clicked', self.__close_button_clicked_cb, home_activity)
     137        button.props.image = Icon(icon_name='dialog-cancel',
     138                                  icon_size=gtk.ICON_SIZE_BUTTON)
     139        canvas_button = hippo.CanvasWidget(widget=button,
     140                                           xalign=hippo.ALIGNMENT_CENTER)
     141        self.append(canvas_button)
     142
     143    def __close_button_clicked_cb(self, button, home_activity):
     144        _destroy_launcher(home_activity)
     145
    113146class _Animation(animator.Animation):
    114147    def __init__(self, icon, start_size, end_size):
    115148        animator.Animation.__init__(self, 0.0, 1.0)
    def setup(): 
    131164    model.connect('launch-completed', __launch_completed_cb)
    132165
    133166def add_launcher(activity_id, icon_path, icon_color):
    134 
    135167    if activity_id in _launchers:
    136168        return
    137169
    def __launch_started_cb(home_model, home_activity): 
    145177                 home_activity.get_icon_color())
    146178
    147179def __launch_failed_cb(home_model, home_activity):
    148     _destroy_launcher(home_activity)
     180    activity_id = home_activity.get_activity_id()
     181
     182    if activity_id in _launchers:
     183        _launchers[activity_id].show_failed(home_activity)
     184    else:
     185        logging.error('Launcher for %s is missing', activity_id)
    149186
    150187def __launch_completed_cb(home_model, home_activity):
    151188    _destroy_launcher(home_activity)
  • src/jarabe/view/service.py

    diff --git a/src/jarabe/view/service.py b/src/jarabe/view/service.py
    index 2b91437..c1da23c 100644
    a b class UIService(dbus.service.Object): 
    9898    def NotifyLaunchFailure(self, activity_id):
    9999        shell.get_model().notify_launch_failed(activity_id)
    100100
     101    @dbus.service.method(_DBUS_SHELL_IFACE,
     102                         in_signature="s", out_signature="")
     103    def NotifyActivityEnded(self, activity_id):
     104        shell.get_model().notify_activity_ended(activity_id)
     105
    101106    @dbus.service.signal(_DBUS_OWNER_IFACE, signature="s")
    102107    def ColorChanged(self, color):
    103108        pass