Enaml enthusiasts might enjoy this little hack:
To try it out: $ git clone https://github.com/11craft/kilometer-browser $ enaml-run kilometer-browser/kmb/components/codedwidget.enaml Renaming suggestions happily accepted! :) I wasn't sure what else to call it for now. I found the exploration toward this particular solution interesting. There is definitely more than one way to do things to achieve the same goal. For example, I originally used something like this (extra code excluded, so this won't work directly): enamldef CodedWidget(Container): attr main_component attr module main_component << include.components[0] if include.components else None Include: id: include components << [module.Main()] if hasattr(module, 'Main') else [] This worked great... the only reason I changed it to what it is now is because I wanted to capture compile-time and run-time exceptions into their own attributes. So it transformed to this: enamldef CodedWidget(Container): attr main_component = None attr module module :: self.main_component = module.Main() Include: components << [main_component] if main_component else [] For discussion here, the source for just the CodedWidget component itself:
-- Matthew Scott ElevenCraft Inc. _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
On Thu, Jun 28, 2012 at 10:31 PM, Matthew Scott <[hidden email]> wrote:
This is pretty clever :-)
As an FYI, attribute declarations can have a default binding.
So instead of: attr main_component main_component << include.components[0] if include.components else None
You could do this (if you wanted): attr main_component << include.components[0] if include.components else None
_______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
Free forum by Nabble | Edit this page |