예제 #1
0
 def test_08_09_removeAll(self):
     c1 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c2.add("Foo")
     c1.removeAll(c2)
     self.assertNotIn("Foo", c1)
예제 #2
0
 def test_08_04_addAll(self):
     c1 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c2.add("Baz")
     c2.addAll(c1.o)
     self.assertIn("Foo", c2)
예제 #3
0
 def getIndex(self):
     index = J.call(self.o, "getIndex", "()Limagej/module/ModuleIndex;")
     index = J.get_collection_wrapper(index, wrap_module_info)
     index.getC = lambda c: J.get_collection_wrapper(
         J.call(index.o, "get", "(Ljava/lang/Class;)Ljava/util/List;", c), wrap_module_info
     )
     index.getS = lambda class_name: index.getC(J.class_for_name(class_name))
     return index
예제 #4
0
 def test_08_07_contains_all(self):
     c1 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c2.add("Baz")
     self.assertFalse(c2.containsAll(c1.o))
     c2 += c1
     self.assertTrue(c2.containsAll(c1.o))
예제 #5
0
 def getIndex(self):
     index = J.call(self.o, "getIndex", "()Limagej/module/ModuleIndex;")
     index = J.get_collection_wrapper(index, wrap_module_info)
     index.getC = lambda c: J.get_collection_wrapper(
         J.call(index.o, "get", "(Ljava/lang/Class;)Ljava/util/List;", c
                ), wrap_module_info)
     index.getS = lambda class_name: \
         index.getC(J.class_for_name(class_name))
     return index
예제 #6
0
 def test_08_09_removeAll(self):
     c1 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c2.add("Foo")
     c1.removeAll(c2)
     self.assertNotIn("Foo", c1)
예제 #7
0
 def test_08_04_addAll(self):
     c1 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c2.add("Baz")
     c2.addAll(c1.o)
     self.assertIn("Foo", c2)
예제 #8
0
 def test_08_07_contains_all(self):
     c1 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c2.add("Baz")
     self.assertFalse(c2.containsAll(c1.o))
     c2 += c1
     self.assertTrue(c2.containsAll(c1.o))
예제 #9
0
 def test_08_06__iadd__(self):
     c1 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c2.add("Baz")
     c2 += c1
     for k in ("Foo", "Bar", "Baz"):
         self.assertIn(k, c2)
     c2 += ["Hello", "World"]
     self.assertIn("Hello", c2)
     self.assertIn("World", c2)
예제 #10
0
 def test_08_05__add__(self):
     c1 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c2.add("Baz")
     c3 = c1 + c2
     for k in ("Foo", "Bar", "Baz"):
         self.assertIn(k, c3)
     
     c4 = c3 + ["Hello", "World"]
     self.assertIn("Hello", c4)
     self.assertIn("World", c4)
예제 #11
0
 def test_08_06__iadd__(self):
     c1 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c1.add("Foo")
     c1.add("Bar")
     c2 = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c2.add("Baz")
     c2 += c1
     for k in ("Foo", "Bar", "Baz"):
         self.assertIn(k, c2)
     c2 += ["Hello", "World"]
     self.assertIn("Hello", c2)
     self.assertIn("World", c2)
예제 #12
0
    def test_08_05__add__(self):
        c1 = J.get_collection_wrapper(
            J.make_instance("java/util/HashSet", "()V"))
        c1.add("Foo")
        c1.add("Bar")
        c2 = J.get_collection_wrapper(
            J.make_instance("java/util/HashSet", "()V"))
        c2.add("Baz")
        c3 = c1 + c2
        for k in ("Foo", "Bar", "Baz"):
            self.assertIn(k, c3)

        c4 = c3 + ["Hello", "World"]
        self.assertIn("Hello", c4)
        self.assertIn("World", c4)
예제 #13
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)
예제 #14
0
 def test_08_01_wrap_collection(self):
     c = J.make_instance("java/util/HashSet", "()V")
     w = J.get_collection_wrapper(c)
     self.assertFalse(hasattr(w, "addI"))
     self.assertEqual(w.size(), 0)
     self.assertEqual(len(w), 0)
     self.assertTrue(w.isEmpty())
