def fn_launch_frame(event): javabridge.execute_runnable_in_main_thread(javabridge.run_script(""" new java.lang.Runnable() { run: function() { with(JavaImporter(java.awt.Frame)) Frame().setVisible(true); } };"""))
def finalize(self, result): try: javabridge.deactivate_awt() import imagej.imagej2 if imagej.imagej2.the_imagej_context is not None: script = """ new java.lang.Runnable () { run: function() { ctx.getContext().dispose(); } }""" runnable = javabridge.run_script( script, dict(ctx=imagej.imagej2.the_imagej_context)) javabridge.execute_runnable_in_main_thread(runnable, True) imagej.imagej2.the_imagej_context = None javabridge.static_call("java/lang/System", "gc", "()V") except: pass try: from ilastik.core.jobMachine import GLOBAL_WM GLOBAL_WM.stopWorkers() except: logging.root.warn("Failed to stop Ilastik") try: from cellprofiler.utilities.zmqrequest import join_to_the_boundary join_to_the_boundary() except: logging.root.warn("Failed to stop zmq boundary")
def fn_launch_frame(event): javabridge.execute_runnable_in_main_thread( javabridge.run_script(""" new java.lang.Runnable() { run: function() { with(JavaImporter(java.awt.Frame)) Frame().setVisible(true); } };"""))
def setActiveDisplay(self, display): '''Make this the active display''' # Note: has to be run in GUI thread on mac r = J.run_script( """new java.lang.Runnable() { run:function() { displayService.setActiveDisplay(display); } } """, dict(displayService=self.o, display=display.o)) J.execute_runnable_in_main_thread(r, True)
def hide(self): J.execute_runnable_in_main_thread( J.run_script( """ new java.lang.Runnable() { run: function() { o.hide(); }}""", dict(o=self.o), ), synchronous=True, )
def set_temp_current_image(imagej_obj): '''Set the temporary current image for the UI thread''' script = """ new java.lang.Runnable() { run: function() { Packages.ij.WindowManager.setTempCurrentImage(ip); } }; """ javabridge.execute_runnable_in_main_thread( javabridge.run_script(script, dict(ip=imagej_obj.o)), True)
def execute_macro(macro_text): '''Execute a macro in ImageJ macro_text - the macro program to be run ''' interp = J.make_instance("ij/macro/Interpreter","()V"); J.execute_runnable_in_main_thread(J.run_script( """new java.lang.Runnable() { run: function() { interp.run(macro_text); }}""", dict(interp=interp, macro_text=macro_text)), synchronous=True)
def close(self): '''Close the display This is run in the UI thread with synchronization. ''' r = J.run_script( """new java.lang.Runnable() { run: function() { display.close(); } }; """, dict(display=self.o)) J.execute_runnable_in_main_thread(r, True)
def execute_macro(macro_text): '''Execute a macro in ImageJ macro_text - the macro program to be run ''' interp = javabridge.make_instance("ij/macro/Interpreter", "()V"); javabridge.execute_runnable_in_main_thread(javabridge.run_script( """new java.lang.Runnable() { run: function() { interp.run(macro_text); }}""", dict(interp=interp, macro_text=macro_text)), synchronous=True)
def set_temp_current_image(imagej_obj): '''Set the temporary current image for the UI thread''' script = """ new java.lang.Runnable() { run: function() { Packages.ij.WindowManager.setTempCurrentImage(ip); } }; """ J.execute_runnable_in_main_thread( J.run_script(script, dict(ip=imagej_obj.o)), True)
def select_overlay(display, overlay, select=True): '''Select or deselect an overlay display - the overlay's display overlay - the overlay to select ''' for view in J.get_collection_wrapper(display, fn_wrapper = wrap_data_view): if J.call(overlay, "equals", "(Ljava/lang/Object;)Z", view.getData()): J.execute_runnable_in_main_thread(J.run_script( """new java.lang.Runnable() { run: function() { view.setSelected(select);} }""", dict(view = view.o, select=select)), synchronous=True) break else: logger.info("Failed to select overlay")
def set_current_image(imagej_obj): '''Set the currently active window imagej_obj - an ImagePlus to become the current image ''' javabridge.execute_runnable_in_main_thread(javabridge.run_script( """new java.lang.Runnable() { run:function() { var w = imp.getWindow(); if (w == null) { imp.show(); } else { Packages.ij.WindowManager.setCurrentWindow(w); } } } """, dict(imp=imagej_obj.o)), synchronous=True)
def set_current_image(imagej_obj): '''Set the currently active window imagej_obj - an ImagePlus to become the current image ''' J.execute_runnable_in_main_thread(J.run_script( """new java.lang.Runnable() { run:function() { var w = imp.getWindow(); if (w == null) { imp.show(); } else { Packages.ij.WindowManager.setCurrentWindow(w); } } } """, dict(imp=imagej_obj.o)), synchronous=True)
def test_06_02_execute_synch_main(self): javabridge.execute_runnable_in_main_thread(javabridge.run_script( "new java.lang.Runnable() { run:function() {}};"), True)
def show(self): javabridge.execute_runnable_in_main_thread(javabridge.run_script(""" new java.lang.Runnable() { run: function() { o.show(); }}""", dict(o=self.o)), synchronous=True)
def test_06_02_execute_synch_main(self): javabridge.execute_runnable_in_main_thread( javabridge.run_script( "new java.lang.Runnable() { run:function() {}};"), True)
def hide(self): javabridge.execute_runnable_in_main_thread(javabridge.run_script( """ new java.lang.Runnable() { run: function() { o.hide(); }}""", dict(o=self.o)), synchronous=True)