More work on the new design

This commit is contained in:
Marco Pesenti Gritti 2006-07-08 15:47:51 +02:00
parent 0cbe559dbf
commit d4cb9a2714
9 changed files with 105 additions and 113 deletions

View File

@ -26,7 +26,10 @@ class BrowserActivity(Activity):
def __init__(self, args):
Activity.__init__(self, _BROWSER_ACTIVITY_TYPE)
self.uri = args[0]
if len(args) > 0:
self.uri = args[0]
else:
self.uri = 'http://www.google.com'
self._mode = BrowserActivity.SOLO
self._share_service = None
@ -76,11 +79,7 @@ class BrowserActivity(Activity):
self._notif_bar.show()
def on_connected_to_shell(self):
self.set_ellipsize_tab(True)
self.set_can_close(True)
self.set_tab_text("Web Page")
self.set_tab_icon(name="web-browser")
self.set_show_tab_icon(True)
self.set_title("Web Page")
vbox = gtk.VBox()
@ -99,10 +98,7 @@ class BrowserActivity(Activity):
vbox.pack_start(nav_toolbar, False)
nav_toolbar.show()
plug = self.gtk_plug()
plug.add(vbox)
plug.show()
self.add(vbox)
vbox.show()
logging.debug('Start presence service')

View File

@ -7,7 +7,6 @@ from sugar.chat.ChatWindow import ChatWindow
from sugar.chat.MeshChat import MeshChat
from ActivityHost import ActivityHost
from PresenceWindow import PresenceWindow
from HomeWindow import HomeWindow
from WindowManager import WindowManager
from StartPage import StartPage
from Owner import ShellOwner
@ -66,16 +65,6 @@ class ActivityContainer(dbus.service.Object):
self._mesh_chat = MeshChat()
home_window = HomeWindow()
wm = WindowManager(home_window)
wm.set_type(WindowManager.TYPE_POPUP)
wm.set_animation(WindowManager.ANIMATION_SLIDE_IN)
wm.set_geometry(0.1, 0.1, 0.9, 0.9)
wm.set_key(gtk.keysyms.F2)
def show(self):
self.window.show()
def set_current_activity(self, activity):
self.current_activity = activity
self._presence_window.set_activity(activity)
@ -93,26 +82,21 @@ class ActivityContainer(dbus.service.Object):
self._signal_helper.activity_ended(activity_id)
self._activities.remove((owner, activity))
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
in_signature="ss", \
out_signature="s", \
sender_keyword="sender")
def add_activity(self, activity_name, default_type, sender):
activity = ActivityHost(self, activity_name, default_type)
self._activities.append((sender, activity))
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer")
def add_activity(self, default_type):
activity = ActivityHost(self._service, default_type)
self._activities.append(activity)
activity_id = activity.get_host_activity_id()
activity_id = activity.get_id()
self._signal_helper.activity_started(activity_id)
self.current_activity = activity
self.set_current_activity(activity)
return activity_id
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
in_signature="sss", \
sender_keyword="sender")
def add_activity_with_id(self, activity_name, default_type, activity_id, sender):
activity = ActivityHost(self, activity_name, default_type, activity_id)
self._activities.append((sender, activity))
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer")
def add_activity_with_id(self, default_type, activity_id):
activity = ActivityHost(self._service, default_type, activity_id)
self._activities.append(activity)
activity_id = activity.get_host_activity_id()
self._signal_helper.activity_started(activity_id)
self.current_activity = activity

View File

