connector.py 3.8 KB

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