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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

8 statements  

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)