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)
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)
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
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))
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
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)
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)
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))
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)
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)
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)
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)
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)
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())
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)
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)
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)
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")
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")
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")
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")
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]
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())
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())
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())
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]