Ejemplo n.º 1
0
 def test_03_09_cw_get_method(self):
     sclass = J.class_for_name('java.lang.String')
     iclass = J.get_static_field('java/lang/Integer', 'TYPE', 
                                 'Ljava/lang/Class;')
     c = J.get_class_wrapper('java.lang.String')
     m = c.getMethod('charAt', [ iclass ])
     self.assertEqual(J.to_string(J.call(m, 'getReturnType', '()Ljava/lang/Class;')), 'char')
     m = c.getMethod('concat', [ sclass])
     self.assertEqual(J.to_string(J.call(m, 'getReturnType', '()Ljava/lang/Class;')), 
                      'class java.lang.String')
Ejemplo n.º 2
0
 def test_03_09_cw_get_method(self):
     sclass = J.class_for_name('java.lang.String')
     iclass = J.get_static_field('java/lang/Integer', 'TYPE',
                                 'Ljava/lang/Class;')
     c = J.get_class_wrapper('java.lang.String')
     m = c.getMethod('charAt', [iclass])
     self.assertEqual(
         J.to_string(J.call(m, 'getReturnType', '()Ljava/lang/Class;')),
         'char')
     m = c.getMethod('concat', [sclass])
     self.assertEqual(
         J.to_string(J.call(m, 'getReturnType', '()Ljava/lang/Class;')),
         'class java.lang.String')
Ejemplo n.º 3
0
 def test_02_01_show_get_and_hide(self):
     file_name = os.path.join(sbs_dir, "Channel1-01-A-01.tif")
     ip = I.load_imageplus(file_name)
     ip.show()
     window = ip.getWindow()
     self.assertTrue(J.to_string(window).startswith("Channel1-01-A-01.tif"))
     ip.hide()
Ejemplo n.º 4
0
 def test_03_05_cw_get_annotations(self):
     c = J.get_class_wrapper('java.security.Identity')
     annotations = c.getAnnotations()
     annotations = J.get_env().get_object_array_elements(annotations)
     self.assertEqual(len(annotations), 1)
     self.assertEqual(J.to_string(annotations[0]),
                      '@java.lang.Deprecated()')
Ejemplo n.º 5
0
 def test_08_11_toArray(self):
     c1 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     result = [J.to_string(x) for x in c1.toArray()]
     self.assertIn("Foo", result)
     self.assertIn("Bar", result)
Ejemplo n.º 6
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.º 7
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.º 8
0
 def test_08_11_toArray(self):
     c1 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     result = [J.to_string(x) for x in c1.toArray()]
     self.assertIn("Foo", result)
     self.assertIn("Bar", result)
Ejemplo n.º 9
0
 def test_01_07_get_dictionary_wrapper(self):
     properties = J.static_call("java/lang/System", "getProperties",
                                "()Ljava/util/Properties;")
     d = J.get_dictionary_wrapper(properties)
     self.assertTrue(d.size() > 10)
     self.assertFalse(d.isEmpty())
     keys = J.get_enumeration_wrapper(d.keys())
     values = J.get_enumeration_wrapper(d.elements())
     n_elems = d.size()
     for i in range(n_elems):
         self.assertTrue(keys.hasMoreElements())
         key = J.to_string(keys.nextElement())
         self.assertTrue(values.hasMoreElements())
         value = J.to_string(values.nextElement())
         self.assertEqual(J.to_string(d.get(key)), value)
     self.assertFalse(keys.hasMoreElements())
     self.assertFalse(values.hasMoreElements())
Ejemplo n.º 10
0
 def test_01_07_get_dictionary_wrapper(self):
     properties = J.static_call("java/lang/System", "getProperties",
                                "()Ljava/util/Properties;")
     d = J.get_dictionary_wrapper(properties)
     self.assertTrue(d.size() > 10)
     self.assertFalse(d.isEmpty())
     keys = J.get_enumeration_wrapper(d.keys())
     values = J.get_enumeration_wrapper(d.elements())
     n_elems = d.size()
     for i in range(n_elems):
         self.assertTrue(keys.hasMoreElements())
         key = J.to_string(keys.nextElement())
         self.assertTrue(values.hasMoreElements())
         value = J.to_string(values.nextElement())
         self.assertEqual(J.to_string(d.get(key)), value)
     self.assertFalse(keys.hasMoreElements())
     self.assertFalse(values.hasMoreElements())
Ejemplo n.º 11
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.º 12
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.º 13
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.º 14
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.º 15
0
 def test_01_06_get_enumeration_wrapper(self):
     properties = J.static_call("java/lang/System", "getProperties",
                                "()Ljava/util/Properties;")
     keys = J.call(properties, "keys", "()Ljava/util/Enumeration;")
     enum = J.get_enumeration_wrapper(keys)
     has_java_vm_name = False
     while(enum.hasMoreElements()):
         key = J.to_string(enum.nextElement())
         if key == "java.vm.name":
             has_java_vm_name = True
     self.assertTrue(has_java_vm_name)
Ejemplo n.º 16
0
 def test_01_06_get_enumeration_wrapper(self):
     properties = J.static_call("java/lang/System", "getProperties",
                                "()Ljava/util/Properties;")
     keys = J.call(properties, "keys", "()Ljava/util/Enumeration;")
     enum = J.get_enumeration_wrapper(keys)
     has_java_vm_name = False
     while (enum.hasMoreElements()):
         key = J.to_string(enum.nextElement())
         if key == "java.vm.name":
             has_java_vm_name = True
     self.assertTrue(has_java_vm_name)
Ejemplo n.º 17
0
 def get_pixel_data(self, axes = None):
     imgplus = self.getImgPlus()
     pixel_data = get_pixel_data(imgplus)
     inv_axes = J.get_env().get_object_array_elements(self.getAxes())
     if axes is None:
         axes = [ Axes().Y, Axes().X]
         if len(inv_axes) > 2:
             axes.append(Axes().CHANNEL)
     transpose = []
     for axis in axes:
         matches = [i for i, inv_axis in enumerate(inv_axes)
                    if J.call(inv_axis, "equals", 
                              "(Ljava/lang/Object;)Z", axis)]
         if len(matches) != 1:
             raise ValueError("No match for %s axis" % J.to_string(axis))
         transpose.append(matches[0])
     return pixel_data.transpose(transpose)
Ejemplo n.º 18
0
 def get_pixel_data(self, axes=None):
     imgplus = self.getImgPlus()
     pixel_data = get_pixel_data(imgplus)
     inv_axes = J.get_env().get_object_array_elements(self.getAxes())
     if axes is None:
         axes = [Axes().Y, Axes().X]
         if len(inv_axes) > 2:
             axes.append(Axes().CHANNEL)
     transpose = []
     for axis in axes:
         matches = [
             i for i, inv_axis in enumerate(inv_axes) if J.call(
                 inv_axis, "equals", "(Ljava/lang/Object;)Z", axis)
         ]
         if len(matches) != 1:
             raise ValueError("No match for %s axis" %
                              J.to_string(axis))
         transpose.append(matches[0])
     return pixel_data.transpose(transpose)
Ejemplo n.º 19
0
 def get_command_settings(self, command, d):
     '''Get the settings associated with the current command
     
     d - the dictionary that persists the setting. None = regular
     '''
     cc = self.get_cached_commands()
     if (not cc.has_key(command)) or (cc[command] is None):
         return []
     if not d.has_key(command):
         classname = cc[command]
         try:
             plugin = M.get_plugin(classname)
         except:
             d[command] = []
             return []
         fp_in = P.get_input_fields_and_parameters(plugin)
         result = []
         for field, parameter in fp_in:
             field_type = P.get_field_type(field)
             label = parameter.label() or ""
             if field_type == P.FT_BOOL:
                 result += [cps.Binary(label, field.getBoolean(plugin))]
             elif field_type == P.FT_INTEGER:
                 result += [cps.Integer(label, field.getLong(plugin))]
             elif field_type == P.FT_FLOAT:
                 result += [cps.Float(label, field.getDouble(plugin))]
             elif field_type == P.FT_STRING:
                 result += [cps.Text(label, J.to_string(field.get(plugin)))]
             else:
                 assert field_type == P.FT_IMAGE
                 result += [cps.ImageNameSubscriber(label, "None")]
                 
         fp_out = P.get_output_fields_and_parameters(plugin)
         for field, parameter in fp_out:
             field_type = P.get_field_type(field)
             if field_type == P.FT_IMAGE:
                 result += [cps.ImageNameProvider(parameter.label() or "",
                                                  "Output")]
         d[command] = result
     else:
         result = d[command]
     return result