@ -2,6 +2,10 @@ import dbus
import gtk
import gobject
from sugar.chat.ActivityChat import ActivityChat
from WindowManager import WindowManager
import sugar.util
class ActivityHostSignalHelper(gobject.GObject):
__gsignals__ = {
'shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
@ -15,22 +19,22 @@ class ActivityHostSignalHelper(gobject.GObject):
self.emit('shared')
class ActivityHost(dbus.service.Object):
def __init__(self, default_type, activity_id = None):
def __init__(self, bus_name, default_type, activity_id = None):
if activity_id is None:
self.activity_id = sugar.util.unique_id()
self._activity_id = sugar.util.unique_id()
else:
self.activity_id = activity_id
self._activity_id = activity_id
self._default_type = default_type
self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%s" % self.activity_id
dbus.service.Object.__init__(self, activity_container.service, self.dbus_object_name)
self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%s" % self._activity_id
dbus.service.Object.__init__(self, bus_name, self.dbus_object_name)
self._signal_helper = ActivityHostSignalHelper(self)
self.peer_service = None
self._shared = False
self._window = gtk.Window()
self._create_chat()
def _create_chat(self):
self._activity_chat = ActivityChat(self)
@ -54,15 +58,10 @@ class ActivityHost(dbus.service.Object):
def connect(self, signal, func):
self._signal_helper.connect(signal, func)
def get_host_activity_id(self):
"""Real function that the shell should use for getting the
activity's ID."""
return self.activity_id
def get_id(self):
"""Interface-type function to match activity.Activity's
get_id() function."""
return self.activity_id
return self._activity_id
def default_type(self):
"""Interface-type function to match activity.Activity's
@ -81,25 +80,20 @@ class ActivityHost(dbus.service.Object):
self._shared = True
self._signal_helper.emit_shared()
@dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \
in_signature="ss", \
out_signature="")
@dbus.service.method("com.redhat.Sugar.Shell.ActivityHost")
def set_peer_service_name(self, peer_service_name, peer_object_name):
self.__peer_service_name = peer_service_name
self.__peer_object_name = peer_object_name
self.peer_service = dbus.Interface(self.activity_container.bus.get_object( \
session_bus = dbus.SessionBus()
self.peer_service = dbus.Interface(session_bus.get_object( \
self.__peer_service_name, self.__peer_object_name), \
"com.redhat.Sugar.Activity")
self.activity_container.bus.add_signal_receiver(self._shared_signal,
session_bus.add_signal_receiver(self._shared_signal,
signal_name="ActivityShared",
dbus_interface="com.redhat.Sugar.Activity",
named_service=self.__peer_service_name,
path=self.__peer_object_name)
@dbus.service.method("com.redhat.Sugar.Shell.ActivityHost")
def set_can_close(self, can_close):
pass
@dbus.service.method("com.redhat.Sugar.Shell.ActivityHost")
def set_has_changes(self, has_changes):
pass

View File

@ -25,6 +25,5 @@ class ActivityRegistry(dbus.service.Object):
def add(self, name, title):
self._activities.append(ActivityInfo(name, title))
@dbus.service.method("com.redhat.Sugar.ActivityRegistry")
def list_activities(self):
return self._activities

View File

@ -24,6 +24,7 @@ class ConsoleLogger(dbus.service.Object):
console_wm = WindowManager(self._window)
console_wm.set_type(WindowManager.TYPE_POPUP)
console_wm.set_geometry(0.1, 0.1, 0.8, 0.8)
console_wm.set_key(gtk.keysyms.F3)
def _create_console(self, application):
sw = gtk.ScrolledWindow()

View File

@ -1,45 +1,50 @@
from gettext import gettext as _
import gtk
from sugar.activity import Activity
class NewActivityButton(gtk.Button):
def __init__(self):
gtk.Button.__init__(self)
class NewActivityButton(gtk.MenuToolButton):
def __init__(self, shell):
gtk.MenuToolButton.__init__(self, None, _('New Activity'))
hbox = gtk.HBox(False, 6)
self._shell = shell
label = gtk.Label("New Activity")
hbox.pack_start(label)
label.show()
arrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_NONE)
hbox.pack_start(arrow)
arrow.show()
self.set_image(hbox)
self.connect("clicked", self.__clicked_cb)
self.set_menu(gtk.Menu())
self.connect("show-menu", self.__show_menu_cb)
def __clicked_cb(self, button):
print Activity.list_activities
class Toolbar(gtk.HBox):
def __init__(self):
gtk.HBox.__init__(self)
def __show_menu_cb(self, button):
menu = gtk.Menu()
new_activity_button = NewActivityButton()
self.pack_start(new_activity_button)
for activity_info in self._shell.get_registry().list_activities():
item = gtk.MenuItem(activity_info.get_title(), False)
name = activity_info.get_name()
item.connect('activate', self.__menu_item_activate_cb, name)
menu.append(item)
item.show()
self.set_menu(menu)
def __menu_item_activate_cb(self, item, name):
Activity.create(name)
class Toolbar(gtk.Toolbar):
def __init__(self, shell):
gtk.Toolbar.__init__(self)
new_activity_button = NewActivityButton(shell)
self.insert(new_activity_button, -1)
new_activity_button.show()
class HomeWindow(gtk.Window):
def __init__(self):
def __init__(self, shell):
gtk.Window.__init__(self)
vbox = gtk.VBox()
toolbar = Toolbar()
vbox.pack_start(toolbar)
toolbar = Toolbar(shell)
vbox.pack_start(toolbar, False)
toolbar.show()
self.add(vbox)
vbox.show()

View File

@ -1,4 +1,5 @@
import dbus
import gtk
import gobject
from sugar.LogWriter import LogWriter
@ -6,6 +7,7 @@ from WindowManager import WindowManager
from ConsoleLogger import ConsoleLogger
from ActivityContainer import ActivityContainer
from ActivityRegistry import ActivityRegistry
from HomeWindow import HomeWindow
class Shell(gobject.GObject):
__gsignals__ = {
@ -22,12 +24,29 @@ class Shell(gobject.GObject):
log_writer = LogWriter("Shell", False)
log_writer.start()
registry = ActivityRegistry()
self._registry = ActivityRegistry()
root_window = gtk.Window()
root_window.set_title('Sugar')
wm = WindowManager(root_window)
wm.set_type(WindowManager.TYPE_ROOT)
wm.show()
home_window = HomeWindow(self)
home_window.set_transient_for(root_window)
wm = WindowManager(home_window)
wm.set_type(WindowManager.TYPE_POPUP)
wm.set_animation(WindowManager.ANIMATION_SLIDE_IN)
wm.set_geometry(0.1, 0.1, 0.8, 0.8)
wm.set_key(gtk.keysyms.F2)
wm.show()
session_bus = dbus.SessionBus()
service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus)
activity_container = ActivityContainer(service, session_bus)
def get_registry(self):
return self._registry
if __name__ == "__main__":
shell = Shell()

View File

@ -63,8 +63,9 @@ class SlidingHelper:
class WindowManager:
__managers_list = []
TYPE_ACTIVITY = 0
TYPE_POPUP = 1
TYPE_ROOT = 0
TYPE_ACTIVITY = 1
TYPE_POPUP = 2
ANIMATION_NONE = 0
ANIMATION_SLIDE_IN = 1
@ -134,7 +135,7 @@ class WindowManager:
screen_height = DEFAULT_HEIGHT
for manager in WindowManager.__managers_list:
if manager._window_type == WindowManager.TYPE_ACTIVITY:
if manager._window_type == WindowManager.TYPE_ROOT:
screen_width = manager._window.allocation.width
screen_height = manager._window.allocation.height
@ -143,7 +144,7 @@ class WindowManager:
def _get_screen_position(self):
result = (0, 0)
for manager in WindowManager.__managers_list:
if manager._window_type == WindowManager.TYPE_ACTIVITY:
if manager._window_type == WindowManager.TYPE_ROOT:
result = manager._window.get_position()
return result
@ -171,7 +172,8 @@ class WindowManager:
self._window.set_skip_taskbar_hint(True)
def _update_size(self):
if self._window_type == WindowManager.TYPE_ACTIVITY:
if (self._window_type == WindowManager.TYPE_ACTIVITY) or \
(self._window_type == WindowManager.TYPE_ROOT):
self._window.resize(DEFAULT_WIDTH, DEFAULT_HEIGHT)
else:
(width, height) = self._transform_dimensions()

View File

@ -68,8 +68,8 @@ class ActivityFactory(dbus.service.Object):
gobject.idle_add(self._start_activity_cb, activity, service)
@dbus.service.method("com.redhat.Sugar.ActivityFactory")
def create(self, args):
self.create_with_service(None, args)
def create(self):
self.create_with_service(None, [])
def _start_activity_cb(self, activity, service):
activity.connect_to_shell(service)
@ -84,17 +84,17 @@ def create(activity_name, service = None, args = None):
proxy_obj = bus.get_object(factory_name, factory_path)
factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory")
if service:
if service and args:
serialized_service = service.serialize(service)
factory.create_with_service(serialized_service, args)
else:
factory.create(args)
factory.create()
def _get_registry():
bus = dbus.SessionBus()
proxy_obj = bus.get_object("com.redhat.Sugar.ActivityRegistry",
"/com/redhat/Sugar/ActivityRegistry")
registry = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityRegistry")
return dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityRegistry")
def list_activities():
registry = _get_registry()
@ -168,10 +168,10 @@ class ActivityDbusService(dbus.service.Object):
SHELL_SERVICE_NAME + ".ActivityContainer")
if service is None:
self._activity_id = self._activity_container.add_activity("", self._activity.default_type())
self._activity_id = self._activity_container.add_activity(self._activity.default_type())
else:
self._activity_id = service.get_activity_id()
self._activity_container.add_activity_with_id("", self._activity.default_type(), self._activity_id)
self._activity_container.add_activity_with_id(self._activity.default_type(), self._activity_id)
self._object_path = SHELL_SERVICE_PATH + "/Activities/%s" % self._activity_id
@ -236,10 +236,12 @@ class ActivityDbusService(dbus.service.Object):
def ActivityShared(self):
pass
class Activity(object):
class Activity(gtk.Window):
"""Base Activity class that all other Activities derive from."""
def __init__(self, default_type):
gtk.Window.__init__(self)
self._dbus_service = self._get_new_dbus_service()
self._dbus_service.register_callback(ON_CONNECTED_TO_SHELL_CB, self._internal_on_connected_to_shell_cb)
self._dbus_service.register_callback(ON_DISCONNECTED_FROM_SHELL_CB, self._internal_on_disconnected_from_shell_cb)
@ -249,7 +251,6 @@ class Activity(object):
self._dbus_service.register_callback(ON_LOST_FOCUS_CB, self._internal_on_lost_focus_cb)
self._dbus_service.register_callback(ON_GOT_FOCUS_CB, self._internal_on_got_focus_cb)
self._has_focus = False
self._plug = None
self._initial_service = None
self._activity_object = None
self._shared = False
@ -258,9 +259,6 @@ class Activity(object):
self._default_type = default_type
def _cleanup(self):
if self._plug:
self._plug.destroy()
self._plug = None
if self._dbus_service:
del self._dbus_service
self._dbus_service = None
@ -292,15 +290,13 @@ class Activity(object):
def connect_to_shell(self, service = None):
"""Called by our controller to tell us to initialize and connect
to the shell."""
self.show()
self._dbus_service.connect_to_shell(service)
def _internal_on_connected_to_shell_cb(self, activity_object, activity_id, service=None):
"""Callback when the dbus service object has connected to the shell."""
self._activity_object = activity_object
self._activity_id = activity_id
self._window_id = self._activity_object.get_host_xembed_id()
print "Activity: XEMBED window ID is %s" % self._window_id
self._plug = gtk.Plug(self._window_id)
self._initial_service = service
if service:
self.set_shared()
@ -335,10 +331,6 @@ class Activity(object):
self.set_has_changes(False)
self.on_got_focus()
def gtk_plug(self):
"""Return our GtkPlug widget."""
return self._plug
def set_ellipsize_tab(self, ellipsize):
"""Sets this Activity's tab text to be ellipsized or not."""
self._activity_object.set_ellipsize_tab(ellipsize)