comparison frontends/src/jp/base.py @ 1642:7ec7ce9cdc4c

jp (base): progressStarted signals are cached until progress_id is known, this avoid missing the progression if we have the signal before the id.
author Goffi <goffi@goffi.org>
date Sun, 22 Nov 2015 17:37:19 +0100
parents 44a14f83e64b
children d17772b0fe22
comparison
equal deleted inserted replaced
1641:44a14f83e64b 1642:7ec7ce9cdc4c
115 return self._progress_id 115 return self._progress_id
116 116
117 @progress_id.setter 117 @progress_id.setter
118 def progress_id(self, value): 118 def progress_id(self, value):
119 self._progress_id = value 119 self._progress_id = value
120 self.replayCache('progress_ids_cache')
120 121
121 @property 122 @property
122 def watch_progress(self): 123 def watch_progress(self):
123 try: 124 try:
124 self.pbar 125 self.pbar
136 def verbosity(self): 137 def verbosity(self):
137 try: 138 try:
138 return self.args.verbose 139 return self.args.verbose
139 except AttributeError: 140 except AttributeError:
140 return 0 141 return 0
142
143 def replayCache(self, cache_attribute):
144 """Replay cached signals
145
146 @param cache_attribute(str): name of the attribute containing the cache
147 if the attribute doesn't exist, there is no cache and the call is ignored
148 else the cache must be a list of tuples containing the replay callback as first item,
149 then the arguments to use
150 """
151 try:
152 cache = getattr(self, cache_attribute)
153 except AttributeError:
154 pass
155 else:
156 for cache_data in cache:
157 cache_data[0](*cache_data[1:])
141 158
142 def disp(self, msg, verbosity=0, error=False): 159 def disp(self, msg, verbosity=0, error=False):
143 """Print a message to user 160 """Print a message to user
144 161
145 @param msg(unicode): message to print 162 @param msg(unicode): message to print
475 self.host.progress_id = value 492 self.host.progress_id = value
476 493
477 def progressStartedHandler(self, uid, metadata, profile): 494 def progressStartedHandler(self, uid, metadata, profile):
478 if profile != self.profile: 495 if profile != self.profile:
479 return 496 return
480 self.onProgressStarted(metadata) 497 if self.progress_id is None:
481 if self.host.watch_progress and self.progress_id and uid == self.progress_id: 498 # the progress started message can be received before the id
482 GLib.timeout_add(PROGRESS_DELAY, self.host.progressUpdate) 499 # so we keep progressStarted signals in cache to replay they
500 # when the progress_id is received
501 cache_data = (self.progressStartedHandler, uid, metadata, profile)
502 try:
503 self.host.progress_ids_cache.append(cache_data)
504 except AttributeError:
505 self.host.progress_ids_cache = [cache_data]
506 else:
507 if self.host.watch_progress and uid == self.progress_id:
508 self.onProgressStarted(metadata)
509 GLib.timeout_add(PROGRESS_DELAY, self.host.progressUpdate)
483 510
484 def progressFinishedHandler(self, uid, metadata, profile): 511 def progressFinishedHandler(self, uid, metadata, profile):
485 if profile != self.profile: 512 if profile != self.profile:
486 return 513 return
487 if uid == self.progress_id: 514 if uid == self.progress_id:
542 # the command doesn't use progress bar 569 # the command doesn't use progress bar
543 pass 570 pass
544 else: 571 else:
545 if show_progress: 572 if show_progress:
546 self.host.watch_progress = True 573 self.host.watch_progress = True
547 # we need to register the following signal even if we don't display the progress bas 574 # we need to register the following signal even if we don't display the progress bar
548 self.host.bridge.register("progressStarted", self.progressStartedHandler) 575 self.host.bridge.register("progressStarted", self.progressStartedHandler)
549 self.host.bridge.register("progressFinished", self.progressFinishedHandler) 576 self.host.bridge.register("progressFinished", self.progressFinishedHandler)
550 self.host.bridge.register("progressError", self.progressErrorHandler) 577 self.host.bridge.register("progressError", self.progressErrorHandler)
551 578
552 def connected(self): 579 def connected(self):