Beispiel #1
0
def get_commands():
    """Return a list of the available command strings"""
    script = """
    new java.util.concurrent.Callable() {
        call: function() {
           importClass(Packages.ij.Menus, Packages.ij.IJ);
           var hashtable=Menus.getCommands();
           if (hashtable==null) {
               IJ.run("pleaseignorethis");
               hashtable = Menus.getCommands();
           }
           return hashtable;
        }
    };
    """
    c = J.run_script(script, class_loader=get_user_loader())
    hashtable = J.execute_callable_in_main_thread(c)
    keys = J.call(hashtable, "keys", "()Ljava/util/Enumeration;")
    keys = J.jenumeration_to_string_list(keys)
    values = J.call(hashtable, "values", "()Ljava/util/Collection;")
    values = [J.to_string(x) for x in J.iterate_java(J.call(values, "iterator", "()Ljava/util/Iterator;"))]

    class CommandList(list):
        def __init__(self):
            super(CommandList, self).__init__(keys)
            self.values = values

    return CommandList()
Beispiel #2
0
 def test_06_03_call_main(self):
     c = J.run_script("""
     new java.util.concurrent.Callable() {
        call: function() { return 2+2; }};""")
     result = J.execute_callable_in_main_thread(c)
     self.assertEqual(J.unwrap_javascript(result), 4)