Ejemplo n.º 1
0
def get_commands():
    '''Return a list of the available command strings'''
    hashtable = J.static_call('ij/Menus', 'getCommands',
                              '()Ljava/util/Hashtable;')
    if hashtable is None:
        #
        # This is a little bogus, but works - trick IJ into initializing
        #
        execute_command("pleaseignorethis")
        hashtable = J.static_call('ij/Menus', 'getCommands',
                                  '()Ljava/util/Hashtable;')
        if hashtable is None:
            return []
    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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
 def test_01_09_jdictionary_to_string_dictionary(self):
     properties = J.static_call("java/lang/System", "getProperties",
                                "()Ljava/util/Properties;")
     d = J.get_dictionary_wrapper(properties)
     pyd = J.jdictionary_to_string_dictionary(properties)
     keys = J.jenumeration_to_string_list(d.keys())
     for key in keys:
         value = J.to_string(d.get(key))
         self.assertEqual(pyd[key], value)
Ejemplo n.º 4
0
 def test_01_08_jenumeration_to_string_list(self):
     properties = J.static_call("java/lang/System", "getProperties",
                                "()Ljava/util/Properties;")
     d = J.get_dictionary_wrapper(properties)
     keys = J.jenumeration_to_string_list(d.keys())
     enum = J.get_enumeration_wrapper(d.keys())
     for i in range(d.size()):
         key = J.to_string(enum.nextElement())
         self.assertEqual(key, keys[i])
Ejemplo n.º 5
0
 def test_01_08_jenumeration_to_string_list(self):
     properties = J.static_call("java/lang/System", "getProperties",
                                "()Ljava/util/Properties;")
     d = J.get_dictionary_wrapper(properties)
     keys = J.jenumeration_to_string_list(d.keys())
     enum = J.get_enumeration_wrapper(d.keys())
     for i in range(d.size()):
         key = J.to_string(enum.nextElement())
         self.assertEqual(key, keys[i])
Ejemplo n.º 6
0
 def test_01_09_jdictionary_to_string_dictionary(self):
     properties = J.static_call("java/lang/System", "getProperties",
                                "()Ljava/util/Properties;")
     d = J.get_dictionary_wrapper(properties)
     pyd = J.jdictionary_to_string_dictionary(properties)
     keys = J.jenumeration_to_string_list(d.keys())
     for key in keys:
         value = J.to_string(d.get(key))
         self.assertEqual(pyd[key], value)
Ejemplo n.º 7
0
 def fn():
     hashtable = J.static_call('ij/Menus', 'getCommands',
                               '()Ljava/util/Hashtable;')
     if hashtable is None:
         #
         # This is a little bogus, but works - trick IJ into initializing
         #
         execute_command("pleaseignorethis")
         hashtable = J.static_call('ij/Menus', 'getCommands',
                                   '()Ljava/util/Hashtable;')
         if hashtable is None:
             return []
     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()