picture.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.xml.constants import DRAWING_NS
  3. from openpyxl.descriptors.serialisable import Serialisable
  4. from openpyxl.descriptors import (
  5. Typed,
  6. Bool,
  7. String,
  8. Alias,
  9. )
  10. from openpyxl.descriptors.excel import ExtensionList as OfficeArtExtensionList
  11. from openpyxl.chart.shapes import GraphicalProperties
  12. from .fill import BlipFillProperties
  13. from .properties import NonVisualDrawingProps
  14. from .geometry import ShapeStyle
  15. class PictureLocking(Serialisable):
  16. tagname = "picLocks"
  17. namespace = DRAWING_NS
  18. # Using attribute group AG_Locking
  19. noCrop = Bool(allow_none=True)
  20. noGrp = Bool(allow_none=True)
  21. noSelect = Bool(allow_none=True)
  22. noRot = Bool(allow_none=True)
  23. noChangeAspect = Bool(allow_none=True)
  24. noMove = Bool(allow_none=True)
  25. noResize = Bool(allow_none=True)
  26. noEditPoints = Bool(allow_none=True)
  27. noAdjustHandles = Bool(allow_none=True)
  28. noChangeArrowheads = Bool(allow_none=True)
  29. noChangeShapeType = Bool(allow_none=True)
  30. extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
  31. __elements__ = ()
  32. def __init__(self,
  33. noCrop=None,
  34. noGrp=None,
  35. noSelect=None,
  36. noRot=None,
  37. noChangeAspect=None,
  38. noMove=None,
  39. noResize=None,
  40. noEditPoints=None,
  41. noAdjustHandles=None,
  42. noChangeArrowheads=None,
  43. noChangeShapeType=None,
  44. extLst=None,
  45. ):
  46. self.noCrop = noCrop
  47. self.noGrp = noGrp
  48. self.noSelect = noSelect
  49. self.noRot = noRot
  50. self.noChangeAspect = noChangeAspect
  51. self.noMove = noMove
  52. self.noResize = noResize
  53. self.noEditPoints = noEditPoints
  54. self.noAdjustHandles = noAdjustHandles
  55. self.noChangeArrowheads = noChangeArrowheads
  56. self.noChangeShapeType = noChangeShapeType
  57. class NonVisualPictureProperties(Serialisable):
  58. tagname = "cNvPicPr"
  59. preferRelativeResize = Bool(allow_none=True)
  60. picLocks = Typed(expected_type=PictureLocking, allow_none=True)
  61. extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
  62. __elements__ = ("picLocks",)
  63. def __init__(self,
  64. preferRelativeResize=None,
  65. picLocks=None,
  66. extLst=None,
  67. ):
  68. self.preferRelativeResize = preferRelativeResize
  69. self.picLocks = picLocks
  70. class PictureNonVisual(Serialisable):
  71. tagname = "nvPicPr"
  72. cNvPr = Typed(expected_type=NonVisualDrawingProps, )
  73. cNvPicPr = Typed(expected_type=NonVisualPictureProperties, )
  74. __elements__ = ("cNvPr", "cNvPicPr")
  75. def __init__(self,
  76. cNvPr=None,
  77. cNvPicPr=None,
  78. ):
  79. if cNvPr is None:
  80. cNvPr = NonVisualDrawingProps(id=0, name="Image 1", descr="Name of file")
  81. self.cNvPr = cNvPr
  82. if cNvPicPr is None:
  83. cNvPicPr = NonVisualPictureProperties()
  84. self.cNvPicPr = cNvPicPr
  85. class PictureFrame(Serialisable):
  86. tagname = "pic"
  87. macro = String(allow_none=True)
  88. fPublished = Bool(allow_none=True)
  89. nvPicPr = Typed(expected_type=PictureNonVisual, )
  90. blipFill = Typed(expected_type=BlipFillProperties, )
  91. spPr = Typed(expected_type=GraphicalProperties, )
  92. graphicalProperties = Alias('spPr')
  93. style = Typed(expected_type=ShapeStyle, allow_none=True)
  94. __elements__ = ("nvPicPr", "blipFill", "spPr", "style")
  95. def __init__(self,
  96. macro=None,
  97. fPublished=None,
  98. nvPicPr=None,
  99. blipFill=None,
  100. spPr=None,
  101. style=None,
  102. ):
  103. self.macro = macro
  104. self.fPublished = fPublished
  105. if nvPicPr is None:
  106. nvPicPr = PictureNonVisual()
  107. self.nvPicPr = nvPicPr
  108. if blipFill is None:
  109. blipFill = BlipFillProperties()
  110. self.blipFill = blipFill
  111. if spPr is None:
  112. spPr = GraphicalProperties()
  113. self.spPr = spPr
  114. self.style = style