Skip to content

Commit 0d03d78

Browse files
authored
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
1 parent 1d5bcbb commit 0d03d78

File tree

6 files changed

+24
-39
lines changed

6 files changed

+24
-39
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ jobs:
3232
strategy:
3333
fail-fast: false
3434
matrix:
35-
python-version: ["3.8", "3.12"]
35+
python-version: ["3.8", "3.11"]
3636
platform: [ubuntu-latest, macos-latest, windows-latest]
3737
include:
3838
- python-version: "3.9"
3939
platform: ubuntu-latest
4040
- python-version: "3.10"
4141
platform: ubuntu-latest
42-
- python-version: "3.11"
42+
- python-version: "3.12"
4343
platform: ubuntu-latest
4444

4545
steps:
@@ -66,6 +66,7 @@ jobs:
6666
run: |
6767
python -m pip install -U pip
6868
python -m pip install -e .[test,thirdparty] ${{ github.event_name == 'schedule' && '--pre' || '' }}
69+
python -m pip install pyqt6
6970
7071
- name: Run test
7172
uses: aganders3/headless-gui@v1.2

docs/colormaps.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ external visualization libraries. To that end, `cmap.Colormap` provides
199199
Colormap("viridis").to_pygfx()
200200
```
201201

202-
Returns an instance of `pygfx.TextureView` (unless `as_view` is `False`, in which case
203-
a `pygfx.Texture` is returned).
202+
Returns an instance of `pygfx.Texture`.
204203

205204
- [plotly](https://plotly.com/python/)
206205

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ thirdparty = [
5454
"plotly",
5555
"pydantic",
5656
"pygfx",
57-
"pyqt6",
5857
"pytest-qt",
5958
"rich",
6059
"viscm",

src/cmap/_colormap.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -472,25 +472,15 @@ def to_vispy(self) -> vispy.color.Colormap:
472472
"""Return a vispy colormap."""
473473
return _external.to_vispy(self)
474474

475-
@overload
476-
def to_pygfx(
477-
self, N: int = ..., *, as_view: Literal[True] = ...
478-
) -> pygfx.TextureView:
479-
...
480-
481-
@overload
482-
def to_pygfx(self, N: int = ..., *, as_view: Literal[False]) -> pygfx.Texture:
483-
...
484-
485-
def to_pygfx(
486-
self, N: int = 256, *, as_view: bool = True
487-
) -> pygfx.TextureView | pygfx.Texture:
488-
"""Return a pygfx TextureView, or Texture if as_view is False.
489-
490-
If you want to customize the TextureView, use `as_view == False` and then
491-
call `get_view()` on the returned Texture, providing the desired arguments.
492-
"""
493-
return _external.to_pygfx(self, N=N, as_view=as_view)
475+
def to_pygfx(self, N: int = 256, *, as_view: bool | None = None) -> pygfx.Texture:
476+
"""Return a pygfx Texture."""
477+
if as_view is not None:
478+
warnings.warn(
479+
"as_view argument is deprecated and does nothing",
480+
DeprecationWarning,
481+
stacklevel=2,
482+
)
483+
return _external.to_pygfx(self, N=N)
494484

495485
def to_napari(self) -> napari.utils.colormaps.Colormap:
496486
"""Return a napari colormap.

src/cmap/_external.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,15 @@ def to_vispy(cm: Colormap) -> VispyColormap:
5252
return Colormap(colors=cm.color_stops.color_array, controls=cm.color_stops.stops)
5353

5454

55-
def to_pygfx(
56-
cm: Colormap, N: int = 256, *, as_view: bool = True
57-
) -> pygfx.TextureView | pygfx.Texture:
58-
"""Return a pygfx TextureView, or Texture if as_view is False.
59-
60-
If you want to customize the TextureView, use `as_view == False` and then
61-
call `get_view()` on the returned Texture, providing the desired arguments.
62-
"""
55+
def to_pygfx(cm: Colormap, N: int = 256) -> pygfx.Texture:
56+
"""Return a pygfx Texture."""
6357
import pygfx
6458

6559
# TODO: check whether pygfx has it's own stop-aware interpolation,
6660
# and if so, use that instead of .lut()
6761
# (get_view has a filter argument... but I don't know whether it will take
6862
# care of the stops)
69-
tex = pygfx.Texture(cm.lut(N).astype(np.float32), dim=1)
70-
return tex.get_view() if as_view else tex
63+
return pygfx.Texture(cm.lut(N).astype(np.float32), dim=1)
7164

7265

7366
def to_plotly(cm: Colormap) -> list[list[float | str]]:

tests/test_third_party.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
CMAP = Colormap(["black", (0, 1, 0), "00FFFF33", "w"])
2121
IMG = np.random.rand(10, 10).astype("float32")
22+
CI = bool(os.getenv("CI"))
23+
LINUX = sys.platform.startswith("linux")
2224

2325

2426
def test_colour_support() -> None:
@@ -79,19 +81,20 @@ def test_plotly() -> None:
7981
px.imshow(IMG, color_continuous_scale=CMAP.to_plotly())
8082

8183

82-
@pytest.mark.skipif(bool(os.getenv("CI")), reason="segfaults")
84+
@pytest.mark.skipif(CI and LINUX, reason="need to fix drivers")
8385
def test_pygfx(qapp: "QApplication") -> None:
8486
from qtpy.QtWidgets import QWidget
8587

86-
gfx = pytest.importorskip("pygfx")
88+
pytest.importorskip("pygfx")
8789
auto = pytest.importorskip("wgpu.gui.auto")
90+
import pygfx as gfx
8891

8992
canvas = auto.WgpuCanvas(size=IMG.shape)
9093
renderer = gfx.renderers.WgpuRenderer(canvas)
9194
camera = gfx.OrthographicCamera(*IMG.shape)
92-
camera.position.y = IMG.shape[0] / 2
93-
camera.position.x = IMG.shape[1] / 2
94-
camera.scale.y = -1
95+
# camera.position.y = IMG.shape[0] / 2
96+
# camera.position.x = IMG.shape[1] / 2
97+
# camera.scale.y = -1
9598

9699
scene = gfx.Scene()
97100
scene.add(

0 commit comments

Comments
 (0)