예제 #15
0
 def test_08_03_contains(self):
     c = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     c.add("Foo")
     self.assertTrue(c.contains("Foo"))
     self.assertFalse(c.contains("Bar"))
     self.assertIn("Foo", c)
     self.assertNotIn("Bar", c)
예제 #16
0
 def test_08_01_wrap_collection(self):
     c = J.make_instance("java/util/HashSet", "()V")
     w = J.get_collection_wrapper(c)
     self.assertFalse(hasattr(w, "addI"))
     self.assertEqual(w.size(), 0)
     self.assertEqual(len(w), 0)
     self.assertTrue(w.isEmpty())
예제 #17
0
 def test_08_03_contains(self):
     c = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     c.add("Foo")
     self.assertTrue(c.contains("Foo"))
     self.assertFalse(c.contains("Bar"))
     self.assertIn("Foo", c)
     self.assertNotIn("Bar", c)
예제 #18
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)
예제 #19
0
def select_overlay(display, overlay, select=True):
    '''Select or deselect an overlay
    
    display - the overlay's display
    
    overlay - the overlay to select
    '''
    for view in J.get_collection_wrapper(display, fn_wrapper=wrap_data_view):
        if J.call(overlay, "equals", "(Ljava/lang/Object;)Z", view.getData()):
            view.setSelected(select)
            break
    else:
        logger.info("Failed to select overlay")
예제 #20
0
def select_overlay(display, overlay, select=True):
    '''Select or deselect an overlay
    
    display - the overlay's display
    
    overlay - the overlay to select
    '''
    for view in J.get_collection_wrapper(display, fn_wrapper = wrap_data_view):
        if J.call(overlay, "equals", "(Ljava/lang/Object;)Z", view.getData()):
            view.setSelected(select)
            break
    else:
        logger.info("Failed to select overlay")
예제 #21
0
def select_overlay(display, overlay, select=True):
    '''Select or deselect an overlay
    
    display - the overlay's display
    
    overlay - the overlay to select
    '''
    for view in J.get_collection_wrapper(display, fn_wrapper = wrap_data_view):
        if J.call(overlay, "equals", "(Ljava/lang/Object;)Z", view.getData()):
            J.execute_runnable_in_main_thread(J.run_script(
                """new java.lang.Runnable() {
                    run: function() { view.setSelected(select);}
                   }""", dict(view = view.o, select=select)), synchronous=True)
            break
    else:
        logger.info("Failed to select overlay")
예제 #22
0
def select_overlay(display, overlay, select=True):
    '''Select or deselect an overlay
    
    display - the overlay's display
    
    overlay - the overlay to select
    '''
    for view in J.get_collection_wrapper(display, fn_wrapper=wrap_data_view):
        if J.call(overlay, "equals", "(Ljava/lang/Object;)Z", view.getData()):
            J.execute_runnable_in_main_thread(J.run_script(
                """new java.lang.Runnable() {
                    run: function() { view.setSelected(select);}
                   }""", dict(view=view.o, select=select)),
                                              synchronous=True)
            break
    else:
        logger.info("Failed to select overlay")
예제 #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):
         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]
예제 #24
0
 def test_08_02_add(self):
     c = J.get_collection_wrapper(J.make_instance("java/util/HashSet", "()V"))
     self.assertTrue(c.add("Foo"))
     self.assertEqual(len(c), 1)
     self.assertFalse(c.isEmpty())
예제 #25
0
 def test_08_02_add(self):
     c = J.get_collection_wrapper(
         J.make_instance("java/util/HashSet", "()V"))
     self.assertTrue(c.add("Foo"))
     self.assertEqual(len(c), 1)
     self.assertFalse(c.isEmpty())
예제 #26
0
def is_image_extension(suffix):
    '''Return True if the extension is one of those recongized by bioformats'''
    extensions = J.get_collection_wrapper(
        J.static_call("org/cellprofiler/imageset/filter/IsImagePredicate",
                      "getImageSuffixes", "()Ljava/util/Set;"))
    return extensions.contains(suffix.lower())
예제 #27
0
def is_image_extension(suffix):
    '''Return True if the extension is one of those recongized by bioformats'''
    extensions = J.get_collection_wrapper(
        J.static_call("org/cellprofiler/imageset/filter/IsImagePredicate",
                      "getImageSuffixes", "()Ljava/util/Set;"))
    return extensions.contains(suffix.lower())
예제 #28
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]