MCPcopy Create free account
hub / github.com/LabPy/lantz / Loop

Class Loop

lantz/ui/blocks/loop.py:27–114  ·  view source on GitHub ↗

The Loop backend allows you to execute task periodically. Usage: from lantz.ui.blocks import Loop, LoopUi def measure(counter, iterations, overrun): print(counter, iterations, overrun) data = osci.measure() print(data) app = Loop()

Source from the content-addressed store, hash-verified

25
26
27class Loop(Backend):
28 """The Loop backend allows you to execute task periodically.
29
30 Usage:
31
32 from lantz.ui.blocks import Loop, LoopUi
33
34 def measure(counter, iterations, overrun):
35 print(counter, iterations, overrun)
36 data = osci.measure()
37 print(data)
38
39 app = Loop()
40
41 app.body = measure
42
43 start_gui_app(app, LoopUi)
44
45 """
46
47 #: Signal emitted before starting a new iteration
48 #: Parameters: loop counter, iterations, overrun
49 iteration = QtCore.Signal(int, int, bool)
50
51 #: Signal emitted when the loop finished.
52 #: The parameter is used to inform if the loop was canceled.
53 loop_done = QtCore.Signal(bool)
54
55 #: The function to be called. It requires three parameters.
56 #: counter - the iteration number
57 #: iterations - total number of iterations
58 #: overrun - a boolean indicating if the time required for the operation
59 #: is longer than the interval.
60 #: :type: (int, int, bool) -> None
61 body = None
62
63 def __init__(self, **kwargs):
64 super().__init__(**kwargs)
65 self._active = False
66 self._internal_func = None
67
68 def stop(self):
69 """Request the scanning to be stop.
70 Will stop when the current iteration is finished.
71 """
72 self._active = False
73
74 def start(self, body, interval=0, iterations=0, timeout=0):
75 """Request the scanning to be started.
76
77 :param body: function to be called at each iteration.
78 If None, the class body will be used.
79 :param interval: interval between starts of the iteration.
80 If the body takes too long, the iteration will
81 be as fast as possible and the overrun flag will be True
82 :param iterations: number of iterations
83 :param timeout: total time in seconds that the scanning will take.
84 If overdue, the scanning will be stopped.

Callers 2

loop.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected