widget_description.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. """Contains the DOMWidget class"""
  4. from traitlets import Unicode
  5. from .widget import Widget, widget_serialization, register
  6. from .trait_types import InstanceDict
  7. from .widget_style import Style
  8. from .widget_core import CoreWidget
  9. from .domwidget import DOMWidget
  10. @register
  11. class DescriptionStyle(Style, CoreWidget, Widget):
  12. """Description style widget."""
  13. _model_name = Unicode('DescriptionStyleModel').tag(sync=True)
  14. description_width = Unicode(help="Width of the description to the side of the control.").tag(sync=True)
  15. class DescriptionWidget(DOMWidget, CoreWidget):
  16. """Widget that has a description label to the side."""
  17. _model_name = Unicode('DescriptionModel').tag(sync=True)
  18. description = Unicode('', help="Description of the control.").tag(sync=True)
  19. description_tooltip = Unicode(None, allow_none=True, help="Tooltip for the description (defaults to description).").tag(sync=True)
  20. style = InstanceDict(DescriptionStyle, help="Styling customizations").tag(sync=True, **widget_serialization)
  21. def _repr_keys(self):
  22. for key in super(DescriptionWidget, self)._repr_keys():
  23. # Exclude style if it had the default value
  24. if key == 'style':
  25. value = getattr(self, key)
  26. if repr(value) == '%s()' % value.__class__.__name__:
  27. continue
  28. yield key