MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _contour_labeler_event_handler

Function _contour_labeler_event_handler

lib/matplotlib/contour.py:30–56  ·  view source on GitHub ↗
(cs, inline, inline_spacing, event)

Source from the content-addressed store, hash-verified

28
29
30def _contour_labeler_event_handler(cs, inline, inline_spacing, event):
31 canvas = cs.axes.get_figure(root=True).canvas
32 is_button = event.name == "button_press_event"
33 is_key = event.name == "key_press_event"
34 # Quit (even if not in infinite mode; this is consistent with
35 # MATLAB and sometimes quite useful, but will require the user to
36 # test how many points were actually returned before using data).
37 if (is_button and event.button == MouseButton.MIDDLE
38 or is_key and event.key in ["escape", "enter"]):
39 canvas.stop_event_loop()
40 # Pop last click.
41 elif (is_button and event.button == MouseButton.RIGHT
42 or is_key and event.key in ["backspace", "delete"]):
43 # Unfortunately, if one is doing inline labels, then there is currently
44 # no way to fix the broken contour - once humpty-dumpty is broken, he
45 # can't be put back together. In inline mode, this does nothing.
46 if not inline:
47 cs.pop_label()
48 canvas.draw()
49 # Add new click.
50 elif (is_button and event.button == MouseButton.LEFT
51 # On macOS/gtk, some keys return None.
52 or is_key and event.key is not None):
53 if cs.axes.contains(event)[0]:
54 cs.add_label_near(event.x, event.y, transform=False,
55 inline=inline, inline_spacing=inline_spacing)
56 canvas.draw()
57
58
59class ContourLabeler:

Callers

nothing calls this directly

Calls 6

pop_labelMethod · 0.80
add_label_nearMethod · 0.80
get_figureMethod · 0.45
stop_event_loopMethod · 0.45
drawMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…