Example #1
0
 class Person(HasTraits):
     married = PrefixMap({
         "yes": 1,
         "yeah": 1,
         "no": 0
     },
                         default_value="meh")
Example #2
0
        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"
Example #3
0
 def info(self):
     keys = [repr(x) for x in self._rmap.keys()]
     keys.sort()
     msg = ' or '.join(keys)
     return PrefixMap.info(self) + ' or ' + msg
Example #4
0
class Person(HasTraits):
    married = PrefixMap({'yes': 1, 'no': 0}, default_value="yes")
    married_2 = PrefixMap([], default_value="yes")  # E: arg-type
Example #5
0
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
Example #6
0
 class Person(HasTraits):
     married = PrefixMap(mapping)
Example #7
0
class Person(HasTraits):
    married = PrefixMap({"yes": 1, "yeah": 1, "no": 0, "nah": 0})
Example #8
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
Example #9
0
 def test_empty_map(self):
     with self.assertRaises(ValueError):
         PrefixMap({})