Add icon for activity to the donut.
Add signals in the shell for window open/close and use them in the task view.
This commit is contained in:
parent
10f356cb22
commit
f65d23c440
@ -20,9 +20,15 @@ class ActivityHost:
|
|||||||
self._gdk_window = gtk.gdk.window_foreign_new(self._xid)
|
self._gdk_window = gtk.gdk.window_foreign_new(self._xid)
|
||||||
self._people_window = PeopleWindow(shell, self)
|
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):
|
def get_id(self):
|
||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
|
def get_icon_name(self):
|
||||||
|
return self._icon_name
|
||||||
|
|
||||||
def share(self):
|
def share(self):
|
||||||
self._people_window.share()
|
self._people_window.share()
|
||||||
self._activity.share()
|
self._activity.share()
|
||||||
|
@ -13,7 +13,8 @@ class ChatController:
|
|||||||
|
|
||||||
self._shell.connect('activity-closed', self.__activity_closed_cb)
|
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):
|
if self._id_to_name.has_key(activity_id):
|
||||||
name = self._id_to_name[activity_id]
|
name = self._id_to_name[activity_id]
|
||||||
del self._name_to_chat[name]
|
del self._name_to_chat[name]
|
||||||
|
@ -7,35 +7,30 @@ from sugar.canvas.DonutItem import DonutItem
|
|||||||
from sugar.canvas.DonutItem import PieceItem
|
from sugar.canvas.DonutItem import PieceItem
|
||||||
|
|
||||||
class TasksItem(DonutItem):
|
class TasksItem(DonutItem):
|
||||||
def __init__(self):
|
def __init__(self, shell):
|
||||||
DonutItem.__init__(self, 250)
|
DonutItem.__init__(self, 250)
|
||||||
|
|
||||||
self._items = {}
|
self._items = {}
|
||||||
|
|
||||||
screen = wnck.screen_get_default()
|
shell.connect('activity_opened', self.__activity_opened_cb)
|
||||||
for window in screen.get_windows():
|
shell.connect('activity_closed', self.__activity_closed_cb)
|
||||||
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)
|
|
||||||
|
|
||||||
def __window_opened_cb(self, screen, window):
|
def __activity_opened_cb(self, shell, activity):
|
||||||
if not window.is_skip_tasklist():
|
self._add(activity)
|
||||||
self._add(window)
|
|
||||||
|
|
||||||
def __window_closed_cb(self, screen, window):
|
def __activity_closed_cb(self, shell, activity):
|
||||||
if not window.is_skip_tasklist():
|
self._remove(activity)
|
||||||
self._remove(window)
|
|
||||||
|
|
||||||
def _remove(self, window):
|
def _remove(self, activity):
|
||||||
item = self._items[window.get_xid()]
|
item = self._items[activity.get_id()]
|
||||||
self.remove_child(item)
|
self.remove_child(item)
|
||||||
del self._items[window.get_xid()]
|
del self._items[activity.get_id()]
|
||||||
|
|
||||||
def _add(self, window):
|
def _add(self, activity):
|
||||||
item = self.add_piece(100 / 8)
|
icon_name = activity.get_icon_name()
|
||||||
item.set_data('window', window)
|
item = self.add_piece(100 / 8, icon_name, 'blue')
|
||||||
self._items[window.get_xid()] = item
|
item.set_data('activity', activity)
|
||||||
|
self._items[activity.get_id()] = item
|
||||||
|
|
||||||
class ActivityItem(IconItem):
|
class ActivityItem(IconItem):
|
||||||
def __init__(self, activity):
|
def __init__(self, activity):
|
||||||
@ -91,7 +86,7 @@ class Model(goocanvas.CanvasModelSimple):
|
|||||||
activity_bar.translate(50, 860)
|
activity_bar.translate(50, 860)
|
||||||
root.add_child(activity_bar)
|
root.add_child(activity_bar)
|
||||||
|
|
||||||
tasks = TasksItem()
|
tasks = TasksItem(shell)
|
||||||
tasks.translate(600, 450)
|
tasks.translate(600, 450)
|
||||||
root.add_child(tasks)
|
root.add_child(tasks)
|
||||||
|
|
||||||
@ -130,8 +125,8 @@ class HomeWindow(gtk.Window):
|
|||||||
self._shell.start_activity(activity_id)
|
self._shell.start_activity(activity_id)
|
||||||
|
|
||||||
def __task_button_press_cb(self, view, target, event):
|
def __task_button_press_cb(self, view, target, event):
|
||||||
window = view.get_item().get_data('window')
|
activity = view.get_item().get_data('activity')
|
||||||
window.activate(gtk.get_current_event_time())
|
activity.present()
|
||||||
|
|
||||||
def __realize_cb(self, window):
|
def __realize_cb(self, window):
|
||||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||||
|
@ -39,7 +39,10 @@ class ShellDbusService(dbus.service.Object):
|
|||||||
|
|
||||||
class Shell(gobject.GObject):
|
class Shell(gobject.GObject):
|
||||||
__gsignals__ = {
|
__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):
|
def __init__(self, registry):
|
||||||
@ -71,14 +74,16 @@ class Shell(gobject.GObject):
|
|||||||
|
|
||||||
def __window_opened_cb(self, screen, window):
|
def __window_opened_cb(self, screen, window):
|
||||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
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):
|
def __window_closed_cb(self, screen, window):
|
||||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||||
xid = window.get_xid()
|
xid = window.get_xid()
|
||||||
|
|
||||||
activity = self._hosts[xid]
|
host = self._hosts[xid]
|
||||||
self.emit('activity-closed', activity.get_id())
|
self.emit('activity-closed', host)
|
||||||
|
|
||||||
del self._hosts[xid]
|
del self._hosts[xid]
|
||||||
|
|
||||||
|
@ -2,6 +2,29 @@ import math
|
|||||||
|
|
||||||
import goocanvas
|
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):
|
class PieceItem(goocanvas.Path):
|
||||||
def __init__(self, angle_start, angle_end, **kwargs):
|
def __init__(self, angle_start, angle_end, **kwargs):
|
||||||
goocanvas.Path.__init__(self, **kwargs)
|
goocanvas.Path.__init__(self, **kwargs)
|
||||||
@ -12,6 +35,12 @@ class PieceItem(goocanvas.Path):
|
|||||||
self.set_property('stroke-color', '#d8d8d8')
|
self.set_property('stroke-color', '#d8d8d8')
|
||||||
self.set_property('line-width', 4)
|
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):
|
def construct(self):
|
||||||
r = self.get_parent().get_radius()
|
r = self.get_parent().get_radius()
|
||||||
|
|
||||||
@ -41,21 +70,28 @@ class DonutItem(goocanvas.Group):
|
|||||||
fill_color='#c2c3c5', line_width=0)
|
fill_color='#c2c3c5', line_width=0)
|
||||||
self.add_child(bg)
|
self.add_child(bg)
|
||||||
|
|
||||||
fg_radius = radius / 2
|
self._inner_radius = radius / 2
|
||||||
fg = goocanvas.Ellipse(radius_x=fg_radius, radius_y=fg_radius,
|
fg = goocanvas.Ellipse(radius_x=self._inner_radius,
|
||||||
|
radius_y=self._inner_radius,
|
||||||
fill_color='#d8d8d8', line_width=0)
|
fill_color='#d8d8d8', line_width=0)
|
||||||
self.add_child(fg)
|
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
|
angle_end = self._angle_start + perc * 2 * math.pi / 100
|
||||||
piece_item = PieceItem(self._angle_start, angle_end)
|
piece_item = PieceItem(self._angle_start, angle_end)
|
||||||
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)
|
self.add_child(piece_item, 1)
|
||||||
piece_item.construct()
|
piece_item.construct()
|
||||||
|
|
||||||
|
icon = PieceIcon(piece_item, icon_name, color)
|
||||||
|
self.add_child(icon)
|
||||||
|
icon.construct()
|
||||||
|
|
||||||
return piece_item
|
return piece_item
|
||||||
|
|
||||||
def remove_piece(self, piece_item):
|
def remove_piece(self, piece_item):
|
||||||
@ -64,3 +100,6 @@ class DonutItem(goocanvas.Group):
|
|||||||
|
|
||||||
def get_radius(self):
|
def get_radius(self):
|
||||||
return self._radius
|
return self._radius
|
||||||
|
|
||||||
|
def get_inner_radius(self):
|
||||||
|
return self._inner_radius
|
||||||
|
Loading…
Reference in New Issue
Block a user