[Sugar-devel] [PATCH sugar v6] Show busy cursor during session shutdown

Sascha Silbe sascha-pgp at silbe.org
Tue Dec 14 14:22:29 EST 2010


Show a busy cursor when shutdown, logout, or reboot options are
selected.  Defer the selected action to an idle task so that the cursor
change is flushed to the display.

Co-Authored-By: James Cameron <quozl at laptop.org>
Co-Authored-By: Aleksey Lim <alsroot at member.fsf.org>
Co-Authored-By: Anurag Chowdhury <anurag at seeta.in>
Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>
---
 v5->v6: move cursor manipulation to jarabe.desktop.homewindow, ensure that
         cursor gets reset if shutdown is aborted (Keep Error)

 I still don't like the cross-call from BuddyMenu to HomeWindow (and Python
 shares my dislike - try to use "from jarabe.desktop import homewindow"
 instead of "import jarabe.desktop.homewindow" to see what I mean).
 But at least it's explicit API now instead of BuddyMenu manipulating
 HomeWindow's cursor behind its back.

 src/jarabe/desktop/homewindow.py |   14 ++++++++++++++
 src/jarabe/view/buddymenu.py     |   14 ++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/jarabe/desktop/homewindow.py b/src/jarabe/desktop/homewindow.py
index 945a9c1..07deff7 100644
--- a/src/jarabe/desktop/homewindow.py
+++ b/src/jarabe/desktop/homewindow.py
@@ -16,6 +16,7 @@

 import logging

+import gobject
 import gtk

 from sugar.graphics import style
@@ -187,6 +188,19 @@ class HomeWindow(gtk.Window):
     def get_home_box(self):
         return self._home_box

+    def busy_during_delayed_action(self, action):
+        """Use busy cursor during execution of action, scheduled via idle_add.
+        """
+        def action_wrapper(old_cursor):
+            try:
+                action()
+            finally:
+                self.get_window().set_cursor(old_cursor)
+
+        old_cursor = self.get_window().get_cursor()
+        self.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
+        gobject.idle_add(action_wrapper, old_cursor)
+

 def get_instance():
     global _instance
diff --git a/src/jarabe/view/buddymenu.py b/src/jarabe/view/buddymenu.py
index 61b10e9..f824e70 100644
--- a/src/jarabe/view/buddymenu.py
+++ b/src/jarabe/view/buddymenu.py
@@ -30,6 +30,7 @@ from jarabe.model import shell
 from jarabe.model import friends
 from jarabe.model.session import get_session_manager
 from jarabe.controlpanel.gui import ControlPanel
+import jarabe.desktop.homewindow


 class BuddyMenu(Palette):
@@ -104,17 +105,18 @@ class BuddyMenu(Palette):
         self.menu.append(item)
         item.show()

+    def _quit(self, action):
+        home_window = jarabe.desktop.homewindow.get_instance()
+        home_window.busy_during_delayed_action(action)
+
     def __logout_activate_cb(self, menu_item):
-        session_manager = get_session_manager()
-        session_manager.logout()
+        self._quit(get_session_manager().logout)

     def __reboot_activate_cb(self, menu_item):
-        session_manager = get_session_manager()
-        session_manager.reboot()
+        self._quit(get_session_manager().reboot)

     def __shutdown_activate_cb(self, menu_item):
-        session_manager = get_session_manager()
-        session_manager.shutdown()
+        self._quit(get_session_manager().shutdown)

     def __controlpanel_activate_cb(self, menu_item):
         panel = ControlPanel()
--
1.7.2.3



More information about the Sugar-devel mailing list