code: def _get_qt_top_parent(globals_dict):
      if (
          "QWidget" not in globals_dict
          and "QMainWindow" not in globals_dict
          and "QtWidgets" not in globals_dict
      ):
          return None
  
      qtwidgets = globals_dict.get("QtWidgets")
      qmainwindow = globals_dict.get(
          "QMainWindow", getattr(qtwidgets, "QMainWindow", None)
      )
      qwidget = globals_dict.get(
          "QWidget", getattr(qtwidgets, "QWidget", qmainwindow)
      )
      all_qt_widgets = [
          widget
          for widget in globals_dict.values()
          if isinstance(widget, qwidget) and widget is not None
      ]
      all_qt_mains = [
          widget
          for widget in all_qt_widgets
          if isinstance(widget, qmainwindow)
      ]
      if all_qt_mains:
          return all_qt_mains[0]
      if all_qt_widgets:
          return all_qt_widgets[0]
      return None
  
imports: from __future__ import annotations
  import os
  import time
  import shutil
  from vispy.io import imsave
  from vispy.gloo.util import _screenshot
  from vispy.scene import SceneCanvas
  from sphinx_gallery.scrapers import optipng, figure_rst
label_desc: Use image node_id 2 for calling a global function with example usage: _get_qt_top_parent(globals_dict) and returns: None, None, all_qt_mains, all_qt_widgets