| 43 | |
| 44 | |
| 45 | def _create_application(): |
| 46 | global _application |
| 47 | |
| 48 | if _application is None: |
| 49 | app = Gio.Application.get_default() |
| 50 | if app is None or getattr(app, '_created_by_matplotlib', False): |
| 51 | # display_is_valid returns False only if on Linux and neither X11 |
| 52 | # nor Wayland display can be opened. |
| 53 | if not mpl._c_internal_utils.display_is_valid(): |
| 54 | raise RuntimeError('Invalid DISPLAY variable') |
| 55 | _application = Gtk.Application.new('org.matplotlib.Matplotlib3', |
| 56 | Gio.ApplicationFlags.NON_UNIQUE) |
| 57 | # The activate signal must be connected, but we don't care for |
| 58 | # handling it, since we don't do any remote processing. |
| 59 | _application.connect('activate', lambda *args, **kwargs: None) |
| 60 | _application.connect('shutdown', _shutdown_application) |
| 61 | _application.register() |
| 62 | cbook._setup_new_guiapp() |
| 63 | else: |
| 64 | _application = app |
| 65 | |
| 66 | return _application |
| 67 | |
| 68 | |
| 69 | def mpl_to_gtk_cursor_name(mpl_cursor): |