File: gui_notifications_threaded.py

package info (click to toggle)
napari 0.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,036 kB
  • sloc: python: 112,264; xml: 72; makefile: 44; sh: 5
file content (29 lines) | stat: -rw-r--r-- 764 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
import warnings

import napari
from napari._qt.widgets.qt_viewer_buttons import QtViewerPushButton
from napari.qt import thread_worker


@thread_worker(start_thread=True)
def make_warning(*_):
    time.sleep(0.05)
    warnings.warn('Warning in another thread')


@thread_worker(start_thread=True)
def make_error(*_):
    time.sleep(0.05)
    raise ValueError('Error in another thread')


viewer = napari.Viewer()
layer_buttons = viewer.window.qt_viewer.layerButtons
err_btn = QtViewerPushButton(None, 'warning', 'new Error', make_error)
warn_btn = QtViewerPushButton(None, 'warning', 'new Warn', make_warning)
layer_buttons.layout().insertWidget(3, warn_btn)
layer_buttons.layout().insertWidget(3, err_btn)

if __name__ == '__main__':
    napari.run()