class Person(HasTraits): married = PrefixMap({ "yes": 1, "yeah": 1, "no": 0 }, default_value="meh")
class Person(HasTraits): married = PrefixMap({"yes": 1, "yeah": 1, "no": 0, "nah": 0}) default_calls = Int(0) def _married_default(self): self.default_calls += 1 return "nah"
def info(self): keys = [repr(x) for x in self._rmap.keys()] keys.sort() msg = ' or '.join(keys) return PrefixMap.info(self) + ' or ' + msg
class Person(HasTraits): married = PrefixMap({'yes': 1, 'no': 0}, default_value="yes") married_2 = PrefixMap([], default_value="yes") # E: arg-type
font_trait = KivaFont(default_font_name) # Bounds trait bounds_trait = CList([0.0, 0.0]) # (w,h) coordinate_trait = CList([0.0, 0.0]) # (x,y) # Component minimum size trait # PZW: Make these just floats, or maybe remove them altogether. ComponentMinSize = Range(0.0, 99999.0) ComponentMaxSize = ComponentMinSize(99999.0) # Pointer shape trait: Pointer = PrefixList(pointer_shapes, default_value="arrow") # Cursor style trait: cursor_style_trait = PrefixMap(cursor_styles, default_value="default") spacing_trait = Range(0, 63, value=4) padding_trait = Range(0, 63, value=4) margin_trait = Range(0, 63) border_size_trait = Range(0, 8, editor=border_size_editor) # Time interval trait: TimeInterval = Union(None, Range(0.0, 3600.0)) # Stretch traits: Stretch = Range(0.0, 1.0, value=1.0) NoStretch = Stretch(0.0) # Scrollbar traits
class Person(HasTraits): married = PrefixMap(mapping)
class Person(HasTraits): married = PrefixMap({"yes": 1, "yeah": 1, "no": 0, "nah": 0})
try: # Require Traits >= 6.1 from traits.api import PrefixMap except ImportError: from traits.api import TraitPrefixMap representation_trait = Trait( "surface", TraitPrefixMap({ "surface": 2, "wireframe": 1, "points": 0 })) else: representation_trait = PrefixMap( { "surface": 2, "wireframe": 1, "points": 0 }, default_value="surface") ###################################################################### # Test classes. class Property(HasStrictTraits): color = Tuple(Range(0.0, 1.0), Range(0.0, 1.0), Range(0.0, 1.0)) opacity = Range(0.0, 1.0, 1.0) representation = representation_trait class Toy(HasTraits): color = Str type = Str
def test_empty_map(self): with self.assertRaises(ValueError): PrefixMap({})