Skip to content

Commit

Permalink
Merge branch 'main' into screenshot_without_margins
Browse files Browse the repository at this point in the history
  • Loading branch information
jni authored Jun 26, 2024
2 parents b511309 + ed160d5 commit 32f9bb3
Show file tree
Hide file tree
Showing 40 changed files with 960 additions and 492 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test_prereleases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
pull_request:
paths:
- '.github/workflows/test_prereleases.yml'
- 'resources/constraints/version_denylist.txt'

env:
COLUMNS: 120
Expand Down Expand Up @@ -42,6 +43,10 @@ jobs:

- uses: tlambert03/setup-qt-libs@v1

- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v2
continue-on-error: true

- name: Install Windows OpenGL
if: runner.os == 'Windows'
run: |
Expand All @@ -64,6 +69,7 @@ jobs:
BACKEND: ${{ matrix.backend }}
COVERAGE: "no_cov"
PYVISTA_OFF_SCREEN: True # required for opengl on windows
PIP_CONSTRAINT: resources/constraints/version_denylist.txt

# If something goes wrong, we can open an issue in the repo
- name: Report Failures
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upgrade_test_constraints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:
#
# --extra pyqt5 etc - names of extra sections from pyproject.toml that should be checked for the dependencies list (maybe we could create a super extra section to collect them all in)
flags+=" --extra pyqt5"
flags+=" --extra pyqt6_experimental"
flags+=" --extra pyqt6"
flags+=" --extra pyside2"
flags+=" --extra pyside6_experimental"
flags+=" --extra testing"
Expand Down
46 changes: 46 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ authors:
affiliation: Chan Zuckerberg Initiative
orcid: https://orcid.org/0000-0002-3841-8344
alias: aganders3
- given-names: Andrew
family-names: Annex
affiliation: SETI Institute/NASA ARC
orcid: https://orcid.org/0000-0002-0253-2313
alias: AndrewAnnex
- given-names: Peter
family-names: Boone
alias: boonepeter
Expand All @@ -121,6 +126,16 @@ authors:
CNRS, Palaiseau, France
orcid: https://orcid.org/0000-0002-9441-9173
alias: ClementCaporal
- given-names: Jan
family-names: Eglinger
affiliation: Friedrich Miescher Institute for Biomedical Research (FMI), Basel (Switzerland)
orcid: https://orcid.org/0000-0001-7234-1435
alias: imagejan
- given-names: Andreas
family-names: Eisenbarth
affiliation: EMBL Heidelberg, Germany
orcid: https://orcid.org/0000-0002-1113-9556
alias: aeisenbarth
- given-names: Jeremy
family-names: Freeman
affiliation: Chan Zuckerberg Initiative
Expand Down Expand Up @@ -209,11 +224,21 @@ authors:
family-names: Nauroth-Kreß
affiliation: University Hospital Würzburg - Institute of Neuroradiology
alias: Chris-N-K
- given-names: David
family-names: Palecek
affiliation: Algarve Centre of Marine Sciences (CCMAR)
orcid: https://orcid.org/0009-0003-9328-8540
alias: palec87
- given-names: Constantin
family-names: Pape
affiliation: Georg-August-Universität Göttingen
orcid: https://orcid.org/0000-0001-6562-7187
alias: constantinpape
- given-names: Eric
family-names: Perlman
affiliation: Yikes LLC
orcid: https://orcid.org/0000-0001-5542-1302
alias: perlman
- given-names: Kim
family-names: Pevey
alias: kcpevey
Expand All @@ -227,6 +252,9 @@ authors:
affiliation: Brown University
orcid: https://orcid.org/0000-0003-4501-5428
alias: kir0ul
- given-names: David
family-names: Pinto
alias: MarchisLost
- given-names: Jaime
family-names: Rodríguez-Guerra
affiliation: Quansight Labs
Expand All @@ -242,11 +270,19 @@ authors:
affiliation: European Bioinformatics Institute - European Molecular Biology Laboratory
orcid: https://orcid.org/0000-0002-2447-5911
alias: ctr26
- given-names: James
family-names: Ryan
alias: jamesyan-git
- given-names: Gabriel
family-names: Selzer
affiliation: University of Wisconsin-Madison
orcid: https://orcid.org/0009-0002-2400-1940
alias: gselzer
- given-names: MB
family-names: Smith
affiliation: AI lab for Living Technologies, University Medical Centre Utrecht (The Netherlands)
orcid: https://orcid.org/0000-0002-1405-0100
alias: odinsbane
- given-names: Paul
family-names: Smith
affiliation: University College London
Expand All @@ -255,6 +291,11 @@ authors:
- given-names: Konstantin
family-names: Sofiiuk
alias: ksofiyuk
- given-names: Johannes
family-names: Soltwedel
affiliation: DFG cluster of excellence 'Physics of Life', TU Dresden
orcid: https://orcid.org/0000-0003-1273-2412
alias: jo-mueller
- given-names: David
family-names: Stansby
affiliation: University College London
Expand All @@ -269,6 +310,11 @@ authors:
family-names: Wadhwa
affiliation: Quansight Labs
alias: ppwadhwa
- given-names: Martin
family-names: Weigert
affiliation: TU-Dresden / EPFL
orcid: https://orcid.org/0000-0002-7780-9057
alias: maweigert
- given-names: Jonas
family-names: Windhager
affiliation: ETH Zurich / University of Zurich
Expand Down
14 changes: 10 additions & 4 deletions napari/_qt/_qapp_model/_tests/test_view_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,28 @@ def test_toggle_axes_scale_bar_attr(


@skip_local_popups
def test_toggle_fullscreen(make_napari_viewer):
def test_toggle_fullscreen(make_napari_viewer, qtbot):
"""Test toggle fullscreen action."""
action_id = 'napari.window.view.toggle_fullscreen'
app = get_app()
viewer = make_napari_viewer(show=True)

# Check initial default state (no fullscreen)
assert not viewer.window._qt_window._fullscreen_flag
assert not viewer.window._qt_window.isFullScreen()

# Check fullscreen state change
app.commands.execute_command(action_id)
assert viewer.window._qt_window._fullscreen_flag
if sys.platform == 'darwin':
# On macOS, wait for the animation to complete
qtbot.wait(250)
assert viewer.window._qt_window.isFullScreen()

# Check return to non fullscreen state
app.commands.execute_command(action_id)
assert not viewer.window._qt_window._fullscreen_flag
if sys.platform == 'darwin':
# On macOS, wait for the animation to complete
qtbot.wait(250)
assert not viewer.window._qt_window.isFullScreen()


@skip_local_focus
Expand Down
97 changes: 97 additions & 0 deletions napari/_qt/_tests/test_qt_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,3 +1116,100 @@ def test_points_2d_to_3d(make_napari_viewer):
QApplication.processEvents()
viewer.dims.ndisplay = 3
QApplication.processEvents()


@skip_local_popups
def test_scale_bar_colored(qt_viewer, qtbot):
viewer = qt_viewer.viewer
scale_bar = viewer.scale_bar

# Add black image
data = np.zeros((2, 2))
viewer.add_image(data)

# Check scale bar is not visible (all the canvas is black - `[0, 0, 0, 255]`)
def check_all_black():
screenshot = qt_viewer.screenshot(flash=False)
assert np.all(screenshot == [0, 0, 0, 255], axis=-1).all()

qtbot.waitUntil(check_all_black)

# Check scale bar is visible (canvas has white `[1, 1, 1, 255]` in it)
def check_white_scale_bar():
screenshot = qt_viewer.screenshot(flash=False)
assert not np.all(screenshot == [0, 0, 0, 255], axis=-1).all()
assert np.all(screenshot == [1, 1, 1, 255], axis=-1).any()

scale_bar.visible = True
qtbot.waitUntil(check_white_scale_bar)

# Check scale bar is colored (canvas has fuchsia `[1, 0, 1, 255]` and not white in it)
def check_colored_scale_bar():
screenshot = qt_viewer.screenshot(flash=False)
assert not np.all(screenshot == [1, 1, 1, 255], axis=-1).any()
assert np.all(screenshot == [1, 0, 1, 255], axis=-1).any()

scale_bar.colored = True
qtbot.waitUntil(check_colored_scale_bar)

# Check scale bar is still visible but not colored (canvas has white again but not fuchsia in it)
def check_only_white_scale_bar():
screenshot = qt_viewer.screenshot(flash=False)
assert np.all(screenshot == [1, 1, 1, 255], axis=-1).any()
assert not np.all(screenshot == [1, 0, 1, 255], axis=-1).any()

scale_bar.colored = False
qtbot.waitUntil(check_only_white_scale_bar)


@skip_local_popups
def test_scale_bar_ticks(qt_viewer, qtbot):
viewer = qt_viewer.viewer
scale_bar = viewer.scale_bar

# Add black image
data = np.zeros((2, 2))
viewer.add_image(data)

# Check scale bar is not visible (all the canvas is black - `[0, 0, 0, 255]`)
def check_all_black():
screenshot = qt_viewer.screenshot(flash=False)
assert np.all(screenshot == [0, 0, 0, 255], axis=-1).all()

qtbot.waitUntil(check_all_black)

# Check scale bar is visible (canvas has white `[1, 1, 1, 255]` in it)
def check_white_scale_bar():
screenshot = qt_viewer.screenshot(flash=False)
assert not np.all(screenshot == [0, 0, 0, 255], axis=-1).all()
assert np.all(screenshot == [1, 1, 1, 255], axis=-1).any()

scale_bar.visible = True
qtbot.waitUntil(check_white_scale_bar)

# Check scale bar has ticks active and take screenshot for later comparison
assert scale_bar.ticks
screenshot_with_ticks = qt_viewer.screenshot(flash=False)

# Check scale bar without ticks (still white present but new screenshot differs from ticks one)
def check_no_ticks_scale_bar():
screenshot = qt_viewer.screenshot(flash=False)
assert np.all(screenshot == [1, 1, 1, 255], axis=-1).any()
npt.assert_raises(
AssertionError,
npt.assert_array_equal,
screenshot,
screenshot_with_ticks,
)

scale_bar.ticks = False
qtbot.waitUntil(check_no_ticks_scale_bar)

# Check scale bar again has ticks (still white present and new screenshot corresponds with ticks one)
def check_ticks_scale_bar():
screenshot = qt_viewer.screenshot(flash=False)
assert np.all(screenshot == [1, 1, 1, 255], axis=-1).any()
npt.assert_array_equal(screenshot, screenshot_with_ticks)

scale_bar.ticks = True
qtbot.waitUntil(check_ticks_scale_bar)
1 change: 1 addition & 0 deletions napari/_qt/containers/qt_layer_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def keyPressEvent(self, e: Optional[QKeyEvent]) -> None:
e.modifiers() & Qt.KeyboardModifier.AltModifier
or e.modifiers() & Qt.KeyboardModifier.ControlModifier
or e.modifiers() & Qt.KeyboardModifier.MetaModifier
or e.modifiers() & Qt.KeyboardModifier.ShiftModifier
):
e.ignore()
elif e.key() != Qt.Key.Key_Space:
Expand Down
6 changes: 3 additions & 3 deletions napari/_qt/dialogs/_tests/test_reader_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_reader_defaults(reader_dialog, tmpdir):