Ejemplo n.º 20
0
def calculate_transpose(actual_axes, desired_axes=None):
    '''Calculate the transpose tuple that converts the actual orientation to the desired
    
    actual_axes - a list of the AxisType arguments as fetched from
                  a display, ImgPlus, view or overlay
                  
    desired_axes - the desired orientation. By default, this is i,j = Y, X
    '''
    if desired_axes is None:
        desired_axes = [ Axes().Y, Axes().X]
        if len(actual_axes) > 2:
            desired_axes.append(Axes().CHANNEL)
    transpose = []
    for axis in desired_axes:
        matches = [i for i, actual_axis in enumerate(actual_axes)
                   if J.call(actual_axis, "equals", 
                             "(Ljava/lang/Object;)Z", axis)]
        if len(matches) != 1:
            raise ValueError("No match for %s axis" % J.to_string(axis))
        transpose.append(matches[0])
    return transpose
Ejemplo n.º 21
0
def calculate_transpose(actual_axes, desired_axes=None):
    '''Calculate the transpose tuple that converts the actual orientation to the desired
    
    actual_axes - a list of the AxisType arguments as fetched from
                  a display, ImgPlus, view or overlay
                  
    desired_axes - the desired orientation. By default, this is i,j = Y, X
    '''
    if desired_axes is None:
        desired_axes = [ Axes().Y, Axes().X]
        if len(actual_axes) > 2:
            desired_axes.append(Axes().CHANNEL)
    transpose = []
    for axis in desired_axes:
        matches = [i for i, actual_axis in enumerate(actual_axes)
                   if J.call(actual_axis, "equals", 
                             "(Ljava/lang/Object;)Z", axis)]
        if len(matches) != 1:
            raise ValueError("No match for %s axis" % J.to_string(axis))
        transpose.append(matches[0])
    return transpose
