Skip to content

Commit e51b2d6

Browse files
committed
WIP: 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).
1 parent 8baaac0 commit e51b2d6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/imagej/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,25 @@ def show(self, image, cmap=None):
391391
pyplot.imshow(self.from_java(image), interpolation="nearest", cmap=cmap)
392392
pyplot.show()
393393

394+
def show_ui(self, name: str = None) -> None:
395+
"""Display the ImageJ2 user interface.
396+
397+
:param name: The name of the ImageJ2 UI to show, or None for the
398+
default interface, which is "legacy" (the original ImageJ
399+
UI) when the add_legacy initialization flag is set, and
400+
"swing" (the "pure ImageJ2" UI) otherwise.
401+
"""
402+
403+
ij = self._ij
404+
def show_or_raise_ui():
405+
ui = ij.ui().getDefaultUI() if name is None else ij.ui().getUI(name)
406+
if ui.isVisible():
407+
ui.getApplicationFrame().setVisible(True)
408+
else:
409+
ui.show()
410+
411+
self._ij.thread().queue(show_or_raise_ui)
412+
394413
def sync_image(self, imp: "jc.ImagePlus" = None):
395414
"""Synchronize data between ImageJ and ImageJ2.
396415

0 commit comments

Comments
 (0)