Make launching a property of the activity model

This commit is contained in:
Marco Pesenti Gritti 2007-06-01 11:03:18 +02:00
parent e1f27fcd34
commit 2f6790105d
4 changed files with 52 additions and 32 deletions

View File

@ -33,6 +33,13 @@ class HomeActivity(gobject.GObject):
accomplish its tasks.
"""
__gtype_name__ = 'SugarHomeActivity'
__gproperties__ = {
'launching' : (bool, None, None, False,
gobject.PARAM_READWRITE),
}
def __init__(self, bundle, activity_id):
"""Initialise the HomeActivity
@ -44,13 +51,14 @@ class HomeActivity(gobject.GObject):
of the activity type
"""
gobject.GObject.__init__(self)
self._window = None
self._xid = None
self._service = None
self._activity_id = activity_id
self._bundle = bundle
self._launch_time = time.time()
self._launching = False
logging.debug("Activity %s (%s) launching..." %
(self._activity_id, self.get_type()))
@ -144,3 +152,11 @@ class HomeActivity(gobject.GObject):
(seconds since the epoch)
"""
return self._launch_time
def do_set_property(self, pspec, value):
if pspec.name == 'launching':
self._launching = value
def do_get_property(self, pspec):
if pspec.name == 'launching':
return self._launching

View File

@ -43,10 +43,10 @@ class HomeModel(gobject.GObject):
the activity factories have set up.
"""
__gsignals__ = {
'activity-launched': (gobject.SIGNAL_RUN_FIRST,
'activity-added': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'activity-added': (gobject.SIGNAL_RUN_FIRST,
'activity-started': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'activity-removed': (gobject.SIGNAL_RUN_FIRST,
@ -219,10 +219,12 @@ class HomeModel(gobject.GObject):
return
activity = HomeActivity(bundle, act_id)
self._activities[act_id] = activity
self.emit('activity-added', activity)
activity.set_service(service)
activity.set_window(window)
self.emit('activity-added', activity)
self.emit('activity-started', activity)
def _internal_remove_activity(self, activity):
if activity == self._current_activity:
@ -244,8 +246,9 @@ class HomeModel(gobject.GObject):
if not bundle:
raise ValueError("Activity service name '%s' was not found in the bundle registry." % service_name)
activity = HomeActivity(bundle, activity_id)
activity.props.launching = True
self._activities[activity_id] = activity
self.emit('activity-launched', activity)
self.emit('activity-added', activity)
def notify_activity_launch_failed(self, activity_id):
if self._activities.has_key(activity_id):

View File

@ -54,14 +54,14 @@ class Shell(gobject.GObject):
self._zoom_level = sugar.ZOOM_HOME
home_model = self._model.get_home()
home_model.connect('activity-added', self._activity_added_cb)
home_model.connect('activity-started', self._activity_started_cb)
home_model.connect('activity-removed', self._activity_removed_cb)
home_model.connect('active-activity-changed',
self._active_activity_changed_cb)
self.start_activity('org.laptop.JournalActivity')
def _activity_added_cb(self, home_model, home_activity):
def _activity_started_cb(self, home_model, home_activity):
activity_host = ActivityHost(home_activity)
self._hosts[activity_host.get_xid()] = activity_host
if home_activity.get_type() in self._activities_starting:

View File

@ -59,14 +59,24 @@ class ActivityIcon(CanvasIcon):
scale=units.MEDIUM_ICON_SCALE, cache=True)
self._activity = activity
self._launched = False
self._pulse_id = gobject.timeout_add(self._INTERVAL, self._pulse_cb)
self._pulse_id = 0
activity.connect('notify::launching', self._launching_changed_cb)
if activity.props.launching:
self._start_pulsing()
def _launching_changed_cb(self, activity, pspec):
print activity.props.launching
if activity.props.launching:
self._start_pulsing()
else:
self._stop_pulsing()
def __del__(self):
self.cleanup()
self._cleanup()
def cleanup(self):
if self._pulse_id > 0:
def _cleanup(self):
if self._pulse_id:
gobject.source_remove(self._pulse_id)
self._pulse_id = 0
# dispose of all rendered icons from launch feedback
@ -107,18 +117,21 @@ class ActivityIcon(CanvasIcon):
self.emit_paint_needed(0, 0, -1, -1)
return True
def set_launched(self):
if self._launched:
def _start_pulsing(self):
if self._pulse_id:
return
self._launched = True
self.cleanup()
self._pulse_id = gobject.timeout_add(self._INTERVAL, self._pulse_cb)
def _stop_pulsing(self):
if not self._pulse_id:
return
self._cleanup()
self._level = 100.0
self.props.xo_color = self._orig_color
self.emit_paint_needed(0, 0, -1, -1)
def get_launched(self):
return self._launched
def get_activity(self):
return self._activity
@ -131,21 +144,12 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
self._shell = shell
self._model = shell.get_model().get_home()
self._model.connect('activity-launched', self._activity_launched_cb)
self._model.connect('activity-added', self._activity_added_cb)
self._model.connect('activity-removed', self._activity_removed_cb)
self._model.connect('active-activity-changed', self._activity_changed_cb)
def _activity_launched_cb(self, model, activity):
self._add_activity(activity)
def _activity_added_cb(self, model, activity):
# Mark the activity as launched
act_id = activity.get_activity_id()
if not self._activities.has_key(act_id):
self._add_activity(activity)
icon = self._activities[act_id]
icon.set_launched()
self._add_activity(activity)
def _activity_removed_cb(self, model, activity):
self._remove_activity(activity)
@ -173,9 +177,6 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
def _activity_icon_clicked_cb(self, icon):
activity = icon.get_activity()
if not icon.get_launched():
return
activity_host = self._shell.get_activity(activity.get_activity_id())
if activity_host:
activity_host.present()