Ejemplo n.º 22
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()
Ejemplo n.º 23
0
    def get_command_settings(self, command, d):
        '''Get the settings associated with the current command
        
        d - the dictionary that persists the setting. None = regular
        '''
        key = command.get_unicode_value()
        if not d.has_key(key):
            if bioformats.USE_IJ2:
                try:
                    module_info = command.get_selected_leaf()[2]
                except cps.ValidationError:
                    return []
                result = []
                inputs = module_info.getInputs()
                module = module_info.createModule()
                implied_outputs = []
                for module_item in inputs:
                    field_type = module_item.getType()
                    label = module_item.getLabel()
                    value = module_item.getValue(module)
                    minimum = module_item.getMinimumValue()
                    maximum = module_item.getMaximumValue()
                    description = module_item.getDescription()
                    if field_type == IJ2.FT_BOOL:
                        setting = cps.Binary(label,
                                             J.call(value, "booleanValue",
                                                    "()Z"),
                                             doc=description)
                    elif field_type == IJ2.FT_INTEGER:
                        if minimum is not None:
                            minimum = J.call(minimum, "intValue", "()I")
                        if maximum is not None:
                            maximum = J.call(maximum, "intValue", "()I")
                        setting = cps.Integer(label,
                                              J.call(value, "intValue", "()I"),
                                              minval=minimum,
                                              maxval=maximum,
                                              doc=description)
                    elif field_type == IJ2.FT_FLOAT:
                        if minimum is not None:
                            minimum = J.call(minimum, "floatValue", "()F")
                        if maximum is not None:
                            maximum = J.call(maximum, "floatValue", "()F")
                        setting = cps.Float(label,
                                            J.call(value, "floatValue", "()F"),
                                            minval=minimum,
                                            maxval=maximum,
                                            doc=description)
                    elif field_type == IJ2.FT_STRING:
                        choices = module_item.getChoices()
                        value = J.to_string(value)
                        if choices is not None:
                            choices = [
                                J.to_string(choice)
                                for choice in J.iterate_collection(choices)
                            ]
                            setting = cps.Choice(label,
                                                 choices,
                                                 value,
                                                 doc=description)
                        else:
                            setting = cps.Text(label, value, doc=description)
                    elif field_type == IJ2.FT_COLOR:
                        if value is not None:
                            value = IJ2.color_rgb_to_html(value)
                        else:
                            value = "#ffffff"
                        setting = cps.Color(label, value, doc=description)
                    elif field_type == IJ2.FT_IMAGE:
                        setting = cps.ImageNameSubscriber(label,
                                                          "InputImage",
                                                          doc=description)
                        #
                        # This is a Display for ij2 - the plugin typically
                        # scribbles all over the display's image. So
                        # we list it as an output too.
                        #
                        implied_outputs.append(
                            (cps.ImageNameProvider(label,
                                                   "OutputImage",
                                                   doc=description),
                             module_item))
                    elif field_type == IJ2.FT_OVERLAY:
                        setting = cps.ObjectNameSubscriber(label,
                                                           "ImageJObject",
                                                           doc=description)
                    else:
                        continue
                    result.append((setting, module_item))
                for output in module_info.getOutputs():
                    field_type = output.getType()
                    if field_type == IJ2.FT_IMAGE:
                        result.append(
                            (cps.ImageNameProvider(label,
                                                   "ImageJImage",
                                                   doc=description), output))
                result += implied_outputs
                d[key] = result
                return [setting for setting, module_info in result]
            else:
                cc = self.get_cached_commands()
                if (not cc.has_key(key)) or (cc[key] is None):
                    return []
                classname = cc[key]
                try:
                    plugin = M.get_plugin(classname)
                except:
                    d[key] = []
                    return []
                fp_in = P.get_input_fields_and_parameters(plugin)
                result = []
                for field, parameter in fp_in:
                    field_type = P.get_field_type(field)
                    label = parameter.label() or ""
                    if field_type == P.FT_BOOL:
                        result += [cps.Binary(label, field.getBoolean(plugin))]
                    elif field_type == P.FT_INTEGER:
                        result += [cps.Integer(label, field.getLong(plugin))]
                    elif field_type == P.FT_FLOAT:
                        result += [cps.Float(label, field.getDouble(plugin))]
                    elif field_type == P.FT_STRING:
                        result += [
                            cps.Text(label, J.to_string(field.get(plugin)))
                        ]
                    else:
                        assert field_type == P.FT_IMAGE
                        result += [cps.ImageNameSubscriber(label, "None")]

                fp_out = P.get_output_fields_and_parameters(plugin)
                for field, parameter in fp_out:
                    field_type = P.get_field_type(field)
                    if field_type == P.FT_IMAGE:
                        result += [
                            cps.ImageNameProvider(parameter.label() or "",
                                                  "Output")
                        ]
            d[key] = result
        elif bioformats.USE_IJ2:
            result = [setting for setting, module_info in d[key]]
        else:
            result = d[key]
        return result
Ejemplo n.º 24
0
 def test_04_03_field_type(self):
     c = J.get_class_wrapper('java.lang.Byte')
     f = J.get_field_wrapper(c.getField('MAX_VALUE'))
     t = f.getType()
     self.assertEqual(J.to_string(t), 'byte')
Ejemplo n.º 25
0
 def test_01_01_to_string(self):
     jstring = self.env.new_string_utf("Hello, world")
     self.assertEqual(J.to_string(jstring), "Hello, world")
Ejemplo n.º 26
0
 def test_01_02_make_instance(self):
     jobject = J.make_instance("java/lang/Object", "()V")
     self.assertTrue(J.to_string(jobject).startswith("java.lang.Object"))
Ejemplo n.º 27
0
 def test_01_01_to_string(self):
     jstring = self.env.new_string_utf("Hello, world")
     self.assertEqual(J.to_string(jstring), "Hello, world")
Ejemplo n.º 28
0
 def test_04_03_field_type(self):
     c = J.get_class_wrapper('java.lang.Byte')
     f = J.get_field_wrapper(c.getField('MAX_VALUE'))
     t = f.getType()
     self.assertEqual(J.to_string(t), 'byte')
Ejemplo n.º 29
0
 def test_04_01_field_get(self):
     c = J.get_class_wrapper('java.lang.Byte')
     f = J.get_field_wrapper(c.getField('MAX_VALUE'))
     v = f.get(None)
     self.assertEqual(J.to_string(v), '127')
Ejemplo n.º 30
0
 def test_04_01_field_get(self):
     c = J.get_class_wrapper('java.lang.Byte')
     f = J.get_field_wrapper(c.getField('MAX_VALUE'))
     v = f.get(None)
     self.assertEqual(J.to_string(v), '127')
Ejemplo n.º 31
0
 def get_command_settings(self, command, d):
     '''Get the settings associated with the current command
     
     d - the dictionary that persists the setting. None = regular
     '''
     key = command.get_unicode_value()
     if not d.has_key(key):
         try:
             module_info = command.get_selected_leaf()[2]
         except cps.ValidationError:
             logger.info("Could not find command %s" % key)
             return []
         result = []
         inputs = module_info.getInputs()
         for module_item in inputs:
             field_type = module_item.getType()
             label = module_item.getLabel()
             if label is None:
                 label = module_item.getName()
             if module_item.isOutput():
                 # if both, qualify which is for input and which for output
                 label = "%s (Input)" % label
             minimum = module_item.getMinimumValue()
             maximum = module_item.getMaximumValue()
             default = module_item.loadValue()
             description = module_item.getDescription()
             if field_type == ij2.FT_BOOL:
                 value = (J.is_instance_of(default, 'java/lang/Boolean') and
                          J.call(default, "booleanValue", "()Z"))
                 setting = cps.Binary(
                     label,
                     value = value,
                     doc = description)
             elif field_type == ij2.FT_INTEGER:
                 if J.is_instance_of(default, 'java/lang/Number'):
                     value = J.call(default, "intValue", "()I")
                 elif minimum is not None:
                     value = minimum
                 elif maximum is not None:
                     value = maximum
                 else:
                     value = 0
                 setting = cps.Integer(
                     label,
                     value = value,
                     doc = description)
             elif field_type == ij2.FT_FLOAT:
                 if J.is_instance_of(default, 'java/lang/Number'):
                     value = J.call(default, "doubleValue", "()D")
                 elif minimum is not None:
                     value = minimum
                 elif maximum is not None:
                     value = maximum
                 else:
                     value = 0
                 setting = cps.Float(
                     label,
                     value=value,
                     doc = description)
             elif field_type == ij2.FT_STRING:
                 choices = module_item.getChoices()
                 value = J.to_string(default)
                 if choices is not None:
                     choices = J.get_collection_wrapper(choices)
                     setting = cps.Choice(
                         label, choices, value, doc = description)
                 else:
                     setting = cps.Text(
                         label, value, doc = description)
             elif field_type == ij2.FT_COLOR:
                 value = "#ffffff"
                 setting = cps.Color(label, value, doc = description)
             elif field_type == ij2.FT_IMAGE:
                 setting = cps.ImageNameSubscriber(
                     label, "InputImage",
                     doc = description)
             elif field_type == ij2.FT_TABLE:
                 setting = IJTableSubscriber(label, "InputTable",
                                             doc=description)
             elif field_type == ij2.FT_FILE:
                 setting = cps.FilenameText(
                     label, None, doc = description)
             else:
                 continue
             result.append((setting, module_item))
         for output in module_info.getOutputs():
             field_type = output.getType()
             label = output.getLabel()
             if label is None:
                 label = output.getName()
             if output.isInput():
                 # if both, qualify which is for input and which for output
                 label = "%s (Output)" % label
             if field_type == ij2.FT_IMAGE:
                 result.append((cps.ImageNameProvider(
                     label, "ImageJImage",
                     doc = description), output))
             elif field_type == ij2.FT_TABLE:
                 result.append((IJTableProvider(
                     label, "ImageJTable", doc=description), output))
         d[key] = result
     else:
         result = d[key]
     return [setting for setting, module_info in result]
