# HG changeset patch # User Goffi # Date 1453575868 -3600 # Node ID 39545dc527a17a923c88f718636be243ab0b9ba2 # Parent 68c0dc13d821c554dcb0a9d2fa7d0367f448ef11 jp: an onProgressUpdate method is now called on each progress update, allowing to handle metadata diff -r 68c0dc13d821 -r 39545dc527a1 frontends/src/jp/base.py --- a/frontends/src/jp/base.py Sat Jan 23 20:01:28 2016 +0100 +++ b/frontends/src/jp/base.py Sat Jan 23 20:04:28 2016 +0100 @@ -393,34 +393,6 @@ return "%s/%s" % (_jid.bare, main_resource) return param_jid - def progressUpdate(self): - """This method is continualy called to update the progress bar""" - data = self.bridge.progressGet(self.progress_id, self.profile) - if data: - try: - size = data['size'] - except KeyError: - self.disp(_(u"file size is not known, we can't show a progress bar"), 1, error=True) - return False - if self.pbar is None: - #first answer, we must construct the bar - self.pbar = progressbar.ProgressBar(int(size), - [_(u"Progress: "),progressbar.Percentage(), - " ", - progressbar.Bar(), - " ", - progressbar.FileTransferSpeed(), - " ", - progressbar.ETA()]) - self.pbar.start() - - self.pbar.update(int(data['position'])) - - elif self.pbar is not None: - return False - - return True - class CommandBase(object): @@ -506,7 +478,7 @@ else: if self.host.watch_progress and uid == self.progress_id: self.onProgressStarted(metadata) - GLib.timeout_add(PROGRESS_DELAY, self.host.progressUpdate) + GLib.timeout_add(PROGRESS_DELAY, self.progressUpdate) def progressFinishedHandler(self, uid, metadata, profile): if profile != self.profile: @@ -530,13 +502,65 @@ self.onProgressError(message) self.host.quitFromSignal(1) + def progressUpdate(self): + """This method is continualy called to update the progress bar""" + data = self.host.bridge.progressGet(self.progress_id, self.profile) + if data: + try: + size = data['size'] + except KeyError: + self.disp(_(u"file size is not known, we can't show a progress bar"), 1, error=True) + return False + if self.host.pbar is None: + #first answer, we must construct the bar + self.host.pbar = progressbar.ProgressBar(int(size), + [_(u"Progress: "),progressbar.Percentage(), + " ", + progressbar.Bar(), + " ", + progressbar.FileTransferSpeed(), + " ", + progressbar.ETA()]) + self.host.pbar.start() + + self.host.pbar.update(int(data['position'])) + + elif self.host.pbar is not None: + return False + + self.onProgressUpdate(data) + + return True + def onProgressStarted(self, metadata): + """Called when progress has just started + + can be overidden by a command + @param metadata(dict): metadata as sent by bridge.progressStarted + """ self.disp(_(u"Operation started"), 2) + def onProgressUpdate(self, metadata): + """Method called on each progress updata + + can be overidden by a command to handle progress metadata + @para metadata(dict): metadata as returned by bridge.progressGet + """ + pass + def onProgressFinished(self, metadata): + """Called when progress has just finished + + can be overidden by a command + @param metadata(dict): metadata as sent by bridge.progressFinished + """ self.disp(_(u"Operation successfully finished"), 2) def onProgressError(self, error_msg): + """Called when a progress failed + + @param error_msg(unicode): error message as sent by bridge.progressError + """ self.disp(_(u"Error while doing operation: {}").format(error_msg), error=True) def disp(self, msg, verbosity=0, error=False):