descriptors.py 848 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from __future__ import absolute_import
  2. # Copyright (c) 2010-2019 openpyxl
  3. from openpyxl.compat import basestring
  4. from openpyxl.descriptors.nested import (
  5. NestedMinMax
  6. )
  7. from openpyxl.descriptors import Typed
  8. from .data_source import NumFmt
  9. """
  10. Utility descriptors for the chart module.
  11. For convenience but also clarity.
  12. """
  13. class NestedGapAmount(NestedMinMax):
  14. allow_none = True
  15. min = 0
  16. max = 500
  17. class NestedOverlap(NestedMinMax):
  18. allow_none = True
  19. min = -100
  20. max = 100
  21. class NumberFormatDescriptor(Typed):
  22. """
  23. Allow direct assignment of format code
  24. """
  25. expected_type = NumFmt
  26. allow_none = True
  27. def __set__(self, instance, value):
  28. if isinstance(value, basestring):
  29. value = NumFmt(value)
  30. super(NumberFormatDescriptor, self).__set__(instance, value)