Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-08-17 12:23:52 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-08-17 12:23:52 (GMT)
commitf65d23c44002fe94477cb3354667e9297e386092 (patch)
treeffa41ac5844b5660288af9f8c80e880e3d5584a7
parent10f356cb22ffcaddfbbcd0b8332ef65409e5bf5f (diff)
Add icon for activity to the donut.
Add signals in the shell for window open/close and use them in the task view.
-rw-r--r--shell/ActivityHost.py6
-rw-r--r--shell/ChatController.py3
-rw-r--r--shell/HomeWindow.py41
-rwxr-xr-xshell/Shell.py13
-rw-r--r--sugar/canvas/DonutItem.py49
5 files changed, 79 insertions, 33 deletions
diff --git a/shell/ActivityHost.py b/shell/ActivityHost.py
index 639c589..84577c1 100644
--- a/shell/ActivityHost.py
+++ b/shell/ActivityHost.py
@@ -20,9 +20,15 @@ class ActivityHost:
self._gdk_window = gtk.gdk.window_foreign_new(self._xid)
self._people_window = PeopleWindow(shell, self)
+ info = self._shell.get_registry().get_activity(self._default_type)
+ self._icon_name = info.get_icon()
+
def get_id(self):
return self._id
+ def get_icon_name(self):
+ return self._icon_name
+
def share(self):
self._people_window.share()
self._activity.share()
diff --git a/shell/ChatController.py b/shell/ChatController.py
index 96d2fd0..00bab80 100644
--- a/shell/ChatController.py
+++ b/shell/ChatController.py
@@ -13,7 +13,8 @@ class ChatController:
self._shell.connect('activity-closed', self.__activity_closed_cb)
- def __activity_closed_cb(self, shell, activity_id):
+ def __activity_closed_cb(self, shell, activity):
+ activity_id = activity.get_id()
if self._id_to_name.has_key(activity_id):
name = self._id_to_name[activity_id]
del self._name_to_chat[name]
diff --git a/shell/HomeWindow.py b/shell/HomeWindow.py
index ed86e6f..26d29cc 100644
--- a/shell/HomeWindow.py
+++ b/shell/HomeWindow.py
@@ -7,35 +7,30 @@ from sugar.canvas.DonutItem import DonutItem
from sugar.canvas.DonutItem import PieceItem
class TasksItem(DonutItem):
- def __init__(self):
+ def __init__(self, shell):
DonutItem.__init__(self, 250)
self._items = {}
- screen = wnck.screen_get_default()
- for window in screen.get_windows():
- if not window.is_skip_tasklist():
- self._add(window)
- screen.connect('window_opened', self.__window_opened_cb)
- screen.connect('window_closed', self.__window_closed_cb)
+ shell.connect('activity_opened', self.__activity_opened_cb)
+ shell.connect('activity_closed', self.__activity_closed_cb)
- def __window_opened_cb(self, screen, window):
- if not window.is_skip_tasklist():
- self._add(window)
+ def __activity_opened_cb(self, shell, activity):
+ self._add(activity)
- def __window_closed_cb(self, screen, window):
- if not window.is_skip_tasklist():
- self._remove(window)
+ def __activity_closed_cb(self, shell, activity):
+ self._remove(activity)
- def _remove(self, window):
- item = self._items[window.get_xid()]
+ def _remove(self, activity):
+ item = self._items[activity.get_id()]
self.remove_child(item)
- del self._items[window.get_xid()]
+ del self._items[activity.get_id()]
- def _add(self, window):
- item = self.add_piece(100 / 8)
- item.set_data('window', window)
- self._items[window.get_xid()] = item
+ def _add(self, activity):
+ icon_name = activity.get_icon_name()
+ item = self.add_piece(100 / 8, icon_name, 'blue')
+ item.set_data('activity', activity)
+ self._items[activity.get_id()] = item
class ActivityItem(IconItem):
def __init__(self, activity):
@@ -91,7 +86,7 @@ class Model(goocanvas.CanvasModelSimple):
activity_bar.translate(50, 860)
root.add_child(activity_bar)
- tasks = TasksItem()
+ tasks = TasksItem(shell)
tasks.translate(600, 450)
root.add_child(tasks)
@@ -130,8 +125,8 @@ class HomeWindow(gtk.Window):
self._shell.start_activity(activity_id)
def __task_button_press_cb(self, view, target, event):
- window = view.get_item().get_data('window')
- window.activate(gtk.get_current_event_time())
+ activity = view.get_item().get_data('activity')
+ activity.present()
def __realize_cb(self, window):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
diff --git a/shell/Shell.py b/shell/Shell.py
index 614e1d1..50072fb 100755
--- a/shell/Shell.py
+++ b/shell/Shell.py
@@ -39,7 +39,10 @@ class ShellDbusService(dbus.service.Object):
class Shell(gobject.GObject):
__gsignals__ = {
- 'activity-closed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([str]))
+ 'activity-opened': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
+ 'activity-closed': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
}
def __init__(self, registry):
@@ -71,14 +74,16 @@ class Shell(gobject.GObject):
def __window_opened_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
- self._hosts[window.get_xid()] = ActivityHost(self, window)
+ host = ActivityHost(self, window)
+ self._hosts[window.get_xid()] = host
+ self.emit('activity-opened', host)
def __window_closed_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
xid = window.get_xid()
- activity = self._hosts[xid]
- self.emit('activity-closed', activity.get_id())
+ host = self._hosts[xid]
+ self.emit('activity-closed', host)
del self._hosts[xid]
diff --git a/sugar/canvas/DonutItem.py b/sugar/canvas/DonutItem.py
index e7f5605..54c6dcc 100644
--- a/sugar/canvas/DonutItem.py
+++ b/sugar/canvas/DonutItem.py
@@ -2,6 +2,29 @@ import math
import goocanvas
+from sugar.canvas.IconItem import IconItem
+
+class PieceIcon(IconItem):
+ def __init__(self, piece_item, icon_name, color, **kwargs):
+ IconItem.__init__(self, icon_name, color, 48, **kwargs)
+ self._piece_item = piece_item
+
+ def construct(self):
+ angle_start = self._piece_item.get_angle_start()
+ angle_end = self._piece_item.get_angle_end()
+ radius = self.get_parent().get_radius()
+ inner_radius = self.get_parent().get_inner_radius()
+
+ icon_radius = (radius + inner_radius) / 2
+ icon_angle = (angle_start + angle_end) / 2
+ x = icon_radius * math.cos(icon_angle)
+ y = - icon_radius * math.sin(icon_angle)
+
+ icon_width = self.get_property('width')
+ icon_height = self.get_property('height')
+ self.set_property('x', x - icon_width / 2)
+ self.set_property('y', y - icon_height / 2)
+
class PieceItem(goocanvas.Path):
def __init__(self, angle_start, angle_end, **kwargs):
goocanvas.Path.__init__(self, **kwargs)
@@ -12,6 +35,12 @@ class PieceItem(goocanvas.Path):
self.set_property('stroke-color', '#d8d8d8')
self.set_property('line-width', 4)
+ def get_angle_start(self):
+ return self._angle_start
+
+ def get_angle_end(self):
+ return self._angle_end
+
def construct(self):
r = self.get_parent().get_radius()
@@ -41,21 +70,28 @@ class DonutItem(goocanvas.Group):
fill_color='#c2c3c5', line_width=0)
self.add_child(bg)
- fg_radius = radius / 2
- fg = goocanvas.Ellipse(radius_x=fg_radius, radius_y=fg_radius,
+ self._inner_radius = radius / 2
+ fg = goocanvas.Ellipse(radius_x=self._inner_radius,
+ radius_y=self._inner_radius,
fill_color='#d8d8d8', line_width=0)
self.add_child(fg)
- def add_piece(self, perc):
+ def add_piece(self, perc, icon_name, color):
+ # FIXME can't override set_parent on the
+ # PieceItem and there is no signal. So we
+ # call a construct item on the childs for now.
+
angle_end = self._angle_start + perc * 2 * math.pi / 100
piece_item = PieceItem(self._angle_start, angle_end)
self._angle_start = angle_end
- # FIXME can't override set_parent on the
- # PieceItem and there is no signal.
self.add_child(piece_item, 1)
piece_item.construct()
+ icon = PieceIcon(piece_item, icon_name, color)
+ self.add_child(icon)
+ icon.construct()
+
return piece_item
def remove_piece(self, piece_item):
@@ -64,3 +100,6 @@ class DonutItem(goocanvas.Group):
def get_radius(self):
return self._radius
+
+ def get_inner_radius(self):
+ return self._inner_radius