Example #1
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)
Example #2
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)
Example #3
0
 def test_07_04_make_future_task_from_callable(self):
     call_able = J.run_script("""
     new java.util.concurrent.Callable() { 
         call: function() { return 2+2; }};""")
     future = J.make_future_task(call_able,
                                 fn_post_process=J.unwrap_javascript)
     future.run()
     self.assertEqual(future.get(), 4)
Example #4
0
 def test_07_04_make_future_task_from_callable(self):
     call_able = J.run_script("""
     new java.util.concurrent.Callable() { 
         call: function() { return 2+2; }};""")
     future = J.make_future_task(call_able, 
                                 fn_post_process=J.unwrap_javascript)
     future.run()
     self.assertEqual(future.get(), 4)
Example #5
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)
Example #6
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()
Example #7
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())
Example #8
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()
Example #9
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())
Example #10
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)
Example #11
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)
Example #12
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)
Example #13
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)
Example #14
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)
Example #15
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))
Example #16
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))
Example #17
0
 def test_07_03_make_future_task_from_runnable(self):
     future = J.make_future_task(
         J.run_script("new java.lang.Runnable() { run: function() {}};"),
         11)
     future.run()
     self.assertEqual(J.call(future.get(), "intValue", "()I"), 11)
Example #18
0
 def test_07_03_make_future_task_from_runnable(self):
     future = J.make_future_task(
         J.run_script("new java.lang.Runnable() { run: function() {}};"),
         11)
     future.run()
     self.assertEqual(J.call(future.get(), "intValue", "()I"), 11)