code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def test_magicgui_add_layer_inheritance(make_napari_viewer):
"""This test validates if the scale and translate are inherited from the
previous layer when adding a new layer with magicgui if function requests,
a Layer type.
It also checks if the presence of additional combo box in the
function does n... | This test validates if the scale and translate are inherited from the
previous layer when adding a new layer with magicgui if function requests,
a Layer type.
It also checks if the presence of additional combo box in the
function does not affect getting the data from the previous layer.
| test_magicgui_add_layer_inheritance | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_magicgui_add_data_inheritance_upper_dim(make_napari_viewer):
"""In the current implementation, layer with dimensionality lower than produced data are ignored"""
rng = np.random.default_rng(0)
viewer = make_napari_viewer()
viewer.add_image(rng.random((10, 10)), scale=(2, 2), translate=(1, 1))
... | In the current implementation, layer with dimensionality lower than produced data are ignored | test_magicgui_add_data_inheritance_upper_dim | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_magicgui_add_future_data(
qtbot, make_napari_viewer, LayerType, data, ndim
):
"""Test that annotating with Future[] works."""
from concurrent.futures import Future
from functools import partial
from qtpy.QtCore import QTimer
viewer = make_napari_viewer()
dtype = getattr(types, f'{... | Test that annotating with Future[] works. | test_magicgui_add_future_data | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_magicgui_add_threadworker(qtbot, make_napari_viewer):
"""Test that annotating with FunctionWorker works."""
from napari.qt.threading import FunctionWorker, thread_worker
viewer = make_napari_viewer()
DATA = np.random.rand(10, 10)
@magicgui
def add_data(x: int) -> FunctionWorker[types.... | Test that annotating with FunctionWorker works. | test_magicgui_add_threadworker | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_magicgui_get_data(make_napari_viewer, LayerType, data, ndim):
"""Test that annotating parameters with napari.types.<layer_type>Data.
This will provide the same dropdown menu appearance as when annotating
a parameter with napari.layers.<layer_type>... but the function will
receive `layer.data` ... | Test that annotating parameters with napari.types.<layer_type>Data.
This will provide the same dropdown menu appearance as when annotating
a parameter with napari.layers.<layer_type>... but the function will
receive `layer.data` rather than `layer`
| test_magicgui_get_data | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_magicgui_data_updated(make_napari_viewer):
"""Test that magic data parameters stay up to date."""
viewer = make_napari_viewer()
_returns = [] # the value of x returned from func
@magicgui(auto_call=True)
def func(x: types.PointsData):
_returns.append(x)
viewer.window.add_doc... | Test that magic data parameters stay up to date. | test_magicgui_data_updated | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_magicgui_get_viewer(make_napari_viewer):
"""Test that annotating with napari.Viewer gets the Viewer"""
# Make two DIFFERENT viewers
viewer1 = make_napari_viewer()
viewer2 = make_napari_viewer()
assert viewer2 is not viewer1
# Ensure one is returned by napari.current_viewer()
from na... | Test that annotating with napari.Viewer gets the Viewer | test_magicgui_get_viewer | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def func_returns(v: Viewer) -> bool:
"""Helper function determining whether func() returns v"""
func_viewer = func()
assert isinstance(func_viewer, PublicOnlyProxy)
return func_viewer.__wrapped__ is v | Helper function determining whether func() returns v | func_returns | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_mgui_forward_refs(name, monkeypatch):
"""make sure that magicgui's `get_widget_class` returns the right widget type
for the various napari types... even when expressed as strings.
"""
import magicgui.widgets
from magicgui.type_map import get_widget_class
monkeypatch.delitem(sys.modules... | make sure that magicgui's `get_widget_class` returns the right widget type
for the various napari types... even when expressed as strings.
| test_mgui_forward_refs | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_layers_populate_immediately(make_napari_viewer):
"""make sure that the layers dropdown is populated upon adding to viewer"""
from magicgui.widgets import create_widget
labels_layer = create_widget(annotation=Labels, label='ROI')
viewer = make_napari_viewer()
viewer.add_labels(np.zeros((10,... | make sure that the layers dropdown is populated upon adding to viewer | test_layers_populate_immediately | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_from_layer_data_tuple_accept_deprecating_dict(make_napari_viewer):
"""Test that a function returning a layer data tuple runs without error."""
viewer = make_napari_viewer()
@magicgui
def from_layer_data_tuple() -> types.LayerDataTuple:
data = np.zeros((10, 10))
meta = _Deprecat... | Test that a function returning a layer data tuple runs without error. | test_from_layer_data_tuple_accept_deprecating_dict | python | napari/napari | src/napari/_tests/test_magicgui.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_magicgui.py | BSD-3-Clause |
def test_viewer_mouse_bindings(qtbot, make_napari_viewer):
"""Test adding mouse bindings to the viewer"""
np.random.seed(0)
viewer = make_napari_viewer()
canvas = viewer.window._qt_viewer.canvas
if os.getenv('CI'):
viewer.show()
mock_press = Mock()
mock_drag = Mock()
mock_relea... | Test adding mouse bindings to the viewer | test_viewer_mouse_bindings | python | napari/napari | src/napari/_tests/test_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_mouse_bindings.py | BSD-3-Clause |
def test_layer_mouse_bindings(qtbot, make_napari_viewer):
"""Test adding mouse bindings to a layer that is selected"""
np.random.seed(0)
viewer = make_napari_viewer()
canvas = viewer.window._qt_viewer.canvas
if os.getenv('CI'):
viewer.show()
layer = viewer.add_image(np.random.random((1... | Test adding mouse bindings to a layer that is selected | test_layer_mouse_bindings | python | napari/napari | src/napari/_tests/test_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_mouse_bindings.py | BSD-3-Clause |
def test_unselected_layer_mouse_bindings(qtbot, make_napari_viewer):
"""Test adding mouse bindings to a layer that is not selected"""
np.random.seed(0)
viewer = make_napari_viewer()
canvas = viewer.window._qt_viewer.canvas
if os.getenv('CI'):
viewer.show()
layer = viewer.add_image(np.r... | Test adding mouse bindings to a layer that is not selected | test_unselected_layer_mouse_bindings | python | napari/napari | src/napari/_tests/test_mouse_bindings.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_mouse_bindings.py | BSD-3-Clause |
def test_make_napari_viewer(pytester_pretty):
"""Make sure that our make_napari_viewer plugin works."""
# create a temporary pytest test file
pytester_pretty.makepyfile(
"""
def test_make_viewer(make_napari_viewer):
viewer = make_napari_viewer()
assert viewer.layers ... | Make sure that our make_napari_viewer plugin works. | test_make_napari_viewer | python | napari/napari | src/napari/_tests/test_pytest_plugin.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_pytest_plugin.py | BSD-3-Clause |
def test_top_level_availability(make_napari_viewer):
"""Current viewer should be available at napari.current_viewer."""
viewer = make_napari_viewer()
assert viewer == napari.current_viewer() | Current viewer should be available at napari.current_viewer. | test_top_level_availability | python | napari/napari | src/napari/_tests/test_top_level_availability.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_top_level_availability.py | BSD-3-Clause |
def test_all_viewer_actions_are_accessible_via_shortcut(make_napari_viewer):
"""
Make sure we do find all the actions attached to a viewer via keybindings
"""
# instantiate to make sure everything is initialized correctly
_ = make_napari_viewer()
_assert_shortcuts_exist_for_each_action(Viewer) |
Make sure we do find all the actions attached to a viewer via keybindings
| test_all_viewer_actions_are_accessible_via_shortcut | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_non_existing_bindings():
"""
Those are condition tested in next unittest; but do not exists; this is
likely due to an oversight somewhere.
"""
assert 'play' in [func.__name__ for func in viewer_actions]
assert 'toggle_fullscreen' in [func.__name__ for func in viewer_actions] |
Those are condition tested in next unittest; but do not exists; this is
likely due to an oversight somewhere.
| test_non_existing_bindings | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_all_layer_actions_are_accessible_via_shortcut(
layer_class, data, ndim
):
"""
Make sure we do find all the actions attached to a layer via keybindings
"""
# instantiate to make sure everything is initialized correctly
_ = layer_class(data)
_assert_shortcuts_exist_for_each_action(lay... |
Make sure we do find all the actions attached to a layer via keybindings
| test_all_layer_actions_are_accessible_via_shortcut | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_add_layer_magic_name(
make_napari_viewer, layer_class, a_unique_name, ndim, tmp_path
):
"""Test magic_name works when using add_* for layers"""
# Tests for issue #1709
viewer = make_napari_viewer() # noqa: F841
layer = eval_with_filename(
'add_layer_by_type(viewer, layer_class, a_u... | Test magic_name works when using add_* for layers | test_add_layer_magic_name | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_changing_theme(make_napari_viewer):
"""Test changing the theme updates the full window."""
viewer = make_napari_viewer(show=False)
viewer.window._qt_viewer.set_welcome_visible(False)
viewer.add_points(data=None)
size = viewer.window._qt_viewer.size()
viewer.window._qt_viewer.setFixedSiz... | Test changing the theme updates the full window. | test_changing_theme | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_roll_transpose_update(make_napari_viewer, layer_class, data, ndim):
"""Check that transpose and roll preserve correct transform sequence."""
viewer = make_napari_viewer()
np.random.seed(0)
layer = add_layer_by_type(viewer, layer_class, data)
# Set translations and scalings (match type of... | Check that transpose and roll preserve correct transform sequence. | test_roll_transpose_update | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_custom_layer(make_napari_viewer):
"""Make sure that custom layers subclasses can be added to the viewer."""
class NewLabels(layers.Labels):
"""'Empty' extension of napari Labels layer."""
# Make a viewer and add the custom layer
viewer = make_napari_viewer(show=True)
viewer.add_la... | Make sure that custom layers subclasses can be added to the viewer. | test_custom_layer | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_empty_shapes_dims(make_napari_viewer):
"""make sure an empty shapes layer can render in 3D"""
viewer = make_napari_viewer(show=True)
viewer.add_shapes(None)
viewer.dims.ndisplay = 3 | make sure an empty shapes layer can render in 3D | test_empty_shapes_dims | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_current_viewer(make_napari_viewer):
"""Test that the viewer made last is the "current_viewer()" until another is activated"""
# Make two DIFFERENT viewers
viewer1: Viewer = make_napari_viewer()
viewer2: Viewer = make_napari_viewer()
assert viewer2 is not viewer1
# Ensure one is returned... | Test that the viewer made last is the "current_viewer()" until another is activated | test_current_viewer | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_close_all(n_viewers, make_napari_viewer):
"""Test that close all closes multiple viewers"""
# Make several viewers
viewers = [make_napari_viewer() for _ in range(n_viewers)]
last_viewer = viewers[-1]
# Ensure the last viewer closes all
assert last_viewer.close_all() == n_viewers | Test that close all closes multiple viewers | test_close_all | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_reset_non_empty(make_napari_viewer):
"""
Test that resetting a non-empty viewer doesn't crash
https://github.com/napari/napari/issues/4867
"""
viewer = make_napari_viewer()
viewer.add_points([(0, 1), (2, 3)])
viewer.reset() |
Test that resetting a non-empty viewer doesn't crash
https://github.com/napari/napari/issues/4867
| test_reset_non_empty | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_negative_translate(make_napari_viewer, qtbot):
"""Check that negative translation behaves as expected.
See https://github.com/napari/napari/issues/7248
"""
data = np.random.random((1, 3, 10, 12, 12))
viewer = make_napari_viewer()
_ = viewer.add_image(data, translate=(-1, 0, 0))
ass... | Check that negative translation behaves as expected.
See https://github.com/napari/napari/issues/7248
| test_negative_translate | python | napari/napari | src/napari/_tests/test_viewer.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_viewer.py | BSD-3-Clause |
def test_singlescreen_window_settings(make_napari_viewer, monkeypatch):
"""Test whether valid screen position is returned even after disconnected secondary screen."""
monkeypatch.setattr(
'napari._qt.qt_main_window.QApplication.screenAt', screen_at
)
settings = get_settings()
viewer = make_... | Test whether valid screen position is returned even after disconnected secondary screen. | test_singlescreen_window_settings | python | napari/napari | src/napari/_tests/test_windowsettings.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_windowsettings.py | BSD-3-Clause |
def test_z_order_images(make_napari_viewer):
"""Test changing order of images changes z order in display."""
data = np.ones((11, 11))
viewer = make_napari_viewer(show=True)
viewer.add_image(data, colormap='red')
viewer.add_image(data, colormap='blue')
screenshot = viewer.screenshot(canvas_only=... | Test changing order of images changes z order in display. | test_z_order_images | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_z_order_image_points(make_napari_viewer):
"""Test changing order of image and points changes z order in display."""
data = np.ones((11, 11))
viewer = make_napari_viewer(show=True)
viewer.add_image(data, colormap='red')
viewer.add_points([5, 5], face_color='blue', size=10)
screenshot = ... | Test changing order of image and points changes z order in display. | test_z_order_image_points | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_z_order_images_after_ndisplay(make_napari_viewer):
"""Test z order of images remanins constant after chaning ndisplay."""
data = np.ones((11, 11))
viewer = make_napari_viewer(show=True)
viewer.add_image(data, colormap='red')
viewer.add_image(data, colormap='blue')
screenshot = viewer.s... | Test z order of images remanins constant after chaning ndisplay. | test_z_order_images_after_ndisplay | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_z_order_image_points_after_ndisplay(make_napari_viewer):
"""Test z order of image and points remanins constant after chaning ndisplay."""
data = np.ones((11, 11))
viewer = make_napari_viewer(show=True)
viewer.add_image(data, colormap='red')
viewer.add_points([5, 5], face_color='blue', size... | Test z order of image and points remanins constant after chaning ndisplay. | test_z_order_image_points_after_ndisplay | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_changing_image_attenuation(make_napari_viewer):
"""Test changing attenuation value changes rendering."""
data = np.zeros((100, 10, 10))
data[0] = 1
viewer = make_napari_viewer(show=True)
viewer.dims.ndisplay = 3
viewer.add_image(data, contrast_limits=[0, 1])
# normal mip
viewe... | Test changing attenuation value changes rendering. | test_changing_image_attenuation | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_welcome(make_napari_viewer):
"""Test that something visible on launch."""
viewer = make_napari_viewer(show=True)
# Check something is visible
screenshot = viewer.screenshot(canvas_only=True, flash=False)
assert len(viewer.layers) == 0
assert screenshot[..., :-1].max() > 0
# Check ... | Test that something visible on launch. | test_welcome | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_axes_visible(make_napari_viewer):
"""Test that something appears when axes become visible."""
viewer = make_napari_viewer(show=True)
viewer.window._qt_viewer.set_welcome_visible(False)
# Check axes are not visible
launch_screenshot = viewer.screenshot(canvas_only=True, flash=False)
ass... | Test that something appears when axes become visible. | test_axes_visible | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_scale_bar_visible(make_napari_viewer):
"""Test that something appears when scale bar becomes visible."""
viewer = make_napari_viewer(show=True)
viewer.window._qt_viewer.set_welcome_visible(False)
# Check scale bar is not visible
launch_screenshot = viewer.screenshot(canvas_only=True, flash... | Test that something appears when scale bar becomes visible. | test_scale_bar_visible | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_screenshot_has_no_border(make_napari_viewer):
"""See https://github.com/napari/napari/issues/3357"""
viewer = make_napari_viewer(show=True)
image_data = np.ones((60, 80))
viewer.add_image(image_data, colormap='red')
# Zoom in dramatically to make the screenshot all red.
viewer.camera.zo... | See https://github.com/napari/napari/issues/3357 | test_screenshot_has_no_border | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def test_shapes_with_holes(make_napari_viewer):
"""Check that a shape with a hole in it is indeed rendered with a hole.
See https://github.com/napari/napari/issues/5673.
"""
embedded = np.array(
[
[0, 0], # outer triangle 0
[0, 100], # outer triangle 1 (clockwise)
... | Check that a shape with a hole in it is indeed rendered with a hole.
See https://github.com/napari/napari/issues/5673.
| test_shapes_with_holes | python | napari/napari | src/napari/_tests/test_with_screenshot.py | https://github.com/napari/napari/blob/master/src/napari/_tests/test_with_screenshot.py | BSD-3-Clause |
def are_objects_equal(object1, object2):
"""
compare two (collections of) arrays or other objects for equality. Ignores nan.
"""
if isinstance(object1, abc.Sequence):
items = zip(object1, object2, strict=False)
elif isinstance(object1, dict):
items = [(value, object2[key]) for key, v... |
compare two (collections of) arrays or other objects for equality. Ignores nan.
| are_objects_equal | python | napari/napari | src/napari/_tests/utils.py | https://github.com/napari/napari/blob/master/src/napari/_tests/utils.py | BSD-3-Clause |
def check_view_transform_consistency(layer, viewer, transf_dict):
"""Check layer transforms have been applied to the view.
Note this check only works for non-multiscale data.
Parameters
----------
layer : napari.layers.Layer
Layer model.
viewer : napari.Viewer
Viewer, including... | Check layer transforms have been applied to the view.
Note this check only works for non-multiscale data.
Parameters
----------
layer : napari.layers.Layer
Layer model.
viewer : napari.Viewer
Viewer, including Qt elements
transf_dict : dict
Dictionary of transform prope... | check_view_transform_consistency | python | napari/napari | src/napari/_tests/utils.py | https://github.com/napari/napari/blob/master/src/napari/_tests/utils.py | BSD-3-Clause |
def check_layer_world_data_extent(layer, extent, scale, translate):
"""Test extents after applying transforms.
Parameters
----------
layer : napari.layers.Layer
Layer to be tested.
extent : array, shape (2, D)
Extent of data in layer.
scale : array, shape (D,)
Scale to b... | Test extents after applying transforms.
Parameters
----------
layer : napari.layers.Layer
Layer to be tested.
extent : array, shape (2, D)
Extent of data in layer.
scale : array, shape (D,)
Scale to be applied to layer.
translate : array, shape (D,)
Translation t... | check_layer_world_data_extent | python | napari/napari | src/napari/_tests/utils.py | https://github.com/napari/napari/blob/master/src/napari/_tests/utils.py | BSD-3-Clause |
def assert_layer_state_equal(
actual: dict[str, Any], expected: dict[str, Any]
) -> None:
"""Asserts that an layer state dictionary is equal to an expected one.
This is useful because some members of state may array-like whereas others
maybe dataframe-like, which need to be checked for equality differe... | Asserts that an layer state dictionary is equal to an expected one.
This is useful because some members of state may array-like whereas others
maybe dataframe-like, which need to be checked for equality differently.
| assert_layer_state_equal | python | napari/napari | src/napari/_tests/utils.py | https://github.com/napari/napari/blob/master/src/napari/_tests/utils.py | BSD-3-Clause |
def assert_colors_equal(actual, expected):
"""Asserts that a sequence of colors is equal to an expected one.
This converts elements in the given sequences from color values
recognized by ``transform_color`` to the canonical RGBA array form.
Examples
--------
>>> assert_colors_equal([[1, 0, 0, ... | Asserts that a sequence of colors is equal to an expected one.
This converts elements in the given sequences from color values
recognized by ``transform_color`` to the canonical RGBA array form.
Examples
--------
>>> assert_colors_equal([[1, 0, 0, 1], [0, 0, 1, 1]], ['red', 'blue'])
>>> asser... | assert_colors_equal | python | napari/napari | src/napari/_tests/utils.py | https://github.com/napari/napari/blob/master/src/napari/_tests/utils.py | BSD-3-Clause |
def _listen_child():
"""
Run by a child process, install an observer and print theme on change
"""
import signal
signal.signal(signal.SIGINT, signal.SIG_IGN)
OBSERVED_KEY = "AppleInterfaceStyle"
class Observer(NSObject):
def observeValueForKeyPath_ofObject_change_context_(
... |
Run by a child process, install an observer and print theme on change
| _listen_child | python | napari/napari | src/napari/_vendor/darkdetect/_mac_detect.py | https://github.com/napari/napari/blob/master/src/napari/_vendor/darkdetect/_mac_detect.py | BSD-3-Clause |
def reject_none(func):
"""Only invoke function if state argument is not None"""
@wraps(func)
def wrapper(self, state):
if state is None:
return
func(self, state)
return wrapper | Only invoke function if state argument is not None | reject_none | python | napari/napari | src/napari/_vendor/qt_json_builder/qt_jsonschema_form/utils.py | https://github.com/napari/napari/blob/master/src/napari/_vendor/qt_json_builder/qt_jsonschema_form/utils.py | BSD-3-Clause |
def angles(self):
"""3-tuple: Euler angles of camera in 3D viewing, in degrees.
Note that angles might be different than the ones that might have generated the quaternion.
"""
if self._view.camera == self._3D_camera:
# Do conversion from quaternion representation to euler an... | 3-tuple: Euler angles of camera in 3D viewing, in degrees.
Note that angles might be different than the ones that might have generated the quaternion.
| angles | python | napari/napari | src/napari/_vispy/camera.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/camera.py | BSD-3-Clause |
def center(self):
"""tuple: Center point of camera view for 2D or 3D viewing."""
if self._view.camera == self._3D_camera:
center = tuple(self._view.camera.center)
else:
# in 2D, we arbitrarily choose 0.0 as the center in z
center = (*self._view.camera.center[:... | tuple: Center point of camera view for 2D or 3D viewing. | center | python | napari/napari | src/napari/_vispy/camera.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/camera.py | BSD-3-Clause |
def zoom(self):
"""float: Scale from canvas pixels to world pixels."""
canvas_size = np.array(self._view.canvas.size)
if self._view.camera == self._3D_camera:
# For fov = 0.0 normalize scale factor by canvas size to get scale factor.
# Note that the scaling is stored in t... | float: Scale from canvas pixels to world pixels. | zoom | python | napari/napari | src/napari/_vispy/camera.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/camera.py | BSD-3-Clause |
def on_draw(self, _event):
"""Called whenever the canvas is drawn.
Update camera model angles, center, and zoom.
"""
if self._view.camera == self._3D_camera:
with self._camera.events.angles.blocker(self._on_angles_change):
self._camera.angles = self.angles
... | Called whenever the canvas is drawn.
Update camera model angles, center, and zoom.
| on_draw | python | napari/napari | src/napari/_vispy/camera.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/camera.py | BSD-3-Clause |
def add_mouse_pan_zoom_toggles(
vispy_camera_cls: type[BaseCamera],
) -> type[BaseCamera]:
"""Add separate mouse pan and mouse zoom toggles to VisPy.
By default, VisPy uses an ``interactive`` toggle that turns *both*
panning and zooming on and off. This decorator adds separate toggles,
``mouse_pan`... | Add separate mouse pan and mouse zoom toggles to VisPy.
By default, VisPy uses an ``interactive`` toggle that turns *both*
panning and zooming on and off. This decorator adds separate toggles,
``mouse_pan`` and ``mouse_zoom``, to enable controlling them
separately.
Parameters
----------
vi... | add_mouse_pan_zoom_toggles | python | napari/napari | src/napari/_vispy/camera.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/camera.py | BSD-3-Clause |
def _process_mouse_event(self, event: MouseEvent):
"""Ignore mouse wheel events which have modifiers."""
if event.type == 'mouse_wheel' and len(event.modifiers) > 0:
return
if event.handled:
return
super()._process_mouse_event(event) | Ignore mouse wheel events which have modifiers. | _process_mouse_event | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _on_cursor(self) -> None:
"""Create a QCursor based on the napari cursor settings and set in Vispy."""
cursor = self.viewer.cursor.style
brush_overlay = self.viewer._brush_circle_overlay
brush_overlay.visible = False
if cursor in {'square', 'circle', 'circle_frozen'}:
... | Create a QCursor based on the napari cursor settings and set in Vispy. | _on_cursor | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _on_interactive(self) -> None:
"""Link interactive attributes of view and viewer."""
# Is this should be changed or renamed?
self.view.interactive = (
self.viewer.camera.mouse_zoom or self.viewer.camera.mouse_pan
) | Link interactive attributes of view and viewer. | _on_interactive | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _map_canvas2world(
self,
position: tuple[int, ...],
) -> tuple[float, float]:
"""Map position from canvas pixels into world coordinates.
Parameters
----------
position : list(int, int)
Position in canvas (x, y).
Returns
-------
... | Map position from canvas pixels into world coordinates.
Parameters
----------
position : list(int, int)
Position in canvas (x, y).
Returns
-------
coords : tuple of two floats
Position in world coordinates, matches the total dimensionality
... | _map_canvas2world | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _canvas_corners_in_world(self) -> npt.NDArray:
"""Location of the corners of canvas in world coordinates.
Returns
-------
corners : np.ndarray
Coordinates of top left and bottom right canvas pixel in the world.
"""
# Find corners of canvas in world coordi... | Location of the corners of canvas in world coordinates.
Returns
-------
corners : np.ndarray
Coordinates of top left and bottom right canvas pixel in the world.
| _canvas_corners_in_world | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def on_draw(self, event: DrawEvent) -> None:
"""Called whenever the canvas is drawn.
This is triggered from vispy whenever new data is sent to the canvas or
the camera is moved and is connected in the `QtViewer`.
Parameters
----------
event : vispy.app.canvas.DrawEvent
... | Called whenever the canvas is drawn.
This is triggered from vispy whenever new data is sent to the canvas or
the camera is moved and is connected in the `QtViewer`.
Parameters
----------
event : vispy.app.canvas.DrawEvent
The draw event from the vispy canvas.
... | on_draw | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def add_layer_visual_mapping(
self, napari_layer: Layer, vispy_layer: VispyBaseLayer
) -> None:
"""Maps a napari layer to its corresponding vispy layer and sets the parent scene of the vispy layer.
Parameters
----------
napari_layer :
Any napari layer, the layer ... | Maps a napari layer to its corresponding vispy layer and sets the parent scene of the vispy layer.
Parameters
----------
napari_layer :
Any napari layer, the layer type is the same as the vispy layer.
vispy_layer :
Any vispy layer, the layer type is the same as t... | add_layer_visual_mapping | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _remove_layer(self, event: Event) -> None:
"""Upon receiving event closes the Vispy visual, deletes it and reorders the still existing layers.
Parameters
----------
event : napari.utils.events.event.Event
The event causing a particular layer to be removed
Return... | Upon receiving event closes the Vispy visual, deletes it and reorders the still existing layers.
Parameters
----------
event : napari.utils.events.event.Event
The event causing a particular layer to be removed
Returns
-------
None
| _remove_layer | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _reorder_layers(self) -> None:
"""When the list is reordered, propagate changes to draw order."""
first_visible_found = False
for i, layer in enumerate(self.viewer.layers):
vispy_layer = self.layer_to_visual[layer]
vispy_layer.order = i
# the bottommost ... | When the list is reordered, propagate changes to draw order. | _reorder_layers | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _add_viewer_overlay(self, overlay: Overlay, parent: Node) -> None:
"""Create vispy overlay and add to dictionary of overlay visuals"""
vispy_overlay = create_vispy_overlay(
overlay=overlay, viewer=self.viewer, parent=parent
)
self._overlay_to_visual[overlay] = vispy_overl... | Create vispy overlay and add to dictionary of overlay visuals | _add_viewer_overlay | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _remove_viewer_overlays(self) -> None:
"""Remove all viewer overlay visuals and disconnect their events."""
for overlay in list(self._overlay_to_visual):
vispy_overlay = self._overlay_to_visual.pop(overlay)
vispy_overlay.close() | Remove all viewer overlay visuals and disconnect their events. | _remove_viewer_overlays | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _update_viewer_overlays(self):
"""Update the viewer overlay visuals.
Also ensures that overlays are properly assigned parents depending on
their class (canvas vs scene overlays).
"""
self._remove_viewer_overlays()
for overlay in self.viewer._overlays.values():
... | Update the viewer overlay visuals.
Also ensures that overlays are properly assigned parents depending on
their class (canvas vs scene overlays).
| _update_viewer_overlays | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _add_layer_overlay(
self, layer: Layer, overlay: Overlay, parent: Node
) -> None:
"""Create vispy overlay and add to dictionary of layer overlay visuals"""
vispy_overlay = create_vispy_overlay(
overlay, layer=layer, parent=parent
)
self._layer_overlay_to_visu... | Create vispy overlay and add to dictionary of layer overlay visuals | _add_layer_overlay | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _remove_layer_overlays(self, layer: Layer) -> None:
"""Remove all layer overlay visuals and disconnect their events."""
for overlay in list(self._layer_overlay_to_visual[layer]):
vispy_overlay = self._layer_overlay_to_visual[layer].pop(overlay)
vispy_overlay.close() | Remove all layer overlay visuals and disconnect their events. | _remove_layer_overlays | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _update_layer_overlays(self, layer: Layer) -> None:
"""Update the overlay visuals for each layer in the canvas.
Also ensures that overlays are properly assigned parents depending on
their class (canvas vs scene overlays).
"""
# reparenting does not work well in a few cases (... | Update the overlay visuals for each layer in the canvas.
Also ensures that overlays are properly assigned parents depending on
their class (canvas vs scene overlays).
| _update_layer_overlays | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _calculate_view_direction(
self, event_pos: tuple[float, float]
) -> npt.NDArray[np.float64] | None:
"""calculate view direction by ray shot from the camera"""
# this method is only implemented for 3 dimension
if self.viewer.dims.ndisplay == 2:
return None
if... | calculate view direction by ray shot from the camera | _calculate_view_direction | python | napari/napari | src/napari/_vispy/canvas.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/canvas.py | BSD-3-Clause |
def _master_transform(self):
"""vispy.visuals.transforms.MatrixTransform:
Central node's firstmost transform.
"""
# whenever a new parent is set, the transform is reset
# to a NullTransform so we reset it here
if not isinstance(self.node.transform, MatrixTransform):
... | vispy.visuals.transforms.MatrixTransform:
Central node's firstmost transform.
| _master_transform | python | napari/napari | src/napari/_vispy/layers/base.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/base.py | BSD-3-Clause |
def _on_poll(self, event=None):
"""Called when camera moves, before we are drawn.
Optionally called for some period once the camera stops, so the
visual can finish up what it was doing, such as loading data into
VRAM or animating itself.
""" | Called when camera moves, before we are drawn.
Optionally called for some period once the camera stops, so the
visual can finish up what it was doing, such as loading data into
VRAM or animating itself.
| _on_poll | python | napari/napari | src/napari/_vispy/layers/base.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/base.py | BSD-3-Clause |
def build_textures_from_dict(
color_dict: dict[int, ColorTuple], max_size: int
) -> np.ndarray:
"""This code assumes that the keys in the color_dict are sequential from 0.
If any keys are larger than the size of the dictionary, they will
overwrite earlier keys in the best case, or it might just crash.
... | This code assumes that the keys in the color_dict are sequential from 0.
If any keys are larger than the size of the dictionary, they will
overwrite earlier keys in the best case, or it might just crash.
| build_textures_from_dict | python | napari/napari | src/napari/_vispy/layers/labels.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/labels.py | BSD-3-Clause |
def _update_text(self, *, update_node=True):
"""Function to update the text node properties
Parameters
----------
update_node : bool
If true, update the node after setting the properties
"""
update_text(node=self._get_text_node(), layer=self.layer)
if... | Function to update the text node properties
Parameters
----------
update_node : bool
If true, update the node after setting the properties
| _update_text | python | napari/napari | src/napari/_vispy/layers/points.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/points.py | BSD-3-Clause |
def _on_blending_change(self, event=None):
"""Function to set the blending mode"""
points_blending_kwargs = BLENDING_MODES[self.layer.blending]
self.node.set_gl_state(**points_blending_kwargs)
text_node = self._get_text_node()
text_blending_kwargs = BLENDING_MODES[self.layer.tex... | Function to set the blending mode | _on_blending_change | python | napari/napari | src/napari/_vispy/layers/points.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/points.py | BSD-3-Clause |
def downsample_texture(
self, data: np.ndarray, MAX_TEXTURE_SIZE: int
) -> np.ndarray:
"""Downsample data based on maximum allowed texture size.
Parameters
----------
data : array
Data to be downsampled if needed.
MAX_TEXTURE_SIZE : int
Maximu... | Downsample data based on maximum allowed texture size.
Parameters
----------
data : array
Data to be downsampled if needed.
MAX_TEXTURE_SIZE : int
Maximum allowed texture size.
Returns
-------
data : array
Data that now fits i... | downsample_texture | python | napari/napari | src/napari/_vispy/layers/scalar_field.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/scalar_field.py | BSD-3-Clause |
def _on_texture_change(self):
"""Update or apply the texture filter"""
# texture images need to be flipped (np.flipud) because of how OpenGL
# expects the texture data to be ordered in memory we flip them here
# when setting up the TextureFilter so napari users can load images
# ... | Update or apply the texture filter | _on_texture_change | python | napari/napari | src/napari/_vispy/layers/surface.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/surface.py | BSD-3-Clause |
def _on_appearance_change(self):
"""Change the appearance of the data."""
# update shader properties related to appearance
self.node.tracks_filter.use_fade = self.layer.use_fade
self.node.tracks_filter.tail_length = self.layer.tail_length
self.node.tracks_filter.head_length = se... | Change the appearance of the data. | _on_appearance_change | python | napari/napari | src/napari/_vispy/layers/tracks.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/tracks.py | BSD-3-Clause |
def _on_tracks_change(self):
"""Update the shader when the track data changes."""
self.node.tracks_filter.use_fade = self.layer.use_fade
self.node.tracks_filter.tail_length = self.layer.tail_length
self.node.tracks_filter.vertex_time = self.layer.track_times
# change the data t... | Update the shader when the track data changes. | _on_tracks_change | python | napari/napari | src/napari/_vispy/layers/tracks.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/tracks.py | BSD-3-Clause |
def _on_graph_change(self):
"""Update the shader when the graph data changes."""
# if the user clears a graph after it has been created, vispy offers
# no method to clear the data, therefore, we need to set private
# attributes to None to prevent errors
if self.layer._view_graph... | Update the shader when the graph data changes. | _on_graph_change | python | napari/napari | src/napari/_vispy/layers/tracks.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/tracks.py | BSD-3-Clause |
def generate_vector_meshes(vectors, width, length, vector_style):
"""Generates list of mesh vertices and triangles from a list of vectors
Parameters
----------
vectors : (N, 2, D) array
A list of N vectors with start point and projections of the vector
in D dimensions, where D is 2 or 3... | Generates list of mesh vertices and triangles from a list of vectors
Parameters
----------
vectors : (N, 2, D) array
A list of N vectors with start point and projections of the vector
in D dimensions, where D is 2 or 3.
width : float
width of the vectors' bases
length : floa... | generate_vector_meshes | python | napari/napari | src/napari/_vispy/layers/vectors.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/vectors.py | BSD-3-Clause |
def generate_vector_meshes_2D(
vectors, width, length, vector_style, p=(0, 0, 1)
):
"""Generates list of mesh vertices and triangles from a list of vectors
Parameters
----------
vectors : (N, 2, D) array
A list of N vectors with start point and projections of the vector
in D dimensi... | Generates list of mesh vertices and triangles from a list of vectors
Parameters
----------
vectors : (N, 2, D) array
A list of N vectors with start point and projections of the vector
in D dimensions, where D is 2 or 3.
width : float
width of the vectors' bases
length : floa... | generate_vector_meshes_2D | python | napari/napari | src/napari/_vispy/layers/vectors.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/vectors.py | BSD-3-Clause |
def generate_meshes_line_2D(vectors, width, length, p):
"""Generates list of mesh vertices and triangles from a list of vectors.
Vectors are composed of 4 vertices and 2 triangles.
Vertices are generated according to the following scheme::
1---x---0
| . |
| . |
| ... | Generates list of mesh vertices and triangles from a list of vectors.
Vectors are composed of 4 vertices and 2 triangles.
Vertices are generated according to the following scheme::
1---x---0
| . |
| . |
| . |
3---v---2
Where x marks the start point of t... | generate_meshes_line_2D | python | napari/napari | src/napari/_vispy/layers/vectors.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/vectors.py | BSD-3-Clause |
def generate_meshes_triangle_2D(vectors, width, length, p):
"""Generate meshes forming 2D isosceles triangles to represent input vectors.
Vectors are composed of 3 vertices and 1 triangles.
Vertices are generated according to the following scheme::
1---x---0
. .
. .
... | Generate meshes forming 2D isosceles triangles to represent input vectors.
Vectors are composed of 3 vertices and 1 triangles.
Vertices are generated according to the following scheme::
1---x---0
. .
. .
. .
2
Where x marks the start point of the v... | generate_meshes_triangle_2D | python | napari/napari | src/napari/_vispy/layers/vectors.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/vectors.py | BSD-3-Clause |
def generate_meshes_arrow_2D(vectors, width, length, p):
"""Generate mesh forming 2D arrows given input vectors.
Vectors are composed of 7 vertices and 3 triangles.
Vertices are generated according to the following scheme::
1---x---0
| . |
| . |
| ... | Generate mesh forming 2D arrows given input vectors.
Vectors are composed of 7 vertices and 3 triangles.
Vertices are generated according to the following scheme::
1---x---0
| . |
| . |
| . |
5---3-------2---4
. .
... | generate_meshes_arrow_2D | python | napari/napari | src/napari/_vispy/layers/vectors.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/layers/vectors.py | BSD-3-Clause |
def _only_when_enabled(callback):
"""Decorator that wraps a callback of VispyLabelsPolygonOverlay.
It ensures that the callback is only executed when all the conditions are met:
1) The overlay is enabled;
2) The number of displayed dimensions is 2 (it can only work in 2D);
3) The number of dimensio... | Decorator that wraps a callback of VispyLabelsPolygonOverlay.
It ensures that the callback is only executed when all the conditions are met:
1) The overlay is enabled;
2) The number of displayed dimensions is 2 (it can only work in 2D);
3) The number of dimensions across which labels will be edited is ... | _only_when_enabled | python | napari/napari | src/napari/_vispy/overlays/labels_polygon.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/overlays/labels_polygon.py | BSD-3-Clause |
def _on_mouse_move(self, layer, event):
"""Continuously redraw the latest polygon point with the current mouse position."""
if self._num_points == 0:
return
pos = self._get_mouse_coordinates(event)
self.overlay.points = self.overlay.points[:-1] + [pos.tolist()] | Continuously redraw the latest polygon point with the current mouse position. | _on_mouse_move | python | napari/napari | src/napari/_vispy/overlays/labels_polygon.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/overlays/labels_polygon.py | BSD-3-Clause |
def _calculate_best_length(
self, desired_length: float
) -> tuple[float, pint.Quantity]:
"""Calculate new quantity based on the pixel length of the bar.
Parameters
----------
desired_length : float
Desired length of the scale bar in world size.
Returns
... | Calculate new quantity based on the pixel length of the bar.
Parameters
----------
desired_length : float
Desired length of the scale bar in world size.
Returns
-------
new_length : float
New length of the scale bar in world size based
... | _calculate_best_length | python | napari/napari | src/napari/_vispy/overlays/scale_bar.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/overlays/scale_bar.py | BSD-3-Clause |
def _on_zoom_change(self, *, force: bool = False):
"""Update axes length based on zoom scale."""
# If scale has not changed, do not redraw
scale = 1 / self.viewer.camera.zoom
if abs(np.log10(self._scale) - np.log10(scale)) < 1e-4 and not force:
return
self._scale = s... | Update axes length based on zoom scale. | _on_zoom_change | python | napari/napari | src/napari/_vispy/overlays/scale_bar.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/overlays/scale_bar.py | BSD-3-Clause |
def _on_data_change(self):
"""Change color and data of scale bar and box."""
color = self.overlay.color
box_color = self.overlay.box_color
if not self.overlay.colored:
if self.overlay.box:
# The box is visible - set the scale bar color to the negative of the
... | Change color and data of scale bar and box. | _on_data_change | python | napari/napari | src/napari/_vispy/overlays/scale_bar.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/overlays/scale_bar.py | BSD-3-Clause |
def crosshair_pixmap():
"""Create a cross cursor with white/black hollow square pixmap in the middle.
For use as points cursor."""
size = 25
pixmap = QPixmap(QSize(size, size))
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
# Base measures
width = 1
center = 3 ... | Create a cross cursor with white/black hollow square pixmap in the middle.
For use as points cursor. | crosshair_pixmap | python | napari/napari | src/napari/_vispy/utils/cursor.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/cursor.py | BSD-3-Clause |
def square_pixmap(size: int):
"""Create a white/black hollow square pixmap. For use as labels cursor."""
size = max(int(size), 1)
pixmap = QPixmap(QSize(size, size))
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
painter.setPen(Qt.GlobalColor.white)
painter.drawRect(0, 0,... | Create a white/black hollow square pixmap. For use as labels cursor. | square_pixmap | python | napari/napari | src/napari/_vispy/utils/cursor.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/cursor.py | BSD-3-Clause |
def _opengl_context() -> Generator[None, None, None]:
"""Assure we are running with a valid OpenGL context.
Only create a Canvas is one doesn't exist. Creating and closing a
Canvas causes vispy to process Qt events which can cause problems.
Ideally call opengl_context() on start after creating your fir... | Assure we are running with a valid OpenGL context.
Only create a Canvas is one doesn't exist. Creating and closing a
Canvas causes vispy to process Qt events which can cause problems.
Ideally call opengl_context() on start after creating your first
Canvas. However it will work either way.
| _opengl_context | python | napari/napari | src/napari/_vispy/utils/gl.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/gl.py | BSD-3-Clause |
def get_max_texture_sizes() -> tuple[int, int]:
"""Return the maximum texture sizes for 2D and 3D rendering.
If this function is called without an OpenGL context it will create a
temporary non-visible Canvas. Either way the lru_cache means subsequent
calls to thing function will return the original val... | Return the maximum texture sizes for 2D and 3D rendering.
If this function is called without an OpenGL context it will create a
temporary non-visible Canvas. Either way the lru_cache means subsequent
calls to thing function will return the original values without
actually running again.
Returns
... | get_max_texture_sizes | python | napari/napari | src/napari/_vispy/utils/gl.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/gl.py | BSD-3-Clause |
def fix_data_dtype(data: npt.NDArray) -> npt.NDArray:
"""Makes sure the dtype of the data is accetpable to vispy.
Acceptable types are int8, uint8, int16, uint16, float32.
Parameters
----------
data : np.ndarray
Data that will need to be of right type.
Returns
-------
np.ndarr... | Makes sure the dtype of the data is accetpable to vispy.
Acceptable types are int8, uint8, int16, uint16, float32.
Parameters
----------
data : np.ndarray
Data that will need to be of right type.
Returns
-------
np.ndarray
Data that is of right type and will be passed to v... | fix_data_dtype | python | napari/napari | src/napari/_vispy/utils/gl.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/gl.py | BSD-3-Clause |
def quaternion2euler_degrees(
quaternion: Quaternion,
) -> tuple[float, float, float]:
"""Converts VisPy quaternion into euler angle representation.
Euler angles have degeneracies, so the output might different
from the Euler angles that might have been used to generate
the input quaternion.
E... | Converts VisPy quaternion into euler angle representation.
Euler angles have degeneracies, so the output might different
from the Euler angles that might have been used to generate
the input quaternion.
Euler angles representation also has a singularity
near pitch = Pi/2 ; to avoid this, we set to... | quaternion2euler_degrees | python | napari/napari | src/napari/_vispy/utils/quaternion.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/quaternion.py | BSD-3-Clause |
def update_text(
*,
node: Text,
layer: Points | Shapes,
):
"""Update the vispy text node with a layer's text parameters.
Parameters
----------
node : vispy.scene.visuals.Text
The text node to be updated.
layer : Union[Points, Shapes]
A layer with text.
"""
ndisp... | Update the vispy text node with a layer's text parameters.
Parameters
----------
node : vispy.scene.visuals.Text
The text node to be updated.
layer : Union[Points, Shapes]
A layer with text.
| update_text | python | napari/napari | src/napari/_vispy/utils/text.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/text.py | BSD-3-Clause |
def create_vispy_layer(
layer: Layer, *args: Any, **kwargs: Any
) -> VispyBaseLayer:
"""Create vispy visual for a layer based on its layer type.
Parameters
----------
layer : napari.layers._base_layer.Layer
Layer that needs its property widget created.
Returns
-------
visual : ... | Create vispy visual for a layer based on its layer type.
Parameters
----------
layer : napari.layers._base_layer.Layer
Layer that needs its property widget created.
Returns
-------
visual : VispyBaseLayer
Vispy layer
| create_vispy_layer | python | napari/napari | src/napari/_vispy/utils/visual.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/visual.py | BSD-3-Clause |
def create_vispy_overlay(overlay: Overlay, **kwargs) -> VispyBaseOverlay:
"""
Create vispy visual for Overlay based on its type.
Parameters
----------
overlay : napari.components.overlays.VispyBaseOverlay
The overlay to create a visual for.
Returns
-------
visual : VispyBaseOve... |
Create vispy visual for Overlay based on its type.
Parameters
----------
overlay : napari.components.overlays.VispyBaseOverlay
The overlay to create a visual for.
Returns
-------
visual : VispyBaseOverlay
Vispy overlay
| create_vispy_overlay | python | napari/napari | src/napari/_vispy/utils/visual.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/visual.py | BSD-3-Clause |
def get_view_direction_in_scene_coordinates(
view: ViewBox,
ndim: int,
dims_displayed: tuple[int],
) -> np.ndarray | None:
"""Calculate the unit vector pointing in the direction of the view.
This is only for 3D viewing, so it returns None when
len(dims_displayed) == 2.
Adapted From:
htt... | Calculate the unit vector pointing in the direction of the view.
This is only for 3D viewing, so it returns None when
len(dims_displayed) == 2.
Adapted From:
https://stackoverflow.com/questions/37877592/
get-view-direction-relative-to-scene-in-vispy/37882984
Parameters
----------
v... | get_view_direction_in_scene_coordinates | python | napari/napari | src/napari/_vispy/utils/visual.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/utils/visual.py | BSD-3-Clause |
def make_dashed_line(num_dashes, axis):
"""Make a dashed line.
Parameters
----------
num_dashes : int
Number of dashes in the line.
axis : int
Axis which is dashed.
Returns
-------
np.ndarray
Dashed line, of shape (num_dashes, 3) with zeros in
the non da... | Make a dashed line.
Parameters
----------
num_dashes : int
Number of dashes in the line.
axis : int
Axis which is dashed.
Returns
-------
np.ndarray
Dashed line, of shape (num_dashes, 3) with zeros in
the non dashed axes and line segments in the dashed
... | make_dashed_line | python | napari/napari | src/napari/_vispy/visuals/axes.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/visuals/axes.py | BSD-3-Clause |
def make_arrow_head(num_segments, axis):
"""Make an arrowhead line.
Parameters
----------
num_segments : int
Number of segments in the arrowhead.
axis
Arrowhead direction.
Returns
-------
np.ndarray, np.ndarray
Vertices and faces of the arrowhead.
"""
co... | Make an arrowhead line.
Parameters
----------
num_segments : int
Number of segments in the arrowhead.
axis
Arrowhead direction.
Returns
-------
np.ndarray, np.ndarray
Vertices and faces of the arrowhead.
| make_arrow_head | python | napari/napari | src/napari/_vispy/visuals/axes.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/visuals/axes.py | BSD-3-Clause |
def set_bounds(self, bounds):
"""Update the bounding box based on a layer's bounds."""
if any(b is None for b in bounds):
return
vertices = np.array(list(product(*bounds)))
self.lines.set_data(
pos=vertices,
connect=self._edges.copy(),
co... | Update the bounding box based on a layer's bounds. | set_bounds | python | napari/napari | src/napari/_vispy/visuals/bounding_box.py | https://github.com/napari/napari/blob/master/src/napari/_vispy/visuals/bounding_box.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.