Show More
@@ -405,11 +405,7 b' class KeyValueConfigLoader(CommandLineConfigLoader):' | |||
|
405 | 405 | if macro is None: |
|
406 | 406 | raise ValueError("Unrecognized argument: %r"%item) |
|
407 | 407 | macro = macros[m] |
|
408 |
if isinstance(macro, |
|
|
409 | # macro is simply a 'Class.trait=value' string | |
|
410 | exec_str = 'self.config.' + macro | |
|
411 | exec exec_str in locals(), globals() | |
|
412 | elif isinstance(macro, (dict, Configurable)): | |
|
408 | if isinstance(macro, (dict, Configurable)): | |
|
413 | 409 | # update self.config with Config: |
|
414 | 410 | self.config.update(macros[m]) |
|
415 | 411 | else: |
@@ -57,7 +57,7 b' class MyApp(Application):' | |||
|
57 | 57 | shortnames = dict(i='Foo.i',j='Foo.j',name='Foo.name', |
|
58 | 58 | enabled='Bar.enabled', log_level='MyApp.log_level') |
|
59 | 59 | |
|
60 |
macros = dict(enable='Bar |
|
|
60 | macros = dict(enable={'Bar': {'enabled' : True}}, disable={'Bar': {'enabled' : False}}) | |
|
61 | 61 | |
|
62 | 62 | macro_help = dict( |
|
63 | 63 | enable="""Enable bar""", |
@@ -44,29 +44,29 b' class Foo(Configurable):' | |||
|
44 | 44 | |
|
45 | 45 | """ |
|
46 | 46 | |
|
47 |
i = Int(0, config=True, |
|
|
48 |
j = Int(1, config=True, |
|
|
49 |
name = Unicode(u'Brian', config=True, |
|
|
47 | i = Int(0, config=True, help="The integer i.") | |
|
48 | j = Int(1, config=True, help="The integer j.") | |
|
49 | name = Unicode(u'Brian', config=True, help="First name.") | |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 52 | class Bar(Configurable): |
|
53 | 53 | |
|
54 |
enabled = Bool(True, config=True, |
|
|
54 | enabled = Bool(True, config=True, help="Enable bar.") | |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | class MyApp(Application): |
|
58 | 58 | |
|
59 | 59 | app_name = Unicode(u'myapp') |
|
60 |
running = Bool(False, config=True, |
|
|
60 | running = Bool(False, config=True, | |
|
61 | 61 | help="Is the app running?") |
|
62 | 62 | classes = List([Bar, Foo]) |
|
63 |
config_file = Unicode(u'', config=True, |
|
|
63 | config_file = Unicode(u'', config=True, | |
|
64 | 64 | help="Load this config file") |
|
65 | 65 | |
|
66 | shortnames = dict(i='Foo.i',j='Foo.j',name='Foo.name', | |
|
66 | shortnames = dict(i='Foo.i',j='Foo.j',name='Foo.name', running='MyApp.running', | |
|
67 | 67 | enabled='Bar.enabled') |
|
68 | 68 | |
|
69 |
macros = dict(enable='Bar |
|
|
69 | macros = dict(enable={'Bar': {'enabled' : True}}, disable={'Bar': {'enabled' : False}}) | |
|
70 | 70 | macro_help = dict( |
|
71 | 71 | enable="""Set Bar.enabled to True""", |
|
72 | 72 | disable="""Set Bar.enabled to False""" |
@@ -91,6 +91,7 b' def main():' | |||
|
91 | 91 | app.init_bar() |
|
92 | 92 | print "app.config:" |
|
93 | 93 | print app.config |
|
94 | print app.bar.enabled | |
|
94 | 95 | |
|
95 | 96 | |
|
96 | 97 | if __name__ == "__main__": |
General Comments 0
You need to be logged in to leave comments.
Login now