diff --git a/itkwidgets/cell_watcher.py b/itkwidgets/cell_watcher.py index 7cbbc440..6131a241 100644 --- a/itkwidgets/cell_watcher.py +++ b/itkwidgets/cell_watcher.py @@ -22,9 +22,11 @@ def data(self): def not_created(self): # Return a list of names of viewers that have not been created yet names = [] - for vals in self.data.values(): - if vals['name'] is not None and not vals['status']: - names.append(vals['name']) + for key, val in self.data.items(): + name = val['name'] + if not val['status']: + name = name if name is not None else key + names.append(name) return names @property @@ -122,7 +124,7 @@ def create_task(self, fn): def capture_event(self, stream, ident, parent): self._events.put((stream, ident, parent)) - if self._events.qsize() == 1 and self.ready_to_run_next_cell(parent): + if self._events.qsize() == 1 and self.ready_to_run_next_cell(): # We've added a new task to an empty queue. # Begin executing tasks again. self.create_task(self.execute_next_request) @@ -137,12 +139,10 @@ def all_getters_resolved(self): getters_resolved = [f.done() for f in self.results.values()] return all(getters_resolved) - def ready_to_run_next_cell(self, parent): + def ready_to_run_next_cell(self): # Any itk_viewer objects need to be available and all getters/setters # need to be resolved - raw = parent.get("content", {}).get("code", "") - viewers_not_ready = [n for n in self.viewers.not_created if n in raw] - self.waiting_on_viewer = any(viewers_not_ready) + self.waiting_on_viewer = len(self.viewers.not_created) return self.all_getters_resolved and not self.waiting_on_viewer async def execute_next_request(self): @@ -155,7 +155,7 @@ async def execute_next_request(self): # Fetch the next request if we haven't already self.current_request = self._events.get() - if self.ready_to_run_next_cell(self.current_request[2]): + if self.ready_to_run_next_cell(): # Continue processing the remaining queued tasks await self._execute_next_request()