Implement the grid, regress UI a bit
This commit is contained in:
+14
-38
@@ -6,25 +6,25 @@ import conf
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar.presence import PresenceService
|
||||
from frame.Panel import Panel
|
||||
from sugar.canvas.GridLayout import GridGroup
|
||||
from sugar.canvas.GridLayout import GridConstraints
|
||||
|
||||
class ActivityItem(IconItem):
|
||||
def __init__(self, activity, size):
|
||||
def __init__(self, activity):
|
||||
icon_name = activity.get_icon()
|
||||
if not icon_name:
|
||||
act_type = activity.get_type()
|
||||
raise RuntimeError("Activity %s did not have an icon!" % act_type)
|
||||
IconItem.__init__(self, icon_name=icon_name,
|
||||
color=IconColor('white'), size=size)
|
||||
IconItem.__init__(self, icon_name=icon_name, color=IconColor('white'))
|
||||
self._activity = activity
|
||||
|
||||
def get_bundle_id(self):
|
||||
return self._activity.get_id()
|
||||
|
||||
class InviteItem(IconItem):
|
||||
def __init__(self, invite, size):
|
||||
def __init__(self, invite):
|
||||
IconItem.__init__(self, icon_name=invite.get_icon(),
|
||||
color=invite.get_color(), size=size)
|
||||
color=invite.get_color())
|
||||
self._invite = invite
|
||||
|
||||
def get_activity_id(self):
|
||||
@@ -33,12 +33,11 @@ class InviteItem(IconItem):
|
||||
def get_bundle_id(self):
|
||||
return self._invite.get_bundle_id()
|
||||
|
||||
class ActivityBar(goocanvas.Group):
|
||||
def __init__(self, shell, invites, height):
|
||||
goocanvas.Group.__init__(self)
|
||||
class BottomPanel(GridGroup):
|
||||
def __init__(self, shell, invites):
|
||||
GridGroup.__init__(self, 16, 1)
|
||||
|
||||
self._shell = shell
|
||||
self._height = height
|
||||
|
||||
registry = conf.get_activity_registry()
|
||||
for activity in registry.list_activities():
|
||||
@@ -66,37 +65,14 @@ class ActivityBar(goocanvas.Group):
|
||||
logging.info("Activity %s did not have an icon. Won't show it." % name)
|
||||
return
|
||||
|
||||
item = ActivityItem(activity, self._height)
|
||||
item = ActivityItem(activity)
|
||||
item.connect('clicked', self.__activity_clicked_cb)
|
||||
|
||||
icon_size = self._height
|
||||
x = (icon_size + 6) * self.get_n_children()
|
||||
item.set_property('x', x)
|
||||
|
||||
constraints = GridConstraints(self.get_n_children() + 1, 0, 1, 1)
|
||||
constraints.padding = 6
|
||||
self._layout.set_constraints(item, constraints)
|
||||
self.add_child(item)
|
||||
|
||||
def add_invite(self, invite):
|
||||
item = InviteItem(invite, self._height)
|
||||
item = InviteItem(invite)
|
||||
item.connect('clicked', self.__invite_clicked_cb)
|
||||
|
||||
icon_size = self._height
|
||||
x = (icon_size + 6) * self.get_n_children()
|
||||
item.set_property('x', x)
|
||||
|
||||
self.add_child(item)
|
||||
|
||||
class BottomPanel(Panel):
|
||||
def __init__(self, shell, invites):
|
||||
Panel.__init__(self)
|
||||
|
||||
self._shell = shell
|
||||
self._invites = invites
|
||||
|
||||
def construct(self):
|
||||
Panel.construct(self)
|
||||
|
||||
root = self.get_root()
|
||||
|
||||
activity_bar = ActivityBar(self._shell, self._invites,
|
||||
self.get_height())
|
||||
root.add_child(activity_bar)
|
||||
|
||||
+51
-23
@@ -1,38 +1,66 @@
|
||||
import gtk
|
||||
import gobject
|
||||
import goocanvas
|
||||
|
||||
from frame.BottomPanel import BottomPanel
|
||||
from frame.RightPanel import RightPanel
|
||||
from frame.TopPanel import TopPanel
|
||||
from frame.Panel import Panel
|
||||
from frame.PanelWindow import PanelWindow
|
||||
|
||||
from sugar.canvas.ScreenContainer import ScreenContainer
|
||||
from sugar.canvas.GridLayout import GridLayout
|
||||
from sugar.canvas.GridLayout import GridConstraints
|
||||
from sugar.canvas.GridLayout import GridGroup
|
||||
|
||||
class Frame:
|
||||
def __init__(self, shell, owner):
|
||||
size = 30
|
||||
self._windows = []
|
||||
|
||||
self._panels = []
|
||||
self._model = goocanvas.CanvasModelSimple()
|
||||
item = goocanvas.Rect(x=0, y=0, width=800, height=600,
|
||||
line_width=0, fill_color="#4f4f4f")
|
||||
self._model.get_root_item().add_child(item)
|
||||
|
||||
self._screen_layout = GridLayout()
|
||||
self._screen_container = ScreenContainer(self._windows)
|
||||
|
||||
group = GridGroup()
|
||||
group.props.width = 800
|
||||
group.props.height = 600
|
||||
layout = group.get_layout()
|
||||
|
||||
constraints = GridConstraints(0, 11, 16, 1)
|
||||
self._create_window(constraints)
|
||||
|
||||
panel = BottomPanel(shell, owner.get_invites())
|
||||
panel.set_position(size, 0)
|
||||
panel.move(0, gtk.gdk.screen_height() - size)
|
||||
panel.resize(gtk.gdk.screen_width(), size)
|
||||
self._panels.append(panel)
|
||||
layout.set_constraints(panel, constraints)
|
||||
group.add_child(panel)
|
||||
|
||||
panel = RightPanel(shell, owner.get_friends())
|
||||
panel.move(gtk.gdk.screen_width() - size, size)
|
||||
panel.resize(size, gtk.gdk.screen_height() - size * 2)
|
||||
self._panels.append(panel)
|
||||
# Top
|
||||
constraints = GridConstraints(0, 0, 16, 1)
|
||||
self._create_window(constraints)
|
||||
|
||||
panel = TopPanel(shell)
|
||||
panel.set_position(size, 0)
|
||||
panel.move(0, 0)
|
||||
panel.resize(gtk.gdk.screen_width(), size)
|
||||
self._panels.append(panel)
|
||||
# Left
|
||||
constraints = GridConstraints(0, 1, 1, 10)
|
||||
self._create_window(constraints)
|
||||
|
||||
panel = Panel()
|
||||
panel.move(0, size)
|
||||
panel.resize(size, gtk.gdk.screen_height() - size * 2)
|
||||
self._panels.append(panel)
|
||||
# Right
|
||||
constraints = GridConstraints(15, 1, 1, 10)
|
||||
self._create_window(constraints)
|
||||
|
||||
self._model.get_root_item().add_child(group)
|
||||
self._screen_container.set_layout(self._screen_layout)
|
||||
|
||||
def _create_window(self, constraints):
|
||||
layout = self._screen_layout
|
||||
|
||||
window = PanelWindow(self._model)
|
||||
layout.set_constraints(window, constraints)
|
||||
self._windows.append(window)
|
||||
|
||||
bounds = layout.get_bounds(self._screen_container, constraints)
|
||||
window.get_view().set_bounds(bounds[0], bounds[1],
|
||||
bounds[2], bounds[3])
|
||||
|
||||
def __hide_timeout_cb(self):
|
||||
self.hide()
|
||||
@@ -43,15 +71,15 @@ class Frame:
|
||||
gobject.timeout_add(seconds * 1000, self.__hide_timeout_cb)
|
||||
|
||||
def show(self):
|
||||
for panel in self._panels:
|
||||
for panel in self._windows:
|
||||
panel.show()
|
||||
|
||||
def hide(self):
|
||||
for panel in self._panels:
|
||||
for panel in self._windows:
|
||||
panel.hide()
|
||||
|
||||
def toggle_visibility(self):
|
||||
for panel in self._panels:
|
||||
for panel in self._windows:
|
||||
if panel.props.visible:
|
||||
panel.hide()
|
||||
else:
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
import gtk
|
||||
import goocanvas
|
||||
|
||||
class PanelView(goocanvas.CanvasView):
|
||||
BORDER = 4
|
||||
|
||||
def construct(self, x, y):
|
||||
model = goocanvas.CanvasModelSimple()
|
||||
root = model.get_root_item()
|
||||
|
||||
item = goocanvas.Rect(x=0, y=0,
|
||||
width=self.get_allocation().width,
|
||||
height=self.get_allocation().height,
|
||||
line_width=0, fill_color="#4f4f4f")
|
||||
root.add_child(item)
|
||||
|
||||
self._group = goocanvas.Group()
|
||||
root.add_child(self._group)
|
||||
self._group.translate(x + PanelView.BORDER, y + PanelView.BORDER)
|
||||
|
||||
self.set_model(model)
|
||||
|
||||
def get_root_group(self):
|
||||
return self._group
|
||||
|
||||
class Panel(gtk.Window):
|
||||
def __init__(self):
|
||||
gtk.Window.__init__(self)
|
||||
self._x = 0
|
||||
self._y = 0
|
||||
self._constructed = False
|
||||
|
||||
self._view = PanelView()
|
||||
self.add(self._view)
|
||||
self._view.show()
|
||||
|
||||
self.set_decorated(False)
|
||||
|
||||
self.realize()
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
||||
self.window.set_accept_focus(False)
|
||||
|
||||
screen = gtk.gdk.screen_get_default()
|
||||
self.window.set_transient_for(screen.get_root_window())
|
||||
|
||||
def get_view(self):
|
||||
return self._view
|
||||
|
||||
def get_root(self):
|
||||
return self._view.get_root_group()
|
||||
|
||||
def get_height(self):
|
||||
height = self._view.get_allocation().height
|
||||
return height - PanelView.BORDER * 2
|
||||
|
||||
def get_width(self):
|
||||
width = self._view.get_allocation().width
|
||||
return width - PanelView.BORDER * 2
|
||||
|
||||
def set_position(self, x, y):
|
||||
self._x = x
|
||||
self._y = y
|
||||
|
||||
def construct(self):
|
||||
self._view.construct(self._x, self._y)
|
||||
self._constructed = True
|
||||
|
||||
def show(self):
|
||||
gtk.Window.show(self)
|
||||
|
||||
if not self._constructed:
|
||||
self.construct()
|
||||
@@ -0,0 +1,16 @@
|
||||
import gtk
|
||||
|
||||
from sugar.canvas.CanvasWindow import CanvasWindow
|
||||
|
||||
class PanelWindow(CanvasWindow):
|
||||
def __init__(self, model):
|
||||
CanvasWindow.__init__(self, model)
|
||||
|
||||
self.set_decorated(False)
|
||||
|
||||
self.realize()
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
||||
self.window.set_accept_focus(False)
|
||||
|
||||
screen = gtk.gdk.screen_get_default()
|
||||
self.window.set_transient_for(screen.get_root_window())
|
||||
Reference in New Issue
Block a user