1+ import os
12from time import sleep
23
34import appose
@@ -93,12 +94,12 @@ def create_settings(self):
9394
9495 self .package_path = Text (
9596 "Path to apposednapari environment" ,
96- "/Users/Nodar/Developer/CellProfiler /apposednapari/.pixi/envs/default" ,
97+ f" { os . path . dirname ( __file__ ) } /apposednapari/.pixi/envs/default" ,
9798 )
9899 self .doit = DoSomething (
99100 "Do the thing" ,
100101 "Do it" ,
101- self .do_it ,
102+ lambda : self .send_to_napari () ,
102103 doc = f"""\
103104 Press this button to do the job.
104105""" ,
@@ -122,50 +123,12 @@ def run(self, workspace):
122123
123124 x_data = x .pixel_data
124125
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 )
126+ self .send_to_napari (x_data )
164127
165128 if self .show_window :
166129 ...
167130
168- def do_it (self ):
131+ def send_to_napari (self , img_data = None ):
169132 env = appose .base (str (self .package_path )).build ()
170133 with env .python () as python :
171134 # Print Appose events verbosely, for debugging purposes.
@@ -180,27 +143,29 @@ def check_ready(event):
180143 global READY
181144 READY = True
182145 print ("Ready..." , READY )
183- print ("attempting to start to listen" , flush = True )
146+ print ("attempting to start to listen" )
184147 setup .listen (check_ready )
185- print ("attempting start setup" , flush = True )
148+ print ("attempting start setup" )
186149 setup .start ()
187- print ("Waiting for Qt startup..." , flush = True )
150+ print ("Waiting for Qt startup..." )
188151 global READY
189152 while not READY :
190- print ("sleeping" , READY )
153+ # print("sleeping", READY)
191154 sleep (0.1 )
192- print ("Qt is ready!" , flush = True )
155+ print ("Qt is ready!" )
156+
157+ if img_data is None :
158+ img_data = np .random .random ([512 , 384 ]).astype ("float64" )
193159
194160 # Create a test image in shared memory.
195- ndarr = appose .NDArray (dtype = "float64" , shape = [512 , 384 ])
196- # Fill the array with random values.
161+ ndarr = appose .NDArray (dtype = str (img_data .dtype ), shape = img_data .shape )
197162 # There's probably a slicker way without needing to slice/copy...
198- ndarr .ndarray ()[:] = np . random . random ( ndarr . shape )
163+ ndarr .ndarray ()[:] = img_data [:]
199164
200165 # Actually do a real thing with napari: create and show an image.
201- print ("Showing image with napari..." , flush = True )
166+ print ("Showing image with napari..." )
202167 task = python .task (napari_show , inputs = {"ndarr" : ndarr })
203168
204169 task .wait_for ()
205170 shape = task .outputs ["shape" ]
206- print (f"Task complete! Got shape: { shape } " , flush = True )
171+ print (f"Task complete! Got shape: { shape } " )
0 commit comments