Start implementing the panels.

This commit is contained in:
Marco Pesenti Gritti 2006-08-23 11:52:18 +02:00
parent 9f674ef232
commit f53af6af4c
12 changed files with 187 additions and 68 deletions

View File

@ -1,4 +1,4 @@
AC_INIT([Sugar],[0.20],[],[sugar])
AC_INIT([Sugar],[0.22],[],[sugar])
AC_PREREQ([2.59])
@ -39,6 +39,7 @@ activities/terminal/Makefile
shell/Makefile
shell/data/Makefile
shell/home/Makefile
shell/panel/Makefile
shell/session/Makefile
shell/PresenceService/Makefile
sugar/Makefile

View File

@ -1,4 +1,4 @@
SUBDIRS = data session home PresenceService
SUBDIRS = data session home panel PresenceService
bin_SCRIPTS = \
sugar \

View File

@ -17,6 +17,7 @@ from ChatController import ChatController
from sugar.activity import ActivityFactory
from sugar.activity import Activity
from FirstTimeDialog import FirstTimeDialog
from panel.PanelManager import PanelManager
from sugar import conf
import sugar.logger
@ -102,6 +103,8 @@ class Shell(gobject.GObject):
self._home_window.set_model(home_model)
self._set_zoom_level(Shell.ZOOM_HOME)
self._panel_manager = PanelManager(self)
def set_console(self, console):
self._console = console

View File

@ -7,7 +7,6 @@ from sugar.canvas.IconItem import IconColor
from sugar.canvas.DonutItem import DonutItem
from sugar.canvas.DonutItem import PieceItem
from sugar.canvas.DonutItem import PieceIcon
from sugar import conf
class TasksItem(DonutItem):
def __init__(self, shell):
@ -39,50 +38,16 @@ class TasksItem(DonutItem):
self._items[activity.get_id()] = item
class ActivityItem(IconItem):
ICON_SIZE = 30
def __init__(self, activity):
IconItem.__init__(self, activity.get_icon(),
IconColor('white'),
ActivityItem.ICON_SIZE)
self._activity = activity
def get_activity_id(self):
return self._activity.get_id()
class ActivityBar(goocanvas.Group):
def __init__(self, shell):
goocanvas.Group.__init__(self)
self._shell = shell
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)
x = (ActivityItem.ICON_SIZE + 6) * self.get_n_children()
item.set_property('x', x)
self.add_child(item)
class Background(goocanvas.Group):
def __init__(self):
goocanvas.Group.__init__(self)
item = goocanvas.Rect(width=1200, height=900,
fill_color="#4f4f4f")
self.add_child(item)
item = goocanvas.Rect(x=50, y=50, width=1100, height=800,
line_width=0, fill_color="#d8d8d8",
radius_x=30, radius_y=30)
fill_color="#d8d8d8")
self.add_child(item)
item = goocanvas.Text(text="My Activities",
x=60, y=10, fill_color="white",
x=12, y=12, fill_color="black",
font="Sans 21")
self.add_child(item)
@ -95,10 +60,6 @@ class Model(goocanvas.CanvasModelSimple):
background = Background()
root.add_child(background)
activity_bar = ActivityBar(shell)
activity_bar.translate(50, 860)
root.add_child(activity_bar)
tasks = TasksItem(shell)
tasks.translate(600, 450)
root.add_child(tasks)
@ -119,11 +80,7 @@ class HomeView(goocanvas.CanvasView):
self.set_model(canvas_model)
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())
elif isinstance(item, PieceItem) or \
if isinstance(item, PieceItem) or \
isinstance(item, PieceIcon):
item_view.connect("button_press_event",
self.__task_button_press_cb)

View File

@ -0,0 +1,5 @@
from panel.Panel import Panel
class FriendsPanel(Panel):
def __init__(self, shell):
Panel.__init__(self)

7
shell/panel/Makefile.am Normal file
View File

@ -0,0 +1,7 @@
sugardir = $(pkgdatadir)/shell/panel
sugar_PYTHON = \
__init__.py \
FriendsPanel.py \
Panel.py \
PanelManager.py \
VerbsPanel.py

53
shell/panel/Panel.py Normal file
View File

@ -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()

View File

@ -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()

64
shell/panel/VerbsPanel.py Normal file
View File

@ -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)

0
shell/panel/__init__.py Normal file
View File

View File

@ -54,22 +54,6 @@ class XnestProcess(Process):
Process.start(self)
os.environ['DISPLAY'] = ":%d" % (self._display)
class DbusProcess(Process):
def __init__(self):
config = sugar.env.get_dbus_config()
cmd = "dbus-daemon --print-address --config-file %s" % config
Process.__init__(self, cmd)
def get_name(self):
return 'Dbus'
def start(self):
Process.start(self, True)
dbus_file = os.fdopen(self._stdout)
addr = dbus_file.readline().strip()
dbus_file.close()
os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr
class Emulator:
"""The OLPC emulator"""
def start(self):
@ -84,6 +68,3 @@ class Emulator:
print 'Cannot run the emulator. You need to install \
Xephyr or Xnest.'
sys.exit(0)
process = DbusProcess()
process.start()

View File

@ -9,6 +9,22 @@ from ConsoleWindow import ConsoleWindow
from session.Process import Process
import sugar.env
class DbusProcess(Process):
def __init__(self):
config = sugar.env.get_dbus_config()
cmd = "dbus-daemon --print-address --config-file %s" % config
Process.__init__(self, cmd)
def get_name(self):
return 'Dbus'
def start(self):
Process.start(self, True)
dbus_file = os.fdopen(self._stdout)
addr = dbus_file.readline().strip()
dbus_file.close()
os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr
class MatchboxProcess(Process):
def __init__(self):
kbd_config = os.path.join(sugar.env.get_data_dir(), 'kbdconfig')
@ -26,6 +42,9 @@ class Session:
"""Takes care of running the shell and all the sugar processes"""
def start(self):
"""Start the session"""
process = DbusProcess()
process.start()
process = MatchboxProcess()
process.start()