code: def _contour_labeler_event_handler(cs, inline, inline_spacing, event):
      canvas = cs.axes.figure.canvas
      is_button = event.name == "button_press_event"
      is_key = event.name == "key_press_event"
      # Quit (even if not in infinite mode; this is consistent with
      # MATLAB and sometimes quite useful, but will require the user to
      # test how many points were actually returned before using data).
      if (
          is_button
          and event.button == MouseButton.MIDDLE
          or is_key
          and event.key in ["escape", "enter"]
      ):
          canvas.stop_event_loop()
      # Pop last click.
      elif (
          is_button
          and event.button == MouseButton.RIGHT
          or is_key
          and event.key in ["backspace", "delete"]
      ):
          # Unfortunately, if one is doing inline labels, then there is currently
          # no way to fix the broken contour - once humpty-dumpty is broken, he
          # can't be put back together.  In inline mode, this does nothing.
          if not inline:
              cs.pop_label()
              canvas.draw()
      # Add new click.
      elif (
          is_button
          and event.button == MouseButton.LEFT
          # On macOS/gtk, some keys return None.
          or is_key
          and event.key is not None
      ):
          if cs.axes.contains(event)[0]:
              cs.add_label_near(
                  event.x,
                  event.y,
                  transform=False,
                  inline=inline,
                  inline_spacing=inline_spacing,
              )
              canvas.draw()
  
imports: from contextlib import ExitStack
  import functools
  import math
  from numbers import Integral
  import numpy
  from numpy import ma
  import matplotlib
  from matplotlib import _api, _docstring
  from matplotlib.backend_bases import MouseButton
  from matplotlib.lines import Line2D
  from matplotlib.path import Path
  from matplotlib.text import Text
  import matplotlib.ticker
  import matplotlib.cm
  import matplotlib.colors
  import matplotlib.collections
  import matplotlib.font_manager
  import matplotlib.cbook
  import matplotlib.patches
  import matplotlib.transforms
label_desc: Use image node_id 1 for calling a global function with example usage: _contour_labeler_event_handler(cs, inline, inline_spacing, event) without return types