Ejemplo n.º 32
0
 def get_command_settings(self, command, d):
     '''Get the settings associated with the current command
     
     d - the dictionary that persists the setting. None = regular
     '''
     key = command.get_unicode_value()
     if not d.has_key(key):
         if bioformats.USE_IJ2:
             try:
                 module_info = command.get_selected_leaf()[2]
             except cps.ValidationError:
                 return []
             result = []
             inputs = module_info.getInputs()
             module = module_info.createModule()
             implied_outputs = []
             for module_item in inputs:
                 field_type = module_item.getType()
                 label = module_item.getLabel()
                 value = module_item.getValue(module)
                 minimum = module_item.getMinimumValue()
                 maximum = module_item.getMaximumValue()
                 description = module_item.getDescription()
                 if field_type == IJ2.FT_BOOL:
                     setting = cps.Binary(
                         label,
                         J.call(value, "booleanValue", "()Z"),
                         doc = description)
                 elif field_type == IJ2.FT_INTEGER:
                     if minimum is not None:
                         minimum = J.call(minimum, "intValue", "()I")
                     if maximum is not None:
                         maximum = J.call(maximum, "intValue", "()I")
                     setting = cps.Integer(
                         label,
                         J.call(value, "intValue", "()I"),
                         minval = minimum,
                         maxval = maximum,
                         doc = description)
                 elif field_type == IJ2.FT_FLOAT:
                     if minimum is not None:
                         minimum = J.call(minimum, "floatValue", "()F")
                     if maximum is not None:
                         maximum = J.call(maximum, "floatValue", "()F")
                     setting = cps.Float(
                         label,
                         J.call(value, "floatValue", "()F"),
                         minval = minimum,
                         maxval = maximum,
                         doc = description)
                 elif field_type == IJ2.FT_STRING:
                     choices = module_item.getChoices()
                     value = J.to_string(value)
                     if choices is not None:
                         choices = [J.to_string(choice) 
                                    for choice 
                                    in J.iterate_collection(choices)]
                         setting = cps.Choice(
                             label, choices, value, doc = description)
                     else:
                         setting = cps.Text(
                             label, value, doc = description)
                 elif field_type == IJ2.FT_COLOR:
                     if value is not None:
                         value = IJ2.color_rgb_to_html(value)
                     else:
                         value = "#ffffff"
                     setting = cps.Color(label, value, doc = description)
                 elif field_type == IJ2.FT_IMAGE:
                     setting = cps.ImageNameSubscriber(
                         label, "InputImage",
                         doc = description)
                     #
                     # This is a Display for ij2 - the plugin typically
                     # scribbles all over the display's image. So
                     # we list it as an output too.
                     #
                     implied_outputs.append((
                         cps.ImageNameProvider(
                             label, "OutputImage",
                             doc = description), module_item))
                 elif field_type == IJ2.FT_OVERLAY:
                     setting = cps.ObjectNameSubscriber(
                         label, "ImageJObject",
                         doc = description)
                 else:
                     continue
                 result.append((setting, module_item))
             for output in module_info.getOutputs():
                 field_type = output.getType()
                 if field_type == IJ2.FT_IMAGE:
                     result.append((cps.ImageNameProvider(
                         label, "ImageJImage",
                         doc = description), output))
             result += implied_outputs
             d[key] = result
             return [setting for setting, module_info in result]
         else:
             cc = self.get_cached_commands()
             if (not cc.has_key(key)) or (cc[key] is None):
                 return []
             classname = cc[key]
             try:
                 plugin = M.get_plugin(classname)
             except:
                 d[key] = []
                 return []
             fp_in = P.get_input_fields_and_parameters(plugin)
             result = []
             for field, parameter in fp_in:
                 field_type = P.get_field_type(field)
                 label = parameter.label() or ""
                 if field_type == P.FT_BOOL:
                     result += [cps.Binary(label, field.getBoolean(plugin))]
                 elif field_type == P.FT_INTEGER:
                     result += [cps.Integer(label, field.getLong(plugin))]
                 elif field_type == P.FT_FLOAT:
                     result += [cps.Float(label, field.getDouble(plugin))]
                 elif field_type == P.FT_STRING:
                     result += [cps.Text(label, J.to_string(field.get(plugin)))]
                 else:
                     assert field_type == P.FT_IMAGE
                     result += [cps.ImageNameSubscriber(label, "None")]
                     
             fp_out = P.get_output_fields_and_parameters(plugin)
             for field, parameter in fp_out:
                 field_type = P.get_field_type(field)
                 if field_type == P.FT_IMAGE:
                     result += [cps.ImageNameProvider(parameter.label() or "",
                                                      "Output")]
         d[key] = result
     elif bioformats.USE_IJ2:
         result = [setting for setting, module_info in d[key]]
     else:
         result = d[key]
     return result
