Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.setWindowModality(Qt.NonModal)
self.setLayout(self.layout)
# stacked keybindings widgets
self.textEditBox = QTextEdit()
self.textEditBox.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.textEditBox.setMinimumWidth(360)
# Can switch to a normal dict when our minimum Python is 3.7
self.keybindings_strs = OrderedDict()
self.keybindings_strs[self.ALL_ACTIVE_KEYBINDINGS] = ''
col = self.viewer.palette['secondary']
layers = [
napari.layers.Image,
napari.layers.Labels,
napari.layers.Points,
napari.layers.Shapes,
napari.layers.Surface,
napari.layers.Vectors,
]
for layer in layers:
if len(layer.class_keymap) == 0:
text = 'No keybindings'
else:
text = get_keybindings_summary(layer.class_keymap, col=col)
self.keybindings_strs[f"{layer.__name__} layer"] = text
# layer type selection
self.layerTypeComboBox = QComboBox()
for name in self.keybindings_strs:
self.layerTypeComboBox.addItem(name)
self.layerTypeComboBox.activated[str].connect(
lambda text=self.layerTypeComboBox: self.change_layer_type(text)
from ..layers import Image, Labels, Points, Shapes, Surface, Vectors
from .vispy_image_layer import VispyImageLayer
from .vispy_points_layer import VispyPointsLayer
from .vispy_shapes_layer import VispyShapesLayer
from .vispy_vectors_layer import VispyVectorsLayer
from .vispy_surface_layer import VispySurfaceLayer
layer_to_visual = {
Image: VispyImageLayer,
Labels: VispyImageLayer,
Points: VispyPointsLayer,
Shapes: VispyShapesLayer,
Surface: VispySurfaceLayer,
Vectors: VispyVectorsLayer,
}
def create_vispy_visual(layer):
"""Create vispy visual for a layer based on its layer type.
Parameters
----------
layer : napari.layers._base_layer.Layer
Layer that needs its propetry widget created.
Returns
----------
visual : vispy.scene.visuals.VisualNode
One of a list of preset blending modes that determines how RGB and
alpha values of the layer visual get mixed. Allowed values are
{'opaque', 'translucent', and 'additive'}.
visible : bool
Whether the layer visual is currently being displayed.
Returns
-------
layer : :class:`napari.layers.Shapes`
The newly-created shapes layer.
"""
if data is None:
ndim = max(self.dims.ndim, 2)
data = np.empty((0, 0, ndim))
layer = layers.Shapes(
data=data,
shape_type=shape_type,
edge_width=edge_width,
edge_color=edge_color,
face_color=face_color,
z_index=z_index,
name=name,
metadata=metadata,
scale=scale,
translate=translate,
opacity=opacity,
blending=blending,
visible=visible,
)
self.add_layer(layer)
return layer
def setup(self, n):
np.random.seed(0)
self.data = [50 * np.random.random((6, 2)) for i in range(n)]
self.layer = Shapes(self.data, shape_type='polygon')
from ...layers import Image, Labels, Points, Shapes, Surface, Vectors
from .qt_image_layer import QtImageControls
from .qt_points_layer import QtPointsControls
from .qt_shapes_layer import QtShapesControls
from .qt_labels_layer import QtLabelsControls
from .qt_surface_layer import QtSurfaceControls
from .qt_vectors_layer import QtVectorsControls
layer_to_controls = {
Image: QtImageControls,
Labels: QtLabelsControls,
Points: QtPointsControls,
Shapes: QtShapesControls,
Surface: QtSurfaceControls,
Vectors: QtVectorsControls,
}
def create_qt_controls(layer):
"""
Create a qt controls widget for a layer based on its layer type.
Parameters
----------
layer : napari.layers._base_layer.Layer
Layer that needs its controls widget created.
Returns
----------
One of a list of preset blending modes that determines how RGB and
alpha values of the layer visual get mixed. Allowed values are
{'opaque', 'translucent', and 'additive'}.
visible : bool
Whether the layer visual is currently being displayed.
Returns
-------
layer : :class:`napari.layers.Shapes`
The newly-created shapes layer.
"""
if data is None:
ndim = max(self.dims.ndim, 2)
data = np.empty((0, 0, ndim))
layer = layers.Shapes(
data=data,
shape_type=shape_type,
edge_width=edge_width,
edge_color=edge_color,
face_color=face_color,
z_index=z_index,
name=name,
metadata=metadata,
scale=scale,
translate=translate,
opacity=opacity,
blending=blending,
visible=visible,
)
self.add_layer(layer)
return layer