Ticket #245: 0001-Show-busy-cursor-while-a-CP-section-is-loading-SL-24.patch

File 0001-Show-busy-cursor-while-a-CP-section-is-loading-SL-24.patch, 3.2 KB (added by manuq, 11 years ago)

Patch

  • src/jarabe/controlpanel/gui.py

    From 21e5403bf511abc1619e3f159e898d7b3278f4b8 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Mon, 25 Mar 2013 17:14:42 -0300
    Subject: [PATCH] Show busy cursor while a CP section is loading - SL #245
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    This takes commit df126bad as reference and wraps the time consuming
    action in a function which is called with GObject.idle_add.
    
    I have also added a blank canvas while the section is loading.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/jarabe/controlpanel/gui.py | 35 +++++++++++++++++++++++++----------
     1 file changed, 25 insertions(+), 10 deletions(-)
    
    diff --git a/src/jarabe/controlpanel/gui.py b/src/jarabe/controlpanel/gui.py
    index c61fb4e..f41a266 100644
    a b class ControlPanel(Gtk.Window): 
    234234        self._section_toolbar.connect('accept-clicked',
    235235                                     self.__accept_clicked_cb)
    236236
     237    def busy_during_delayed_action(self, action):
     238        """Use busy cursor during execution of action, scheduled via idle_add.
     239        """
     240        def action_wrapper(old_cursor):
     241            try:
     242                action()
     243            finally:
     244                self.get_window().set_cursor(old_cursor)
     245
     246        old_cursor = self.get_window().get_cursor()
     247        self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
     248        GObject.idle_add(action_wrapper, old_cursor)
     249
    237250    def show_section_view(self, option):
    238251        self._set_toolbar(self._section_toolbar)
    239252
    class ControlPanel(Gtk.Window): 
    255268                         globals(), locals(), ['model'])
    256269        model = ModelWrapper(mod)
    257270
    258         try:
    259             self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
     271        def change_canvas():
    260272            self._section_view = view_class(model,
    261273                                            self._options[option]['alerts'])
    262 
    263274            self._set_canvas(self._section_view)
    264275            self._section_view.show()
    265         finally:
    266             self.get_window().set_cursor(None)
    267 
    268         self._section_view.connect('notify::is-valid',
    269                                    self.__valid_section_cb)
    270         self._section_view.connect('request-close',
    271                                    self.__close_request_cb)
     276            self._section_view.connect('notify::is-valid',
     277                                       self.__valid_section_cb)
     278            self._section_view.connect('request-close',
     279                                       self.__close_request_cb)
     280            self._main_view.modify_bg(Gtk.StateType.NORMAL,
     281                                      style.COLOR_WHITE.get_gdk_color())
     282
     283        blank_canvas = Gtk.VBox()
     284        self._set_canvas(blank_canvas)
     285        blank_canvas.show()
    272286        self._main_view.modify_bg(Gtk.StateType.NORMAL,
    273287                                  style.COLOR_WHITE.get_gdk_color())
     288        self.busy_during_delayed_action(change_canvas)
    274289
    275290    def set_section_view_auto_close(self):
    276291        """Automatically close the control panel if there is "nothing to do"