Ejemplo n.º 33
0
 def test_01_01_load_imageplus(self):
     file_name = os.path.join(sbs_dir, "Channel1-01-A-01.tif")
     ip = I.load_imageplus(file_name)
     self.assertTrue(J.to_string(ip.o).startswith("imp"))
Ejemplo n.º 34
0
 def test_01_02_make_instance(self):
     jobject = J.make_instance("java/lang/Object", "()V")
     self.assertTrue(J.to_string(jobject).startswith("java.lang.Object"))
Ejemplo n.º 35
0
 def test_01_13_get_channel_processor(self):
     file_name = os.path.join(sbs_dir, "Channel1-01-A-01.tif")
     ip = I.load_imageplus(file_name)
     p = ip.getChannelProcessor()
     self.assertTrue(J.to_string(p).startswith("ip"))
Ejemplo n.º 36
0
 def get_command_settings(self, command, d):
     '''Get the settings associated with the current command
     
     d - the dictionary that persists the setting. None = regular
     '''
     key = command.get_unicode_value()
     if not d.has_key(key):
         try:
             module_info = command.get_selected_leaf()[2]
         except cps.ValidationError:
             logger.info("Could not find command %s" % key)
             return []
         result = []
         inputs = module_info.getInputs()
         for module_item in inputs:
             field_type = module_item.getType()
             label = module_item.getLabel()
             if label is None:
                 label = module_item.getName()
             if module_item.isOutput():
                 # if both, qualify which is for input and which for output
                 label = "%s (Input)" % label
             minimum = module_item.getMinimumValue()
             maximum = module_item.getMaximumValue()
             default = module_item.loadValue()
             description = module_item.getDescription()
             if field_type == ij2.FT_BOOL:
                 value = (J.is_instance_of(default, 'java/lang/Boolean')
                          and J.call(default, "booleanValue", "()Z"))
                 setting = cps.Binary(label, value=value, doc=description)
             elif field_type == ij2.FT_INTEGER:
                 if J.is_instance_of(default, 'java/lang/Number'):
                     value = J.call(default, "intValue", "()I")
                 elif minimum is not None:
                     value = minimum
                 elif maximum is not None:
                     value = maximum
                 else:
                     value = 0
                 setting = cps.Integer(label, value=value, doc=description)
             elif field_type == ij2.FT_FLOAT:
                 if J.is_instance_of(default, 'java/lang/Number'):
                     value = J.call(default, "doubleValue", "()D")
                 elif minimum is not None:
                     value = minimum
                 elif maximum is not None:
                     value = maximum
                 else:
                     value = 0
                 setting = cps.Float(label, value=value, doc=description)
             elif field_type == ij2.FT_STRING:
                 choices = module_item.getChoices()
                 value = J.to_string(default)
                 if choices is not None:
                     choices = J.get_collection_wrapper(choices)
                     setting = cps.Choice(label,
                                          choices,
                                          value,
                                          doc=description)
                 else:
                     setting = cps.Text(label, value, doc=description)
             elif field_type == ij2.FT_COLOR:
                 value = "#ffffff"
                 setting = cps.Color(label, value, doc=description)
             elif field_type == ij2.FT_IMAGE:
                 setting = cps.ImageNameSubscriber(label,
                                                   "InputImage",
                                                   doc=description)
             elif field_type == ij2.FT_TABLE:
                 setting = IJTableSubscriber(label,
                                             "InputTable",
                                             doc=description)
             elif field_type == ij2.FT_FILE:
                 setting = cps.FilenameText(label, None, doc=description)
             else:
                 continue
             result.append((setting, module_item))
         for output in module_info.getOutputs():
             field_type = output.getType()
             label = output.getLabel()
             if label is None:
                 label = output.getName()
             if output.isInput():
                 # if both, qualify which is for input and which for output
                 label = "%s (Output)" % label
             if field_type == ij2.FT_IMAGE:
                 result.append(
                     (cps.ImageNameProvider(label,
                                            "ImageJImage",
                                            doc=description), output))
             elif field_type == ij2.FT_TABLE:
                 result.append((IJTableProvider(label,
                                                "ImageJTable",
                                                doc=description), output))
         d[key] = result
     else:
         result = d[key]
     return [setting for setting, module_info in result]
