question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Viewer buttons don't work as expected when having two napari viewers in a single program

See original GitHub issue

šŸ› Bug

Hi,

Since napari 0.4.8, the buttons that by default are in the lower left corner don’t work as expected when having two napari viewers in a single program. More specifically, when clicking one of the lower left corner buttons in the napari viewer that was added first, the button’s action is executed on the other viewer. This seems to be related to the new action manager features that were added in 0.4.8.

I’m not sure if this is actually a bug or if napari simply isn’t meant to be used like this, but until 0.4.8 I hadn’t experienced any issues, so it would be nice if it could continue to work when used like this.

Demo

To Reproduce

Steps to reproduce the behavior:

  1. Run the following minimal working example with napari 0.4.8 or later:
import napari
from qtpy import QtWidgets
from skimage import data


class Window(QtWidgets.QWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.napari1 = napari.Viewer(show=False)
        self.napari1.add_image(data.cat())
        self.napari2 = napari.Viewer(show=False)
        self.napari2.add_image(data.astronaut())

        self.setLayout(QtWidgets.QHBoxLayout())
        self.layout().addWidget(self.napari1.window._qt_window)
        self.layout().addWidget(self.napari2.window._qt_window)


app = QtWidgets.QApplication([])
window = Window()
window.show()
app.exec_()
  1. Click the console button in the lower left corner of the napari viewer that displays the cat image.

The console will show up in the napari viewer displaying the astronaut image, instead of in the one displaying the cat image.

The same issue applies to the other buttons in the lower left corner.

Environment

napari: 0.4.9
Platform: Windows-10-10.0.19041-SP0
Python: 3.9.4 (default, Apr 9 2021, 11:43:21) [MSC v.1916 64 bit (AMD64)]
Qt: 5.15.2
PyQt5: 5.15.4
NumPy: 1.19.3
SciPy: 1.6.3
Dask: 2021.05.0
VisPy: 0.6.6

OpenGL:
- GL version: 4.6.0 NVIDIA 465.89
- MAX_TEXTURE_SIZE: 32768

Screens:
- screen 1: resolution 2560x1440, scale 1.0

Plugins:
- console: 0.0.3
- scikit-image: 0.4.9
- svg: 0.1.5

Additional context

The keyboard shortcuts for the buttons work as expected.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
tlambert03commented, Jun 17, 2021

I’m not sure if this is actually a bug or if napari simply isn’t meant to be used like this

definitely a bug! we still support multiple independent viewer instances. Thanks for the very clear report!

1reaction
brisvagcommented, Jun 21, 2021

git bisect says this started on #2612.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple viewer in one napari window example - Image.sc Forum
This example should work on napari 0.4.16 release. This is the first step in adding native support for this in napari and all...
Read more >
Are some operations impossible via the Viewer.update ...
This code works how I expect: the screen updates with random "snow". import numpy as np import napari import time with napari.gui_qt(): viewer...
Read more >
napari viewer tutorial
napari viewer tutorial¶. Welcome to the tutorial on the napari viewer! This tutorial assumes you have already installed napari and know how to...
Read more >
Multi-dimensional image visualization in Python using napari ...
We introduce napari, a fast, interactive, multi-dimensional image viewer for Python. napari is designed for browsing, annotating,Ā ...
Read more >
napari Changelog - PyUp.io
We added `napari.imshow` in 4928 as a convenience function to load image data and return both a `Viewer` and the image `Layer` all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found