From 0d03d7866bd55ed820e97f52a3df38d4df32dbf9 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Mon, 4 Dec 2023 10:55:34 -0500 Subject: [PATCH] update to_pygfx (#31) * update to_pygfx * try pyside2 * more stuff * add more drivers * skip again * update docs and overload * update test * back to pyqt6 --- .github/workflows/ci.yml | 5 +++-- docs/colormaps.md | 3 +-- pyproject.toml | 1 - src/cmap/_colormap.py | 28 +++++++++------------------- src/cmap/_external.py | 13 +++---------- tests/test_third_party.py | 13 ++++++++----- 6 files changed, 24 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 492f0f274..70bfe3c3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,14 +32,14 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.12"] + python-version: ["3.8", "3.11"] platform: [ubuntu-latest, macos-latest, windows-latest] include: - python-version: "3.9" platform: ubuntu-latest - python-version: "3.10" platform: ubuntu-latest - - python-version: "3.11" + - python-version: "3.12" platform: ubuntu-latest steps: @@ -66,6 +66,7 @@ jobs: run: | python -m pip install -U pip python -m pip install -e .[test,thirdparty] ${{ github.event_name == 'schedule' && '--pre' || '' }} + python -m pip install pyqt6 - name: Run test uses: aganders3/headless-gui@v1.2 diff --git a/docs/colormaps.md b/docs/colormaps.md index 5702a96e2..48b3aaee6 100644 --- a/docs/colormaps.md +++ b/docs/colormaps.md @@ -199,8 +199,7 @@ external visualization libraries. To that end, `cmap.Colormap` provides Colormap("viridis").to_pygfx() ``` - Returns an instance of `pygfx.TextureView` (unless `as_view` is `False`, in which case - a `pygfx.Texture` is returned). + Returns an instance of `pygfx.Texture`. - [plotly](https://plotly.com/python/) diff --git a/pyproject.toml b/pyproject.toml index 453bd4146..8d2dad5d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,6 @@ thirdparty = [ "plotly", "pydantic", "pygfx", - "pyqt6", "pytest-qt", "rich", "viscm", diff --git a/src/cmap/_colormap.py b/src/cmap/_colormap.py index cbe27bd56..72938f6f4 100644 --- a/src/cmap/_colormap.py +++ b/src/cmap/_colormap.py @@ -472,25 +472,15 @@ def to_vispy(self) -> vispy.color.Colormap: """Return a vispy colormap.""" return _external.to_vispy(self) - @overload - def to_pygfx( - self, N: int = ..., *, as_view: Literal[True] = ... - ) -> pygfx.TextureView: - ... - - @overload - def to_pygfx(self, N: int = ..., *, as_view: Literal[False]) -> pygfx.Texture: - ... - - def to_pygfx( - self, N: int = 256, *, as_view: bool = True - ) -> pygfx.TextureView | pygfx.Texture: - """Return a pygfx TextureView, or Texture if as_view is False. - - If you want to customize the TextureView, use `as_view == False` and then - call `get_view()` on the returned Texture, providing the desired arguments. - """ - return _external.to_pygfx(self, N=N, as_view=as_view) + def to_pygfx(self, N: int = 256, *, as_view: bool | None = None) -> pygfx.Texture: + """Return a pygfx Texture.""" + if as_view is not None: + warnings.warn( + "as_view argument is deprecated and does nothing", + DeprecationWarning, + stacklevel=2, + ) + return _external.to_pygfx(self, N=N) def to_napari(self) -> napari.utils.colormaps.Colormap: """Return a napari colormap. diff --git a/src/cmap/_external.py b/src/cmap/_external.py index 5fe9c0e66..53642bd37 100644 --- a/src/cmap/_external.py +++ b/src/cmap/_external.py @@ -52,22 +52,15 @@ def to_vispy(cm: Colormap) -> VispyColormap: return Colormap(colors=cm.color_stops.color_array, controls=cm.color_stops.stops) -def to_pygfx( - cm: Colormap, N: int = 256, *, as_view: bool = True -) -> pygfx.TextureView | pygfx.Texture: - """Return a pygfx TextureView, or Texture if as_view is False. - - If you want to customize the TextureView, use `as_view == False` and then - call `get_view()` on the returned Texture, providing the desired arguments. - """ +def to_pygfx(cm: Colormap, N: int = 256) -> pygfx.Texture: + """Return a pygfx Texture.""" import pygfx # TODO: check whether pygfx has it's own stop-aware interpolation, # and if so, use that instead of .lut() # (get_view has a filter argument... but I don't know whether it will take # care of the stops) - tex = pygfx.Texture(cm.lut(N).astype(np.float32), dim=1) - return tex.get_view() if as_view else tex + return pygfx.Texture(cm.lut(N).astype(np.float32), dim=1) def to_plotly(cm: Colormap) -> list[list[float | str]]: diff --git a/tests/test_third_party.py b/tests/test_third_party.py index 709427943..4d74af7d5 100644 --- a/tests/test_third_party.py +++ b/tests/test_third_party.py @@ -19,6 +19,8 @@ CMAP = Colormap(["black", (0, 1, 0), "00FFFF33", "w"]) IMG = np.random.rand(10, 10).astype("float32") +CI = bool(os.getenv("CI")) +LINUX = sys.platform.startswith("linux") def test_colour_support() -> None: @@ -79,19 +81,20 @@ def test_plotly() -> None: px.imshow(IMG, color_continuous_scale=CMAP.to_plotly()) -@pytest.mark.skipif(bool(os.getenv("CI")), reason="segfaults") +@pytest.mark.skipif(CI and LINUX, reason="need to fix drivers") def test_pygfx(qapp: "QApplication") -> None: from qtpy.QtWidgets import QWidget - gfx = pytest.importorskip("pygfx") + pytest.importorskip("pygfx") auto = pytest.importorskip("wgpu.gui.auto") + import pygfx as gfx canvas = auto.WgpuCanvas(size=IMG.shape) renderer = gfx.renderers.WgpuRenderer(canvas) camera = gfx.OrthographicCamera(*IMG.shape) - camera.position.y = IMG.shape[0] / 2 - camera.position.x = IMG.shape[1] / 2 - camera.scale.y = -1 + # camera.position.y = IMG.shape[0] / 2 + # camera.position.x = IMG.shape[1] / 2 + # camera.scale.y = -1 scene = gfx.Scene() scene.add(