Skip to content

remove JupyterWgpuCanvas from imports, allow minimal install to work #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions fastplotlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from .plot import Plot
from .layouts import GridPlot
from .widgets import ImageWidget
from pathlib import Path

from wgpu.gui.auto import run

from .plot import Plot
from .layouts import GridPlot

try:
import ipywidgets
except (ModuleNotFoundError, ImportError):
pass
else:
from .widgets import ImageWidget


with open(Path(__file__).parent.joinpath("VERSION"), "r") as f:
__version__ = f.read().split("\n")[0]
8 changes: 4 additions & 4 deletions fastplotlib/layouts/_gridplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import pygfx

from wgpu.gui.auto import WgpuCanvas
from wgpu.gui.jupyter import JupyterWgpuCanvas
from wgpu.gui.auto import WgpuCanvas, is_jupyter

from ipywidgets import HBox, Layout, Button, ToggleButton, VBox, Dropdown
if is_jupyter():
from ipywidgets import HBox, Layout, Button, ToggleButton, VBox, Dropdown

from ._utils import make_canvas_and_renderer
from ._defaults import create_controller
Expand Down Expand Up @@ -310,7 +310,7 @@ def show(
subplot.auto_scale(maintain_aspect=_maintain_aspect, zoom=0.95)

# check if in jupyter notebook, or if toolbar is False
if (not isinstance(self.canvas, JupyterWgpuCanvas)) or (not toolbar):
if (self.canvas.__class__.__name__ != "JupyterWgpuCanvas") or (not toolbar):
return self.canvas

if self.toolbar is None:
Expand Down
15 changes: 9 additions & 6 deletions fastplotlib/plot.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from typing import *
from datetime import datetime
import traceback

import pygfx
from wgpu.gui.auto import WgpuCanvas
from wgpu.gui.auto import WgpuCanvas, is_jupyter

if is_jupyter():
from ipywidgets import HBox, Layout, Button, ToggleButton, VBox

from .layouts._subplot import Subplot
from ipywidgets import HBox, Layout, Button, ToggleButton, VBox
from wgpu.gui.jupyter import JupyterWgpuCanvas
from .layouts._record_mixin import RecordMixin
from datetime import datetime
import traceback


class Plot(Subplot, RecordMixin):
Expand Down Expand Up @@ -140,7 +143,7 @@ def show(
self.auto_scale(maintain_aspect=maintain_aspect, zoom=0.95)

# check if in jupyter notebook, or if toolbar is False
if (not isinstance(self.canvas, JupyterWgpuCanvas)) or (not toolbar):
if (self.canvas.__class__.__name__ != "JupyterWgpuCanvas") or (not toolbar):
return self.canvas

if self.toolbar is None:
Expand Down
19 changes: 9 additions & 10 deletions fastplotlib/widgets/image.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from typing import *
from warnings import warn
from functools import partial
from copy import deepcopy
import weakref

import numpy as np
from ipywidgets.widgets import IntSlider, VBox, HBox, Layout, FloatRangeSlider, Button, BoundedIntText, Play, jslink

from wgpu.gui.jupyter import JupyterWgpuCanvas
from wgpu.gui.auto import is_jupyter
from ipywidgets.widgets import IntSlider, VBox, HBox, Layout, FloatRangeSlider, Button, BoundedIntText, Play, jslink

from ..plot import Plot
from ..layouts import GridPlot
from ..graphics import ImageGraphic
from ..utils import quick_min_max, calculate_gridshape
Expand Down Expand Up @@ -242,6 +239,11 @@ def __init__(
kwargs: Any
passed to fastplotlib.graphics.Image
"""
if not is_jupyter():
raise EnvironmentError(
"ImageWidget is currently not supported outside of jupyter"
)

self._names = None
self.toolbar = None

Expand Down Expand Up @@ -913,11 +915,8 @@ def show(self, toolbar: bool = True):
``ipywidgets.VBox`` stacking the plotter and sliders in a vertical layout
"""

if not isinstance(self.gridplot.canvas, JupyterWgpuCanvas):
raise TypeError("ImageWidget is currently not supported outside of Jupyter")

# check if in jupyter notebook, or if toolbar is False
if (not isinstance(self.gridplot.canvas, JupyterWgpuCanvas)) or (not toolbar):
# don't need to check for jupyter since ImageWidget is only supported within jupyter anyways
if not toolbar:
return VBox([self.gridplot.show(toolbar=False), self._vbox_sliders])

if self.toolbar is None:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"docs": [
"sphinx",
"pydata-sphinx-theme<0.10.0",
"glfw"
"glfw",
"jupyter_rfb" # required so ImageWidget docs show up
],

"notebook":
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy