picture.py 4.2 KB

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