Repository: napari/napari

Issue:
`NapariQtNotification` show as separate dialog when use only QtViewer
## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

When using `QtViewer` (for example in PartSeg)  and there is called `show_info` (For example press A when having active points layer in current main) the  

## To Reproduce

Steps to reproduce the behavior:

1. run this script:
```python
from napari.components import ViewerModel
from napari.qt import get_app, QtViewer, get_stylesheet
from napari.settings import get_settings

from qtpy.QtWidgets import QApplication, QWidget, QVBoxLayout


app = QApplication([])
get_app() # to register resources needed to have working buttons
model = ViewerModel()
qt_viewer = QtViewer(model)
model.add_points([[0, 0, 0], [0, 30, 30], [1, 15, 15]])

w = QWidget()
layout = QVBoxLayout()
layout.addWidget(qt_viewer)
layout.addWidget(qt_viewer.dockLayerList)
w.setLayout(layout)
w.setStyleSheet(get_stylesheet(get_settings().appearance.theme))

w.show()

app.exec_()
```
3. press letter A

![Zrzut ekranu z 2022-07-18 18-04-18](https://user-images.githubusercontent.com/3826210/179553949-fddf9104-20cb-4437-b736-455a1264a3e3.png)



<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

Notification should show in bottom lower corner of canvas, or dialog should not be created if there is no QtViewer. Or there should be other version of `get_app` that will allow properly use QtViewer without whole notifications stack.

<!-- A clear and concise description of what you expected to happen. -->

## Environment

 - Please copy and paste the information at napari info option in help menubar here:

 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->

@tlambert03 In this Issue I extract more critical, for me, part of #4835


Discussion:
thanks.  For what it's worth, I don't actually see a dialog on mac (and I suspect windows too).  I _have_ seen it on linux where the moment you make a window it shows though, (without content, as in your video).

In any case, I think this can be fixed either  in the `__init__` here:
https://github.com/napari/napari/blob/e490e5535438ab338a23b17905a1952f15a6d27a/napari/_qt/dialogs/qt_notification.py#L92

or by modifying the show method to be aware of a missing window:
https://github.com/napari/napari/blob/e490e5535438ab338a23b17905a1952f15a6d27a/napari/_qt/dialogs/qt_notification.py#L158
> thanks. For what it's worth, I don't actually see a dialog on mac (and I suspect windows too). 

This may vary on exact library and python versions as the only place where the parent is set is here: 
https://github.com/napari/napari/blob/e490e5535438ab338a23b17905a1952f15a6d27a/napari/_qt/dialogs/qt_notification.py#L90 

and in `show_notification` function: 

https://github.com/napari/napari/blob/e490e5535438ab338a23b17905a1952f15a6d27a/napari/_qt/dialogs/qt_notification.py#L425 

there is no reference kept, so it may be garbage collected before you could notice it. 



Resolving patch:
diff --git a/napari/_qt/dialogs/qt_notification.py b/napari/_qt/dialogs/qt_notification.py
--- a/napari/_qt/dialogs/qt_notification.py
+++ b/napari/_qt/dialogs/qt_notification.py
@@ -412,6 +412,7 @@ def _enter_debug_mode():
     @classmethod
     @ensure_main_thread
     def show_notification(cls, notification: Notification):
+        from ..._qt.qt_main_window import _QtMainWindow
         from ...settings import get_settings
 
         settings = get_settings()
@@ -421,6 +422,7 @@ def show_notification(cls, notification: Notification):
         if (
             notification.severity
             >= settings.application.gui_notification_level
+            and _QtMainWindow.current()
         ):
             cls.from_notification(notification).show()
 


Test patch: