| 114 | iterations = len(steps) |
| 115 | |
| 116 | def internal(counter, overrun=False, schedule=QtCore.QTimer.singleShot): |
| 117 | if not self._active: |
| 118 | self.loop_done.emit(True) |
| 119 | return |
| 120 | |
| 121 | st = time.time() |
| 122 | self.iteration.emit(counter, iterations, overrun) |
| 123 | if self._pre_body is not None: |
| 124 | self._pre_body(counter, steps[counter], overrun) |
| 125 | if body is not None: |
| 126 | body(counter, steps[counter], overrun) |
| 127 | if self._post_body is not None: |
| 128 | self._post_body(counter, steps[counter], overrun) |
| 129 | |
| 130 | if iterations and counter + 1 == iterations: |
| 131 | self._active = False |
| 132 | self.loop_done.emit(False) |
| 133 | return |
| 134 | elif not self._active: |
| 135 | self.loop_done.emit(True) |
| 136 | return |
| 137 | |
| 138 | sleep = interval - (time.time() - st) |
| 139 | schedule(sleep * 1000 if sleep > 0 else 0, |
| 140 | lambda: self._internal_func(counter + 1, sleep < 0)) |
| 141 | |
| 142 | self._internal_func = internal |
| 143 | if timeout: |