Pass around the shell so that groups can reuse the grid

This commit is contained in:
Marco Pesenti Gritti 2006-09-15 14:24:26 +02:00
parent 5f99dcf9a5
commit 844216585a
10 changed files with 53 additions and 45 deletions

View File

@ -14,11 +14,11 @@ class _PopupShell:
class FriendIcon(IconItem): class FriendIcon(IconItem):
_popup_shell = _PopupShell() _popup_shell = _PopupShell()
def __init__(self, shell_model, friend): def __init__(self, shell, friend):
IconItem.__init__(self, icon_name='stock-buddy', IconItem.__init__(self, icon_name='stock-buddy',
color=friend.get_color(), size=96) color=friend.get_color(), size=96)
self._shell_model = shell_model self._shell = shell
self._friend = friend self._friend = friend
self._popup = None self._popup = None
self._popup_distance = 0 self._popup_distance = 0
@ -44,8 +44,8 @@ class FriendIcon(IconItem):
FriendIcon._popup_shell.set_active(None) FriendIcon._popup_shell.set_active(None)
grid = Grid() grid = self._shell.get_grid()
self._popup = FriendPopup(grid, icon.get_friend()) self._popup = FriendPopup(self._shell, icon.get_friend())
self._popup.connect('action', self._popup_action_cb) self._popup.connect('action', self._popup_action_cb)
self._popup.connect('enter-notify-event', self._popup.connect('enter-notify-event',
self._popup_enter_notify_event_cb) self._popup_enter_notify_event_cb)
@ -82,11 +82,12 @@ class FriendIcon(IconItem):
if buddy == None: if buddy == None:
return return
model = self._shell.get_model()
if action == FriendPopup.ACTION_INVITE: if action == FriendPopup.ACTION_INVITE:
activity = self._shell_model.get_current_activity() activity = model.get_current_activity()
activity.invite(buddy) activity.invite(buddy)
elif action == FriendPopup.ACTION_MAKE_FRIEND: elif action == FriendPopup.ACTION_MAKE_FRIEND:
friends = self._shell_model.get_friends() friends = model.get_friends()
friends.add_buddy(buddy) friends.add_buddy(buddy)
def _popdown_cb(self, friend): def _popdown_cb(self, friend):

View File

@ -15,7 +15,7 @@ class FriendPopup(gtk.Window):
gobject.TYPE_NONE, ([int])), gobject.TYPE_NONE, ([int])),
} }
def __init__(self, grid, friend): def __init__(self, shell, friend):
gtk.Window.__init__(self, gtk.WINDOW_POPUP) gtk.Window.__init__(self, gtk.WINDOW_POPUP)
self._friend = friend self._friend = friend
@ -24,6 +24,8 @@ class FriendPopup(gtk.Window):
self._width = 13 self._width = 13
self._height = 10 self._height = 10
grid = shell.get_grid()
canvas = CanvasView() canvas = CanvasView()
self.add(canvas) self.add(canvas)
canvas.show() canvas.show()

View File

@ -2,6 +2,7 @@ import gtk
import gobject import gobject
import wnck import wnck
from sugar.canvas.Grid import Grid
from view.home.HomeWindow import HomeWindow from view.home.HomeWindow import HomeWindow
from view.ActivityHost import ActivityHost from view.ActivityHost import ActivityHost
from view.frame.Frame import Frame from view.frame.Frame import Frame
@ -14,6 +15,7 @@ class Shell(gobject.GObject):
self._model = model self._model = model
self._screen = wnck.screen_get_default() self._screen = wnck.screen_get_default()
self._grid = Grid()
self._key_grabber = KeyGrabber() self._key_grabber = KeyGrabber()
self._key_grabber.connect('key-pressed', self.__global_key_pressed_cb) self._key_grabber.connect('key-pressed', self.__global_key_pressed_cb)
@ -24,7 +26,7 @@ class Shell(gobject.GObject):
self._key_grabber.grab('F5') self._key_grabber.grab('F5')
self._key_grabber.grab('F6') self._key_grabber.grab('F6')
self._home_window = HomeWindow(self.get_model()) self._home_window = HomeWindow(self)
self._home_window.show() self._home_window.show()
self.set_zoom_level(sugar.ZOOM_HOME) self.set_zoom_level(sugar.ZOOM_HOME)
@ -66,6 +68,9 @@ class Shell(gobject.GObject):
def get_model(self): def get_model(self):
return self._model return self._model
def get_grid(self):
return self._grid
def set_zoom_level(self, level): def set_zoom_level(self, level):
if level == sugar.ZOOM_ACTIVITY: if level == sugar.ZOOM_ACTIVITY:
self._screen.toggle_showing_desktop(False) self._screen.toggle_showing_desktop(False)

