import sys import importlib from pathlib import Path import wgpu # --- Prepare # Ultimately, we let wgpu-py decide, but we can prime things a bit to create our # own preferred order, by importing a Qt lib. But we only do this if no GUI has # been imported yet. # Qt libs that we will try to import qt_libs = ["PySide6", "PyQt6", "PySide2", "PyQt5"] # Other known libs that, if imported, we should probably not try to force qt other_libs = ["glfw", "wx", "ipykernel"] already_imported = [name for name in (qt_libs + other_libs) if name in sys.modules] if not already_imported: for name in qt_libs: try: importlib.import_module(name) except Exception: pass else: break # --- Triage # Let wgpu do the auto gui selection from rendercanvas import BaseRenderCanvas from rendercanvas.auto import RenderCanvas, loop # Get the name of the backend ('qt', 'glfw', 'jupyter') GUI_BACKEND = RenderCanvas.__module__.split(".")[-1] IS_JUPYTER = GUI_BACKEND == "jupyter" # --- Some backend-specific preparations def _notebook_print_banner(): from ipywidgets import Image from IPython.display import display, HTML logo_path = Path(__file__).parent.parent.joinpath( "assets", "fastplotlib_face_logo.png" ) with open(logo_path, "rb") as f: logo_data = f.read() # get small logo image image = Image(value=logo_data, format="png", width=300, height=55) # get adapters and info adapters = [a for a in wgpu.gpu.enumerate_adapters_sync()] adapters_info = [a.info for a in adapters] default_adapter_info = wgpu.gpu.request_adapter_sync().info default_ix = adapters_info.index(default_adapter_info) if len(adapters) < 1: return # start HTML table table_str = ( "Available devices:" "
| Valid | " "Device | " "Type | " "Backend | " "Driver | " "
|---|---|---|---|---|
| {s} | " table_str += "