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);
         }
     };"""))
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
 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);
         }
     };"""))
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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,
     )
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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")
Ejemplo n.º 14
0
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")
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
 def test_06_02_execute_synch_main(self):
     javabridge.execute_runnable_in_main_thread(javabridge.run_script(
         "new java.lang.Runnable() { run:function() {}};"), True)
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
 def test_06_02_execute_synch_main(self):
     javabridge.execute_runnable_in_main_thread(
         javabridge.run_script(
             "new java.lang.Runnable() { run:function() {}};"), True)
Ejemplo n.º 20
0
 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)