View File

@ -33,12 +33,12 @@ class InviteItem(IconItem):
return self._invite return self._invite
class BottomPanel(CanvasBox): class BottomPanel(CanvasBox):
def __init__(self, grid, shell_model): def __init__(self, shell):
CanvasBox.__init__(self, grid, CanvasBox.HORIZONTAL, 1) CanvasBox.__init__(self, shell.get_grid(), CanvasBox.HORIZONTAL, 1)
self._shell_model = shell_model self._shell_model = shell.get_model()
self._invite_to_item = {} self._invite_to_item = {}
self._invites = shell_model.get_invites() self._invites = self._shell_model.get_invites()
registry = conf.get_activity_registry() registry = conf.get_activity_registry()
for activity in registry.list_activities(): for activity in registry.list_activities():

View File

@ -12,31 +12,29 @@ class Frame:
def __init__(self, shell): def __init__(self, shell):
self._windows = [] self._windows = []
shell_model = shell.get_model()
model = goocanvas.CanvasModelSimple() model = goocanvas.CanvasModelSimple()
root = model.get_root_item() root = model.get_root_item()
grid = Grid() grid = shell.get_grid()
bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0) bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0)
grid.set_constraints(bg, 0, 0, 80, 60) grid.set_constraints(bg, 0, 0, 80, 60)
root.add_child(bg) root.add_child(bg)
panel = BottomPanel(grid, shell_model) panel = BottomPanel(shell)
grid.set_constraints(panel, 5, 55) grid.set_constraints(panel, 5, 55)
root.add_child(panel) root.add_child(panel)
panel_window = PanelWindow(grid, model, 0, 55, 80, 5) panel_window = PanelWindow(grid, model, 0, 55, 80, 5)
self._windows.append(panel_window) self._windows.append(panel_window)
panel = TopPanel(grid, shell) panel = TopPanel(shell)
root.add_child(panel) root.add_child(panel)
panel_window = PanelWindow(grid, model, 0, 0, 80, 5) panel_window = PanelWindow(grid, model, 0, 0, 80, 5)
self._windows.append(panel_window) self._windows.append(panel_window)
panel = RightPanel(grid, shell_model) panel = RightPanel(shell)
grid.set_constraints(panel, 75, 5) grid.set_constraints(panel, 75, 5)
root.add_child(panel) root.add_child(panel)

View File

@ -8,10 +8,9 @@ from view.FriendIcon import FriendIcon
from model.Friends import Friend from model.Friends import Friend
class RightPanel(CanvasBox): class RightPanel(CanvasBox):
def __init__(self, grid, shell_model): def __init__(self, shell):
CanvasBox.__init__(self, grid, CanvasBox.VERTICAL, 1) CanvasBox.__init__(self, shell.get_grid(), CanvasBox.VERTICAL, 1)
self._shell_model = shell_model self._shell = shell
self._friends = shell_model.get_friends()
self._activity_ps = None self._activity_ps = None
self._joined_hid = -1 self._joined_hid = -1
self._left_hid = -1 self._left_hid = -1
@ -21,11 +20,12 @@ class RightPanel(CanvasBox):
self._pservice.connect('activity-appeared', self._pservice.connect('activity-appeared',
self.__activity_appeared_cb) self.__activity_appeared_cb)
shell_model.connect('activity-changed', self.__activity_changed_cb) shell.get_model().connect('activity-changed',
self.__activity_changed_cb)
def add(self, buddy): def add(self, buddy):
friend = Friend(buddy.get_name(), buddy.get_color()) friend = Friend(buddy.get_name(), buddy.get_color())
icon = FriendIcon(self._shell_model, friend) icon = FriendIcon(self._shell, friend)
icon.set_popup_distance(1) icon.set_popup_distance(1)
self.set_constraints(icon, 3, 3) self.set_constraints(icon, 3, 3)
self.add_child(icon) self.add_child(icon)
@ -42,7 +42,7 @@ class RightPanel(CanvasBox):
self._buddies = {} self._buddies = {}
def __activity_appeared_cb(self, pservice, activity_ps): def __activity_appeared_cb(self, pservice, activity_ps):
activity = self._shell_model.get_current_activity() activity = self._shell.get_model().get_current_activity()
if activity and activity_ps.get_id() == activity.get_id(): if activity and activity_ps.get_id() == activity.get_id():
self._set_activity_ps(activity_ps) self._set_activity_ps(activity_ps)

View File

