Request the scanning to be started. :param body: function to be called at each iteration. If None, the class body will be used. :param interval: interval between starts of the iteration. If the body takes too long, the iteration will
(self, body, interval=0, steps=(), timeout=0)
| 96 | self._active = False |
| 97 | |
| 98 | def start(self, body, interval=0, steps=(), timeout=0): |
| 99 | """Request the scanning to be started. |
| 100 | |
| 101 | :param body: function to be called at each iteration. |
| 102 | If None, the class body will be used. |
| 103 | :param interval: interval between starts of the iteration. |
| 104 | If the body takes too long, the iteration will |
| 105 | be as fast as possible and the overrun flag will be True |
| 106 | :param steps: iterable |
| 107 | :param timeout: total time in seconds that the scanning will take. |
| 108 | If overdue, the scanning will be stopped. |
| 109 | If 0, there is no timeout. |
| 110 | """ |
| 111 | self._active = True |
| 112 | body = body or self.body |
| 113 | |
| 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: |
| 144 | QtCore.QTimer.singleShot(timeout * 1000, self.stop) |
| 145 | QtCore.QTimer.singleShot(0, lambda: self._internal_func(0)) |
| 146 | |
| 147 | |
| 148 | class ScanUi(Frontend): |
no outgoing calls
no test coverage detected