Skip to content

Commit d700d86

Browse files
committed
Transfer image on run
1 parent 6ae5085 commit d700d86

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

CP5/active_plugins/appose_demo.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@
7171
def show(narr):
7272
napari.imshow(narr)
7373
74-
narr = np.random.random([512, 384])
75-
show(narr)
76-
task.outputs["shape"] = narr.shape
74+
show(ndarr.ndarray())
75+
task.outputs["shape"] = ndarr.shape
7776
"""
7877

7978
READY = False
@@ -106,7 +105,7 @@ def create_settings(self):
106105
)
107106

108107
def settings(self):
109-
return super().settings() + [self.package_path, self.doit]
108+
return super().settings() + [self.x_name, self.package_path, self.doit]
110109

111110
def visible_settings(self):
112111
return self.settings()
@@ -123,6 +122,46 @@ def run(self, workspace):
123122

124123
x_data = x.pixel_data
125124

125+
env = appose.base(str(self.package_path)).build()
126+
with env.python() as python:
127+
# Print Appose events verbosely, for debugging purposes.
128+
python.debug(print)
129+
130+
# Start the Qt application event loop in the worker process.
131+
print("Starting Qt app event loop")
132+
setup = python.task(qt_setup, queue="main")
133+
def check_ready(event):
134+
if event.response_type == ResponseType.UPDATE:
135+
print("Got update event! Marking Qt as ready")
136+
global READY
137+
READY = True
138+
print("Ready...", READY)
139+
print("attempting to start to listen", flush=True)
140+
setup.listen(check_ready)
141+
print("attempting start setup", flush=True)
142+
setup.start()
143+
print("Waiting for Qt startup...", flush=True)
144+
global READY
145+
while not READY:
146+
print("sleeping", READY)
147+
sleep(0.1)
148+
print("Qt is ready!", flush=True)
149+
150+
print("IMAGE INFO: ", x_data.dtype, x_data.shape)
151+
152+
# Create a test image in shared memory.
153+
ndarr = appose.NDArray(dtype=str(x_data.dtype), shape=x_data.shape)
154+
# There's probably a slicker way without needing to slice/copy...
155+
ndarr.ndarray()[:] = x_data[:]
156+
157+
# Actually do a real thing with napari: create and show an image.
158+
print("Showing image with napari...", flush=True)
159+
task = python.task(napari_show, inputs={"ndarr": ndarr})
160+
161+
task.wait_for()
162+
shape = task.outputs["shape"]
163+
print(f"Task complete! Got shape: {shape}", flush=True)
164+
126165
if self.show_window:
127166
...
128167

0 commit comments

Comments
 (0)