connector.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. from __future__ import absolute_import
  2. # Copyright (c) 2010-2019 openpyxl
  3. from openpyxl.descriptors.serialisable import Serialisable
  4. from openpyxl.descriptors import (
  5. Typed,
  6. Bool,
  7. Integer,
  8. String,
  9. Alias,
  10. )
  11. from openpyxl.descriptors.excel import ExtensionList as OfficeArtExtensionList
  12. from openpyxl.chart.shapes import GraphicalProperties
  13. from openpyxl.chart.text import RichText
  14. from .properties import (
  15. NonVisualDrawingProps,
  16. NonVisualDrawingShapeProps,
  17. )
  18. from .geometry import ShapeStyle
  19. class Connection(Serialisable):
  20. id = Integer()
  21. idx = Integer()
  22. def __init__(self,
  23. id=None,
  24. idx=None,
  25. ):
  26. self.id = id
  27. self.idx = idx
  28. class ConnectorLocking(Serialisable):
  29. extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
  30. def __init__(self,
  31. extLst=None,
  32. ):
  33. self.extLst = extLst
  34. class NonVisualConnectorProperties(Serialisable):
  35. cxnSpLocks = Typed(expected_type=ConnectorLocking, allow_none=True)
  36. stCxn = Typed(expected_type=Connection, allow_none=True)
  37. endCxn = Typed(expected_type=Connection, allow_none=True)
  38. extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
  39. def __init__(self,
  40. cxnSpLocks=None,
  41. stCxn=None,
  42. endCxn=None,
  43. extLst=None,
  44. ):
  45. self.cxnSpLocks = cxnSpLocks
  46. self.stCxn = stCxn
  47. self.endCxn = endCxn
  48. self.extLst = extLst
  49. class ConnectorNonVisual(Serialisable):
  50. cNvPr = Typed(expected_type=NonVisualDrawingProps, )
  51. cNvCxnSpPr = Typed(expected_type=NonVisualConnectorProperties, )
  52. __elements__ = ("cNvPr", "cNvCxnSpPr",)
  53. def __init__(self,
  54. cNvPr=None,
  55. cNvCxnSpPr=None,
  56. ):
  57. self.cNvPr = cNvPr
  58. self.cNvCxnSpPr = cNvCxnSpPr
  59. class ConnectorShape(Serialisable):
  60. tagname = "cxnSp"
  61. nvCxnSpPr = Typed(expected_type=ConnectorNonVisual)
  62. spPr = Typed(expected_type=GraphicalProperties)
  63. style = Typed(expected_type=ShapeStyle, allow_none=True)
  64. macro = String(allow_none=True)
  65. fPublished = Bool(allow_none=True)
  66. def __init__(self,
  67. nvCxnSpPr=None,
  68. spPr=None,
  69. style=None,
  70. macro=None,
  71. fPublished=None,
  72. ):
  73. self.nvCxnSpPr = nvCxnSpPr
  74. self.spPr = spPr
  75. self.style = style
  76. self.macro = macro
  77. self.fPublished = fPublished
  78. class ShapeMeta(Serialisable):
  79. tagname = "nvSpPr"
  80. cNvPr = Typed(expected_type=NonVisualDrawingProps)
  81. cNvSpPr = Typed(expected_type=NonVisualDrawingShapeProps)
  82. def __init__(self, cNvPr=None, cNvSpPr=None):
  83. self.cNvPr = cNvPr
  84. self.cNvSpPr = cNvSpPr
  85. class Shape(Serialisable):
  86. macro = String(allow_none=True)
  87. textlink = String(allow_none=True)
  88. fPublished = Bool(allow_none=True)
  89. fLocksText = Bool(allow_none=True)
  90. nvSpPr = Typed(expected_type=ShapeMeta, allow_none=True)
  91. meta = Alias("nvSpPr")
  92. spPr = Typed(expected_type=GraphicalProperties)
  93. graphicalProperties = Alias("spPr")
  94. style = Typed(expected_type=ShapeStyle, allow_none=True)
  95. txBody = Typed(expected_type=RichText, allow_none=True)
  96. def __init__(self,
  97. macro=None,
  98. textlink=None,
  99. fPublished=None,
  100. fLocksText=None,
  101. nvSpPr=None,
  102. spPr=None,
  103. style=None,
  104. txBody=None,
  105. ):
  106. self.macro = macro
  107. self.textlink = textlink
  108. self.fPublished = fPublished
  109. self.fLocksText = fLocksText
  110. self.nvSpPr = nvSpPr
  111. self.spPr = spPr
  112. self.style = style
  113. self.txBody = txBody