assert widg.findChild(QLabel).text().startswith('Choose reader')
assert widg._get_plugin_choice() == 'p1'
assert widg.persist_checkbox.isChecked()
assert not widg.persist_checkbox.isChecked()


def test_reader_with_error_message(reader_dialog):
Expand Down Expand Up @@ -84,10 +84,10 @@ def test_get_plugin_choice(tmpdir, reader_dialog):
def test_get_persist_choice(tmpdir, reader_dialog):
file_pth = tmpdir.join('my_file.tif')
widg = reader_dialog(pth=file_pth, readers={'p1': 'p1', 'p2': 'p2'})
assert widg._get_persist_choice()
assert not widg._get_persist_choice()

widg.persist_checkbox.toggle()
assert not widg._get_persist_choice()
assert widg._get_persist_choice()


def test_prepare_dialog_options_no_readers():
Expand Down
4 changes: 2 additions & 2 deletions napari/_qt/dialogs/qt_reader_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
parent: QWidget = None,
readers: Optional[dict[str, str]] = None,
error_message: str = '',
persist_checked: bool = True,
persist_checked: bool = False,
) -> None:
if readers is None:
readers = {}
Expand Down Expand Up @@ -194,7 +194,7 @@ def handle_gui_reading(
pth=_path,
error_message=error_message,
readers=readers,
persist_checked=not plugin_override,
persist_checked=plugin_override,
)
display_name, persist = readerDialog.get_user_choices()
if display_name:
Expand Down
2 changes: 1 addition & 1 deletion napari/_qt/qt_resources/styles/01_buttons.qss
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ QtModeRadioButton[mode="polygon"]::indicator {
}

QtModeRadioButton[mode="labels_polygon"]::indicator {
image: url("theme_{{ id }}:/polygon_lasso.svg");
image: url("theme_{{ id }}:/polygon.svg");
}

QtModeRadioButton[mode="polygon_lasso"]::indicator {
Expand Down
Loading

0 comments on commit 32f9bb3

Please sign in to comment.