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 _filter_compatible_readers(self, new_pattern):
"""Filter reader dropwdown items to those that accept `new_extension`"""
self._new_reader_dropdown.clear()
readers = self._npe2_readers.copy()
to_delete = []
try:
compatible_readers = get_potential_readers(new_patter... | Filter reader dropwdown items to those that accept `new_extension` | _filter_compatible_readers | python | napari/napari | src/napari/_qt/widgets/qt_extension2reader.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_extension2reader.py | BSD-3-Clause |
def _save_new_preference(self, event):
"""Save current preference to settings and show in table"""
fn_pattern = self._fn_pattern_edit.text()
reader = self._new_reader_dropdown.currentData()
if not fn_pattern or not reader:
return
# if user types pattern that starts ... | Save current preference to settings and show in table | _save_new_preference | python | napari/napari | src/napari/_qt/widgets/qt_extension2reader.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_extension2reader.py | BSD-3-Clause |
def _add_new_row(self, fn_pattern, reader):
"""Add new reader preference to table"""
last_row = self._table.rowCount()
if (
last_row == 1
and 'No filename preferences found'
in self._table.item(0, 0).text()
):
self._table.removeRow(0)
... | Add new reader preference to table | _add_new_row | python | napari/napari | src/napari/_qt/widgets/qt_extension2reader.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_extension2reader.py | BSD-3-Clause |
def remove_existing_preference(self, event):
"""Delete extension to reader mapping setting and remove table row"""
pattern_to_remove = self.sender().objectName()
current_settings = get_settings().plugins.extension2reader
# need explicit assignment to new object here for persistence
... | Delete extension to reader mapping setting and remove table row | remove_existing_preference | python | napari/napari | src/napari/_qt/widgets/qt_extension2reader.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_extension2reader.py | BSD-3-Clause |
def _reset(self) -> None:
"""
Reset the widget value to the current selected theme font size value.
"""
current_theme_name = get_settings().appearance.theme
if current_theme_name == 'system':
# system isn't a theme, so get the name
current_theme_name = get... |
Reset the widget value to the current selected theme font size value.
| _reset | python | napari/napari | src/napari/_qt/widgets/qt_font_size.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_font_size.py | BSD-3-Clause |
def setValue(self, value: int, color: QColor = None):
"""Set line width value of star widget.
Parameters
----------
value : int
line width value for star
"""
self._value = value
if color is not None:
self._color = color
self.updat... | Set line width value of star widget.
Parameters
----------
value : int
line width value for star
| setValue | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def drawStar(self, qp):
"""Draw a star in the preview pane.
Parameters
----------
qp : QPainter object
"""
width = self.rect().width()
height = self.rect().height()
col = self._color
pen = QPen(col, self._value)
pen.setJoinStyle(Qt.PenJoin... | Draw a star in the preview pane.
Parameters
----------
qp : QPainter object
| drawStar | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def mousePressEvent(self, event):
"""When mouse is clicked, adjust to new values."""
# set value based on position of event
perc = event.pos().x() / self.rect().width()
value = ((self._max_value - self._min_value) * perc) + self._min_value
self.setValue(value) | When mouse is clicked, adjust to new values. | mousePressEvent | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def drawTriangle(self, qp):
"""Draw triangle.
Parameters
----------
qp : QPainter object
"""
width = self.rect().width()
col = self._color
qp.setPen(QPen(col, 1))
qp.setBrush(col)
path = QPainterPath()
height = 10
path.mo... | Draw triangle.
Parameters
----------
qp : QPainter object
| drawTriangle | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def setValue(self, value, color=None):
"""Set value for triangle widget.
Parameters
----------
value : int
Value to use for line in triangle widget.
"""
self._value = value
if color is not None:
self._color = color
self.update() | Set value for triangle widget.
Parameters
----------
value : int
Value to use for line in triangle widget.
| setValue | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def setMinimum(self, value: int):
"""Set minimum value
Parameters
----------
value : int
Minimum value of triangle.
"""
self._min_value = value
self._value = max(self._value, value) | Set minimum value
Parameters
----------
value : int
Minimum value of triangle.
| setMinimum | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def setMaximum(self, value: int):
"""Set maximum value.
Parameters
----------
value : int
Maximum value of triangle.
"""
self._max_value = value
self._value = min(self._value, value) | Set maximum value.
Parameters
----------
value : int
Maximum value of triangle.
| setMaximum | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def drawLine(self, qp, value: int):
"""Draw line on triangle indicating value.
Parameters
----------
qp : QPainter object
value : int
Value of highlight thickness.
"""
col = QColor('white')
qp.setPen(QPen(col, 2))
qp.setBrush(col)
... | Draw line on triangle indicating value.
Parameters
----------
qp : QPainter object
value : int
Value of highlight thickness.
| drawLine | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def _update_thickness_value(self, thickness_value):
"""Update highlight thickness value.
Parameters
----------
thickness_value : int
Highlight thickness value.
"""
if thickness_value == '':
return
thickness_value = int(thickness_value)
... | Update highlight thickness value.
Parameters
----------
thickness_value : int
Highlight thickness value.
| _update_thickness_value | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def _update_color_value(self, color_value):
"""Update highlight color value.
Parameters
----------
color_value : List[float]
Highlight color value as a list of floats.
"""
if isinstance(color_value, np.ndarray):
color_value = color_value.tolist()
... | Update highlight color value.
Parameters
----------
color_value : List[float]
Highlight color value as a list of floats.
| _update_color_value | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def _refresh(self):
"""Set every widget value to the new set value."""
self.blockSignals(True)
# Transform color value from a float representation
# (values from 0.0 to 1.0) to RGB values (values from 0 to 255)
# to set widgets color.
color = QColor(*[int(np.ceil(v * 255)... | Set every widget value to the new set value. | _refresh | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def setValue(self, value: dict):
"""Set new value and update widget.
Parameters
----------
value : dict
Highlight value (thickness and color).
"""
self._update_thickness_value(value.get('highlight_thickness', ''))
self._update_color_value(value.get('h... | Set new value and update widget.
Parameters
----------
value : dict
Highlight value (thickness and color).
| setValue | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def setMinimum(self, value):
"""Set minimum highlight value for star, triangle, text and slider.
Parameters
----------
value : int
Minimum highlight value.
"""
value = int(value)
if value >= self._max_value:
raise ValueError(
... | Set minimum highlight value for star, triangle, text and slider.
Parameters
----------
value : int
Minimum highlight value.
| setMinimum | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def setMaximum(self, value):
"""Set maximum highlight value.
Parameters
----------
value : int
Maximum highlight value.
"""
value = int(value)
if value <= self._min_value:
raise ValueError(
trans._(
'Max... | Set maximum highlight value.
Parameters
----------
value : int
Maximum highlight value.
| setMaximum | python | napari/napari | src/napari/_qt/widgets/qt_highlight_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_highlight_preview.py | BSD-3-Clause |
def restore_defaults(self):
"""Launches dialog to confirm restore choice."""
prev = QApplication.instance().testAttribute(
Qt.ApplicationAttribute.AA_DontUseNativeDialogs
)
QApplication.instance().setAttribute(
Qt.ApplicationAttribute.AA_DontUseNativeDialogs, True... | Launches dialog to confirm restore choice. | restore_defaults | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def _set_table(self, layer_str: str = ''):
"""Builds and populates keybindings table.
Parameters
----------
layer_str : str
If layer_str is not empty, then show the specified layers'
keybinding shortcut table.
"""
# Keep track of what is in each ... | Builds and populates keybindings table.
Parameters
----------
layer_str : str
If layer_str is not empty, then show the specified layers'
keybinding shortcut table.
| _set_table | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def _get_potential_conflicting_actions(self):
"""
Get all actions we want to avoid keybinding conflicts with.
If current selected keybinding group is a layer, return
the selected layer actions and viewer actions.
If the current selected keybinding group is viewer,
return... |
Get all actions we want to avoid keybinding conflicts with.
If current selected keybinding group is a layer, return
the selected layer actions and viewer actions.
If the current selected keybinding group is viewer,
return viewer actions and actions from all layers.
Ret... | _get_potential_conflicting_actions | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def _set_keybinding(self, row, col):
"""Checks the new keybinding to determine if it can be set.
Parameters
----------
row : int
Row in keybindings table that is being edited.
col : int
Column being edited (shortcut column).
"""
if self._... | Checks the new keybinding to determine if it can be set.
Parameters
----------
row : int
Row in keybindings table that is being edited.
col : int
Column being edited (shortcut column).
| _set_keybinding | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def _show_warning_icons(self, rows):
"""Creates and displays the warning icons.
Parameters
----------
rows : list[int]
List of row numbers that should have the icon.
"""
for row in rows:
self.warning_indicator = QLabel(self)
self.warn... | Creates and displays the warning icons.
Parameters
----------
rows : list[int]
List of row numbers that should have the icon.
| _show_warning_icons | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def _cleanup_warning_icons(self, rows):
"""Remove the warning icons from the shortcut table.
Parameters
----------
rows : list[int]
List of row numbers to remove warning icon from.
"""
for row in rows:
self._table.setCellWidget(row, self._icon_co... | Remove the warning icons from the shortcut table.
Parameters
----------
rows : list[int]
List of row numbers to remove warning icon from.
| _cleanup_warning_icons | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def _show_warning(self, row: int, message: str) -> None:
"""Creates and displays warning message when shortcut is already assigned.
Parameters
----------
row : int
Row in table where the shortcut is attempting to be set.
message : str
Message to be displa... | Creates and displays warning message when shortcut is already assigned.
Parameters
----------
row : int
Row in table where the shortcut is attempting to be set.
message : str
Message to be displayed in warning pop up.
| _show_warning | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def value(self):
"""Return the actions and shortcuts currently assigned in action manager.
Returns
-------
value: dict
Dictionary of action names and shortcuts assigned to them.
"""
value = {}
for action_name in action_manager._actions:
... | Return the actions and shortcuts currently assigned in action manager.
Returns
-------
value: dict
Dictionary of action names and shortcuts assigned to them.
| value | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def _handleEditModifiersOnly(self, event) -> None:
"""
Shared handler between keyPressEvent and keyReleaseEvent for modifiers.
This is valid both on keyPress and Keyrelease events during edition as we
are sure to not have received any real keys events yet. If that was the case
t... |
Shared handler between keyPressEvent and keyReleaseEvent for modifiers.
This is valid both on keyPress and Keyrelease events during edition as we
are sure to not have received any real keys events yet. If that was the case
the shortcut would have been validated and we would not be in e... | _handleEditModifiersOnly | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def keyevent_to_keyseq(self, event) -> QKeySequence:
"""Return a QKeySequence representation of the provided QKeyEvent.
This only works for complete key sequence that do not contain only
modifiers. If the event is only pressing modifiers, this will return an
empty sequence as QKeySequen... | Return a QKeySequence representation of the provided QKeyEvent.
This only works for complete key sequence that do not contain only
modifiers. If the event is only pressing modifiers, this will return an
empty sequence as QKeySequence does not support only modifiers
| keyevent_to_keyseq | python | napari/napari | src/napari/_qt/widgets/qt_keyboard_settings.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_keyboard_settings.py | BSD-3-Clause |
def _set_mode(self, mode_selected):
"""Toggle the mode associated with the layer.
Parameters
----------
mode_selected : bool
Whether this mode is currently selected or not.
"""
layer = self.layer_ref()
if layer is None:
return
wit... | Toggle the mode associated with the layer.
Parameters
----------
mode_selected : bool
Whether this mode is currently selected or not.
| _set_mode | python | napari/napari | src/napari/_qt/widgets/qt_mode_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_mode_buttons.py | BSD-3-Clause |
def _set_enabled(self, state: bool | int):
"""Set the enabled state of this hook implementation to ``state``."""
self.item.hook_implementation.enabled = bool(state)
self.opacity.setOpacity(1 if state else 0.5)
self.on_changed.emit() | Set the enabled state of this hook implementation to ``state``. | _set_enabled | python | napari/napari | src/napari/_qt/widgets/qt_plugin_sorter.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_plugin_sorter.py | BSD-3-Clause |
def set_hook_caller(self, hook_caller: HookCaller | None):
"""Set the list widget to show hook implementations for ``hook_caller``.
Parameters
----------
hook_caller : HookCaller, optional
A ``HookCaller`` for which to show implementations. by default None
(i.e. ... | Set the list widget to show hook implementations for ``hook_caller``.
Parameters
----------
hook_caller : HookCaller, optional
A ``HookCaller`` for which to show implementations. by default None
(i.e. no hooks shown)
| set_hook_caller | python | napari/napari | src/napari/_qt/widgets/qt_plugin_sorter.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_plugin_sorter.py | BSD-3-Clause |
def append_hook_implementation(
self, hook_implementation: HookImplementation
):
"""Add a list item for ``hook_implementation`` with a custom widget.
Parameters
----------
hook_implementation : HookImplementation
The hook implementation object to add to the list.... | Add a list item for ``hook_implementation`` with a custom widget.
Parameters
----------
hook_implementation : HookImplementation
The hook implementation object to add to the list.
| append_hook_implementation | python | napari/napari | src/napari/_qt/widgets/qt_plugin_sorter.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_plugin_sorter.py | BSD-3-Clause |
def dropEvent(self, event: QEvent):
"""Triggered when the user moves & drops one of the items in the list.
Parameters
----------
event : QEvent
The event that triggered the dropEvent.
"""
super().dropEvent(event)
order = [self.item(r).hook_implementat... | Triggered when the user moves & drops one of the items in the list.
Parameters
----------
event : QEvent
The event that triggered the dropEvent.
| dropEvent | python | napari/napari | src/napari/_qt/widgets/qt_plugin_sorter.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_plugin_sorter.py | BSD-3-Clause |
def _change_settings_plugins(self):
"""Update settings if plugin call order changes."""
settings = get_settings()
settings.plugins.call_order = self.plugin_manager.call_order() | Update settings if plugin call order changes. | _change_settings_plugins | python | napari/napari | src/napari/_qt/widgets/qt_plugin_sorter.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_plugin_sorter.py | BSD-3-Clause |
def keyPressEvent(self, event):
"""On key press lose focus of the lineEdits.
Parameters
----------
event : qtpy.QtCore.QKeyEvent
Event from the Qt context.
"""
# we override the parent keyPressEvent so that hitting enter does not
# hide the window... ... | On key press lose focus of the lineEdits.
Parameters
----------
event : qtpy.QtCore.QKeyEvent
Event from the Qt context.
| keyPressEvent | python | napari/napari | src/napari/_qt/widgets/qt_range_slider_popup.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_range_slider_popup.py | BSD-3-Clause |
def _update_line_width(self):
"""Update width ofg line text edit."""
txt = 'm' * (1 + len(str(self._max_value)))
fm = self._lineedit.fontMetrics()
if hasattr(fm, 'horizontalAdvance'):
# Qt >= 5.11
size = fm.horizontalAdvance(txt)
else:
size = f... | Update width ofg line text edit. | _update_line_width | python | napari/napari | src/napari/_qt/widgets/qt_size_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_size_preview.py | BSD-3-Clause |
def _refresh(self, value: int | None = None):
"""Refresh the value on all subwidgets."""
value = value or self._value
self.blockSignals(True)
self._lineedit.setText(str(value))
self._slider.setValue(value)
font = QFont()
font.setPixelSize(value)
self._prev... | Refresh the value on all subwidgets. | _refresh | python | napari/napari | src/napari/_qt/widgets/qt_size_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_size_preview.py | BSD-3-Clause |
def setMinimum(self, value: int):
"""Set the current minimum value for the slider and value in textbox.
Parameters
----------
value : int
The minimum value for the slider.
"""
if value >= self._max_value:
raise ValueError(
trans._(... | Set the current minimum value for the slider and value in textbox.
Parameters
----------
value : int
The minimum value for the slider.
| setMinimum | python | napari/napari | src/napari/_qt/widgets/qt_size_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_size_preview.py | BSD-3-Clause |
def setMaximum(self, value: int):
"""Set the maximum value for the slider and value in textbox.
Parameters
----------
value : int
The maximum value for the slider.
"""
if value <= self._min_value:
raise ValueError(
trans._(
... | Set the maximum value for the slider and value in textbox.
Parameters
----------
value : int
The maximum value for the slider.
| setMaximum | python | napari/napari | src/napari/_qt/widgets/qt_size_preview.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_size_preview.py | BSD-3-Clause |
def eventFilter(self, qobject, event):
"""Have Alt/Option key rotate layers with the transpose button."""
modifiers = QApplication.keyboardModifiers()
if (
modifiers == Qt.AltModifier
and qobject == self.transposeDimsButton
and event.type() == QEvent.MouseButt... | Have Alt/Option key rotate layers with the transpose button. | eventFilter | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _position_popup_inside_viewer(
self, popup: QtPopup, button: QPushButton
) -> None:
"""Position the popup so that it remains with the viewer.
Use the location of the button as a reference and place the popup
above it. move_to will adjust the position if the popup is too close
... | Position the popup so that it remains with the viewer.
Use the location of the button as a reference and place the popup
above it. move_to will adjust the position if the popup is too close
to the edge of the screen.
| _position_popup_inside_viewer | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _add_3d_camera_controls(
self,
popup: QtPopup,
grid_layout: QGridLayout,
) -> None:
"""Add 3D camera controls to the popup."""
self.perspective = labeled_double_slider(
parent=popup,
value=self.viewer.camera.perspective,
value_range=(0,... | Add 3D camera controls to the popup. | _add_3d_camera_controls | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _add_shared_camera_controls(
self,
popup: QtPopup,
grid_layout: QGridLayout,
) -> None:
"""Add shared camera controls to the popup."""
self.zoom = labeled_double_slider(
parent=popup,
value=self.viewer.camera.zoom,
value_range=(0.01, 10... | Add shared camera controls to the popup. | _add_shared_camera_controls | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _add_orientation_controls(
self,
popup: QtPopup,
grid_layout: QGridLayout,
) -> None:
"""Add orientation controls to the popup."""
orientation_widget = QWidget(popup)
orientation_layout = QHBoxLayout()
orientation_layout.setContentsMargins(0, 0, 0, 0)
... | Add orientation controls to the popup. | _add_orientation_controls | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _update_handedness_help_symbol(self, event=None) -> None:
"""Update the handedness symbol based on the camera orientation."""
handedness = self.viewer.camera.handedness
tooltip_text = (
'Controls the orientation of the depth, vertical, and horizontal camera axes.\n'
'... | Update the handedness symbol based on the camera orientation. | _update_handedness_help_symbol | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def open_ndisplay_camera_popup(self) -> None:
"""Show controls for camera settings based on ndisplay mode."""
popup = QtPopup(self)
grid_layout = QGridLayout()
# Add orientation controls
self._add_orientation_controls(popup, grid_layout)
# Add shared camera controls
... | Show controls for camera settings based on ndisplay mode. | open_ndisplay_camera_popup | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _update_orientation(
self,
orientation_type: type[
DepthAxisOrientation
| VerticalAxisOrientation
| HorizontalAxisOrientation
],
orientation_value: (
DepthAxisOrientationStr
| VerticalAxisOrientationStr
| Horizon... | Update the orientation of the camera.
Parameters
----------
orientation_type : type[DepthAxisOrientation | VerticalAxisOrientation | HorizontalAxisOrientation]
The orientation type (which implies the position/axis) to update.
value : DepthAxisOrientationStr | VerticalAxisOri... | _update_orientation | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _update_camera_angles(self, idx: int, value: float) -> None:
"""Update the camera angles.
Parameters
----------
idx : int
Index of the angle to update. In the order of (rx, ry, rz).
value : float
New angle value.
"""
angles = list(sel... | Update the camera angles.
Parameters
----------
idx : int
Index of the angle to update. In the order of (rx, ry, rz).
value : float
New angle value.
| _update_camera_angles | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _open_roll_popup(self):
"""Open a grid popup to manually order the dimensions"""
pop = QtPopup(self)
# dims sorter widget
dim_sorter = QtDimsSorter(self.viewer.dims, pop)
dim_sorter.setObjectName('dim_sorter')
# make layout
layout = QHBoxLayout()
lay... | Open a grid popup to manually order the dimensions | _open_roll_popup | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def _open_grid_popup(self):
"""Open grid options pop up widget."""
# widgets
popup = QtPopup(self)
grid_stride = QtSpinBox(popup)
grid_width = QtSpinBox(popup)
grid_height = QtSpinBox(popup)
grid_spacing = QDoubleSpinBox(popup)
shape_help_symbol = QtToolT... | Open grid options pop up widget. | _open_grid_popup | python | napari/napari | src/napari/_qt/widgets/qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_buttons.py | BSD-3-Clause |
def destroyOnClose(self):
"""Destroys dock plugin dock widget when 'x' is clicked."""
from napari.viewer import Viewer
viewer = self._ref_qt_viewer().viewer
if isinstance(viewer, Viewer):
viewer.window.remove_dock_widget(self) | Destroys dock plugin dock widget when 'x' is clicked. | destroyOnClose | python | napari/napari | src/napari/_qt/widgets/qt_viewer_dock_widget.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_dock_widget.py | BSD-3-Clause |
def _maybe_add_vertical_stretch(self, widget):
"""Add vertical stretch to the bottom of a vertical layout only
...if there is not already a widget that wants vertical space
(like a textedit or listwidget or something).
"""
exempt_policies = {
QSizePolicy.Expanding,
... | Add vertical stretch to the bottom of a vertical layout only
...if there is not already a widget that wants vertical space
(like a textedit or listwidget or something).
| _maybe_add_vertical_stretch | python | napari/napari | src/napari/_qt/widgets/qt_viewer_dock_widget.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_viewer_dock_widget.py | BSD-3-Clause |
def paintEvent(self, event):
"""Override Qt method.
Parameters
----------
event : qtpy.QtCore.QEvent
Event from the Qt context.
"""
option = QStyleOption()
option.initFrom(self)
p = QPainter(self)
self.style().drawPrimitive(QStyle.PE_W... | Override Qt method.
Parameters
----------
event : qtpy.QtCore.QEvent
Event from the Qt context.
| paintEvent | python | napari/napari | src/napari/_qt/widgets/qt_welcome.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_welcome.py | BSD-3-Clause |
def dragEnterEvent(self, event):
"""Override Qt method.
Provide style updates on event.
Parameters
----------
event : qtpy.QtCore.QDragEnterEvent
Event from the Qt context.
"""
self._update_property('drag', True)
if event.mimeData().hasUrls()... | Override Qt method.
Provide style updates on event.
Parameters
----------
event : qtpy.QtCore.QDragEnterEvent
Event from the Qt context.
| dragEnterEvent | python | napari/napari | src/napari/_qt/widgets/qt_welcome.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/qt_welcome.py | BSD-3-Clause |
def test_radio_button(qtbot):
"""Make sure the QtModeRadioButton works to change layer modes"""
layer = Points()
assert layer.mode != Mode.ADD
btn = QtModeRadioButton(layer, 'test_button', Mode.ADD, tooltip='tooltip')
assert btn.property('mode') == 'test_button'
assert btn.toolTip() == 'tooltip... | Make sure the QtModeRadioButton works to change layer modes | test_radio_button | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_buttons.py | BSD-3-Clause |
def test_push_button(qtbot):
"""Make sure the QtModePushButton works with callbacks"""
layer = Points()
layer.test_prop = False
def set_test_prop():
layer.test_prop = True
btn = QtModePushButton(
layer, 'test_button', slot=set_test_prop, tooltip='tooltip'
)
assert btn.prope... | Make sure the QtModePushButton works with callbacks | test_push_button | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_buttons.py | BSD-3-Clause |
def test_changing_ndim(qtbot):
"""
Test changing the number of dimensions
"""
ndim = 4
view = QtDims(Dims(ndim=ndim))
qtbot.addWidget(view)
# Check that adding dimensions adds sliders
view.dims.ndim = 5
assert view.nsliders == view.dims.ndim
assert np.sum(view._displayed_slider... |
Test changing the number of dimensions
| test_changing_ndim | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_changing_focus(qtbot):
"""Test changing focus updates the dims.last_used prop."""
# Initialize to 0th axis
ndim = 2
view = QtDims(Dims(ndim=ndim))
qtbot.addWidget(view)
assert view.dims.last_used == 0
view.dims._focus_down()
view.dims._focus_up()
assert view.dims.last_used =... | Test changing focus updates the dims.last_used prop. | test_changing_focus | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_changing_display(qtbot):
"""
Test changing the displayed property of an axis
"""
ndim = 4
view = QtDims(Dims(ndim=ndim))
qtbot.addWidget(view)
assert view.nsliders == view.dims.ndim
assert np.sum(view._displayed_sliders) == view.dims.ndim - 2
assert np.all(
[
... |
Test changing the displayed property of an axis
| test_changing_display | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_slider_values(qtbot):
"""
Test the values of a slider stays matched to the values of the dims point.
"""
ndim = 4
view = QtDims(Dims(ndim=ndim))
qtbot.addWidget(view)
# Check that values of the dimension slider matches the values of the
# dims point at initialization
first_... |
Test the values of a slider stays matched to the values of the dims point.
| test_slider_values | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_slider_range(qtbot):
"""
Tests range of the slider is matched to the range of the dims
"""
ndim = 4
view = QtDims(Dims(ndim=ndim))
qtbot.addWidget(view)
# Check the maximum allowed value of the slider is one less
# than the allowed nsteps of the dims at initialization
first... |
Tests range of the slider is matched to the range of the dims
| test_slider_range | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_singleton_dims(qtbot):
"""
Test singleton dims causes no slider.
"""
ndim = 4
dims = Dims(ndim=ndim)
dims.set_range(0, (0, 0, 1))
view = QtDims(dims)
qtbot.addWidget(view)
# Check that the dims model has been appended to the dims view
assert view.dims == dims
# Che... |
Test singleton dims causes no slider.
| test_singleton_dims | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_order_when_changing_ndim(qtbot):
"""
Test order of the sliders when changing the number of dimensions.
"""
ndim = 4
view = QtDims(Dims(ndim=ndim))
qtbot.addWidget(view)
# Check that values of the dimension slider matches the values of the
# dims point after the point has been m... |
Test order of the sliders when changing the number of dimensions.
| test_order_when_changing_ndim | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_slider_press_updates_last_used(qtbot):
"""pressing on the slider should update the dims.last_used property"""
ndim = 5
view = QtDims(Dims(ndim=ndim))
qtbot.addWidget(view)
for i, widg in enumerate(view.slider_widgets):
widg.slider.sliderPressed.emit()
if i in [0, 1, 2]:
... | pressing on the slider should update the dims.last_used property | test_slider_press_updates_last_used | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_play_button(qtbot):
"""test that the play button and its popup dialog work"""
ndim = 3
view = QtDims(Dims(ndim=ndim))
qtbot.addWidget(view)
slider = view.slider_widgets[0]
button = slider.play_button
# Need looping playback so that it does not stop before we can assert that.
as... | test that the play button and its popup dialog work | test_play_button | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims.py | BSD-3-Clause |
def test_not_playing_after_ndim_changes(qtbot):
"""See https://github.com/napari/napari/issues/3998"""
dims = Dims(ndim=3, ndisplay=2, range=((0, 10, 1), (0, 20, 1), (0, 30, 1)))
view = QtDims(dims)
qtbot.addWidget(view)
# Loop to prevent finishing before the assertions in this test.
view.play(l... | See https://github.com/napari/napari/issues/3998 | test_not_playing_after_ndim_changes | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims_2.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims_2.py | BSD-3-Clause |
def test_set_axis_labels_after_ndim_changes(qtbot):
"""See https://github.com/napari/napari/issues/3753"""
dims = Dims(ndim=3, ndisplay=2)
view = QtDims(dims)
qtbot.addWidget(view)
dims.ndim = 2
dims.axis_labels = ['y', 'x']
assert len(view.slider_widgets) == 2
assert view.slider_widge... | See https://github.com/napari/napari/issues/3753 | test_set_axis_labels_after_ndim_changes | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dims_2.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dims_2.py | BSD-3-Clause |
def test_add_dock_widget_from_list(make_napari_viewer):
"""Test that we can add a list of widgets and they will be combined"""
viewer = make_napari_viewer()
widg = QPushButton('button')
widg2 = QPushButton('button')
dwidg = viewer.window.add_dock_widget(
[widg, widg2], name='test', area='ri... | Test that we can add a list of widgets and they will be combined | test_add_dock_widget_from_list | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dock_widget.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dock_widget.py | BSD-3-Clause |
def test_add_dock_widget_raises(make_napari_viewer):
"""Test that the widget passed must be a DockWidget."""
viewer = make_napari_viewer()
widg = object()
with pytest.raises(TypeError):
viewer.window.add_dock_widget(widg, name='test') | Test that the widget passed must be a DockWidget. | test_add_dock_widget_raises | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dock_widget.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dock_widget.py | BSD-3-Clause |
def test_adding_stretch(make_napari_viewer):
"""Make sure that vertical stretch only gets added when appropriate."""
viewer = make_napari_viewer()
# adding a widget to the left/right will usually addStretch to the layout
widg = QWidget()
widg.setLayout(QVBoxLayout())
widg.layout().addWidget(QPu... | Make sure that vertical stretch only gets added when appropriate. | test_adding_stretch | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dock_widget.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dock_widget.py | BSD-3-Clause |
def test_combine_widgets_error():
"""Check error raised when combining widgets with invalid types."""
with pytest.raises(
TypeError, match='"widgets" must be a QWidget, a magicgui'
):
combine_widgets(['string']) | Check error raised when combining widgets with invalid types. | test_combine_widgets_error | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_dock_widget.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_dock_widget.py | BSD-3-Clause |
def test_animation_thread_variants(qtbot, nframes, fps, mode, rng, result):
"""This is mostly testing that AnimationWorker.advance works as expected"""
with make_worker(
qtbot, fps=fps, nframes=nframes, frame_range=rng, loop_mode=mode
) as worker:
current = worker.go()
if rng:
nr... | This is mostly testing that AnimationWorker.advance works as expected | test_animation_thread_variants | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_play.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_play.py | BSD-3-Clause |
def test_animation_thread_once(qtbot):
"""Single shot animation should stop when it reaches the last frame"""
nframes = 13
with make_worker(
qtbot, nframes=nframes, loop_mode=LoopMode.ONCE
) as worker:
with qtbot.waitSignal(worker.finished, timeout=8000):
worker.start()
a... | Single shot animation should stop when it reaches the last frame | test_animation_thread_once | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_play.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_play.py | BSD-3-Clause |
def ref_view(make_napari_viewer):
"""basic viewer with data that we will use a few times
It is problematic to yield the qt_viewer directly as it will stick
around in the generator frames and causes issues if we want to make sure
there is only a single instance of QtViewer instantiated at all times duri... | basic viewer with data that we will use a few times
It is problematic to yield the qt_viewer directly as it will stick
around in the generator frames and causes issues if we want to make sure
there is only a single instance of QtViewer instantiated at all times during
the test suite. Thus we yield a we... | ref_view | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_play.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_play.py | BSD-3-Clause |
def test_playing_hidden_slider_does_nothing(ref_view):
"""Make sure playing a dimension without a slider does nothing"""
view = ref_view()
def increment(e):
view.dims._frame = e.value # this is provided by the step event
# if we don't "enable play" again, view.dims won't request a new fra... | Make sure playing a dimension without a slider does nothing | test_playing_hidden_slider_does_nothing | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_play.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_play.py | BSD-3-Clause |
def test_change_play_axis(ref_view, qtbot):
"""Make sure changing the play axis stops the current animation.
Prior to https://github.com/napari/napari/pull/7158, starting a new play
animation resulted in QThread warnings and could crash Python in
some environments. In the future, we may want to allow m... | Make sure changing the play axis stops the current animation.
Prior to https://github.com/napari/napari/pull/7158, starting a new play
animation resulted in QThread warnings and could crash Python in
some environments. In the future, we may want to allow multiple
multiple simultaneous play axes [1]_, s... | test_change_play_axis | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_play.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_play.py | BSD-3-Clause |
def test_change_play_fps(ref_view, qtbot):
"""Make sure changing the play fps stops the current animation"""
view = ref_view()
with qtbot.waitSignal(view.dims._animation_thread.started):
view.dims.play(0, 20)
qtbot.waitUntil(lambda: view.dims.is_playing)
assert view.dims._animation_thread.sl... | Make sure changing the play fps stops the current animation | test_change_play_fps | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_play.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_play.py | BSD-3-Clause |
def test_range_slider_changes_labels(popup):
"""make sure setting the slider updates the labels"""
popup.slider.setValue((10, 20))
assert popup.slider._handle_labels[0].value() == 10
assert popup.slider._handle_labels[1].value() == 20 | make sure setting the slider updates the labels | test_range_slider_changes_labels | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_range_slider_popup.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_range_slider_popup.py | BSD-3-Clause |
def test_roll_dims_button_popup(qt_viewer_buttons, qtbot):
"""
Make sure the QtViewerButtons.rollDimsButton popup works.
"""
# get viewer model and buttons
viewer, viewer_buttons = qt_viewer_buttons
assert viewer_buttons.rollDimsButton
# make dims order settings popup
viewer_buttons.rol... |
Make sure the QtViewerButtons.rollDimsButton popup works.
| test_roll_dims_button_popup | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_viewer_buttons.py | BSD-3-Clause |
def test_grid_view_button_popup(qt_viewer_buttons, qtbot):
"""
Make sure the QtViewerButtons.gridViewbutton popup works.
The popup widget should be able to show/change viewer grid settings.
"""
# get viewer model and buttons
viewer, viewer_buttons = qt_viewer_buttons
assert viewer_buttons.g... |
Make sure the QtViewerButtons.gridViewbutton popup works.
The popup widget should be able to show/change viewer grid settings.
| test_grid_view_button_popup | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_viewer_buttons.py | BSD-3-Clause |
def test_ndisplay_button_popup(qt_viewer_buttons, qtbot):
"""
Make sure the QtViewerButtons.ndisplayButton popup works.
"""
# get viewer model and buttons
viewer, viewer_buttons = qt_viewer_buttons
assert viewer_buttons.ndisplayButton
# trigger popup for ndisplay==2
viewer.dims.ndisplay... |
Make sure the QtViewerButtons.ndisplayButton popup works.
| test_ndisplay_button_popup | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_viewer_buttons.py | BSD-3-Clause |
def test_transpose_rotate_button(monkeypatch, qt_viewer_buttons, qtbot):
"""
Click should trigger `transpose_axes`. Alt/Option-click should trigger `rotate_layers.`
"""
_, viewer_buttons = qt_viewer_buttons
assert viewer_buttons.transposeDimsButton
action_manager_mock = Mock(trigger=Mock())
... |
Click should trigger `transpose_axes`. Alt/Option-click should trigger `rotate_layers.`
| test_transpose_rotate_button | python | napari/napari | src/napari/_qt/widgets/_tests/test_qt_viewer_buttons.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_qt_viewer_buttons.py | BSD-3-Clause |
def test_keybinding_editor_modifier_key_detection(
shortcut_editor_widget,
qtbot,
recwarn,
modifier_key,
modifiers,
key_symbols,
):
"""
Test modifier keys detection with pyautogui to trigger keyboard events
from the OS.
Notes:
* Skipped on macOS CI due to accessibility p... |
Test modifier keys detection with pyautogui to trigger keyboard events
from the OS.
Notes:
* Skipped on macOS CI due to accessibility permissions not being
settable on macOS GitHub Actions runners.
* For this test to pass locally, you need to give the Terminal/iTerm
app... | test_keybinding_editor_modifier_key_detection | python | napari/napari | src/napari/_qt/widgets/_tests/test_shortcut_editor_widget.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_shortcut_editor_widget.py | BSD-3-Clause |
def test_theme_sample(qtbot):
"""Just a smoke test to make sure that the theme sample can be created."""
w = SampleWidget()
qtbot.addWidget(w)
w.show()
assert w.isVisible() | Just a smoke test to make sure that the theme sample can be created. | test_theme_sample | python | napari/napari | src/napari/_qt/widgets/_tests/test_theme_sample.py | https://github.com/napari/napari/blob/master/src/napari/_qt/widgets/_tests/test_theme_sample.py | BSD-3-Clause |
def build_qmodel_menu(
menu_id: str,
title: str | None = None,
parent: Optional['QWidget'] = None,
) -> QModelMenu:
"""Build a QModelMenu from the napari app model
Parameters
----------
menu_id : str
ID of a menu registered with napari._app_model.get_app_model().menus
title : Op... | Build a QModelMenu from the napari app model
Parameters
----------
menu_id : str
ID of a menu registered with napari._app_model.get_app_model().menus
title : Optional[str]
Title of the menu
parent : Optional[QWidget]
Parent of the menu
Returns
-------
QModelMenu... | build_qmodel_menu | python | napari/napari | src/napari/_qt/_qapp_model/_menus.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/_menus.py | BSD-3-Clause |
def _add_layer_data_to_viewer(
data: Any,
return_type: Any,
viewer: viewer.Viewer | None = None,
layer_name: str | None = None,
source: dict | None = None,
meta: dict | None = None,
) -> None:
"""Show a result in the viewer.
Parameters
----------
data : Any
The result of... | Show a result in the viewer.
Parameters
----------
data : Any
The result of the function call. For this function, this should be
*just* the data part of the corresponding layer type.
return_type : Any
The return annotation that was used in the decorated function.
viewer : Vi... | _add_layer_data_to_viewer | python | napari/napari | src/napari/_qt/_qapp_model/injection/_qprocessors.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/injection/_qprocessors.py | BSD-3-Clause |
def _add_future_data(
future: Future,
return_type: Any,
_from_tuple: bool = True,
viewer: viewer.Viewer | None = None,
source: dict | None = None,
) -> None:
"""Process a Future object.
This function will be called to process function that has a
return annotation of one of the `napari.t... | Process a Future object.
This function will be called to process function that has a
return annotation of one of the `napari.types.<layer_name>Data` ... and
will add the data in `result` to the current viewer as the corresponding
layer type.
Parameters
----------
future : Future
An... | _add_future_data | python | napari/napari | src/napari/_qt/_qapp_model/injection/_qprocessors.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/injection/_qprocessors.py | BSD-3-Clause |
def _provide_viewer(public_proxy: bool = True) -> viewer.Viewer | None:
"""Provide `PublicOnlyProxy` (allows internal napari access) of current viewer."""
if current_viewer := viewer.current_viewer():
if public_proxy:
return PublicOnlyProxy(current_viewer)
return current_viewer
r... | Provide `PublicOnlyProxy` (allows internal napari access) of current viewer. | _provide_viewer | python | napari/napari | src/napari/_qt/_qapp_model/injection/_qproviders.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/injection/_qproviders.py | BSD-3-Clause |
def _start_trace_dialog(qt_viewer: QtViewer) -> None:
"""Open Save As dialog to start recording a trace file."""
dlg = QFileDialog()
hist = get_save_history()
dlg.setHistory(hist)
filename, _ = dlg.getSaveFileName(
qt_viewer, # parent
trans._('Record performance trace file'), # cap... | Open Save As dialog to start recording a trace file. | _start_trace_dialog | python | napari/napari | src/napari/_qt/_qapp_model/qactions/_debug.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/qactions/_debug.py | BSD-3-Clause |
def _plugin_manager_dialog_avail() -> bool:
"""Returns whether the plugin manager class is available."""
plugin_dlg = find_spec('napari_plugin_manager')
if plugin_dlg:
return True
# not available
logger.debug('QtPluginDialog not available')
return False | Returns whether the plugin manager class is available. | _plugin_manager_dialog_avail | python | napari/napari | src/napari/_qt/_qapp_model/qactions/_plugins.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/qactions/_plugins.py | BSD-3-Clause |
def _show_plugin_install_dialog(window: Window) -> None:
"""Show dialog that allows users to install and enable/disable plugins."""
# TODO: Once menu contributions supported, `napari_plugin_manager` should be
# amended to be a napari plugin and simply add this menu item itself.
# This callback is only ... | Show dialog that allows users to install and enable/disable plugins. | _show_plugin_install_dialog | python | napari/napari | src/napari/_qt/_qapp_model/qactions/_plugins.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/qactions/_plugins.py | BSD-3-Clause |
def _toggle_canvas_ndim(viewer: ViewerModel):
"""Toggle the current canvas between 3D and 2D."""
if viewer.dims.ndisplay == 2:
viewer.dims.ndisplay = 3
else: # == 3
viewer.dims.ndisplay = 2 | Toggle the current canvas between 3D and 2D. | _toggle_canvas_ndim | python | napari/napari | src/napari/_qt/_qapp_model/qactions/_view.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/qactions/_view.py | BSD-3-Clause |
def init_qactions() -> None:
"""Initialize all Qt-based Actions with app-model
This function will be called in _QtMainWindow.__init__(). It should only
be called once (hence the lru_cache decorator).
It is responsible for:
- injecting Qt-specific names into the application injection_store namespa... | Initialize all Qt-based Actions with app-model
This function will be called in _QtMainWindow.__init__(). It should only
be called once (hence the lru_cache decorator).
It is responsible for:
- injecting Qt-specific names into the application injection_store namespace
(this is what allows functi... | init_qactions | python | napari/napari | src/napari/_qt/_qapp_model/qactions/__init__.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/qactions/__init__.py | BSD-3-Clause |
def add_dummy_actions(context: Context) -> None:
"""Register dummy 'Empty' actions for all contributable menus.
Each action is registered with its own `when` condition, that
ensures the action is not visible once the menu is populated.
The context key used in the `when` condition is also added to
t... | Register dummy 'Empty' actions for all contributable menus.
Each action is registered with its own `when` condition, that
ensures the action is not visible once the menu is populated.
The context key used in the `when` condition is also added to
the given `context` and assigned to a partial function th... | add_dummy_actions | python | napari/napari | src/napari/_qt/_qapp_model/qactions/__init__.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/qactions/__init__.py | BSD-3-Clause |
def test_debug_menu_exists(perfmon_activation, make_napari_viewer, qtbot):
"""Test debug menu existence following performance monitor usage."""
use_perfmon = perfmon_activation
viewer = make_napari_viewer()
# Check the menu exists following `NAPARI_PERFMON` value
# * `NAPARI_PERFMON=1` -> `perf.U... | Test debug menu existence following performance monitor usage. | test_debug_menu_exists | python | napari/napari | src/napari/_qt/_qapp_model/_tests/test_debug_menu.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/_tests/test_debug_menu.py | BSD-3-Clause |
def test_start_stop_trace_actions(
perfmon_activation, make_napari_viewer, tmp_path, qtbot
):
"""Test start and stop recording trace actions."""
use_perfmon = perfmon_activation
if use_perfmon:
trace_file = tmp_path / 'trace.json'
app = get_app_model()
viewer = make_napari_viewer... | Test start and stop recording trace actions. | test_start_stop_trace_actions | python | napari/napari | src/napari/_qt/_qapp_model/_tests/test_debug_menu.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/_tests/test_debug_menu.py | BSD-3-Clause |
def test_sample_data_triggers_reader_dialog(
make_napari_viewer, tmp_plugin: DynamicPlugin
):
"""Sample data pops reader dialog if multiple compatible readers"""
# make two tmp readers that take tif files
tmp2 = tmp_plugin.spawn(register=True)
@tmp_plugin.contribute.reader(filename_patterns=['*.tif... | Sample data pops reader dialog if multiple compatible readers | test_sample_data_triggers_reader_dialog | python | napari/napari | src/napari/_qt/_qapp_model/_tests/test_file_menu.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/_tests/test_file_menu.py | BSD-3-Clause |
def test_plugin_display_name_use_for_multiple_samples(
make_napari_viewer,
builtins,
):
"""Check 'display_name' used for submenu when plugin has >1 sample data."""
app = get_app_model()
viewer = make_napari_viewer()
# builtins provides more than one sample,
# so the submenu should use the `... | Check 'display_name' used for submenu when plugin has >1 sample data. | test_plugin_display_name_use_for_multiple_samples | python | napari/napari | src/napari/_qt/_qapp_model/_tests/test_file_menu.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/_tests/test_file_menu.py | BSD-3-Clause |
def test_sample_menu_plugin_state_change(
make_napari_viewer,
tmp_plugin: DynamicPlugin,
):
"""Check samples submenu correct after plugin changes state."""
app = get_app_model()
pm = tmp_plugin.plugin_manager
# Check no samples menu before plugin registration
with pytest.raises(KeyError):
... | Check samples submenu correct after plugin changes state. | test_sample_menu_plugin_state_change | python | napari/napari | src/napari/_qt/_qapp_model/_tests/test_file_menu.py | https://github.com/napari/napari/blob/master/src/napari/_qt/_qapp_model/_tests/test_file_menu.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.