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_shear_matrix_from_angle():
"""Test creating a shear matrix from an angle."""
matrix = shear_matrix_from_angle(35)
np.testing.assert_almost_equal(np.diag(matrix), [1] * 3)
np.testing.assert_almost_equal(matrix[-1, 0], np.tan(np.deg2rad(55))) | Test creating a shear matrix from an angle. | test_shear_matrix_from_angle | python | napari/napari | src/napari/utils/transforms/_tests/test_transform_utils.py | https://github.com/napari/napari/blob/master/src/napari/utils/transforms/_tests/test_transform_utils.py | BSD-3-Clause |
def test_is_matrix_upper_triangular():
"""Test if a matrix is upper triangular."""
assert is_matrix_upper_triangular(upper)
assert not is_matrix_upper_triangular(lower)
assert not is_matrix_upper_triangular(full) | Test if a matrix is upper triangular. | test_is_matrix_upper_triangular | python | napari/napari | src/napari/utils/transforms/_tests/test_transform_utils.py | https://github.com/napari/napari/blob/master/src/napari/utils/transforms/_tests/test_transform_utils.py | BSD-3-Clause |
def test_is_matrix_lower_triangular():
"""Test if a matrix is lower triangular."""
assert not is_matrix_lower_triangular(upper)
assert is_matrix_lower_triangular(lower)
assert not is_matrix_lower_triangular(full) | Test if a matrix is lower triangular. | test_is_matrix_lower_triangular | python | napari/napari | src/napari/utils/transforms/_tests/test_transform_utils.py | https://github.com/napari/napari/blob/master/src/napari/utils/transforms/_tests/test_transform_utils.py | BSD-3-Clause |
def __delitem__(self, key: MaybeNestedIndex):
"""Remove item at ``key``, and unparent."""
if isinstance(key, int | tuple):
self[key].parent = None # type: ignore
else:
for item in self[key]:
item.parent = None
super().__delitem__(key) | Remove item at ``key``, and unparent. | __delitem__ | python | napari/napari | src/napari/utils/tree/group.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/group.py | BSD-3-Clause |
def traverse(
self, leaves_only=False, with_ancestors=False
) -> Generator[NodeType, None, None]:
"""Recursive all nodes and leaves of the Group tree."""
obj = self.root() if with_ancestors else self
if not leaves_only:
yield obj
for child in obj:
yiel... | Recursive all nodes and leaves of the Group tree. | traverse | python | napari/napari | src/napari/utils/tree/group.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/group.py | BSD-3-Clause |
def index_from_root(self) -> tuple[int, ...]:
"""Return index of this Node relative to root.
Will return ``()`` if this object *is* the root.
"""
item = self
indices: list[int] = []
while item.parent is not None:
indices.insert(0, item.index_in_parent()) # t... | Return index of this Node relative to root.
Will return ``()`` if this object *is* the root.
| index_from_root | python | napari/napari | src/napari/utils/tree/node.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/node.py | BSD-3-Clause |
def iter_parents(self):
"""Iterate the parent chain, starting with nearest relatives"""
obj = self.parent
while obj:
yield obj
obj = obj.parent | Iterate the parent chain, starting with nearest relatives | iter_parents | python | napari/napari | src/napari/utils/tree/node.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/node.py | BSD-3-Clause |
def traverse(
self, leaves_only=False, with_ancestors=False
) -> Generator['Node', None, None]:
"""Recursive all nodes and leaves of the Node.
This is mostly used by :class:`~napari.utils.tree.Group`, which can
also traverse children. A ``Node`` simply yields itself.
"""
... | Recursive all nodes and leaves of the Node.
This is mostly used by :class:`~napari.utils.tree.Group`, which can
also traverse children. A ``Node`` simply yields itself.
| traverse | python | napari/napari | src/napari/utils/tree/node.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/node.py | BSD-3-Clause |
def unparent(self):
"""Remove this object from its parent."""
if self.parent is not None:
self.parent.remove(self)
return self
raise IndexError(
trans._(
'Cannot unparent orphaned Node: {node!r}',
deferred=True,
... | Remove this object from its parent. | unparent | python | napari/napari | src/napari/utils/tree/node.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/node.py | BSD-3-Clause |
def test_relative_node_indexing(tree):
"""Test that nodes know their index relative to parent and root."""
root: Group[Node] = tree
assert root.is_group()
assert not root[0].is_group()
assert root.index_from_root() == ()
assert root.index_in_parent() is None
g1 = root[1]
assert g1.name ... | Test that nodes know their index relative to parent and root. | test_relative_node_indexing | python | napari/napari | src/napari/utils/tree/_tests/test_tree_model.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/_tests/test_tree_model.py | BSD-3-Clause |
def test_slicing(tree):
"""Indexing into a group returns a group instance."""
assert tree.is_group()
slc = tree[::-2] # take every other item, starting from the end
assert [x.name for x in slc] == ['9', 'g1']
assert slc.is_group()
expected = ['Group', '9', 'g1', '2', 'g2', '3', '4', '5', '6', '... | Indexing into a group returns a group instance. | test_slicing | python | napari/napari | src/napari/utils/tree/_tests/test_tree_model.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/_tests/test_tree_model.py | BSD-3-Clause |
def test_contains(tree):
"""Test that the ``in`` operator works for nested nodes."""
g1 = tree[1]
assert g1.name == 'g1'
assert g1 in tree
g1_0 = g1[0]
assert g1_0.name == '2'
assert g1_0 in g1
assert g1_0 in tree
# If you need to know if an item is an immediate child, you can use ... | Test that the ``in`` operator works for nested nodes. | test_contains | python | napari/napari | src/napari/utils/tree/_tests/test_tree_model.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/_tests/test_tree_model.py | BSD-3-Clause |
def test_nested_deletion(tree):
"""Test that we can delete nested indices from the root."""
# a tree is a NestedEventedList, so we can use nested_indices
node5 = tree[1, 2]
assert node5.name == '5'
del tree[1, 2]
assert node5 not in tree
# nested indices may also be slices
g2 = tree[1, ... | Test that we can delete nested indices from the root. | test_nested_deletion | python | napari/napari | src/napari/utils/tree/_tests/test_tree_model.py | https://github.com/napari/napari/blob/master/src/napari/utils/tree/_tests/test_tree_model.py | BSD-3-Clause |
def test_bind_multiple_action(action_manager):
"""
Test we can have multiple bindings per action
"""
action_manager.register_action(
'napari:test_action_2', lambda: None, 'this is a test action', None
)
action_manager.bind_shortcut('napari:test_action_2', 'X')
action_manager.bind_s... |
Test we can have multiple bindings per action
| test_bind_multiple_action | python | napari/napari | src/napari/utils/_tests/test_action_manager.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_action_manager.py | BSD-3-Clause |
def test_normalize_dtype_torch(dtype_str):
"""torch doesn't have uint for >8bit, so it gets its own test."""
# torch doesn't let you specify dtypes as str,
# see https://github.com/pytorch/pytorch/issues/40568
torch_arr = torch.zeros(5, dtype=getattr(torch, dtype_str))
np_arr = np.zeros(5, dtype=dty... | torch doesn't have uint for >8bit, so it gets its own test. | test_normalize_dtype_torch | python | napari/napari | src/napari/utils/_tests/test_dtype.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_dtype.py | BSD-3-Clause |
def test_normalize_dtype_np_noop(module, dtype_str):
"""Check that normalize dtype works as expected for plain NumPy dtypes."""
module_arr = module.zeros(5, dtype=dtype_str)
np_arr = np.zeros(5, dtype=normalize_dtype(module_arr.dtype))
assert normalize_dtype(module_arr.dtype) is normalize_dtype(np_arr.d... | Check that normalize dtype works as expected for plain NumPy dtypes. | test_normalize_dtype_np_noop | python | napari/napari | src/napari/utils/_tests/test_dtype.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_dtype.py | BSD-3-Clause |
def test_rotation_matrix_from_vectors_3d(vec_1, vec_2):
"""Test that calculated rotation matrices align vec1 to vec2."""
rotation_matrix = rotation_matrix_from_vectors_3d(vec_1, vec_2)
rotated_1 = rotation_matrix.dot(vec_1)
unit_rotated_1 = rotated_1 / np.linalg.norm(rotated_1)
unit_vec_2 = vec_2 ... | Test that calculated rotation matrices align vec1 to vec2. | test_rotation_matrix_from_vectors_3d | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_intersect_line_with_plane_3d(
line_position, line_direction, plane_position, plane_normal, expected
):
"""Test that arbitrary line-plane intersections are correctly calculated."""
intersection = intersect_line_with_plane_3d(
line_position, line_direction, plane_position, plane_normal
)
... | Test that arbitrary line-plane intersections are correctly calculated. | test_intersect_line_with_plane_3d | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_intersect_line_with_multiple_planes_3d():
"""Test intersecting a ray with multiple planes and getting the intersection
with each one.
"""
line_position = [0, 0, 1]
line_direction = [0, 0, -1]
plane_positions = [[0, 0, 0], [0, 0, 1]]
plane_normals = [[0, 0, 1], [0, 0, 1]]
interse... | Test intersecting a ray with multiple planes and getting the intersection
with each one.
| test_intersect_line_with_multiple_planes_3d | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_clamp_multiple_points_to_bounding_box():
"""test that an array of points can be clamped to the bbox"""
points = np.array([[10, 10, 10], [0, 5, 0], [20, 0, 20]])
bbox = np.array([[0, 25], [0, 10], [3, 25]])
expected_points = np.array([[10, 9, 10], [0, 5, 3], [20, 0, 20]])
clamped_points = cl... | test that an array of points can be clamped to the bbox | test_clamp_multiple_points_to_bounding_box | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_face_coordinate_from_bounding_box(
bounding_box, face_normal, expected
):
"""Test that the correct face coordinate is calculated.
Face coordinate is a float which is the value where a face of a bounding box,
defined by a face normal, intersects the axis the normal vector is aligned with.
"... | Test that the correct face coordinate is calculated.
Face coordinate is a float which is the value where a face of a bounding box,
defined by a face normal, intersects the axis the normal vector is aligned with.
| test_face_coordinate_from_bounding_box | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_line_with_axis_aligned_plane(
plane_intercept, plane_normal, line_start, line_direction, expected
):
"""Test that intersections between line and axis aligned plane are
calculated correctly.
"""
intersection = intersect_line_with_axis_aligned_plane(
plane_intercept, plane_normal, lin... | Test that intersections between line and axis aligned plane are
calculated correctly.
| test_line_with_axis_aligned_plane | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_bounding_box_to_face_vertices_3d():
"""Test that bounding_box_to_face_vertices returns a dictionary of vertices
for each face of an axis aligned 3D bounding box.
"""
bounding_box = np.array([[5, 10], [15, 20], [25, 30]])
face_vertices = bounding_box_to_face_vertices(bounding_box)
expect... | Test that bounding_box_to_face_vertices returns a dictionary of vertices
for each face of an axis aligned 3D bounding box.
| test_bounding_box_to_face_vertices_3d | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_bounding_box_to_face_vertices_nd():
"""Test that bounding_box_to_face_vertices returns a dictionary of vertices
for each face of an axis aligned nD bounding box.
"""
bounding_box = np.array([[0, 0], [0, 0], [5, 10], [15, 20], [25, 30]])
face_vertices = bounding_box_to_face_vertices(bounding... | Test that bounding_box_to_face_vertices returns a dictionary of vertices
for each face of an axis aligned nD bounding box.
| test_bounding_box_to_face_vertices_nd | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_inside_triangles(triangle, expected):
"""Test that inside triangles returns an array of True for triangles which
contain the origin, False otherwise.
"""
inside = np.all(inside_triangles(triangle))
assert inside == expected | Test that inside triangles returns an array of True for triangles which
contain the origin, False otherwise.
| test_inside_triangles | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_point_in_quadrilateral_2d(point, quadrilateral, expected):
"""Test that point_in_quadrilateral_2d determines whether a point
is inside a quadrilateral.
"""
inside = point_in_quadrilateral_2d(point, quadrilateral)
assert inside == expected | Test that point_in_quadrilateral_2d determines whether a point
is inside a quadrilateral.
| test_point_in_quadrilateral_2d | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_click_in_quadrilateral_3d(
click_position, quadrilateral, view_dir, expected
):
"""Test that click in quadrilateral 3d determines whether the projection
of a 3D point onto a plane falls within a 3d quadrilateral projected
onto the same plane
"""
in_quadrilateral = line_in_quadrilateral_... | Test that click in quadrilateral 3d determines whether the projection
of a 3D point onto a plane falls within a 3d quadrilateral projected
onto the same plane
| test_click_in_quadrilateral_3d | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_find_front_back_face(
click_position, bounding_box, view_dir, expected
):
"""Test that find front_back face finds the faces of an axis aligned
bounding box that a ray intersects with.
"""
result = find_front_back_face(click_position, bounding_box, view_dir)
for idx, item in enumerate(re... | Test that find front_back face finds the faces of an axis aligned
bounding box that a ray intersects with.
| test_find_front_back_face | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_intersect_line_with_axis_aligned_bounding_box_3d(
line_position, line_direction, bounding_box, face_normal, expected
):
"""Test that intersections between lines and axis aligned
bounding boxes are correctly computed.
"""
result = intersect_line_with_axis_aligned_bounding_box_3d(
lin... | Test that intersections between lines and axis aligned
bounding boxes are correctly computed.
| test_intersect_line_with_axis_aligned_bounding_box_3d | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_distance_between_point_and_line_3d():
"""Test that distance between points and lines are correctly computed."""
line_position = np.random.random(size=3)
line_direction = np.array([0, 0, 1])
# find a point a random distance away on the line
point_on_line = line_position + np.random.random(1... | Test that distance between points and lines are correctly computed. | test_distance_between_point_and_line_3d | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_find_nearest_triangle_intersection_no_intersection():
"""Test find_nearest_triangle_intersection() when there is not intersection"""
triangles = np.array(
[
[[3, 0, 0], [3, 0, 10], [3, 10, 0]],
[[5, 0, 0], [5, 0, 10], [5, 10, 0]],
[
[2, 50, 50... | Test find_nearest_triangle_intersection() when there is not intersection | test_find_nearest_triangle_intersection_no_intersection | python | napari/napari | src/napari/utils/_tests/test_geometry.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_geometry.py | BSD-3-Clause |
def test_napari_from_conda_with_metadata(monkeypatch):
"""Test _napari_from_conda when the napari metadata file exists."""
from napari import __version__
def mock_glob(self, pattern):
return [
Path(f'/mock/conda-meta/napari-{__version__}-py2foo3bar.json'),
Path('/mock/conda-... | Test _napari_from_conda when the napari metadata file exists. | test_napari_from_conda_with_metadata | python | napari/napari | src/napari/utils/_tests/test_info.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_info.py | BSD-3-Clause |
def test_napari_from_conda_without_metadata(monkeypatch):
"""Test _napari_from_conda when no napari metadata file exists."""
def mock_glob(self, pattern):
return [
Path('/mock/conda-meta/napari-svg-0.2.1-py3bar2foo.json'),
Path('/mock/conda-meta/napari-console-0.1.3-py2foo3bar.j... | Test _napari_from_conda when no napari metadata file exists. | test_napari_from_conda_without_metadata | python | napari/napari | src/napari/utils/_tests/test_info.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_info.py | BSD-3-Clause |
def test_imsave_bool_tiff(tmp_path):
"""Test saving a boolean array to a tiff file."""
np.random.seed(0)
data = np.random.randint(low=0, high=2, size=(10, 15), dtype=bool)
image_file_path = tmp_path / 'bool_image.tif'
assert not image_file_path.is_file()
# create image and assert image file cre... | Test saving a boolean array to a tiff file. | test_imsave_bool_tiff | python | napari/napari | src/napari/utils/_tests/test_io.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_io.py | BSD-3-Clause |
def test_imsave_large_file(monkeypatch, tmp_path):
"""Test saving a bigtiff file.
In napari IO, we use compression when saving to tiff. bigtiff mode
is required when data size *after compression* is over 4GB. However,
bigtiff is not as broadly implemented as normal tiff, so we don't want to
always ... | Test saving a bigtiff file.
In napari IO, we use compression when saving to tiff. bigtiff mode
is required when data size *after compression* is over 4GB. However,
bigtiff is not as broadly implemented as normal tiff, so we don't want to
always use that flag. Therefore, in our internal code, we catch t... | test_imsave_large_file | python | napari/napari | src/napari/utils/_tests/test_io.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_io.py | BSD-3-Clause |
def test_deprecated_class_name():
"""Test the deprecated class name function."""
class macOS:
pass
MacOSX = deprecated_class_name(
macOS, 'MacOSX', version='10.12', since_version='10.11'
)
with pytest.warns(FutureWarning, match='deprecated.*macOS'):
_os = MacOSX()
wit... | Test the deprecated class name function. | test_deprecated_class_name | python | napari/napari | src/napari/utils/_tests/test_migrations.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_migrations.py | BSD-3-Clause |
def test_basic():
"""Check that name is guessed correctly."""
assert magic_name(42) is None
z = 5
assert magic_name(z) == 'z'
assert eval_with_filename("magic_name(y:='SPAM')") == 'y' | Check that name is guessed correctly. | test_basic | python | napari/napari | src/napari/utils/_tests/test_naming.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_naming.py | BSD-3-Clause |
def test_function_chains():
"""Check that nothing weird happens with function chains."""
def foo():
return 42
assert magic_name(foo()) is None | Check that nothing weird happens with function chains. | test_function_chains | python | napari/napari | src/napari/utils/_tests/test_naming.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_naming.py | BSD-3-Clause |
def test_assignment():
"""Check that assignment expressions do not confuse it."""
result = magic_name(17)
assert result is None
t = 3
result = magic_name(t)
assert result == 't'
result = eval_with_filename('magic_name(d:=42)')
assert result == 'd' | Check that assignment expressions do not confuse it. | test_assignment | python | napari/napari | src/napari/utils/_tests/test_naming.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_naming.py | BSD-3-Clause |
def test_path_prefix(tmp_path):
"""Test that path prefixes work as expected."""
mname = functools.partial(magic_name, path_prefix=__file__)
def foo(x):
def bar(y):
return mname(y)
return bar(x)
assert eval_with_filename('foo(42)', str(tmp_path / 'hi.py')) is None
r = ... | Test that path prefixes work as expected. | test_path_prefix | python | napari/napari | src/napari/utils/_tests/test_naming.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_naming.py | BSD-3-Clause |
def test_empty_path_prefix(tmp_path):
"""Test an empty path prefix that matches the entire stack"""
# Repeat tests with an empty path_prefix
mname = functools.partial(magic_name, path_prefix='')
def foo(x):
def bar(y):
return mname(y)
return bar(x)
# Test are all None ... | Test an empty path prefix that matches the entire stack | test_empty_path_prefix | python | napari/napari | src/napari/utils/_tests/test_naming.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_naming.py | BSD-3-Clause |
def test_notification_manager_no_gui(monkeypatch):
"""
Direct test of the notification manager.
This does not test the integration with the gui, but test that the
notification manager itself can receive a info, warning or error.
"""
previous_exhook = sys.excepthook
with notification_manager... |
Direct test of the notification manager.
This does not test the integration with the gui, but test that the
notification manager itself can receive a info, warning or error.
| test_notification_manager_no_gui | python | napari/napari | src/napari/utils/_tests/test_notification_manager.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_notification_manager.py | BSD-3-Clause |
def test_notification_manager_no_gui_with_threading():
"""
Direct test of the notification manager.
This does not test the integration with the gui, but test that
exceptions and warnings from threads are correctly captured.
"""
def _warn():
warnings.showwarning(
UserWarning... |
Direct test of the notification manager.
This does not test the integration with the gui, but test that
exceptions and warnings from threads are correctly captured.
| test_notification_manager_no_gui_with_threading | python | napari/napari | src/napari/utils/_tests/test_notification_manager.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_notification_manager.py | BSD-3-Clause |
def assert_progress_added_to_all(prog):
"""Check prog is added to `progress_instances` on init & removed on close"""
assert prog in progress._all_instances
yield
assert prog not in progress._all_instances | Check prog is added to `progress_instances` on init & removed on close | assert_progress_added_to_all | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progress_with_iterable():
"""Test typical iterable is correctly built"""
r = range(100)
pbr = progress(r, desc='iterable')
assert pbr.iterable is r
assert pbr.n == 0
with assert_progress_added_to_all(pbr):
pbr.close() | Test typical iterable is correctly built | test_progress_with_iterable | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progress_with_total():
"""Test progress with total not iterable, and manual updates"""
pbr = progress(total=5, desc='total')
assert pbr.n == 0
pbr.update(1)
assert pbr.n == 1
with assert_progress_added_to_all(pbr):
pbr.close() | Test progress with total not iterable, and manual updates | test_progress_with_total | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progress_with_context():
"""Test context manager works as expected"""
with progress(range(100), desc='context') as pbr:
assert pbr in progress._all_instances
assert pbr.n == 0
assert pbr not in progress._all_instances | Test context manager works as expected | test_progress_with_context | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progress_set_description():
"""Test setting description works as expected"""
pbr = progress(total=5)
pbr.set_description('Test')
assert pbr.desc == 'Test: '
pbr.close()
assert pbr not in progress._all_instances | Test setting description works as expected | test_progress_set_description | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progress_set_disable():
"""Test that the progress bar does not throw an attribute error when it is disabled."""
# before the changes in #5964 this failed with an AttributeError, because self.desc was not
# set in the super constructor of tqdm
pbr = progress(
total=5, disable=True, desc=... | Test that the progress bar does not throw an attribute error when it is disabled. | test_progress_set_disable | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progrange():
"""Test progrange shorthand for progress(range(n))"""
with progrange(10) as pbr, progress(range(10)) as pbr2:
assert pbr.iterable == pbr2.iterable
assert pbr not in progress._all_instances | Test progrange shorthand for progress(range(n)) | test_progrange | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progress_cancellation():
"""Test cancellation breaks the for loop"""
total = 10
pbr = cancelable_progress(range(total))
last_loop = -1
for i in pbr:
last_loop = i
# Let's cancel at i=total/2
if i == total / 2:
pbr.cancel()
assert pbr.is_canceled
a... | Test cancellation breaks the for loop | test_progress_cancellation | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progress_cancellation_with_callback():
"""Test that cancellation runs the callback function"""
total = 10
last_loop = -1
expected_last_loop = -2
def cancel_callback():
nonlocal last_loop
last_loop = expected_last_loop
pbr = cancelable_progress(range(total), cancel_call... | Test that cancellation runs the callback function | test_progress_cancellation_with_callback | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_progress_cancellation_with_generator():
"""Test that cancellation closes a generator with a finally clause."""
closed = False
def test_generator():
try:
i = 0
while True:
yield i
i += 1
finally:
nonlocal closed
... | Test that cancellation closes a generator with a finally clause. | test_progress_cancellation_with_generator | python | napari/napari | src/napari/utils/_tests/test_progress.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_progress.py | BSD-3-Clause |
def test_ReadOnlyWrapper_setitem():
"""test that ReadOnlyWrapper prevents setting items"""
d = {'hi': 3}
d_read_only = ReadOnlyWrapper(d)
with pytest.raises(TypeError):
d_read_only['hi'] = 5 | test that ReadOnlyWrapper prevents setting items | test_ReadOnlyWrapper_setitem | python | napari/napari | src/napari/utils/_tests/test_proxies.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_proxies.py | BSD-3-Clause |
def test_ReadOnlyWrapper_setattr():
"""test that ReadOnlyWrapper prevents setting attributes"""
class TestClass:
x = 3
tc = TestClass()
tc_read_only = ReadOnlyWrapper(tc)
with pytest.raises(TypeError):
tc_read_only.x = 5 | test that ReadOnlyWrapper prevents setting attributes | test_ReadOnlyWrapper_setattr | python | napari/napari | src/napari/utils/_tests/test_proxies.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_proxies.py | BSD-3-Clause |
def test_public_proxy_limited_to_napari():
"""Test that the recursive public proxy goes no farther than napari."""
viewer = ViewerModel()
viewer.add_points(None)
pv = PublicOnlyProxy(viewer)
assert not isinstance(pv.layers[0].data, PublicOnlyProxy) | Test that the recursive public proxy goes no farther than napari. | test_public_proxy_limited_to_napari | python | napari/napari | src/napari/utils/_tests/test_proxies.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_proxies.py | BSD-3-Clause |
def test_unwrap_on_call():
"""Check that PublicOnlyProxy'd arguments to methods of a
PublicOnlyProxy'd object are unwrapped before calling the method.
"""
evset = EventedSet()
public_only_evset = PublicOnlyProxy(evset)
text = 'aaa'
wrapped_text = PublicOnlyProxy(text)
public_only_evset.a... | Check that PublicOnlyProxy'd arguments to methods of a
PublicOnlyProxy'd object are unwrapped before calling the method.
| test_unwrap_on_call | python | napari/napari | src/napari/utils/_tests/test_proxies.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_proxies.py | BSD-3-Clause |
def test_unwrap_setattr():
"""Check that objects added with __setattr__ of an object wrapped with
PublicOnlyProxy are unwrapped before setting the attribute.
"""
@dataclass
class Sample:
attribute = 'aaa'
sample = Sample()
public_only_sample = PublicOnlyProxy(sample)
text = 'b... | Check that objects added with __setattr__ of an object wrapped with
PublicOnlyProxy are unwrapped before setting the attribute.
| test_unwrap_setattr | python | napari/napari | src/napari/utils/_tests/test_proxies.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_proxies.py | BSD-3-Clause |
def trans(tmp_path):
"""A good plugin that uses entry points."""
distinfo = tmp_path / 'napari_language_pack_es_CO-0.1.0.dist-info'
distinfo.mkdir()
(distinfo / 'top_level.txt').write_text('napari_language_pack_es_CO')
(distinfo / 'entry_points.txt').write_text(
'[napari.languagepack]\nes_CO... | A good plugin that uses entry points. | trans | python | napari/napari | src/napari/utils/_tests/test_translations.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_translations.py | BSD-3-Clause |
def test_deepcopy(kwargs):
"""Object containing translation strings can't be deep-copied.
See:
- https://github.com/napari/napari/issues/2911
- https://github.com/napari/napari/issues/4736
"""
kwargs['domain'] = 'napari'
t = TranslationString(**kwargs)
u = deepcopy(t)
assert t i... | Object containing translation strings can't be deep-copied.
See:
- https://github.com/napari/napari/issues/2911
- https://github.com/napari/napari/issues/4736
| test_deepcopy | python | napari/napari | src/napari/utils/_tests/test_translations.py | https://github.com/napari/napari/blob/master/src/napari/utils/_tests/test_translations.py | BSD-3-Clause |
def contains_dummy_action(menu_items: list[MenuOrSubmenu]) -> bool:
"""True if one of the menu_items is the dummy action, otherwise False.
Parameters
----------
menu_items : list[MenuOrSubmenu]
menu items belonging to a given menu
Returns
-------
bool
True if menu_items con... | True if one of the menu_items is the dummy action, otherwise False.
Parameters
----------
menu_items : list[MenuOrSubmenu]
menu items belonging to a given menu
Returns
-------
bool
True if menu_items contains dummy item otherwise false
| contains_dummy_action | python | napari/napari | src/napari/_app_model/utils.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/utils.py | BSD-3-Clause |
def is_empty_menu(menu_id: str) -> bool:
"""Return True if the given menu_id is empty, otherwise False
Parameters
----------
menu_id : str
id of the menu to check
Returns
-------
bool
True if the given menu_id is empty, otherwise False
"""
app = get_app_model()
... | Return True if the given menu_id is empty, otherwise False
Parameters
----------
menu_id : str
id of the menu to check
Returns
-------
bool
True if the given menu_id is empty, otherwise False
| is_empty_menu | python | napari/napari | src/napari/_app_model/utils.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/utils.py | BSD-3-Clause |
def get_dummy_action(menu_id: MenuId) -> tuple[Action, str]:
"""Return a dummy action to be used for the given menu.
The part of the menu_id after the final `/` will form
a unique id_key used for the action ID and the when
expression context key.
Parameters
----------
menu_id: MenuId
... | Return a dummy action to be used for the given menu.
The part of the menu_id after the final `/` will form
a unique id_key used for the action ID and the when
expression context key.
Parameters
----------
menu_id: MenuId
id of the menu to add the dummy action to
Returns
------... | get_dummy_action | python | napari/napari | src/napari/_app_model/utils.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/utils.py | BSD-3-Clause |
def _napari_names() -> dict[str, object]:
"""Napari names to inject into local namespace when evaluating type hints."""
import napari
from napari import components, layers, viewer
def _public_types(module):
return {
name: val
for name, val in vars(module).items()
... | Napari names to inject into local namespace when evaluating type hints. | _napari_names | python | napari/napari | src/napari/_app_model/_app.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/_app.py | BSD-3-Clause |
def get_current(viewer: ViewerModel) -> bool:
"""return the current value of the viewer attribute"""
attr = getattr(viewer, viewer_attribute)
return getattr(attr, sub_attribute) | return the current value of the viewer attribute | get_current | python | napari/napari | src/napari/_app_model/actions/_toggle_action.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/actions/_toggle_action.py | BSD-3-Clause |
def contributables(cls) -> set['MenuId']:
"""Set of all menu ids that can be contributed to by plugins."""
# TODO: add these to docs, with a lookup for what each menu is/does.
_contributables = {
cls.FILE_IO_UTILITIES,
cls.FILE_ACQUIRE,
cls.FILE_NEW_LAYER,
... | Set of all menu ids that can be contributed to by plugins. | contributables | python | napari/napari | src/napari/_app_model/constants/_menus.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/constants/_menus.py | BSD-3-Clause |
def is_menu_contributable(menu_id: str) -> bool:
"""Return True if the given menu_id is a menu that plugins can contribute to."""
return (
menu_id in MenuId.contributables()
if menu_id.startswith('napari/')
# TODO: this is intended to allow plugins to contribute to other plugins' menus b... | Return True if the given menu_id is a menu that plugins can contribute to. | is_menu_contributable | python | napari/napari | src/napari/_app_model/constants/_menus.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/constants/_menus.py | BSD-3-Clause |
def new_child(self, m: dict | None = None) -> Context: # type: ignore
"""New ChainMap with a new map followed by all previous maps.
If no map is provided, an empty dict is used.
"""
# important to use self, not *self.maps
return Context(m or {}, self) # type: ignore | New ChainMap with a new map followed by all previous maps.
If no map is provided, an empty dict is used.
| new_child | python | napari/napari | src/napari/_app_model/context/_context.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/context/_context.py | BSD-3-Clause |
def update(self, event: 'Event') -> None:
"""Trigger an update of all "getter" functions in this namespace."""
for k, get in self._getters.items():
setattr(self, k, get(event.source)) | Trigger an update of all "getter" functions in this namespace. | update | python | napari/napari | src/napari/_app_model/context/_context_keys.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/context/_context_keys.py | BSD-3-Clause |
def test_app(mock_app_model):
"""just make sure our app model is registering menus and commands"""
app = get_app_model()
assert app.name == 'test_app'
assert list(app.menus)
assert list(app.commands)
# assert list(app.keybindings) # don't have any yet | just make sure our app model is registering menus and commands | test_app | python | napari/napari | src/napari/_app_model/_tests/test_app.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/_tests/test_app.py | BSD-3-Clause |
def test_app_injection(mock_app_model):
"""Simple test to make sure napari namespaces are working in app injection."""
app = get_app_model()
def use_points(points: 'Points'):
return points
p = Points()
def provide_points() -> 'Points':
return p
with app.injection_store.regist... | Simple test to make sure napari namespaces are working in app injection. | test_app_injection | python | napari/napari | src/napari/_app_model/_tests/test_app.py | https://github.com/napari/napari/blob/master/src/napari/_app_model/_tests/test_app.py | BSD-3-Clause |
def create_worker(
func: FunctionType | GeneratorType,
*args,
_start_thread: bool | None = None,
_connect: dict[str, Callable | Sequence[Callable]] | None = None,
_progress: bool | dict[str, int | bool | str] | None = None,
_worker_class: type[GeneratorWorker] | type[FunctionWorker] | None = Non... | Convenience function to start a function in another thread.
By default, uses :class:`Worker`, but a custom ``WorkerBase`` subclass may
be provided. If so, it must be a subclass of :class:`Worker`, which
defines a standard set of signals and a run method.
Parameters
----------
func : Callable
... | create_worker | python | napari/napari | src/napari/_qt/qthreading.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qthreading.py | BSD-3-Clause |
def get_qapp(
*,
app_name: str | None = None,
app_version: str | None = None,
icon: str | None = None,
org_name: str | None = None,
org_domain: str | None = None,
app_id: str | None = None,
ipy_interactive: bool | None = None,
) -> QApplication:
"""Get or create the Qt QApplication.
... | Get or create the Qt QApplication.
There is only one global QApplication instance, which can be retrieved by
calling get_qapp, (or by using QApplication.instance())
Parameters
----------
app_name : str, optional
Set app name (if creating for the first time), by default 'napari'
app_ver... | get_qapp | python | napari/napari | src/napari/_qt/qt_event_loop.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_event_loop.py | BSD-3-Clause |
def quit_app():
"""Close all windows and quit the QApplication if napari started it."""
for v in list(Viewer._instances):
v.close()
QApplication.closeAllWindows()
# if we started the application then the app will be named 'napari'.
if (
QApplication.applicationName() == 'napari'
... | Close all windows and quit the QApplication if napari started it. | quit_app | python | napari/napari | src/napari/_qt/qt_event_loop.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_event_loop.py | BSD-3-Clause |
def _ipython_has_eventloop() -> bool:
"""Return True if IPython %gui qt is active.
Using this is better than checking ``QApp.thread().loopLevel() > 0``,
because IPython starts and stops the event loop continuously to accept code
at the prompt. So it will likely "appear" like there is no event loop
... | Return True if IPython %gui qt is active.
Using this is better than checking ``QApp.thread().loopLevel() > 0``,
because IPython starts and stops the event loop continuously to accept code
at the prompt. So it will likely "appear" like there is no event loop
running, but we still don't need to start on... | _ipython_has_eventloop | python | napari/napari | src/napari/_qt/qt_event_loop.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_event_loop.py | BSD-3-Clause |
def _pycharm_has_eventloop(app: QApplication) -> bool:
"""Return true if running in PyCharm and eventloop is active.
Explicit checking is necessary because PyCharm runs a custom interactive
shell which overrides `InteractiveShell.enable_gui()`, breaking some
superclass behaviour.
"""
in_pycharm... | Return true if running in PyCharm and eventloop is active.
Explicit checking is necessary because PyCharm runs a custom interactive
shell which overrides `InteractiveShell.enable_gui()`, breaking some
superclass behaviour.
| _pycharm_has_eventloop | python | napari/napari | src/napari/_qt/qt_event_loop.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_event_loop.py | BSD-3-Clause |
def run(
*, force=False, gui_exceptions=False, max_loop_level=1, _func_name='run'
):
"""Start the Qt Event Loop
Parameters
----------
force : bool, optional
Force the application event_loop to start, even if there are no top
level widgets to show.
gui_exceptions : bool, optional... | Start the Qt Event Loop
Parameters
----------
force : bool, optional
Force the application event_loop to start, even if there are no top
level widgets to show.
gui_exceptions : bool, optional
Whether to show uncaught exceptions in the GUI. By default they will be
shown i... | run | python | napari/napari | src/napari/_qt/qt_event_loop.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_event_loop.py | BSD-3-Clause |
def showEvent(self, event: QShowEvent):
"""Override to handle window state changes."""
settings = get_settings()
# if event loop is not running, we don't want to start the thread
# If event loop is running, the loopLevel will be above 0
if (
settings.appearance.update... | Override to handle window state changes. | showEvent | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _load_window_settings(self):
"""
Load window layout settings from configuration.
"""
settings = get_settings()
window_position = settings.application.window_position
# It's necessary to verify if the window/position value is valid with
# the current screen.
... |
Load window layout settings from configuration.
| _load_window_settings | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _get_window_settings(self):
"""Return current window settings.
Symmetric to the 'set_window_settings' setter.
"""
window_fullscreen = self.isFullScreen()
if window_fullscreen:
window_maximized = self._maximized_flag
else:
window_maximized = s... | Return current window settings.
Symmetric to the 'set_window_settings' setter.
| _get_window_settings | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _set_window_settings(
self,
window_state,
window_size,
window_position,
window_maximized,
window_fullscreen,
):
"""
Set window settings.
Symmetric to the 'get_window_settings' accessor.
"""
self.setUpdatesEnabled(False)
... |
Set window settings.
Symmetric to the 'get_window_settings' accessor.
| _set_window_settings | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _save_current_window_settings(self):
"""Save the current geometry of the main window."""
(
window_state,
window_size,
window_position,
window_maximized,
window_fullscreen,
) = self._get_window_settings()
settings = get_sett... | Save the current geometry of the main window. | _save_current_window_settings | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _warn_on_shimmed_plugins(self) -> None:
"""Warn about shimmed plugins if needed.
In 0.6.0, a plugin using the deprecated plugin engine will be automatically
converted so it can be used with npe2. By default, a dialog is displayed
with each startup listing all shimmed plugins. The us... | Warn about shimmed plugins if needed.
In 0.6.0, a plugin using the deprecated plugin engine will be automatically
converted so it can be used with npe2. By default, a dialog is displayed
with each startup listing all shimmed plugins. The user can change this setting
to only be warned ab... | _warn_on_shimmed_plugins | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def close(self, quit_app=False, confirm_need=False):
"""Override to handle closing app or just the window."""
if not quit_app and not self._qt_viewer.viewer.layers:
return super().close()
confirm_need_local = confirm_need and self._is_close_dialog[quit_app]
self._is_close_dia... | Override to handle closing app or just the window. | close | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def close_window(self):
"""Close active dialog or active window."""
parent = QApplication.focusWidget()
while parent is not None:
if isinstance(parent, QMainWindow):
self.close()
break
if isinstance(parent, QDialog):
parent... | Close active dialog or active window. | close_window | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def keyPressEvent(self, event):
"""Called whenever a key is pressed.
Parameters
----------
event : qtpy.QtCore.QEvent
Event from the Qt context.
"""
self._qt_viewer.canvas._scene_canvas._backend._keyEvent(
self._qt_viewer.canvas._scene_canvas.even... | Called whenever a key is pressed.
Parameters
----------
event : qtpy.QtCore.QEvent
Event from the Qt context.
| keyPressEvent | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def keyReleaseEvent(self, event):
"""Called whenever a key is released.
Parameters
----------
event : qtpy.QtCore.QEvent
Event from the Qt context.
"""
self._qt_viewer.canvas._scene_canvas._backend._keyEvent(
self._qt_viewer.canvas._scene_canvas.e... | Called whenever a key is released.
Parameters
----------
event : qtpy.QtCore.QEvent
Event from the Qt context.
| keyReleaseEvent | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def resizeEvent(self, event):
"""Override to handle original size before maximizing."""
# the first resize event will have nonsense positions that we don't
# want to store (and potentially restore)
if event.oldSize().isValid():
self._old_size = event.oldSize()
sel... | Override to handle original size before maximizing. | resizeEvent | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def closeEvent(self, event):
"""This method will be called when the main window is closing.
Regardless of whether cmd Q, cmd W, or the close button is used...
"""
if (
event.spontaneous()
and get_settings().application.confirm_close_window
and self._q... | This method will be called when the main window is closing.
Regardless of whether cmd Q, cmd W, or the close button is used...
| closeEvent | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def restart(self):
"""Restart the napari application in a detached process."""
process = QProcess()
process.setProgram(sys.executable)
if not running_as_constructor_app():
process.setArguments(sys.argv)
process.startDetached()
self.close(quit_app=True) | Restart the napari application in a detached process. | restart | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def toggle_menubar_visibility(self):
"""
Change menubar to be shown or to be hidden and shown on mouse movement.
For the mouse movement functionality see the `eventFilter` implementation.
"""
self._toggle_menubar_visibility = not self._toggle_menubar_visibility
self.menu... |
Change menubar to be shown or to be hidden and shown on mouse movement.
For the mouse movement functionality see the `eventFilter` implementation.
| toggle_menubar_visibility | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _setup_existing_themes(self, connect: bool = True):
"""This function is only executed once at the startup of napari
to connect events to themes that have not been connected yet.
Parameters
----------
connect : bool
Determines whether the `connect` or `disconnect`... | This function is only executed once at the startup of napari
to connect events to themes that have not been connected yet.
Parameters
----------
connect : bool
Determines whether the `connect` or `disconnect` method should be used.
| _setup_existing_themes | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _update_menu_state(self, menu: MenuStr):
"""Update enabled/visible state of menu item with context."""
layerlist = self._qt_viewer.viewer.layers
menu_model = getattr(self, menu)
menu_model.update_from_context(get_context(layerlist)) | Update enabled/visible state of menu item with context. | _update_menu_state | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _setup_npe1_samples_menu(self):
"""Register npe1 sample data, build menu and connect to events."""
plugin_manager.discover_sample_data()
plugin_manager.events.enabled.connect(_rebuild_npe1_samples_menu)
plugin_manager.events.disabled.connect(_rebuild_npe1_samples_menu)
plugin... | Register npe1 sample data, build menu and connect to events. | _setup_npe1_samples_menu | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _setup_npe1_plugins_menu(self):
"""Register npe1 widgets, build menu and connect to events"""
plugin_manager.discover_widgets()
plugin_manager.events.registered.connect(_rebuild_npe1_plugins_menu)
plugin_manager.events.disabled.connect(_rebuild_npe1_plugins_menu)
plugin_manag... | Register npe1 widgets, build menu and connect to events | _setup_npe1_plugins_menu | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _toggle_command_palette(self):
"""Toggle the visibility of the command palette."""
palette = self._qt_window._command_palette
if palette.isVisible():
palette.hide()
else:
palette.update_context(self._qt_window)
palette.show() | Toggle the visibility of the command palette. | _toggle_command_palette | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def add_plugin_dock_widget(
self,
plugin_name: str,
widget_name: str | None = None,
tabify: bool = False,
) -> tuple[QtViewerDockWidget, Any]:
"""Add plugin dock widget if not already added.
Parameters
----------
plugin_name : str
Name of ... | Add plugin dock widget if not already added.
Parameters
----------
plugin_name : str
Name of a plugin providing a widget
widget_name : str, optional
Name of a widget provided by `plugin_name`. If `None`, and the
specified plugin provides only a single... | add_plugin_dock_widget | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _add_plugin_function_widget(self, plugin_name: str, widget_name: str):
"""Add plugin function widget if not already added.
Parameters
----------
plugin_name : str
Name of a plugin providing a widget
widget_name : str, optional
Name of a widget provide... | Add plugin function widget if not already added.
Parameters
----------
plugin_name : str
Name of a plugin providing a widget
widget_name : str, optional
Name of a widget provided by `plugin_name`. If `None`, and the
specified plugin provides only a si... | _add_plugin_function_widget | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def add_dock_widget(
self,
widget: Union[QWidget, 'Widget'],
*,
name: str = '',
area: str | None = None,
allowed_areas: Sequence[str] | None = None,
shortcut=_sentinel,
add_vertical_stretch=True,
tabify: bool = False,
menu: QMenu | None = N... | Convenience method to add a QDockWidget to the main window.
If name is not provided a generic name will be addded to avoid
`saveState` warnings on close.
Parameters
----------
widget : QWidget
`widget` will be added as QDockWidget's main widget.
name : str, ... | add_dock_widget | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
def _add_viewer_dock_widget(
self,
dock_widget: QtViewerDockWidget,
tabify: bool = False,
menu: QMenu | None = None,
):
"""Add a QtViewerDockWidget to the main window
If other widgets already present in area then will tabify.
Parameters
----------
... | Add a QtViewerDockWidget to the main window
If other widgets already present in area then will tabify.
Parameters
----------
dock_widget : QtViewerDockWidget
`dock_widget` will be added to the main window.
tabify : bool
Flag to tabify dockwidget or not.
... | _add_viewer_dock_widget | python | napari/napari | src/napari/_qt/qt_main_window.py | https://github.com/napari/napari/blob/master/src/napari/_qt/qt_main_window.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.