Coverage for /usr/lib/python3/dist-packages/matplotlib/_blocking_input.py: 12%

8 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-14 15:55 +0200

1def blocking_input_loop(figure, event_names, timeout, handler): 

2 """ 

3 Run *figure*'s event loop while listening to interactive events. 

4 

5 The events listed in *event_names* are passed to *handler*. 

6 

7 This function is used to implement `.Figure.waitforbuttonpress`, 

8 `.Figure.ginput`, and `.Axes.clabel`. 

9 

10 Parameters 

11 ---------- 

12 figure : `~matplotlib.figure.Figure` 

13 event_names : list of str 

14 The names of the events passed to *handler*. 

15 timeout : float 

16 If positive, the event loop is stopped after *timeout* seconds. 

17 handler : Callable[[Event], Any] 

18 Function called for each event; it can force an early exit of the event 

19 loop by calling ``canvas.stop_event_loop()``. 

20 """ 

21 if figure.canvas.manager: 

22 figure.show() # Ensure that the figure is shown if we are managing it. 

23 # Connect the events to the on_event function call. 

24 cids = [figure.canvas.mpl_connect(name, handler) for name in event_names] 

25 try: 

26 figure.canvas.start_event_loop(timeout) # Start event loop. 

27 finally: # Run even on exception like ctrl-c. 

28 # Disconnect the callbacks. 

29 for cid in cids: 

30 figure.canvas.mpl_disconnect(cid)