Write a model for activities and use it in home page
This commit is contained in:
parent
e079d76380
commit
5ff09a10f7
43
shell/ActivitiesModel.py
Normal file
43
shell/ActivitiesModel.py
Normal file
@ -0,0 +1,43 @@
|
||||
import gobject
|
||||
|
||||
class ActivityInfo:
|
||||
def __init__(self, service):
|
||||
self._service = service
|
||||
|
||||
def get_id(self):
|
||||
activity_id = service.get_one_property('activity_id')
|
||||
|
||||
def get_title(self):
|
||||
escaped_title = service.get_one_property('Title')
|
||||
title = xml.sax.saxutils.unescape(escaped_title)
|
||||
|
||||
class ActivitiesModel(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT])),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
gobject.GObject(self)
|
||||
|
||||
self._activities = []
|
||||
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._pservice.connect("activity-announced", self._on_activity_announced_cb)
|
||||
self._pservice.connect("new-service-adv", self._on_new_service_adv_cb)
|
||||
self._pservice.start()
|
||||
|
||||
def add_activity(self, service):
|
||||
activity_info = ActivityInfo(service)
|
||||
self._activities.append(activity_info)
|
||||
self.emit('activity-added', activity_info)
|
||||
|
||||
def __iter__(self):
|
||||
return activities.__iter__()
|
||||
|
||||
def _on_new_service_adv_cb(self, pservice, activity_id, short_stype):
|
||||
if activity_id:
|
||||
self._pservice.track_service_type(short_stype)
|
||||
|
||||
def _on_activity_announced_cb(self, pservice, service, buddy):
|
||||
self.add_activity(buddy, service)
|
@ -37,7 +37,39 @@ class Toolbar(gtk.Toolbar):
|
||||
self.insert(new_activity_button, -1)
|
||||
new_activity_button.show()
|
||||
|
||||
class ActivityGrid(gtk.VBox):
|
||||
class ActivitiesGrid(gtk.VBox):
|
||||
def __init__(self, model):
|
||||
gtk.VBox.__init__(self)
|
||||
|
||||
self._buttons = {}
|
||||
|
||||
for activity in model:
|
||||
self._add(activity)
|
||||
screen.connect('activity-added', self.__activity_added_cb)
|
||||
screen.connect('activity-removed', self.__activity_removed_cb)
|
||||
|
||||
def __activity_added_cb(self, model, activity):
|
||||
self._add(activity)
|
||||
|
||||
def __activity_closed_cb(self, model, activity):
|
||||
self._remove(window)
|
||||
|
||||
def _remove(self, activity):
|
||||
button = self._buttons[activity.get_id()]
|
||||
self.remove(button)
|
||||
|
||||
def _add(self, activity):
|
||||
button = gtk.Button(window.get_title())
|
||||
button.connect('clicked', self.__button_clicked_cb, window)
|
||||
self.pack_start(button, False)
|
||||
button.show()
|
||||
|
||||
self._buttons[activity.get_id()] = button
|
||||
|
||||
def __button_clicked_cb(self, button, window):
|
||||
self._home.activate(window)
|
||||
|
||||
class TasksGrid(gtk.VBox):
|
||||
def __init__(self, home):
|
||||
gtk.VBox.__init__(self)
|
||||
|
||||
@ -94,15 +126,20 @@ class HomeWindow(gtk.Window):
|
||||
vbox.pack_start(label, False)
|
||||
label.show()
|
||||
|
||||
self._grid = ActivityGrid(self)
|
||||
vbox.pack_start(self._grid)
|
||||
self._grid.show()
|
||||
grid = TasksGrid(self)
|
||||
vbox.pack_start(grid)
|
||||
grid.show()
|
||||
|
||||
label = gtk.Label('Shared activities:')
|
||||
label.set_alignment(0.0, 0.5)
|
||||
vbox.pack_start(label, False)
|
||||
label.show()
|
||||
|
||||
model = ActivitiesModel()
|
||||
grid = ActivitiesGrid(model)
|
||||
vbox.pack_start(grid)
|
||||
grid.show()
|
||||
|
||||
self.add(vbox)
|
||||
vbox.show()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user