Mercurial > libervia-backend
changeset 1832:39545dc527a1
jp: an onProgressUpdate method is now called on each progress update, allowing to handle metadata
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 23 Jan 2016 20:04:28 +0100 |
parents | 68c0dc13d821 |
children | a123e881f9e5 |
files | frontends/src/jp/base.py |
diffstat | 1 files changed, 53 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- 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):