FaxDocument.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #
  2. # This file is part of the LibreOffice project.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #
  8. # This file incorporates work covered by the following license notice:
  9. #
  10. # Licensed to the Apache Software Foundation (ASF) under one or more
  11. # contributor license agreements. See the NOTICE file distributed
  12. # with this work for additional information regarding copyright
  13. # ownership. The ASF licenses this file to you under the Apache
  14. # License, Version 2.0 (the "License"); you may not use this file
  15. # except in compliance with the License. You may obtain a copy of
  16. # the License at http://www.apache.org/licenses/LICENSE-2.0 .
  17. #
  18. from ..text.TextDocument import TextDocument, traceback, \
  19. TextFieldHandler, Configuration
  20. from ..text.TextSectionHandler import TextSectionHandler
  21. from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
  22. from com.sun.star.style.ParagraphAdjust import CENTER
  23. from com.sun.star.text.PageNumberType import CURRENT
  24. from com.sun.star.style.NumberingType import ARABIC
  25. class FaxDocument(TextDocument):
  26. def __init__(self, xMSF, listener):
  27. super(FaxDocument,self).__init__(xMSF, listener, None,
  28. "WIZARD_LIVE_PREVIEW")
  29. self.keepLogoFrame = True
  30. self.keepTypeFrame = True
  31. def switchElement(self, sElement, bState):
  32. try:
  33. mySectionHandler = TextSectionHandler(self.xMSF,
  34. self.xTextDocument)
  35. oSection = \
  36. mySectionHandler.xTextDocument.TextSections.getByName(sElement)
  37. oSection.IsVisible = bState
  38. except Exception:
  39. traceback.print_exc()
  40. def updateDateFields(self):
  41. FH = TextFieldHandler(
  42. self.xTextDocument, self.xTextDocument)
  43. FH.updateDateFields()
  44. def switchFooter(self, sPageStyle, bState, bPageNumber, sText):
  45. if self.xTextDocument is not None:
  46. try:
  47. self.xTextDocument.lockControllers()
  48. xPageStyleCollection = \
  49. self.xTextDocument.StyleFamilies.getByName("PageStyles")
  50. xPageStyle = xPageStyleCollection.getByName(sPageStyle)
  51. if bState:
  52. xPageStyle.setPropertyValue("FooterIsOn", True)
  53. xFooterText = xPageStyle.FooterText
  54. xFooterText.String = sText
  55. if bPageNumber:
  56. #Adding the Page Number
  57. myCursor = xFooterText.Text.createTextCursor()
  58. myCursor.gotoEnd(False)
  59. xFooterText.insertControlCharacter(myCursor,
  60. PARAGRAPH_BREAK, False)
  61. myCursor.setPropertyValue("ParaAdjust", CENTER )
  62. xPageNumberField = \
  63. self.xTextDocument.createInstance(
  64. "com.sun.star.text.TextField.PageNumber")
  65. xPageNumberField.setPropertyValue("SubType", CURRENT)
  66. xPageNumberField.NumberingType = ARABIC
  67. xFooterText.insertTextContent(xFooterText.End,
  68. xPageNumberField, False)
  69. else:
  70. xPageStyle.FooterIsOn = False
  71. self.xTextDocument.unlockControllers()
  72. except Exception:
  73. self.xTextDocument.lockControllers()
  74. traceback.print_exc()
  75. def hasElement(self, sElement):
  76. if self.xTextDocument is not None:
  77. mySectionHandler = TextSectionHandler(self.xMSF,
  78. self.xTextDocument)
  79. return mySectionHandler.hasTextSectionByName(sElement)
  80. else:
  81. return False
  82. def switchUserField(self, sFieldName, sNewContent, bState):
  83. myFieldHandler = TextFieldHandler( self.xMSF, self.xTextDocument)
  84. if bState:
  85. myFieldHandler.changeUserFieldContent(sFieldName, sNewContent)
  86. else:
  87. myFieldHandler.changeUserFieldContent(sFieldName, "")
  88. def fillSenderWithUserData(self):
  89. try:
  90. myFieldHandler = TextFieldHandler(self.xTextDocument,
  91. self.xTextDocument)
  92. oUserDataAccess = Configuration.getConfigurationRoot(
  93. self.xMSF, "org.openoffice.UserProfile/Data", False)
  94. myFieldHandler.changeUserFieldContent(
  95. "Company", oUserDataAccess.getByName("o"))
  96. myFieldHandler.changeUserFieldContent(
  97. "Street", oUserDataAccess.getByName("street"))
  98. myFieldHandler.changeUserFieldContent(
  99. "PostCode", oUserDataAccess.getByName("postalcode"))
  100. myFieldHandler.changeUserFieldContent(
  101. "State", oUserDataAccess.getByName("st"))
  102. myFieldHandler.changeUserFieldContent(
  103. "City", oUserDataAccess.getByName("l"))
  104. myFieldHandler.changeUserFieldContent(
  105. "Fax", oUserDataAccess.getByName("facsimiletelephonenumber"))
  106. except Exception:
  107. traceback.print_exc()
  108. def killEmptyUserFields(self):
  109. myFieldHandler = TextFieldHandler(
  110. self.xMSF, self.xTextDocument)
  111. myFieldHandler.removeUserFieldByContent()
  112. def killEmptyFrames(self):
  113. try:
  114. if not self.keepLogoFrame:
  115. xTF = self.getFrameByName("Company Logo",
  116. self.xTextDocument)
  117. if xTF is not None:
  118. xTF.dispose()
  119. if not self.keepTypeFrame:
  120. xTF = self.getFrameByName("Communication Type",
  121. self.xTextDocument)
  122. if xTF is not None:
  123. xTF.dispose()
  124. except Exception:
  125. traceback.print_exc()