Pass around the shell so that groups can reuse the grid
This commit is contained in:
parent
5f99dcf9a5
commit
844216585a
@ -14,11 +14,11 @@ class _PopupShell:
|
||||
class FriendIcon(IconItem):
|
||||
_popup_shell = _PopupShell()
|
||||
|
||||
def __init__(self, shell_model, friend):
|
||||
def __init__(self, shell, friend):
|
||||
IconItem.__init__(self, icon_name='stock-buddy',
|
||||
color=friend.get_color(), size=96)
|
||||
|
||||
self._shell_model = shell_model
|
||||
self._shell = shell
|
||||
self._friend = friend
|
||||
self._popup = None
|
||||
self._popup_distance = 0
|
||||
@ -44,8 +44,8 @@ class FriendIcon(IconItem):
|
||||
|
||||
FriendIcon._popup_shell.set_active(None)
|
||||
|
||||
grid = Grid()
|
||||
self._popup = FriendPopup(grid, icon.get_friend())
|
||||
grid = self._shell.get_grid()
|
||||
self._popup = FriendPopup(self._shell, icon.get_friend())
|
||||
self._popup.connect('action', self._popup_action_cb)
|
||||
self._popup.connect('enter-notify-event',
|
||||
self._popup_enter_notify_event_cb)
|
||||
@ -82,11 +82,12 @@ class FriendIcon(IconItem):
|
||||
if buddy == None:
|
||||
return
|
||||
|
||||
model = self._shell.get_model()
|
||||
if action == FriendPopup.ACTION_INVITE:
|
||||
activity = self._shell_model.get_current_activity()
|
||||
activity = model.get_current_activity()
|
||||
activity.invite(buddy)
|
||||
elif action == FriendPopup.ACTION_MAKE_FRIEND:
|
||||
friends = self._shell_model.get_friends()
|
||||
friends = model.get_friends()
|
||||
friends.add_buddy(buddy)
|
||||
|
||||
def _popdown_cb(self, friend):
|
||||
|
@ -15,7 +15,7 @@ class FriendPopup(gtk.Window):
|
||||
gobject.TYPE_NONE, ([int])),
|
||||
}
|
||||
|
||||
def __init__(self, grid, friend):
|
||||
def __init__(self, shell, friend):
|
||||
gtk.Window.__init__(self, gtk.WINDOW_POPUP)
|
||||
|
||||
self._friend = friend
|
||||
@ -24,6 +24,8 @@ class FriendPopup(gtk.Window):
|
||||
self._width = 13
|
||||
self._height = 10
|
||||
|
||||
grid = shell.get_grid()
|
||||
|
||||
canvas = CanvasView()
|
||||
self.add(canvas)
|
||||
canvas.show()
|
||||
|
@ -2,6 +2,7 @@ import gtk
|
||||
import gobject
|
||||
import wnck
|
||||
|
||||
from sugar.canvas.Grid import Grid
|
||||
from view.home.HomeWindow import HomeWindow
|
||||
from view.ActivityHost import ActivityHost
|
||||
from view.frame.Frame import Frame
|
||||
@ -14,6 +15,7 @@ class Shell(gobject.GObject):
|
||||
|
||||
self._model = model
|
||||
self._screen = wnck.screen_get_default()
|
||||
self._grid = Grid()
|
||||
|
||||
self._key_grabber = KeyGrabber()
|
||||
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('F6')
|
||||
|
||||
self._home_window = HomeWindow(self.get_model())
|
||||
self._home_window = HomeWindow(self)
|
||||
self._home_window.show()
|
||||
self.set_zoom_level(sugar.ZOOM_HOME)
|
||||
|
||||
@ -66,6 +68,9 @@ class Shell(gobject.GObject):
|
||||
def get_model(self):
|
||||
return self._model
|
||||
|
||||
def get_grid(self):
|
||||
return self._grid
|
||||
|
||||
def set_zoom_level(self, level):
|
||||
if level == sugar.ZOOM_ACTIVITY:
|
||||
self._screen.toggle_showing_desktop(False)
|
||||
|
@ -33,12 +33,12 @@ class InviteItem(IconItem):
|
||||
return self._invite
|
||||
|
||||
class BottomPanel(CanvasBox):
|
||||
def __init__(self, grid, shell_model):
|
||||
CanvasBox.__init__(self, grid, CanvasBox.HORIZONTAL, 1)
|
||||
def __init__(self, shell):
|
||||
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._invites = shell_model.get_invites()
|
||||
self._invites = self._shell_model.get_invites()
|
||||
|
||||
registry = conf.get_activity_registry()
|
||||
for activity in registry.list_activities():
|
||||
|
@ -12,31 +12,29 @@ class Frame:
|
||||
def __init__(self, shell):
|
||||
self._windows = []
|
||||
|
||||
shell_model = shell.get_model()
|
||||
|
||||
model = goocanvas.CanvasModelSimple()
|
||||
root = model.get_root_item()
|
||||
|
||||
grid = Grid()
|
||||
grid = shell.get_grid()
|
||||
|
||||
bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0)
|
||||
grid.set_constraints(bg, 0, 0, 80, 60)
|
||||
root.add_child(bg)
|
||||
|
||||
panel = BottomPanel(grid, shell_model)
|
||||
panel = BottomPanel(shell)
|
||||
grid.set_constraints(panel, 5, 55)
|
||||
root.add_child(panel)
|
||||
|
||||
panel_window = PanelWindow(grid, model, 0, 55, 80, 5)
|
||||
self._windows.append(panel_window)
|
||||
|
||||
panel = TopPanel(grid, shell)
|
||||
panel = TopPanel(shell)
|
||||
root.add_child(panel)
|
||||
|
||||
panel_window = PanelWindow(grid, model, 0, 0, 80, 5)
|
||||
self._windows.append(panel_window)
|
||||
|
||||
panel = RightPanel(grid, shell_model)
|
||||
panel = RightPanel(shell)
|
||||
grid.set_constraints(panel, 75, 5)
|
||||
root.add_child(panel)
|
||||
|
||||
|
@ -8,10 +8,9 @@ from view.FriendIcon import FriendIcon
|
||||
from model.Friends import Friend
|
||||
|
||||
class RightPanel(CanvasBox):
|
||||
def __init__(self, grid, shell_model):
|
||||
CanvasBox.__init__(self, grid, CanvasBox.VERTICAL, 1)
|
||||
self._shell_model = shell_model
|
||||
self._friends = shell_model.get_friends()
|
||||
def __init__(self, shell):
|
||||
CanvasBox.__init__(self, shell.get_grid(), CanvasBox.VERTICAL, 1)
|
||||
self._shell = shell
|
||||
self._activity_ps = None
|
||||
self._joined_hid = -1
|
||||
self._left_hid = -1
|
||||
@ -21,11 +20,12 @@ class RightPanel(CanvasBox):
|
||||
self._pservice.connect('activity-appeared',
|
||||
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):
|
||||
friend = Friend(buddy.get_name(), buddy.get_color())
|
||||
icon = FriendIcon(self._shell_model, friend)
|
||||
icon = FriendIcon(self._shell, friend)
|
||||
icon.set_popup_distance(1)
|
||||
self.set_constraints(icon, 3, 3)
|
||||
self.add_child(icon)
|
||||
@ -42,7 +42,7 @@ class RightPanel(CanvasBox):
|
||||
self._buddies = {}
|
||||
|
||||
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():
|
||||
self._set_activity_ps(activity_ps)
|
||||
|
||||
|
@ -5,14 +5,15 @@ from sugar.canvas.IconItem import IconItem
|
||||
import sugar
|
||||
|
||||
class TopPanel(goocanvas.Group):
|
||||
def __init__(self, grid, shell):
|
||||
def __init__(self, shell):
|
||||
goocanvas.Group.__init__(self)
|
||||
|
||||
self._grid = grid
|
||||
self._shell = shell
|
||||
|
||||
grid = shell.get_grid()
|
||||
|
||||
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
|
||||
self._grid.set_constraints(box, 5, 0)
|
||||
grid.set_constraints(box, 5, 0)
|
||||
self.add_child(box)
|
||||
|
||||
icon = IconItem(icon_name='stock-zoom-activity')
|
||||
@ -36,7 +37,7 @@ class TopPanel(goocanvas.Group):
|
||||
box.add_child(icon)
|
||||
|
||||
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
|
||||
self._grid.set_constraints(box, 60, 0)
|
||||
grid.set_constraints(box, 60, 0)
|
||||
self.add_child(box)
|
||||
|
||||
icon = IconItem(icon_name='stock-share')
|
||||
|
@ -7,25 +7,26 @@ from view.home.MyIcon import MyIcon
|
||||
from view.FriendIcon import FriendIcon
|
||||
|
||||
class FriendsGroup(goocanvas.Group):
|
||||
def __init__(self, shell_model):
|
||||
def __init__(self, shell):
|
||||
goocanvas.Group.__init__(self)
|
||||
|
||||
self._shell_model = shell_model
|
||||
self._shell = shell
|
||||
self._icon_layout = IconLayout(1200, 900)
|
||||
self._friends = shell_model.get_friends()
|
||||
|
||||
me = MyIcon(100)
|
||||
me.translate(600 - (me.get_property('size') / 2),
|
||||
450 - (me.get_property('size') / 2))
|
||||
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._friends.connect('friend-added', self._friend_added_cb)
|
||||
friends.connect('friend-added', self._friend_added_cb)
|
||||
|
||||
def add_friend(self, friend):
|
||||
icon = FriendIcon(self._shell_model, friend)
|
||||
icon = FriendIcon(self._shell, friend)
|
||||
self.add_child(icon)
|
||||
self._icon_layout.add_icon(icon)
|
||||
|
||||
|
@ -4,14 +4,14 @@ from view.home.DonutItem import DonutItem
|
||||
from view.home.MyIcon import MyIcon
|
||||
|
||||
class TasksItem(DonutItem):
|
||||
def __init__(self, shell_model):
|
||||
def __init__(self, shell):
|
||||
DonutItem.__init__(self, 250)
|
||||
|
||||
self._items = {}
|
||||
|
||||
self._shell_model = shell_model
|
||||
self._shell_model.connect('activity_opened', self.__activity_opened_cb)
|
||||
self._shell_model.connect('activity_closed', self.__activity_closed_cb)
|
||||
shell_model = shell.get_model()
|
||||
shell_model.connect('activity_opened', self.__activity_opened_cb)
|
||||
shell_model.connect('activity_closed', self.__activity_closed_cb)
|
||||
|
||||
def __activity_opened_cb(self, model, activity):
|
||||
self._add(activity)
|
||||
@ -39,10 +39,10 @@ class TasksItem(DonutItem):
|
||||
activity.present()
|
||||
|
||||
class HomeGroup(goocanvas.Group):
|
||||
def __init__(self, shell_model):
|
||||
def __init__(self, shell):
|
||||
goocanvas.Group.__init__(self)
|
||||
|
||||
tasks = TasksItem(shell_model)
|
||||
tasks = TasksItem(shell)
|
||||
tasks.translate(600, 450)
|
||||
self.add_child(tasks)
|
||||
|
||||
|
@ -9,9 +9,9 @@ from view.home.FriendsGroup import FriendsGroup
|
||||
import sugar
|
||||
|
||||
class HomeWindow(gtk.Window):
|
||||
def __init__(self, shell_model):
|
||||
def __init__(self, shell):
|
||||
gtk.Window.__init__(self)
|
||||
self._shell_model = shell_model
|
||||
self._shell = shell
|
||||
|
||||
self.realize()
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||
@ -23,8 +23,8 @@ class HomeWindow(gtk.Window):
|
||||
self.add(self._nb)
|
||||
self._nb.show()
|
||||
|
||||
self._add_page(HomeGroup(shell_model))
|
||||
self._add_page(FriendsGroup(shell_model))
|
||||
self._add_page(HomeGroup(shell))
|
||||
self._add_page(FriendsGroup(shell))
|
||||
self._add_page(MeshGroup())
|
||||
|
||||
def _add_page(self, group):
|
||||
|
Loading…
Reference in New Issue
Block a user