changeset 1636:e00f450c25fc

primitivus: fixed progress panel
author Goffi <goffi@goffi.org>
date Fri, 20 Nov 2015 01:57:18 +0100
parents 591e04f0103c
children 7751b5a51586
files frontends/src/primitivus/constants.py frontends/src/primitivus/primitivus frontends/src/primitivus/progress.py frontends/src/quick_frontend/quick_app.py
diffstat 4 files changed, 41 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/constants.py	Fri Nov 20 01:57:18 2015 +0100
+++ b/frontends/src/primitivus/constants.py	Fri Nov 20 01:57:18 2015 +0100
@@ -55,8 +55,8 @@
                ('directory_focus', 'dark cyan, bold', 'dark green'),
                ('separator', 'brown', 'default'),
                ('warning', 'light red', 'default'),
-               ('progress_normal', 'default', 'black'),
-               ('progress_complete', 'default', 'light red'),
+               ('progress_normal', 'default', 'brown'),
+               ('progress_complete', 'default', 'dark green'),
                ('show_disconnected', 'dark gray', 'default'),
                ('show_normal', 'default', 'default'),
                ('show_normal_focus', 'default, bold', 'default'),
--- a/frontends/src/primitivus/primitivus	Fri Nov 20 01:57:18 2015 +0100
+++ b/frontends/src/primitivus/primitivus	Fri Nov 20 01:57:18 2015 +0100
@@ -563,11 +563,13 @@
         self.center_part.focus_position = 0
         self.redraw()
 
-    def addProgress (self, id, message):
-        """Follow a SàT progress bar
-        @param id: SàT id of the progression
-        @param message: message to show to identify the progression"""
-        self.progress_wid.addProgress(id, message)
+    def addProgress(self, pid, message, profile):
+        """Follow a SàT progression
+
+        @param pid: progression id
+        @param message: message to show to identify the progression
+        """
+        self.progress_wid.add(pid, message, profile)
 
     def setProgress(self, percentage):
         """Set the progression shown in notification bar"""
@@ -631,6 +633,7 @@
                 self.main_widget.hide('notif_bar')
         else:
             self.main_widget.show('notif_bar')
+            self.redraw() # FIXME: invalidate cache in a more efficient way
 
     def _actionManagerUnknownError(self):
         self.alert(_("Error"), _(u"Unmanaged action"))
@@ -707,11 +710,21 @@
             log.error (_("FIXME FIXME FIXME: type [%s] not implemented") % type_)
             raise NotImplementedError
 
-
     def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, profile):
         super(PrimitivusApp, self).roomJoinedHandler(room_jid_s, room_nicks, user_nick, profile)
         self.contact_lists[profile].setFocus(jid.JID(room_jid_s), True)
 
+    def progressStartedHandler(self, pid, metadata, profile):
+        super(PrimitivusApp, self).progressStartedHandler(pid, metadata, profile)
+        self.addProgress(pid, metadata.get('name', _(u'unkown')), profile)
+
+    def progressFinishedHandler(self, pid, metadata, profile):
+        log.info(u"Progress {} finished".format(pid))
+        super(PrimitivusApp, self).progressFinishedHandler(pid, metadata, profile)
+
+    def progressErrorHandler(self, pid, err_msg, profile):
+        log.warning(u"Progress {pid} error: {err_msg}".format(pid=pid, err_msg=err_msg))
+        super(PrimitivusApp, self).progressErrorHandler(pid, err_msg, profile)
 
 
     ##DIALOGS CALLBACKS##
--- a/frontends/src/primitivus/progress.py	Fri Nov 20 01:57:18 2015 +0100
+++ b/frontends/src/primitivus/progress.py	Fri Nov 20 01:57:18 2015 +0100
@@ -34,14 +34,13 @@
         self.progress_dict = {}
         listbox = urwid.ListBox(self.progress_list)
         buttons = []
-        buttons.append(sat_widgets.CustomButton(_('Clear progress list'), self.__onClear))
+        buttons.append(sat_widgets.CustomButton(_('Clear progress list'), self._onClear))
         max_len = max([button.getSize() for button in buttons])
         buttons_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
         main_wid = sat_widgets.FocusFrame(listbox, footer=buttons_wid)
         urwid.WidgetWrap.__init__(self, main_wid)
 
-    def addProgress(self, progress_id, message):
-        profile = self.host.profile # TODO: manage multiple profiles
+    def add(self, progress_id, message, profile):
         mess_wid = urwid.Text(message)
         progr_wid = urwid.ProgressBar('progress_normal', 'progress_complete')
         column = urwid.Columns([mess_wid, progr_wid])
@@ -51,8 +50,8 @@
 
     def progressCB(self, loop, data):
         progress_id, message, profile = data
-        data = self.host.bridge.getProgress(progress_id, profile)
-        pbar = self.progress_dict[(progress_id, profile)]['progress'] #FIXME: must manage profiles
+        data = self.host.bridge.progressGet(progress_id, profile)
+        pbar = self.progress_dict[(progress_id, profile)]['progress']
         if data:
             if self.progress_dict[(progress_id, profile)]['state'] == 'init':
                 #first answer, we must construct the bar
@@ -68,20 +67,20 @@
                 self.updateNotBar()
                 return
 
-        loop.set_alarm_in(1,self.progressCB, (progress_id, message, profile))
+        loop.set_alarm_in(0.2,self.progressCB, (progress_id, message, profile))
 
-    def __removeBar(self, progress_id, profile):
+    def _removeBar(self, progress_id, profile):
         wid = self.progress_dict[(progress_id, profile)]['full']
         self.progress_list.remove(wid)
         del(self.progress_dict[(progress_id, profile)])
 
-    def __onClear(self, button):
+    def _onClear(self, button):
        to_remove = []
        for progress_id, profile in self.progress_dict:
            if self.progress_dict[(progress_id, profile)]['state'] == 'done':
                to_remove.append((progress_id, profile))
        for progress_id, profile in to_remove:
-           self.__removeBar(progress_id, profile)
+           self._removeBar(progress_id, profile)
        self.updateNotBar()
 
     def updateNotBar(self):
--- a/frontends/src/quick_frontend/quick_app.py	Fri Nov 20 01:57:18 2015 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Fri Nov 20 01:57:18 2015 +0100
@@ -249,6 +249,9 @@
         self.registerSignal("entityDataUpdated")
         self.registerSignal("askConfirmation")
         self.registerSignal("actionResult")
+        self.registerSignal("progressStarted")
+        self.registerSignal("progressFinished")
+        self.registerSignal("progressError")
         self.registerSignal("actionResultExt", self.actionResultHandler)
         self.registerSignal("roomJoined", iface="plugin")
         self.registerSignal("roomLeft", iface="plugin")
@@ -646,6 +649,15 @@
             else:
                 log.warning("Unmanaged PubSub event type {}".format(event_type))
 
+    def progressStartedHandler(self, pid, metadata, profile):
+        log.info(u"Progress {} started".format(pid))
+
+    def progressFinishedHandler(self, pid, metadata, profile):
+        log.info(u"Progress {} finished".format(pid))
+
+    def progressErrorHandler(self, pid, err_msg, profile):
+        log.warning(u"Progress {pid} error: {err_msg}".format(pid=pid, err_msg=err_msg))
+
     def _subscribe_cb(self, answer, data):
         entity, profile = data
         type_ = "subscribed" if answer else "unsubscribed"