Port to new shell API

This commit is contained in:
Marco Pesenti Gritti 2006-04-20 22:02:51 -04:00
parent 31da882217
commit 6f9dd97073
2 changed files with 148 additions and 53 deletions

View File

@ -3,5 +3,5 @@ DEPENDENCIES
gecko-embed gecko-embed
http://gnome.org/~marco/gecko-embed-0.1-2.i386.rpm http://gnome.org/~marco/gecko-embed-0.1-3.i386.rpm
http://gnome.org/~marco/gecko-embed-0.1-2.src.rpm http://gnome.org/~marco/gecko-embed-0.1-3.src.rpm

View File

@ -10,6 +10,107 @@ import gtk
import geckoembed import geckoembed
################################################################################
# Code below will be moved to a module someday
class Activity(dbus.service.Object):
def __init__(self):
pass
def name_owner_changed(self, service_name, old_service_name, new_service_name):
#print "in name_owner_changed: svc=%s oldsvc=%s newsvc=%s"%(service_name, old_service_name, new_service_name)
if service_name == "com.redhat.Sugar.Shell" and new_service_name == "":
self.activity_on_disconnected_from_shell()
#elif service_name == "com.redhat.Sugar.Shell" and old_service_name == "":
# self.activity_on_shell_reappeared()
def activity_connect_to_shell(self):
self.__bus = dbus.SessionBus()
self.__bus.add_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged")
self.__activity_container_object = self.__bus.get_object("com.redhat.Sugar.Shell", \
"/com/redhat/Sugar/Shell/ActivityContainer")
self.__activity_container = dbus.Interface(self.__activity_container_object, \
"com.redhat.Sugar.Shell.ActivityContainer")
self.__activity_id = self.__activity_container.add_activity("")
self.__object_path = "/com/redhat/Sugar/Shell/Activities/%d"%self.__activity_id
print "object_path = %s"%self.__object_path
self.__activity_object = dbus.Interface(self.__bus.get_object("com.redhat.Sugar.Shell", self.__object_path), \
"com.redhat.Sugar.Shell.ActivityHost")
self.__window_id = self.__activity_object.get_host_xembed_id()
print "XEMBED window_id = %d"%self.__window_id
self.__plug = gtk.Plug(self.__window_id)
# Now let the Activity register a peer service so the Shell can poke it
self.__peer_service_name = "com.redhat.Sugar.Activity%d"%self.__activity_id
self.__peer_object_name = "/com/redhat/Sugar/Activity/%d"%self.__activity_id
self.__service = dbus.service.BusName(self.__peer_service_name, bus=self.__bus)
dbus.service.Object.__init__(self, self.__service, self.__peer_object_name)
self.__activity_object.set_peer_service_name(self.__peer_service_name, self.__peer_object_name)
self.activity_on_connected_to_shell()
def activity_get_gtk_plug(self):
return self.__plug
def activity_set_tab_text(self, text):
self.__activity_object.set_tab_text(text)
@dbus.service.method("com.redhat.Sugar.Activity", \
in_signature="", \
out_signature="")
def lost_focus(self):
self.activity_on_lost_focus()
@dbus.service.method("com.redhat.Sugar.Activity", \
in_signature="", \
out_signature="")
def got_focus(self):
self.activity_on_got_focus()
@dbus.service.method("com.redhat.Sugar.Activity", \
in_signature="", \
out_signature="")
def close_from_user(self):
self.activity_on_close_from_user()
def activity_get_id(self):
return self.__activity_id
# pure virtual methods
def activity_on_connected_to_shell(self):
print "act %d: you need to override activity_on_connected_to_shell"%self.activity_get_id()
def activity_on_disconnected_from_shell(self):
print "act %d: you need to override activity_on_disconnected_to_shell"%self.activity_get_id()
def activity_on_close_from_user(self):
print "act %d: you need to override activity_on_close_from_user"%self.activity_get_id()
def activity_on_lost_focus(self):
print "act %d: you need to override activity_on_lost_focus"%self.activity_get_id()
def activity_on_got_focus(self):
print "act %d: you need to override activity_on_got_focus"%self.activity_get_id()
def my_exit():
sys.exit(0)
def deferred_exit():
gobject.timeout_add(0, my_exit)
################################################################################
class AddressToolbar(gtk.Toolbar): class AddressToolbar(gtk.Toolbar):
def __init__(self): def __init__(self):
gtk.Toolbar.__init__(self) gtk.Toolbar.__init__(self)
@ -19,7 +120,8 @@ class AddressToolbar(gtk.Toolbar):
address_item.show() address_item.show()
def __open_address_cb(self, address): def __open_address_cb(self, address):
web_activity.openAddress(address) browser = BrowserActivity(uri)
browser.activity_connect_to_shell()
class AddressItem(gtk.ToolItem): class AddressItem(gtk.ToolItem):
def __init__(self, callback): def __init__(self, callback):
@ -129,77 +231,70 @@ class NavigationToolbar(gtk.Toolbar):
def __open_address_cb(self, address): def __open_address_cb(self, address):
self.embed.load_url(address) self.embed.load_url(address)
class BrowserActivity(gtk.VBox): class BrowserActivity(Activity):
def __init__(self, uri): def __init__(self, uri):
gtk.VBox.__init__(self) Activity.__init__(self)
self.uri = uri
def activity_on_connected_to_shell(self):
self.activity_set_tab_text("Web Page")
vbox = gtk.VBox()
self.embed = geckoembed.Embed() self.embed = geckoembed.Embed()
self.pack_start(self.embed) self.embed.connect("title", self.__title_cb)
vbox.pack_start(self.embed)
self.embed.show() self.embed.show()
self.embed.load_url(uri) self.embed.load_url(self.uri)
nav_toolbar = NavigationToolbar(self.embed) nav_toolbar = NavigationToolbar(self.embed)
self.pack_start(nav_toolbar, False) vbox.pack_start(nav_toolbar, False)
nav_toolbar.show() nav_toolbar.show()
class SearchActivity(gtk.VBox): plug = self.activity_get_gtk_plug()
def __init__(self): plug.add(vbox)
gtk.VBox.__init__(self) plug.show()
self.connect("delete-event", self.__delete_event); vbox.show()
def __title_cb(self, embed):
self.activity_set_tab_text(embed.get_title())
class WebActivity(Activity):
def __init__(self):
Activity.__init__(self)
def activity_on_connected_to_shell(self):
self.activity_set_tab_text("Web Browser")
vbox = gtk.VBox()
self.embed = geckoembed.Embed() self.embed = geckoembed.Embed()
self.embed.connect("open-address", self.__open_address); self.embed.connect("open-address", self.__open_address);
vbox.pack_start(self.embed)
self.pack_start(self.embed)
self.embed.show() self.embed.show()
address_toolbar = AddressToolbar() address_toolbar = AddressToolbar()
self.pack_start(address_toolbar, False) vbox.pack_start(address_toolbar, False)
address_toolbar.show() address_toolbar.show()
self.embed.load_url("http://www.google.com") plug = self.activity_get_gtk_plug()
plug.add(vbox)
plug.show()
def __delete_event(self, widget, event, data=None): vbox.show()
return True;
self.embed.load_url("http://www.google.com")
def __open_address(self, embed, uri, data=None): def __open_address(self, embed, uri, data=None):
if uri.startswith("http://www.google.com"): if uri.startswith("http://www.google.com"):
return False return False
else: else:
web_activity.openAddress(uri) browser = BrowserActivity(uri)
browser.activity_connect_to_shell()
return True return True
class WebActivity:
def __init__(self):
bus = dbus.SessionBus()
container_object = bus.get_object("com.redhat.Sugar.Shell", \
"/com/redhat/Sugar/Shell/ActivityContainer")
self.container = dbus.Interface(container_object, \
"com.redhat.Sugar.Shell.ActivityContainer")
def run(self):
window_id = self.container.add_activity("Web")
plug = gtk.Plug(window_id)
window = SearchActivity()
plug.add(window)
window.show()
plug.show()
def openAddress(self, uri):
window_id = self.container.add_activity("Page")
plug = gtk.Plug(window_id)
window = BrowserActivity(uri)
plug.add(window)
window.show()
plug.show()
web_activity = WebActivity() web_activity = WebActivity()
web_activity.run() web_activity.activity_connect_to_shell()
gtk.main() gtk.main()