Start implementing the panels.
parent
9f674ef232
commit
f53af6af4c
@ -0,0 +1,5 @@
|
||||
from panel.Panel import Panel
|
||||
|
||||
class FriendsPanel(Panel):
|
||||
def __init__(self, shell):
|
||||
Panel.__init__(self)
|
@ -0,0 +1,7 @@
|
||||
sugardir = $(pkgdatadir)/shell/panel
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
FriendsPanel.py \
|
||||
Panel.py \
|
||||
PanelManager.py \
|
||||
VerbsPanel.py
|
@ -0,0 +1,53 @@
|
||||
import gtk
|
||||
import goocanvas
|
||||
|
||||
class PanelModel(goocanvas.CanvasModelSimple):
|
||||
BORDER = 4
|
||||
|
||||
def __init__(self, width, height):
|
||||
goocanvas.CanvasModelSimple.__init__(self)
|
||||
|
||||
root = self.get_root_item()
|
||||
|
||||
item = goocanvas.Rect(x=0, y=0, width=width, height=height,
|
||||
line_width=0, fill_color="#4f4f4f")
|
||||
root.add_child(item)
|
||||
|
||||
class PanelView(goocanvas.CanvasView):
|
||||
def construct(self):
|
||||
canvas_model = PanelModel(self.get_allocation().width,
|
||||
self.get_allocation().height)
|
||||
self.set_model(canvas_model)
|
||||
|
||||
class Panel(gtk.Window):
|
||||
def __init__(self):
|
||||
gtk.Window.__init__(self)
|
||||
|
||||
self._view = PanelView()
|
||||
self.add(self._view)
|
||||
self._view.show()
|
||||
|
||||
self.connect('realize', self.__realize_cb)
|
||||
|
||||
def get_view(self):
|
||||
return self._view
|
||||
|
||||
def get_model(self):
|
||||
return self._view.get_model()
|
||||
|
||||
def get_border(self):
|
||||
return PanelModel.BORDER
|
||||
|
||||
def get_height(self):
|
||||
height = self._view.get_allocation().height
|
||||
return height - self.get_border() * 2
|
||||
|
||||
def __realize_cb(self, window):
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK)
|
||||
|
||||
def construct(self):
|
||||
self._view.construct()
|
||||
|
||||
def show(self):
|
||||
gtk.Window.show(self)
|
||||
self.construct()
|
@ -0,0 +1,29 @@
|
||||
import gtk
|
||||
|
||||
from panel.VerbsPanel import VerbsPanel
|
||||
from panel.FriendsPanel import FriendsPanel
|
||||
from panel.Panel import Panel
|
||||
|
||||
class PanelManager:
|
||||
def __init__(self, shell):
|
||||
size = 30
|
||||
|
||||
self._verbs_panel = VerbsPanel(shell)
|
||||
self._verbs_panel.move(0, gtk.gdk.screen_height() - size)
|
||||
self._verbs_panel.resize(gtk.gdk.screen_width(), size)
|
||||
self._verbs_panel.show()
|
||||
|
||||
self._friends_panel = FriendsPanel(shell)
|
||||
self._friends_panel.move(gtk.gdk.screen_width() - size, 0)
|
||||
self._friends_panel.resize(size, gtk.gdk.screen_height())
|
||||
self._friends_panel.show()
|
||||
|
||||
panel = Panel()
|
||||
panel.move(0, 0)
|
||||
panel.resize(gtk.gdk.screen_width(), size)
|
||||
panel.show()
|
||||
|
||||
panel = Panel()
|
||||
panel.move(0, 0)
|
||||
panel.resize(size, gtk.gdk.screen_height())
|
||||
panel.show()
|
@ -0,0 +1,64 @@
|
||||
import gtk
|
||||
import goocanvas
|
||||
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconItem import IconColor
|
||||
from sugar import conf
|
||||
from panel.Panel import Panel
|
||||
|
||||
class ActivityItem(IconItem):
|
||||
def __init__(self, activity, size):
|
||||
IconItem.__init__(self, activity.get_icon(),
|
||||
IconColor('white'), size)
|
||||
self._activity = activity
|
||||
|
||||
def get_activity_id(self):
|
||||
return self._activity.get_id()
|
||||
|
||||
class ActivityBar(goocanvas.Group):
|
||||
def __init__(self, shell, height):
|
||||
goocanvas.Group.__init__(self)
|
||||
|
||||
self._shell = shell
|
||||
self._height = height
|
||||
|
||||
registry = conf.get_activity_registry()
|
||||
for activity in registry.list_activities():
|
||||
if activity.get_show_launcher():
|
||||
self.add_activity(activity)
|
||||
|
||||
def add_activity(self, activity):
|
||||
item = ActivityItem(activity, self._height)
|
||||
|
||||
icon_size = self._height
|
||||
x = (icon_size + 6) * self.get_n_children()
|
||||
item.set_property('x', x)
|
||||
|
||||
self.add_child(item)
|
||||
|
||||
class VerbsPanel(Panel):
|
||||
def __init__(self, shell):
|
||||
Panel.__init__(self)
|
||||
|
||||
self._shell = shell
|
||||
|
||||
view = self.get_view()
|
||||
view.connect("item_view_created", self.__item_view_created_cb)
|
||||
|
||||
def construct(self):
|
||||
Panel.construct(self)
|
||||
|
||||
root = self.get_model().get_root_item()
|
||||
|
||||
activity_bar = ActivityBar(self._shell, self.get_height())
|
||||
activity_bar.translate(self.get_border(), self.get_border())
|
||||
root.add_child(activity_bar)
|
||||
|
||||
def __item_view_created_cb(self, view, item_view, item):
|
||||
if isinstance(item, ActivityItem):
|
||||
item_view.connect("button_press_event",
|
||||
self.__activity_button_press_cb,
|
||||
item.get_activity_id())
|
||||
|
||||
def __activity_button_press_cb(self, view, target, event, activity_id):
|
||||
self._shell.start_activity(activity_id)
|
Loading…
Reference in New Issue