Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ruff format everything #421

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 2 commits into from
Mar 4, 2024
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
4 changes: 1 addition & 3 deletions fastplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
adapters = [a.request_adapter_info() for a in enumerate_adapters()]

if len(adapters) < 1:
raise IndexError(
"No WGPU adapters found, fastplotlib will not work."
)
raise IndexError("No WGPU adapters found, fastplotlib will not work.")

with open(Path(__file__).parent.joinpath("VERSION"), "r") as f:
__version__ = f.read().split("\n")[0]
Expand Down
2 changes: 1 addition & 1 deletion fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def link(
feature=feature,
new_data=new_data,
callback=callback,
bidirectional=False # else infinite recursion, otherwise target will call
bidirectional=False, # else infinite recursion, otherwise target will call
# this instance .link(), and then it will happen again etc.
)

Expand Down
7 changes: 6 additions & 1 deletion fastplotlib/graphics/_features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from ._sizes import PointsSizesFeature
from ._present import PresentFeature
from ._thickness import ThicknessFeature
from ._base import GraphicFeature, GraphicFeatureIndexable, FeatureEvent, to_gpu_supported_dtype
from ._base import (
GraphicFeature,
GraphicFeatureIndexable,
FeatureEvent,
to_gpu_supported_dtype,
)
from ._selection_features import LinearSelectionFeature, LinearRegionSelectionFeature
from ._deleted import Deleted

Expand Down
10 changes: 8 additions & 2 deletions fastplotlib/graphics/_features/_colors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import numpy as np
import pygfx