Ejemplo n.º 37
0
    '''
    never = J.get_static_field("java/lang/Long", "MAX_VALUE", "J")
    J.static_call("imagej/updater/core/UpToDate", "setLatestNag", "(J)V",
                  never)


def wrap_user_interface(o):
    '''Return a wrapped imagej.ui.UserInterface'''
    class UserInterface(object):
        def __init__(self):
            self.o = o

        show = J.make_method("show", "()V")
        isVisible = J.make_method("isVisible", "()Z")

    return UserInterface()


if __name__ == "__main__":
    jar_dir = os.path.join(os.path.split(__file__)[0], "jars")
    classpath = os.pathsep.join([
        os.path.join(jar_dir, filename) for filename in os.listdir(jar_dir)
        if filename.endswith(".jar")
    ])
    J.start_vm(["-Djava.class.path=" + classpath])
    my_context = create_context(REQUIRED_SERVICES)
    module_service = get_module_service(my_context)
    module_infos = module_service.getModules()
    for module_info in module_infos:
        print J.to_string(module_info.o)
Ejemplo n.º 38
0
    '''Make an imagej.util.ColorRGB from an HTML color
    
    HTML colors have the form, #rrggbb or are one of the names
    from the CSS-3 colors.
    '''
    return J.static_call("fromHTMLColor", 
                         "(Ljava/lang/String;)Limagej/util/ColorRGB;", s)
    

def color_rgb_to_html(color_rgb):
    '''Return an HTML-encoded color value from an imagej.util.ColorRGB
    
    color_rgb - a Java imagej.util.ColorRGB object
    '''
    return J.call(color_rgb, "toHTMLColor()", "()Ljava/lang/String;")
    
if __name__=="__main__":
    classpath = os.path.join(os.path.split(__file__)[0], "imagej-2.0-SNAPSHOT-all.jar")
    J.start_vm(["-Djava.class.path="+classpath])
    my_context = create_context([
            "imagej.event.EventService",
            "imagej.object.ObjectService",
            "imagej.platform.PlatformService",
            "imagej.ext.plugin.PluginService",
            "imagej.ext.module.ModuleService"
        ])
    module_service = get_module_service(my_context)
    module_infos = module_service.getModules()
    for module_info in module_infos:
        print J.to_string(module_info.o)
Ejemplo n.º 39
0
 def test_01_14_get_processor(self):
     file_name = os.path.join(
         self.root_dir, "ExampleSBSImages", "Channel1-01-A-01.tif")
     ip = I.load_imageplus(file_name)
     p = ip.getProcessor()
     self.assertTrue(J.to_string(p).startswith("ip"))  
Ejemplo n.º 40
0
 def test_03_05_cw_get_annotations(self):
     c = J.get_class_wrapper('java.security.Identity')
     annotations = c.getAnnotations()
     annotations = J.get_env().get_object_array_elements(annotations)
     self.assertEqual(len(annotations), 1)
     self.assertEqual(J.to_string(annotations[0]),'@java.lang.Deprecated()')