From da89103081c3f49d235699d2bd66e1109067e7f5 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 21 Apr 2006 14:02:54 -0400 Subject: [PATCH] Whitespace cleanup. Always use tabs and tabs are four spaces. --- shell/example-activity/example-activity.py | 222 ++++++++------- shell/src/shell.py | 303 +++++++++++---------- 2 files changed, 270 insertions(+), 255 deletions(-) diff --git a/shell/example-activity/example-activity.py b/shell/example-activity/example-activity.py index 17b640c6..3f0b97e1 100755 --- a/shell/example-activity/example-activity.py +++ b/shell/example-activity/example-activity.py @@ -1,4 +1,5 @@ #!/usr/bin/python +# -*- tab-width: 4; indent-tabs-mode: t -*- import string @@ -16,160 +17,173 @@ import gtk,sys class Activity(dbus.service.Object): - def __init__(self): - pass + 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 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() + 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.__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_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 + 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 + 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() + 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 + print "XEMBED window_id = %d"%self.__window_id - self.__plug = gtk.Plug(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) + # 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_object.set_peer_service_name(self.__peer_service_name, self.__peer_object_name) - self.activity_on_connected_to_shell() + self.activity_on_connected_to_shell() - def activity_get_gtk_plug(self): - return self.__plug + def activity_get_gtk_plug(self): + return self.__plug - def activity_set_tab_text(self, text): - self.__activity_object.set_tab_text(text) + 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 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 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() + @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 + def activity_get_id(self): + return self.__activity_id - def __reply_cb(self): - print "in __reply_cb" - self.activity_on_disconnected_from_shell() + def __shutdown_reply_cb(self): + print "in __reply_cb" - def __error_cb(self, error): - print "in __error_cb" + self.__plug.destroy() + self.__plug = None - def activity_shutdown(self): - self.__activity_object.shutdown(reply_handler = self.__reply_cb, error_handler = self.__error_cb) + self.__bus = None + self.__activity_container_object = None + self.__activity_container = None + self.__activity_object = None + self.__service = None - # pure virtual methods + self.__bus.remove_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged") - def activity_on_connected_to_shell(self): - print "act %d: you need to override activity_on_connected_to_shell"%self.activity_get_id() + self.activity_on_disconnected_from_shell() - 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() + del self - 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 __shutdown_error_cb(self, error): + print "in __error_cb" + + def activity_shutdown(self): + self.__activity_object.shutdown(reply_handler = self.__shutdown_reply_cb, error_handler = self.__shutdown_error_cb) + + # 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_from_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) + sys.exit(0) def deferred_exit(): - gobject.timeout_add(0, my_exit) + gobject.timeout_add(0, my_exit) ################################################################################ class ExampleActivity(Activity): - def __init__(self, name): - self.name = name + def __init__(self, name): + self.name = name - def entry_changed(self, entry): - self.activity_set_tab_text(entry.get_text()) - - def activity_on_connected_to_shell(self): - print "act %d: in activity_on_connected_to_shell"%self.activity_get_id() + def entry_changed(self, entry): + self.activity_set_tab_text(entry.get_text()) + + def activity_on_connected_to_shell(self): + print "act %d: in activity_on_connected_to_shell"%self.activity_get_id() - self.activity_set_tab_text(self.name) + self.activity_set_tab_text(self.name) - plug = self.activity_get_gtk_plug() - self.entry = gtk.Entry() - self.entry.set_text(self.name) - self.entry.connect("changed", self.entry_changed) - plug.add(self.entry) - plug.show_all() + plug = self.activity_get_gtk_plug() + self.entry = gtk.Entry() + self.entry.set_text(self.name) + self.entry.connect("changed", self.entry_changed) + plug.add(self.entry) + plug.show_all() - def activity_on_disconnected_from_shell(self): - print "act %d: in activity_on_disconnected_to_shell"%self.activity_get_id() - print "act %d: Shell disappeared..."%self.activity_get_id() - plug = self.activity_get_gtk_plug() - plug.destroy() + def activity_on_disconnected_from_shell(self): + print "act %d: in activity_on_disconnected_from_shell"%self.activity_get_id() + print "act %d: Shell disappeared..."%self.activity_get_id() - del self + gc.collect() - gc.collect() + def activity_on_close_from_user(self): + print "act %d: in activity_on_close_from_user"%self.activity_get_id() + self.activity_shutdown() - def activity_on_close_from_user(self): - print "act %d: in activity_on_close_from_user"%self.activity_get_id() - self.activity_shutdown() + def activity_on_lost_focus(self): + print "act %d: in activity_on_lost_focus"%self.activity_get_id() - def activity_on_lost_focus(self): - print "act %d: in activity_on_lost_focus"%self.activity_get_id() + def activity_on_got_focus(self): + print "act %d: in activity_on_got_focus"%self.activity_get_id() - def activity_on_got_focus(self): - print "act %d: in activity_on_got_focus"%self.activity_get_id() - - def __del__(self): - print "in __del__ for ExampleActivity" + def __del__(self): + print "in __del__ for ExampleActivity" if len(sys.argv) != 2: - print "usage: example-activity.py " - sys.exit(1) + print "usage: example-activity.py " + sys.exit(1) gc.set_debug(gc.DEBUG_LEAK) diff --git a/shell/src/shell.py b/shell/src/shell.py index b450f7bb..f5f648d5 100755 --- a/shell/src/shell.py +++ b/shell/src/shell.py @@ -1,4 +1,5 @@ #!/usr/bin/python +# -*- tab-width: 4; indent-tabs-mode: t -*- import string @@ -15,196 +16,196 @@ activity_counter = 0 class ActivityHost(dbus.service.Object): - def __init__(self, activity_container, activity_name): - global activity_counter + def __init__(self, activity_container, activity_name): + global activity_counter - self.activity_name = activity_name + self.activity_name = activity_name - self.activity_container = activity_container + self.activity_container = activity_container + + self.activity_id = activity_counter + activity_counter += 1 + + self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%d"%self.activity_id + print "object name = %s"%self.dbus_object_name + + dbus.service.Object.__init__(self, activity_container.service, self.dbus_object_name) + self.socket = gtk.Socket() + self.socket.set_data("sugar-activity", self) + self.socket.show() + + hbox = gtk.HBox(); + self.tab_activity_image = gtk.Image() + self.tab_activity_image.set_from_stock(gtk.STOCK_CONVERT, gtk.ICON_SIZE_MENU) + self.tab_activity_image.show() + + self.tab_label = gtk.Label(self.activity_name) + self.tab_label.show() + + self.tab_close_button = gtk.Button() + settings = self.tab_close_button.get_settings() + [w, h] = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) + self.tab_close_button.set_size_request(w + 2, h + 2) + close_image = gtk.Image() + close_image.set_from_stock (gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) + close_image.show() + self.tab_close_button.add(close_image) + self.tab_close_button.set_relief(gtk.RELIEF_NONE) + self.tab_close_button.set_focus_on_click(gtk.FALSE) + self.tab_close_button.show() + self.tab_close_button.connect("clicked", self.tab_close_button_clicked) + + hbox.set_spacing(4) + hbox.pack_start(self.tab_activity_image) + hbox.pack_start(self.tab_label) + hbox.pack_start(self.tab_close_button) + hbox.show() + + notebook = self.activity_container.notebook + index = notebook.append_page(self.socket, hbox) + notebook.set_current_page(index) + + def tab_close_button_clicked(self, button): + self.peer_service.close_from_user() - self.activity_id = activity_counter - activity_counter += 1 + @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ + in_signature="", \ + out_signature="t") + def get_host_xembed_id(self): + window_id = self.socket.get_id() + print "window_id = %d"%window_id + return window_id - self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%d"%self.activity_id - print "object name = %s"%self.dbus_object_name - - dbus.service.Object.__init__(self, activity_container.service, self.dbus_object_name) - self.socket = gtk.Socket() - self.socket.set_data("sugar-activity", self) - self.socket.show() - - hbox = gtk.HBox(); - self.tab_activity_image = gtk.Image() - self.tab_activity_image.set_from_stock(gtk.STOCK_CONVERT, gtk.ICON_SIZE_MENU) - self.tab_activity_image.show() - - self.tab_label = gtk.Label(self.activity_name) - self.tab_label.show() - - self.tab_close_button = gtk.Button() - settings = self.tab_close_button.get_settings() - [w, h] = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) - self.tab_close_button.set_size_request(w + 2, h + 2) - close_image = gtk.Image() - close_image.set_from_stock (gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) - close_image.show() - self.tab_close_button.add(close_image) - self.tab_close_button.set_relief(gtk.RELIEF_NONE) - self.tab_close_button.set_focus_on_click(gtk.FALSE) - self.tab_close_button.show() - self.tab_close_button.connect("clicked", self.tab_close_button_clicked) - - hbox.set_spacing(4) - hbox.pack_start(self.tab_activity_image) - hbox.pack_start(self.tab_label) - hbox.pack_start(self.tab_close_button) - hbox.show() - - notebook = self.activity_container.notebook - index = notebook.append_page(self.socket, hbox) - notebook.set_current_page(index) - - def tab_close_button_clicked(self, button): - self.peer_service.close_from_user() - - @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ - in_signature="", \ - out_signature="t") - def get_host_xembed_id(self): - window_id = self.socket.get_id() - print "window_id = %d"%window_id - return window_id - - @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ + @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ in_signature="ss", \ out_signature="") - def set_peer_service_name(self, peer_service_name, peer_object_name): - print "peer_service_name = %s, peer_object_name = %s"%(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( \ - self.__peer_service_name, self.__peer_object_name), \ - "com.redhat.Sugar.Activity") + def set_peer_service_name(self, peer_service_name, peer_object_name): + print "peer_service_name = %s, peer_object_name = %s"%(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( \ + self.__peer_service_name, self.__peer_object_name), \ + "com.redhat.Sugar.Activity") - @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ + @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ in_signature="s", \ out_signature="") - def set_tab_text(self, text): - self.tab_label.set_text(text) + def set_tab_text(self, text): + self.tab_label.set_text(text) - @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ - in_signature="", \ - out_signature="") - def shutdown(self): - print "shutdown" - for owner, activity in self.activity_container.activities[:]: - if activity == self: - self.activity_container.activities.remove((owner, activity)) + @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ + in_signature="", \ + out_signature="") + def shutdown(self): + print "shutdown" + for owner, activity in self.activity_container.activities[:]: + if activity == self: + self.activity_container.activities.remove((owner, activity)) + + for i in range(self.activity_container.notebook.get_n_pages()): + child = self.activity_container.notebook.get_nth_page(i) + if child == self.socket: + print "found child" + self.activity_container.notebook.remove_page(i) + break - for i in range(self.activity_container.notebook.get_n_pages()): - child = self.activity_container.notebook.get_nth_page(i) - if child == self.socket: - print "found child" - self.activity_container.notebook.remove_page(i) - break + del self - del self + def get_host_activity_id(self): + return self.activity_id - def get_host_activity_id(self): - return self.activity_id - - def get_object_path(self): - return self.dbus_object_name + def get_object_path(self): + return self.dbus_object_name class ActivityContainer(dbus.service.Object): - def __init__(self, service, bus): + def __init__(self, service, bus): - self.activities = [] + self.activities = [] - self.bus = bus - self.service = service + self.bus = bus + self.service = service - dbus.service.Object.__init__(self, self.service, "/com/redhat/Sugar/Shell/ActivityContainer") - bus.add_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged") + dbus.service.Object.__init__(self, self.service, "/com/redhat/Sugar/Shell/ActivityContainer") + bus.add_signal_receiver(self.name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged") - self.window = gtk.Window() - self.window.set_title("OLPC Sugar") - self.window.resize(640, 480) - self.window.set_geometry_hints(min_width = 640, max_width = 640, min_height = 480, max_height = 480) - self.notebook = gtk.Notebook() - tab_label = gtk.Label("My Laptop") - empty_label = gtk.Label("This activity could launch other activities / be a help page") - empty_label.show() - self.notebook.append_page(empty_label, tab_label) - self.notebook.show() - self.notebook.connect("switch-page", self.notebook_tab_changed) - self.window.add(self.notebook) - - self.window.connect("destroy", lambda w: gtk.main_quit()) - self.window.show() - - self.current_activity = None + self.window = gtk.Window() + self.window.set_title("OLPC Sugar") + self.window.resize(640, 480) + self.window.set_geometry_hints(min_width = 640, max_width = 640, min_height = 480, max_height = 480) + self.notebook = gtk.Notebook() + tab_label = gtk.Label("My Laptop") + empty_label = gtk.Label("This activity could launch other activities / be a help page") + empty_label.show() + self.notebook.append_page(empty_label, tab_label) + self.notebook.show() + self.notebook.connect("switch-page", self.notebook_tab_changed) + self.window.add(self.notebook) + + self.window.connect("destroy", lambda w: gtk.main_quit()) + self.window.show() + + self.current_activity = None - def __focus_reply_cb(self): - pass + def __focus_reply_cb(self): + pass - def __focus_error_cb(self, error): - pass + def __focus_error_cb(self, error): + pass - def notebook_tab_changed(self, notebook, page, page_number): - print "in notebook_tab_changed" - new_activity = notebook.get_nth_page(page_number).get_data("sugar-activity") - print " Current activity: ", self.current_activity - print " New activity: ", new_activity + def notebook_tab_changed(self, notebook, page, page_number): + print "in notebook_tab_changed" + new_activity = notebook.get_nth_page(page_number).get_data("sugar-activity") + print " Current activity: ", self.current_activity + print " New activity: ", new_activity - if self.current_activity != None: - if self.has_activity(self.current_activity): - self.current_activity.peer_service.lost_focus(reply_handler = self.__focus_reply_cb, error_handler = self.__focus_error_cb) + if self.current_activity != None: + if self.has_activity(self.current_activity): + self.current_activity.peer_service.lost_focus(reply_handler = self.__focus_reply_cb, error_handler = self.__focus_error_cb) + + self.current_activity = new_activity - self.current_activity = new_activity - - if self.current_activity != None: - if self.has_activity(self.current_activity): - self.current_activity.peer_service.got_focus(reply_handler = self.__focus_reply_cb, error_handler = self.__focus_error_cb) + if self.current_activity != None: + if self.has_activity(self.current_activity): + self.current_activity.peer_service.got_focus(reply_handler = self.__focus_reply_cb, error_handler = self.__focus_error_cb) - def has_activity(self, activity_to_check_for): - for owner, activity in self.activities[:]: - if activity_to_check_for == activity: - return True - return False + def has_activity(self, activity_to_check_for): + for owner, activity in self.activities[:]: + if activity_to_check_for == activity: + return True + return False - 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) - for owner, activity in self.activities[:]: - if owner == old_service_name: - self.activities.remove((owner, activity)) - self.__print_activities() + 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) + for owner, activity in self.activities[:]: + if owner == old_service_name: + self.activities.remove((owner, activity)) + self.__print_activities() - @dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \ + @dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \ in_signature="s", \ out_signature="i", \ sender_keyword="sender") - def add_activity(self, activity_name, sender): - print "hello world, activity_name = '%s', sender = '%s'"%(activity_name, sender) - activity = ActivityHost(self, activity_name) - self.activities.append((sender, activity)) + def add_activity(self, activity_name, sender): + print "hello world, activity_name = '%s', sender = '%s'"%(activity_name, sender) + activity = ActivityHost(self, activity_name) + self.activities.append((sender, activity)) - self.__print_activities() - return activity.get_host_activity_id() + self.__print_activities() + return activity.get_host_activity_id() - def __print_activities(self): - print "__print_activities: %d activities registered"%len(self.activities) - i = 0 - for owner, activity in self.activities: - print " %d: owner=%s activity_object_name=%s"%(i, owner, activity.dbus_object_name) - i += 1 + def __print_activities(self): + print "__print_activities: %d activities registered"%len(self.activities) + i = 0 + for owner, activity in self.activities: + print " %d: owner=%s activity_object_name=%s"%(i, owner, activity.dbus_object_name) + i += 1