jp: an onProgressUpdate method is now called on each progress update, allowing to handle metadata
This commit is contained in:
parent
7fddbe943e
commit
d1fed06699
1 changed files with 53 additions and 29 deletions
|
|
@ -393,34 +393,6 @@ class Jp(object):
|
|||
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 @@ class CommandBase(object):
|
|||
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 @@ class CommandBase(object):
|
|||
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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue