2006-07-08 15:47:51 +02:00
|
|
|
from gettext import gettext as _
|
|
|
|
|
2006-07-08 11:56:13 +02:00
|
|
|
import gtk
|
2006-07-10 13:42:34 +02:00
|
|
|
import wnck
|
2006-07-08 11:56:13 +02:00
|
|
|
|
|
|
|
from sugar.activity import Activity
|
2006-07-14 16:40:45 +02:00
|
|
|
from ActivitiesModel import ActivitiesModel
|
2006-07-08 11:56:13 +02:00
|
|
|
|
2006-07-08 15:47:51 +02:00
|
|
|
class NewActivityButton(gtk.MenuToolButton):
|
2006-07-10 13:42:34 +02:00
|
|
|
def __init__(self, home):
|
2006-07-08 15:47:51 +02:00
|
|
|
gtk.MenuToolButton.__init__(self, None, _('New Activity'))
|
2006-07-08 11:56:13 +02:00
|
|
|
|
2006-07-10 13:42:34 +02:00
|
|
|
self._home = home
|
2006-07-08 11:56:13 +02:00
|
|
|
|
2006-07-08 15:47:51 +02:00
|
|
|
self.set_menu(gtk.Menu())
|
|
|
|
self.connect("show-menu", self.__show_menu_cb)
|
2006-07-08 11:56:13 +02:00
|
|
|
|
2006-07-08 15:47:51 +02:00
|
|
|
def __show_menu_cb(self, button):
|
|
|
|
menu = gtk.Menu()
|
|
|
|
|
2006-07-12 17:21:22 +02:00
|
|
|
for module in self._home.list_activities():
|
|
|
|
item = gtk.MenuItem(module.get_name(), False)
|
|
|
|
activity_id = module.get_id()
|
|
|
|
item.connect('activate', self.__menu_item_activate_cb, activity_id)
|
2006-07-08 15:47:51 +02:00
|
|
|
menu.append(item)
|
|
|
|
item.show()
|
|
|
|
|
|
|
|
self.set_menu(menu)
|
|
|
|
|
2006-07-12 17:21:22 +02:00
|
|
|
def __menu_item_activate_cb(self, item, activity_id):
|
|
|
|
self._home.create(activity_id)
|
2006-07-08 11:56:13 +02:00
|
|
|
|
2006-07-08 15:47:51 +02:00
|
|
|
class Toolbar(gtk.Toolbar):
|
|
|
|
def __init__(self, shell):
|
|
|
|
gtk.Toolbar.__init__(self)
|
2006-07-08 11:56:13 +02:00
|
|
|
|
2006-07-08 15:47:51 +02:00
|
|
|
new_activity_button = NewActivityButton(shell)
|
|
|
|
self.insert(new_activity_button, -1)
|
2006-07-08 11:56:13 +02:00
|
|
|
new_activity_button.show()
|
|
|
|
|
2006-07-14 15:47:42 +02:00
|
|
|
class ActivitiesGrid(gtk.VBox):
|
2006-07-15 12:31:06 +02:00
|
|
|
def __init__(self, shell, model):
|
|
|
|
gtk.VBox.__init__(self, shell)
|
2006-07-14 15:47:42 +02:00
|
|
|
|
2006-07-15 12:31:06 +02:00
|
|
|
self._shell = shell
|
2006-07-14 15:47:42 +02:00
|
|
|
self._buttons = {}
|
|
|
|
|
|
|
|
for activity in model:
|
|
|
|
self._add(activity)
|
2006-07-14 16:40:45 +02:00
|
|
|
model.connect('activity-added', self.__activity_added_cb)
|
|
|
|
model.connect('activity-removed', self.__activity_removed_cb)
|
2006-07-14 15:47:42 +02:00
|
|
|
|
|
|
|
def __activity_added_cb(self, model, activity):
|
|
|
|
self._add(activity)
|
|
|
|
|
2006-07-14 16:40:45 +02:00
|
|
|
def __activity_removed_cb(self, model, activity):
|
2006-07-14 15:47:42 +02:00
|
|
|
self._remove(window)
|
|
|
|
|
|
|
|
def _remove(self, activity):
|
|
|
|
button = self._buttons[activity.get_id()]
|
|
|
|
self.remove(button)
|
|
|
|
|
|
|
|
def _add(self, activity):
|
2006-07-15 12:31:06 +02:00
|
|
|
button = gtk.Button(activity.get_title())
|
|
|
|
button.connect('clicked', self.__button_clicked_cb, activity)
|
2006-07-14 15:47:42 +02:00
|
|
|
self.pack_start(button, False)
|
|
|
|
button.show()
|
|
|
|
|
|
|
|
self._buttons[activity.get_id()] = button
|
|
|
|
|
2006-07-15 12:31:06 +02:00
|
|
|
def __button_clicked_cb(self, button, info):
|
|
|
|
activity = self._shell.get_registry().get_activity(info.get_type())
|
|
|
|
Activity.create(activity.get_id(), info.get_service())
|
2006-07-14 15:47:42 +02:00
|
|
|
|
|
|
|
class TasksGrid(gtk.VBox):
|
2006-07-10 13:42:34 +02:00
|
|
|
def __init__(self, home):
|
|
|
|
gtk.VBox.__init__(self)
|
|
|
|
|
|
|
|
self._home = home
|
2006-07-13 11:10:27 +02:00
|
|
|
self._buttons = {}
|
2006-07-10 13:42:34 +02:00
|
|
|
|
|
|
|
screen = wnck.screen_get_default()
|
|
|
|
for window in screen.get_windows():
|
|
|
|
if not window.is_skip_tasklist():
|
2006-07-13 11:10:27 +02:00
|
|
|
self._add(window)
|
|
|
|
screen.connect('window_opened', self.__window_opened_cb)
|
|
|
|
screen.connect('window_closed', self.__window_closed_cb)
|
|
|
|
|
|
|
|
def __window_opened_cb(self, screen, window):
|
|
|
|
if not window.is_skip_tasklist():
|
|
|
|
self._add(window)
|
|
|
|
|
|
|
|
def __window_closed_cb(self, screen, window):
|
|
|
|
if not window.is_skip_tasklist():
|
|
|
|
self._remove(window)
|
2006-07-10 13:42:34 +02:00
|
|
|
|
2006-07-13 11:10:27 +02:00
|
|
|
def _remove(self, window):
|
|
|
|
button = self._buttons[window.get_xid()]
|
|
|
|
self.remove(button)
|
2006-07-10 13:42:34 +02:00
|
|
|
|
2006-07-19 18:43:24 +02:00
|
|
|
def __window_name_changed_cb(self, window, button):
|
|
|
|
button.set_label(window.get_name())
|
|
|
|
|
2006-07-13 11:10:27 +02:00
|
|
|
def _add(self, window):
|
2006-07-10 13:42:34 +02:00
|
|
|
button = gtk.Button(window.get_name())
|
2006-07-19 18:43:24 +02:00
|
|
|
window.connect('name-changed', self.__window_name_changed_cb, button)
|
2006-07-10 13:42:34 +02:00
|
|
|
button.connect('clicked', self.__button_clicked_cb, window)
|
|
|
|
self.pack_start(button, False)
|
|
|
|
button.show()
|
2006-07-13 11:10:27 +02:00
|
|
|
|
|
|
|
self._buttons[window.get_xid()] = button
|
2006-07-10 13:42:34 +02:00
|
|
|
|
|
|
|
def __button_clicked_cb(self, button, window):
|
|
|
|
self._home.activate(window)
|
|
|
|
|
2006-07-08 11:56:13 +02:00
|
|
|
class HomeWindow(gtk.Window):
|
2006-07-08 15:47:51 +02:00
|
|
|
def __init__(self, shell):
|
2006-07-08 11:56:13 +02:00
|
|
|
gtk.Window.__init__(self)
|
2006-07-08 15:47:51 +02:00
|
|
|
|
2006-07-10 13:42:34 +02:00
|
|
|
self._shell = shell
|
2006-07-13 11:10:27 +02:00
|
|
|
|
2006-07-18 21:13:10 +02:00
|
|
|
self.connect('realize', self.__realize_cb)
|
2006-07-13 11:10:27 +02:00
|
|
|
|
|
|
|
vbox = gtk.VBox(False, 6)
|
|
|
|
vbox.set_border_width(24)
|
2006-07-08 11:56:13 +02:00
|
|
|
|
2006-07-10 13:42:34 +02:00
|
|
|
toolbar = Toolbar(self)
|
2006-07-08 15:47:51 +02:00
|
|
|
vbox.pack_start(toolbar, False)
|
2006-07-08 11:56:13 +02:00
|
|
|
toolbar.show()
|
2006-07-13 11:10:27 +02:00
|
|
|
|
|
|
|
label = gtk.Label('Open activities:')
|
|
|
|
label.set_alignment(0.0, 0.5)
|
|
|
|
vbox.pack_start(label, False)
|
|
|
|
label.show()
|
2006-07-08 11:56:13 +02:00
|
|
|
|
2006-07-14 15:47:42 +02:00
|
|
|
grid = TasksGrid(self)
|
|
|
|
vbox.pack_start(grid)
|
|
|
|
grid.show()
|
2006-07-13 11:10:27 +02:00
|
|
|
|
|
|
|
label = gtk.Label('Shared activities:')
|
|
|
|
label.set_alignment(0.0, 0.5)
|
|
|
|
vbox.pack_start(label, False)
|
|
|
|
label.show()
|
|
|
|
|
2006-07-14 15:47:42 +02:00
|
|
|
model = ActivitiesModel()
|
2006-07-15 12:31:06 +02:00
|
|
|
grid = ActivitiesGrid(shell, model)
|
2006-07-14 15:47:42 +02:00
|
|
|
vbox.pack_start(grid)
|
|
|
|
grid.show()
|
|
|
|
|
2006-07-08 11:56:13 +02:00
|
|
|
self.add(vbox)
|
2006-07-08 15:47:51 +02:00
|
|
|
vbox.show()
|
2006-07-10 13:42:34 +02:00
|
|
|
|
2006-07-18 21:13:10 +02:00
|
|
|
def __realize_cb(self, window):
|
|
|
|
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
|
|
|
|
2006-07-10 13:42:34 +02:00
|
|
|
def list_activities(self):
|
|
|
|
return self._shell.get_registry().list_activities()
|
|
|
|
|
|
|
|
def create(self, activity_name):
|
|
|
|
Activity.create(activity_name)
|
|
|
|
|
|
|
|
def activate(self, activity_window):
|
|
|
|
activity_window.activate(gtk.get_current_event_time())
|