A class that has configurable, typed attributes.
| 47 | |
| 48 | |
| 49 | class Foo(Configurable): |
| 50 | """A class that has configurable, typed attributes.""" |
| 51 | |
| 52 | i = Int(0, help="The integer i.").tag(config=True) |
| 53 | j = Int(1, help="The integer j.").tag(config=True) |
| 54 | name = Unicode("Brian", help="First name.").tag(config=True, shortname="B") |
| 55 | mode = Enum(values=["on", "off", "other"], default_value="on").tag(config=True) |
| 56 | |
| 57 | def __init__(self, **kwargs): |
| 58 | super().__init__(**kwargs) |
| 59 | # using parent=self allows configuration in the form c.Foo.SubConfigurable.subvalue=1 |
| 60 | # while c.SubConfigurable.subvalue=1 will still work, this allow to |
| 61 | # target specific instances of SubConfigurables |
| 62 | self.subconf = SubConfigurable(parent=self) |
| 63 | |
| 64 | def describe(self): |
| 65 | print("I am Foo with:") |
| 66 | print(" i =", self.i) |
| 67 | print(" j =", self.j) |
| 68 | print(" name =", self.name) |
| 69 | print(" mode =", self.mode) |
| 70 | self.subconf.describe() |
| 71 | |
| 72 | |
| 73 | class Bar(Configurable): |