Exemple #1
0
 def fn(self, *args):
     script = """
     new java.lang.Runnable() {
         run: function() {
             o.%s(%s);
         }
     };
     """ % (method, ",".join(["arg%d" % i for i in range(len(args))]))
     d = dict([("arg%d" % i, arg) for i, arg in enumerate(args)])
     d["o"] = self.o
     future = J.make_future_task(J.run_script(script, d))
     J.execute_future_in_main_thread(future)
     return future.get()
Exemple #2
0
 def fn(self, *args):
     script = """
     new java.lang.Runnable() {
         run: function() {
             o.%s(%s);
         }
     };
     """ % (method, ",".join(["arg%d" % i for i in range(len(args))]))
     d = dict([("arg%d" % i, arg) for i, arg in enumerate(args)])
     d["o"] = self.o
     future = J.make_future_task(J.run_script(script, d))
     J.execute_future_in_main_thread(future)
     return future.get()
Exemple #3
0
 def fn(self, *args):
     script = """
     new java.util.concurrent.Callable() {
         call: function() {
             return o.%s(%s);
         }
     };
     """ % (method, ",".join(["arg%d" % i for i in range(len(args))]))
     d = dict([("arg%d" % i, arg) for i, arg in enumerate(args)])
     d["o"] = self.o
     future = J.make_future_task(J.run_script(script, d))
     J.execute_future_in_main_thread(future)
     return fn_post_process(future.get())
Exemple #4
0
 def fn(self, *args):
     script = """
     new java.util.concurrent.Callable() {
         call: function() {
             return o.%s(%s);
         }
     };
     """ % (method, ",".join(["arg%d" % i for i in range(len(args))]))
     d = dict([("arg%d" % i, arg) for i, arg in enumerate(args)])
     d["o"] = self.o
     future = J.make_future_task(J.run_script(script, d))
     J.execute_future_in_main_thread(future)
     return fn_post_process(future.get())
Exemple #5
0
 def test_06_03_future_main(self):
     c = J.run_script("""
     new java.util.concurrent.Callable() {
        call: function() { return 2+2; }};""")
     result = J.execute_future_in_main_thread(
         J.make_future_task(c, fn_post_process=J.unwrap_javascript))
     self.assertEqual(result, 4)
Exemple #6
0
 def test_06_03_future_main(self):
     c = J.run_script("""
     new java.util.concurrent.Callable() {
        call: function() { return 2+2; }};""")
     result = J.execute_future_in_main_thread(
         J.make_future_task(c, fn_post_process=J.unwrap_javascript))
     self.assertEqual(result, 4)
Exemple #7
0
def get_temp_current_image():
    '''Get the temporary ImagePlus object for the current thread'''
    script = """
    new java.util.concurrent.Callable() {
        call: function() {
            return Packages.ij.WindowManager.getTempCurrentImage();
        }
    };
    """
    gtci = J.make_future_task(J.run_script(script))
    imageplus_obj = J.execute_future_in_main_thread(gtci)
    return get_imageplus_wrapper(imageplus_obj)
Exemple #8
0
 def createDisplay(self, name, dataset):
     '''Create a display that contains the given dataset'''
     #
     # Must be run on the gui thread
     #
     jcallable = J.run_script(
         """new java.util.concurrent.Callable() {
             call:function() {
                 return displayService.createDisplay(name, dataset);
             }
         };
         """, dict(displayService=self.o, name=name, dataset=dataset.o))
     future = J.make_future_task(jcallable,
                                 fn_post_process=wrap_display)
     return J.execute_future_in_main_thread(future)
 def createDisplay(self, name, dataset):
     """Create a display that contains the given dataset"""
     #
     # Must be run on the gui thread
     #
     jcallable = J.run_script(
         """new java.util.concurrent.Callable() {
             call:function() {
                 return displayService.createDisplay(name, dataset);
             }
         };
         """,
         dict(displayService=self.o, name=name, dataset=dataset.o),
     )
     future = J.make_future_task(jcallable, fn_post_process=wrap_display)
     return J.execute_future_in_main_thread(future)
Exemple #10
0
def run_batch_macro(macro_text, imp):
    '''Run a macro in batch mode
    
    macro_text - the macro program to be run
    imp - an image plus to become the active image
    
    returns the image plus that was the active image at the end of the run
    '''
    script = """
    new java.util.concurrent.Callable() {
        call: function() {
             return interp.runBatchMacro(macro_text, imp);
        }
    };
    """
    interp = J.make_instance("ij/macro/Interpreter","()V");
    future = J.make_future_task(J.run_script(
        script, dict(interp=interp, macro_text=macro_text, imp=imp)))
    return J.execute_future_in_main_thread(future)
Exemple #11
0
def get_current_image():
    '''Get the WindowManager's current image
    
    returns a wrapped ImagePlus object
    '''
    #
    # Run this on the UI thread so its thread context is the same
    # as the macro invocation
    #
    script = """
    new java.util.concurrent.Callable() {
        call: function() {
            return Packages.ij.WindowManager.getCurrentImage();
        }
    };
    """
    gci = J.make_future_task(J.run_script(script))
    imageplus_obj = J.execute_future_in_main_thread(gci)
    return get_imageplus_wrapper(imageplus_obj)
Exemple #12
0
def run_batch_macro(macro_text, imp):
    '''Run a macro in batch mode
    
    macro_text - the macro program to be run
    imp - an image plus to become the active image
    
    returns the image plus that was the active image at the end of the run
    '''
    script = """
    new java.util.concurrent.Callable() {
        call: function() {
             return interp.runBatchMacro(macro_text, imp);
        }
    };
    """
    interp = J.make_instance("ij/macro/Interpreter", "()V")
    future = J.make_future_task(
        J.run_script(script, dict(interp=interp,
                                  macro_text=macro_text,
                                  imp=imp)))
    return J.execute_future_in_main_thread(future)
Exemple #13
0
        def __init__(self):
            if service_classes is None:
                classes = None
                ctxt_fn = J.run_script("""new java.util.concurrent.Callable() {
                        call: function() {
                            return new Packages.imagej.ImageJ(false);
                        }
                    }""")
            else:
                classes = [
                    J.class_for_name(x)
                    for x in service_classes or REQUIRED_SERVICES
                ]
                classes = J.make_list(classes)
                ctxt_fn = J.run_script(
                    """new java.util.concurrent.Callable() {
                        call: function() {
                            return new Packages.imagej.ImageJ(classes);
                        }
                    }""", dict(classes=classes.o))

            self.o = J.execute_future_in_main_thread(
                J.make_future_task(ctxt_fn))
Exemple #14
0
 def __init__(self):
     if service_classes is None:
         classes = None
         ctxt_fn = J.run_script(
             """new java.util.concurrent.Callable() {
                 call: function() {
                     return new Packages.imagej.ImageJ(false);
                 }
             }""")
     else:
         classes = [ 
             J.class_for_name(x) 
             for x in service_classes or REQUIRED_SERVICES]
         classes = J.make_list(classes)
         ctxt_fn = J.run_script(
             """new java.util.concurrent.Callable() {
                 call: function() {
                     return new Packages.imagej.ImageJ(classes);
                 }
             }""", dict(classes = classes.o))
     
     self.o = J.execute_future_in_main_thread(
         J.make_future_task(ctxt_fn))