forked from napari/napari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_key_bindings.py
59 lines (40 loc) · 1.06 KB
/
custom_key_bindings.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Custom key bindings
===================
Display one 4-D image layer using the ``add_image`` API
.. tags:: gui
"""
from skimage import data
import napari
blobs = data.binary_blobs(
length=128, blob_size_fraction=0.05, n_dim=2, volume_fraction=0.25
).astype(float)
viewer = napari.view_image(blobs, name='blobs')
@viewer.bind_key('a')
def accept_image(viewer):
msg = 'this is a good image'
viewer.status = msg
print(msg)
set_layer_data(viewer)
@viewer.bind_key('r')
def reject_image(viewer):
msg = 'this is a bad image'
viewer.status = msg
print(msg)
set_layer_data(viewer)
def set_layer_data(viewer):
blobs = data.binary_blobs(
length=128, blob_size_fraction=0.05, n_dim=2, volume_fraction=0.25
).astype(float)
viewer.layers[0].data = blobs
@napari.Viewer.bind_key('w')
def hello(viewer):
# on press
viewer.status = 'hello world!'
yield
# on release
viewer.status = 'goodbye world :('
# change viewer title
viewer.title = 'quality control images'
if __name__ == '__main__':
napari.run()