@ -5,14 +5,15 @@ from sugar.canvas.IconItem import IconItem
import sugar import sugar
class TopPanel(goocanvas.Group): class TopPanel(goocanvas.Group):
def __init__(self, grid, shell): def __init__(self, shell):
goocanvas.Group.__init__(self) goocanvas.Group.__init__(self)
self._grid = grid
self._shell = shell self._shell = shell
grid = shell.get_grid()
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1) box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
self._grid.set_constraints(box, 5, 0) grid.set_constraints(box, 5, 0)
self.add_child(box) self.add_child(box)
icon = IconItem(icon_name='stock-zoom-activity') icon = IconItem(icon_name='stock-zoom-activity')
@ -36,7 +37,7 @@ class TopPanel(goocanvas.Group):
box.add_child(icon) box.add_child(icon)
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1) box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
self._grid.set_constraints(box, 60, 0) grid.set_constraints(box, 60, 0)
self.add_child(box) self.add_child(box)
icon = IconItem(icon_name='stock-share') icon = IconItem(icon_name='stock-share')

View File

@ -7,25 +7,26 @@ from view.home.MyIcon import MyIcon
from view.FriendIcon import FriendIcon from view.FriendIcon import FriendIcon
class FriendsGroup(goocanvas.Group): class FriendsGroup(goocanvas.Group):
def __init__(self, shell_model): def __init__(self, shell):
goocanvas.Group.__init__(self) goocanvas.Group.__init__(self)
self._shell_model = shell_model self._shell = shell
self._icon_layout = IconLayout(1200, 900) self._icon_layout = IconLayout(1200, 900)
self._friends = shell_model.get_friends()
me = MyIcon(100) me = MyIcon(100)
me.translate(600 - (me.get_property('size') / 2), me.translate(600 - (me.get_property('size') / 2),
450 - (me.get_property('size') / 2)) 450 - (me.get_property('size') / 2))
self.add_child(me) self.add_child(me)
for friend in self._friends: friends = self._shell.get_model().get_friends()
for friend in friends:
self.add_friend(friend) self.add_friend(friend)
self._friends.connect('friend-added', self._friend_added_cb) friends.connect('friend-added', self._friend_added_cb)
def add_friend(self, friend): def add_friend(self, friend):
icon = FriendIcon(self._shell_model, friend) icon = FriendIcon(self._shell, friend)
self.add_child(icon) self.add_child(icon)
self._icon_layout.add_icon(icon) self._icon_layout.add_icon(icon)

View File

@ -4,14 +4,14 @@ from view.home.DonutItem import DonutItem
from view.home.MyIcon import MyIcon from view.home.MyIcon import MyIcon
class TasksItem(DonutItem): class TasksItem(DonutItem):
def __init__(self, shell_model): def __init__(self, shell):
DonutItem.__init__(self, 250) DonutItem.__init__(self, 250)
self._items = {} self._items = {}
self._shell_model = shell_model shell_model = shell.get_model()
self._shell_model.connect('activity_opened', self.__activity_opened_cb) shell_model.connect('activity_opened', self.__activity_opened_cb)
self._shell_model.connect('activity_closed', self.__activity_closed_cb) shell_model.connect('activity_closed', self.__activity_closed_cb)
def __activity_opened_cb(self, model, activity): def __activity_opened_cb(self, model, activity):
self._add(activity) self._add(activity)
@ -39,10 +39,10 @@ class TasksItem(DonutItem):
activity.present() activity.present()
class HomeGroup(goocanvas.Group): class HomeGroup(goocanvas.Group):
def __init__(self, shell_model): def __init__(self, shell):
goocanvas.Group.__init__(self) goocanvas.Group.__init__(self)
tasks = TasksItem(shell_model) tasks = TasksItem(shell)
tasks.translate(600, 450) tasks.translate(600, 450)
self.add_child(tasks) self.add_child(tasks)

View File

@ -9,9 +9,9 @@ from view.home.FriendsGroup import FriendsGroup
import sugar import sugar
class HomeWindow(gtk.Window): class HomeWindow(gtk.Window):
def __init__(self, shell_model): def __init__(self, shell):
gtk.Window.__init__(self) gtk.Window.__init__(self)
self._shell_model = shell_model self._shell = shell
self.realize() self.realize()
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP) self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
@ -23,8 +23,8 @@ class HomeWindow(gtk.Window):
self.add(self._nb) self.add(self._nb)
self._nb.show() self._nb.show()
self._add_page(HomeGroup(shell_model)) self._add_page(HomeGroup(shell))
self._add_page(FriendsGroup(shell_model)) self._add_page(FriendsGroup(shell))
self._add_page(MeshGroup()) self._add_page(MeshGroup())
def _add_page(self, group): def _add_page(self, group):