from ...utils import make_colors, get_cmap_texture, make_pygfx_colors, parse_cmap_values, quick_min_max
from ...utils import (
make_colors,
get_cmap_texture,
make_pygfx_colors,
parse_cmap_values,
quick_min_max,
)
from ._base import (
GraphicFeature,
GraphicFeatureIndexable,
Expand Down Expand Up @@ -426,4 +432,4 @@ def vmax(self) -> float:
@vmax.setter
def vmax(self, value: float):
"""Maximum contrast limit."""
self._parent._material.clim = (self._parent._material.clim[0], value)
self._parent._material.clim = (self._parent._material.clim[0], value)
16 changes: 11 additions & 5 deletions fastplotlib/graphics/_features/_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ def __getitem__(self, item):

def _fix_sizes(self, sizes, parent):
graphic_type = parent.__class__.__name__

n_datapoints = parent.data().shape[0]
if not isinstance(sizes, (list, tuple, np.ndarray)):
sizes = np.full(n_datapoints, sizes, dtype=np.float32) # force it into a float to avoid weird gpu errors
elif not isinstance(sizes, np.ndarray): # if it's not a ndarray already, make it one
sizes = np.array(sizes, dtype=np.float32) # read it in as a numpy.float32
sizes = np.full(
n_datapoints, sizes, dtype=np.float32
) # force it into a float to avoid weird gpu errors
elif not isinstance(
sizes, np.ndarray
): # if it's not a ndarray already, make it one
sizes = np.array(sizes, dtype=np.float32) # read it in as a numpy.float32
if (sizes.ndim != 1) or (sizes.size != parent.data().shape[0]):
raise ValueError(
f"sequence of `sizes` must be 1 dimensional with "
Expand All @@ -49,7 +53,9 @@ def _fix_sizes(self, sizes, parent):
sizes = to_gpu_supported_dtype(sizes)

if any(s < 0 for s in sizes):
raise ValueError("All sizes must be positive numbers greater than or equal to 0.0.")
raise ValueError(
"All sizes must be positive numbers greater than or equal to 0.0."
)

if sizes.ndim == 1:
if graphic_type == "ScatterGraphic":
Expand Down
6 changes: 1 addition & 5 deletions fastplotlib/graphics/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,7 @@ def col_chunk_index(self, index: int):


class HeatmapGraphic(Graphic, Interaction, _AddSelectorsMixin):
feature_events = {
"data",
"cmap",
"present"
}
feature_events = {"data", "cmap", "present"}

def __init__(
self,
Expand Down
4 changes: 3 additions & 1 deletion fastplotlib/graphics/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def __init__(
super(ScatterGraphic, self).__init__(*args, **kwargs)

world_object = pygfx.Points(
pygfx.Geometry(positions=self.data(), sizes=self.sizes(), colors=self.colors()),
pygfx.Geometry(
positions=self.data(), sizes=self.sizes(), colors=self.colors()
),
material=pygfx.PointsMaterial(color_mode="vertex", vertex_sizes=True),
)

Expand Down
2 changes: 1 addition & 1 deletion fastplotlib/graphics/selectors/_base_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
hover_responsive: Tuple[WorldObject, ...] = None,
arrow_keys_modifier: str = None,
axis: str = None,
name: str = None
name: str = None,
):
if edges is None:
edges = tuple()
Expand Down
19 changes: 9 additions & 10 deletions fastplotlib/graphics/selectors/_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def limits(self, values: Tuple[float, float]):
# check that `values` is an iterable of two real numbers
# using `Real` here allows it to work with builtin `int` and `float` types, and numpy scaler types
if len(values) != 2 or not all(map(lambda v: isinstance(v, Real), values)):
raise TypeError(
"limits must be an iterable of two numeric values"
)
self._limits = tuple(map(round, values)) # if values are close to zero things get weird so round them
raise TypeError("limits must be an iterable of two numeric values")
self._limits = tuple(
map(round, values)
) # if values are close to zero things get weird so round them
self.selection._limits = self._limits

# TODO: make `selection` arg in graphics data space not world space
Expand Down Expand Up @@ -267,11 +267,7 @@ def make_ipywidget_slider(self, kind: str = "IntSlider", **kwargs):

return slider

def add_ipywidget_handler(
self,
widget,
step: Union[int, float] = None
):
def add_ipywidget_handler(self, widget, step: Union[int, float] = None):
"""
Bidirectionally connect events with a ipywidget slider

Expand All @@ -285,7 +281,10 @@ def add_ipywidget_handler(

"""

if not isinstance(widget, (ipywidgets.IntSlider, ipywidgets.FloatSlider, ipywidgets.FloatLogSlider)):
if not isinstance(
widget,
(ipywidgets.IntSlider, ipywidgets.FloatSlider, ipywidgets.FloatLogSlider),
):
raise TypeError(
f"`widget` must be one of: ipywidgets.IntSlider, ipywidgets.FloatSlider, or ipywidgets.FloatLogSlider\n"
f"You have passed a: <{type(widget)}"
Expand Down
20 changes: 9 additions & 11 deletions fastplotlib/graphics/selectors/_linear_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def limits(self, values: Tuple[float, float]):
# check that `values` is an iterable of two real numbers
# using `Real` here allows it to work with builtin `int` and `float` types, and numpy scaler types
if len(values) != 2 or not all(map(lambda v: isinstance(v, Real), values)):
raise TypeError(
"limits must be an iterable of two numeric values"
)
self._limits = tuple(map(round, values)) # if values are close to zero things get weird so round them
raise TypeError("limits must be an iterable of two numeric values")
self._limits = tuple(
map(round, values)
) # if values are close to zero things get weird so round them
self.selection._limits = self._limits

def __init__(
Expand Down Expand Up @@ -243,7 +243,7 @@ def __init__(
hover_responsive=self.edges,
arrow_keys_modifier=arrow_keys_modifier,
axis=axis,
name=name
name=name,
)

def get_selected_data(
Expand Down Expand Up @@ -417,11 +417,7 @@ def make_ipywidget_slider(self, kind: str = "IntRangeSlider", **kwargs):

return slider

def add_ipywidget_handler(
self,
widget,
step: Union[int, float] = None
):
def add_ipywidget_handler(self, widget, step: Union[int, float] = None):
"""
Bidirectionally connect events with a ipywidget slider

Expand All @@ -434,7 +430,9 @@ def add_ipywidget_handler(
step size, if ``None`` 100 steps are created

"""
if not isinstance(widget, (ipywidgets.IntRangeSlider, ipywidgets.FloatRangeSlider)):
if not isinstance(
widget, (ipywidgets.IntRangeSlider, ipywidgets.FloatRangeSlider)
):
raise TypeError(
f"`widget` must be one of: ipywidgets.IntRangeSlider or ipywidgets.FloatRangeSlider\n"
f"You have passed a: <{type(widget)}"
Expand Down
1 change: 0 additions & 1 deletion fastplotlib/graphics/selectors/_mesh_positions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import numpy as np

26 changes: 16 additions & 10 deletions fastplotlib/graphics/selectors/_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(
parent: Graphic = None,
name: str = None,
):

self.parent = parent

group = pygfx.Group()
Expand Down Expand Up @@ -47,7 +46,9 @@ def _add_plot_area_hook(self, plot_area):
self._plot_area.renderer.add_event_handler(self._add_segment, "click")

# pointer move to change endpoint of segment
self._plot_area.renderer.add_event_handler(self._move_segment_endpoint, "pointer_move")
self._plot_area.renderer.add_event_handler(
self._move_segment_endpoint, "pointer_move"
)

# click to finish existing segment
self._plot_area.renderer.add_event_handler(self._finish_segment, "click")
Expand All @@ -69,7 +70,9 @@ def _add_segment(self, ev):

new_line = pygfx.Line(
geometry=pygfx.Geometry(positions=data.astype(np.float32)),
material=pygfx.LineMaterial(thickness=self.edge_width, color=pygfx.Color(self.edge_color))
material=pygfx.LineMaterial(
thickness=self.edge_width, color=pygfx.Color(self.edge_color)
),
)

self.world_object.add(new_line)
Expand All @@ -86,7 +89,9 @@ def _move_segment_endpoint(self, ev):
return

# change endpoint
self.world_object.children[-1].geometry.positions.data[1] = np.array([world_pos]).astype(np.float32)
self.world_object.children[-1].geometry.positions.data[1] = np.array(
[world_pos]
).astype(np.float32)
self.world_object.children[-1].geometry.positions.update_range()

def _finish_segment(self, ev):
Expand Down Expand Up @@ -114,14 +119,15 @@ def _finish_polygon(self, ev):
return

# make new line to connect first and last vertices
data = np.vstack([
world_pos,
self.world_object.children[0].geometry.positions.data[0]
])
data = np.vstack(
[world_pos, self.world_object.children[0].geometry.positions.data[0]]
)

new_line = pygfx.Line(
geometry=pygfx.Geometry(positions=data.astype(np.float32)),
material=pygfx.LineMaterial(thickness=self.edge_width, color=pygfx.Color(self.edge_color))
material=pygfx.LineMaterial(
thickness=self.edge_width, color=pygfx.Color(self.edge_color)
),
)

self.world_object.add(new_line)
Expand All @@ -130,7 +136,7 @@ def _finish_polygon(self, ev):
self._add_segment: "click",
self._move_segment_endpoint: "pointer_move",
self._finish_segment: "click",
self._finish_polygon: "double_click"
self._finish_polygon: "double_click",
}

for handler, event in handlers.items():
Expand Down
4 changes: 3 additions & 1 deletion fastplotlib/graphics/selectors/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@


class Synchronizer:
def __init__(self, *selectors: LinearSelector, key_bind: Union[str, None] = "Shift"):
def __init__(
self, *selectors: LinearSelector, key_bind: Union[str, None] = "Shift"
):
"""
Synchronize the movement of `Selectors`. Selectors will move in sync only when the selected `"key_bind"` is
used during the mouse movement event. Valid key binds are: ``"Control"``, ``"Shift"`` and ``"Alt"``.
Expand Down
3 changes: 1 addition & 2 deletions fastplotlib/graphics/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(
screen_space: bool = True,
anchor: str = "middle-center",
*args,
**kwargs
**kwargs,
):
"""
Create a text Graphic
Expand Down Expand Up @@ -144,4 +144,3 @@ def outline_color(self, color: Union[str, np.ndarray]):
raise ValueError("Outline color must be of type str or np.ndarray")

self.world_object.material.outline_color = color

2 changes: 0 additions & 2 deletions fastplotlib/layouts/_defaults.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@



24 changes: 11 additions & 13 deletions fastplotlib/layouts/_frame/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ def __call__(self, *args, **kwargs):
JupyterOutputContext = UnavailableOutputContext(
"Jupyter",
"You must install fastplotlib using the `'notebook'` option to use this context:\n"
'pip install "fastplotlib[notebook]"'
'pip install "fastplotlib[notebook]"',
)

if CANVAS_OPTIONS_AVAILABLE["qt"]:
from ._qt_output import QOutputContext
else:
QtOutput = UnavailableOutputContext(
"Qt",
"You must install `PyQt6` to use this output context"
"Qt", "You must install `PyQt6` to use this output context"
)


Expand All @@ -45,6 +44,7 @@ class Frame:

Gives them their `show()` call that returns the appropriate output context.
"""

def __init__(self):
self._output = None

Expand Down Expand Up @@ -83,13 +83,13 @@ def start_render(self):
self.canvas.set_logical_size(*self._starting_size)

def show(
self,
autoscale: bool = True,
maintain_aspect: bool = None,
toolbar: bool = True,
sidecar: bool = False,
sidecar_kwargs: dict = None,
add_widgets: list = None,
self,
autoscale: bool = True,
maintain_aspect: bool = None,
toolbar: bool = True,
sidecar: bool = False,
sidecar_kwargs: dict = None,
add_widgets: list = None,
):
"""
Begins the rendering event loop and shows the plot in the desired output context (jupyter, qt or glfw).
Expand Down Expand Up @@ -168,9 +168,7 @@ def show(

elif self.canvas.__class__.__name__ == "QWgpuCanvas":
self._output = QOutputContext(
frame=self,
make_toolbar=toolbar,
add_widgets=add_widgets
frame=self, make_toolbar=toolbar, add_widgets=add_widgets
)

else: # assume GLFW, the output context is just the canvas
Expand Down
Loading