From e346e7d93b87b6cd3b7ac203c3c18dad49dfe552 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 4 May 2023 21:04:18 -0500 Subject: [PATCH 1/2] Add an ij.py.show_ui function It takes care to show the UI on the AWT event dispatch thread. If the UI is already visible, it raises the application frame instead of calling ij.ui().showUI() again, since SciJava Common currently has a bug when doing that where it hoses the UI (see scijava/scijava-common#460). --- src/imagej/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/imagej/__init__.py b/src/imagej/__init__.py index 18aa9a85..794673f1 100644 --- a/src/imagej/__init__.py +++ b/src/imagej/__init__.py @@ -391,6 +391,26 @@ def show(self, image, cmap=None): pyplot.imshow(self.from_java(image), interpolation="nearest", cmap=cmap) pyplot.show() + def show_ui(self, name: str = None) -> None: + """Display the ImageJ2 user interface. + + :param name: The name of the ImageJ2 UI to show, or None for the + default interface, which is "legacy" (the original ImageJ + UI) when the add_legacy initialization flag is set, and + "swing" (the "pure ImageJ2" UI) otherwise. + """ + + ij = self._ij + + def show_or_raise_ui(): + ui = ij.ui().getDefaultUI() if name is None else ij.ui().getUI(name) + if ui.isVisible(): + ui.getApplicationFrame().setVisible(True) + else: + ui.show() + + self._ij.thread().queue(show_or_raise_ui) + def sync_image(self, imp: "jc.ImagePlus" = None): """Synchronize data between ImageJ and ImageJ2. From e9b6e1ebed4c13cba478c35e74ab0436f63a5c9a Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 5 May 2023 15:24:42 -0500 Subject: [PATCH 2/2] Update src/imagej/__init__.py Co-authored-by: Gabriel Selzer --- src/imagej/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imagej/__init__.py b/src/imagej/__init__.py index 794673f1..d5ba2ad0 100644 --- a/src/imagej/__init__.py +++ b/src/imagej/__init__.py @@ -409,7 +409,7 @@ def show_or_raise_ui(): else: ui.show() - self._ij.thread().queue(show_or_raise_ui) + ij.thread().queue(show_or_raise_ui) def sync_image(self, imp: "jc.ImagePlus" = None): """Synchronize data between ImageJ and ImageJ2.