##// END OF EJS Templates
Dynamic traits.
Jonathan Frederic -
Show More
@@ -292,6 +292,13 b' class Widget(LoggingConfigurable):'
292 True if the callback should be unregistered."""
292 True if the callback should be unregistered."""
293 self._display_callbacks.register_callback(callback, remove=remove)
293 self._display_callbacks.register_callback(callback, remove=remove)
294
294
295 def add_trait(self, traitname, trait):
296 """Dynamically add a trait attribute to the Widget."""
297 super(Widget, self).add_trait(traitname, trait)
298 if trait.get_metadata('sync'):
299 self.keys.append(traitname)
300 self.send_state(traitname)
301
295 #-------------------------------------------------------------------------
302 #-------------------------------------------------------------------------
296 # Support methods
303 # Support methods
297 #-------------------------------------------------------------------------
304 #-------------------------------------------------------------------------
@@ -801,6 +801,12 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):'
801 else:
801 else:
802 return trait.get_metadata(key, default)
802 return trait.get_metadata(key, default)
803
803
804 def add_trait(self, traitname, trait):
805 """Dynamically add a trait attribute to the HasTraits instance."""
806 self.__class__ = type(self.__class__.__name__, (self.__class__,),
807 {traitname: trait})
808 trait.set_default_value(self)
809
804 #-----------------------------------------------------------------------------
810 #-----------------------------------------------------------------------------
805 # Actual TraitTypes implementations/subclasses
811 # Actual TraitTypes implementations/subclasses
806 #-----------------------------------------------------------------------------
812 #-----------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now