LetterWizardDialogImpl.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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. import traceback
  19. import os.path
  20. from .LetterWizardDialog import LetterWizardDialog, uno, HelpIds, HID
  21. from .LetterDocument import LetterDocument, BusinessPaperObject
  22. from .CGLetterWizard import CGLetterWizard
  23. from ..common.FileAccess import FileAccess
  24. from ..common.Configuration import Configuration
  25. from ..common.SystemDialog import SystemDialog
  26. from ..common.Desktop import Desktop
  27. from ..ui.PathSelection import PathSelection
  28. from ..ui.event.UnoDataAware import UnoDataAware
  29. from ..ui.event.RadioDataAware import RadioDataAware
  30. from ..ui.event.CommonListener import TerminateListenerProcAdapter
  31. from ..text.TextElement import TextElement
  32. from ..text.TextFieldHandler import TextFieldHandler
  33. from ..document.OfficeDocument import OfficeDocument
  34. from com.sun.star.awt.VclWindowPeerAttribute import YES_NO, DEF_NO
  35. from com.sun.star.util import CloseVetoException
  36. from com.sun.star.view.DocumentZoomType import OPTIMAL
  37. from com.sun.star.document.UpdateDocMode import FULL_UPDATE
  38. from com.sun.star.document.MacroExecMode import ALWAYS_EXECUTE
  39. class LetterWizardDialogImpl(LetterWizardDialog):
  40. RM_TYPESTYLE = 1
  41. RM_BUSINESSPAPER = 2
  42. RM_SENDERRECEIVER = 4
  43. RM_FOOTER = 5
  44. def enterStep(self, OldStep, NewStep):
  45. pass
  46. def leaveStep(self, OldStep, NewStep):
  47. pass
  48. def __init__(self, xmsf):
  49. super(LetterWizardDialogImpl, self).__init__(xmsf)
  50. self.lstBusinessStylePos = None
  51. self.lstPrivateStylePos = None
  52. self.lstPrivOfficialStylePos = None
  53. self.xmsf = xmsf
  54. self.bSaveSuccess = False
  55. self.filenameChanged = False
  56. self.BusCompanyLogo = None
  57. self.BusCompanyAddress = None
  58. self.BusCompanyAddressReceiver = None
  59. self.BusFooter = None
  60. def startWizard(self, xMSF):
  61. self.running = True
  62. try:
  63. #Number of steps on WizardDialog
  64. self.nMaxStep = 6
  65. #instantiate The Document Frame for the Preview
  66. self.terminateListener = TerminateListenerProcAdapter(self.queryTermination)
  67. self.myLetterDoc = LetterDocument(xMSF, self.terminateListener)
  68. #create the dialog
  69. self.drawNaviBar()
  70. self.buildStep1()
  71. self.buildStep2()
  72. self.buildStep3()
  73. self.buildStep4()
  74. self.buildStep5()
  75. self.buildStep6()
  76. self.initializePaths()
  77. self.initializeSalutation()
  78. self.initializeGreeting()
  79. #special Control fFrameor setting the save Path:
  80. self.insertPathSelectionControl()
  81. self.myConfig = CGLetterWizard()
  82. self.initializeTemplates(xMSF)
  83. #load the last used settings
  84. #from the registry and apply listeners to the controls:
  85. self.initConfiguration()
  86. if self.myConfig.cp_BusinessLetter.cp_Greeting :
  87. self.myConfig.cp_BusinessLetter.cp_Greeting = \
  88. self.resources.GreetingLabels[0]
  89. if self.myConfig.cp_BusinessLetter.cp_Salutation:
  90. self.myConfig.cp_BusinessLetter.cp_Salutation = \
  91. self.resources.SalutationLabels[0]
  92. if self.myConfig.cp_PrivateOfficialLetter.cp_Greeting:
  93. self.myConfig.cp_PrivateOfficialLetter.cp_Greeting = \
  94. self.resources.GreetingLabels[1]
  95. if self.myConfig.cp_PrivateOfficialLetter.cp_Salutation:
  96. self.myConfig.cp_PrivateOfficialLetter.cp_Salutation = \
  97. self.resources.SalutationLabels[1]
  98. if self.myConfig.cp_PrivateLetter.cp_Greeting:
  99. self.myConfig.cp_PrivateLetter.cp_Greeting = \
  100. self.resources.GreetingLabels[2]
  101. if self.myConfig.cp_PrivateLetter.cp_Salutation:
  102. self.myConfig.cp_PrivateLetter.cp_Salutation = \
  103. self.resources.SalutationLabels[2]
  104. if self.myPathSelection.xSaveTextBox.Text.lower() == "":
  105. self.myPathSelection.initializePath()
  106. xContainerWindow = self.myLetterDoc.xFrame.ContainerWindow
  107. self.createWindowPeer(xContainerWindow)
  108. self.insertRoadmap()
  109. self.setConfiguration()
  110. self.setDefaultForGreetingAndSalutation()
  111. self.initializeElements()
  112. self.myLetterDoc.xFrame.ComponentWindow.Enable = False
  113. self.executeDialogFromComponent(self.myLetterDoc.xFrame)
  114. self.removeTerminateListener()
  115. self.closeDocument()
  116. self.running = False
  117. except Exception:
  118. self.removeTerminateListener()
  119. traceback.print_exc()
  120. self.running = False
  121. return
  122. def cancelWizard(self):
  123. self.xUnoDialog.endExecute()
  124. self.running = False
  125. def finishWizard(self):
  126. self.switchToStep(self.getCurrentStep(), self.nMaxStep)
  127. endWizard = True
  128. try:
  129. self.sPath = self.myPathSelection.getSelectedPath()
  130. if not self.sPath or not os.path.exists(self.sPath):
  131. self.myPathSelection.triggerPathPicker()
  132. self.sPath = self.myPathSelection.getSelectedPath()
  133. if not self.filenameChanged:
  134. answer = SystemDialog.showMessageBox(
  135. self.xMSF, "MessBox", YES_NO + DEF_NO,
  136. self.resources.resOverwriteWarning,
  137. self.xUnoDialog.Peer)
  138. if answer == 3:
  139. # user said: no, do not overwrite...
  140. endWizard = False
  141. return False
  142. self.myLetterDoc.setWizardTemplateDocInfo(
  143. self.resources.resLetterWizardDialog_title,
  144. self.resources.resTemplateDescription)
  145. self.myLetterDoc.killEmptyUserFields()
  146. self.myLetterDoc.keepLogoFrame = self.chkUseLogo.State != 0
  147. if self.chkBusinessPaper.State != 0 \
  148. and self.chkPaperCompanyLogo.State != 0:
  149. self.myLetterDoc.keepLogoFrame = False
  150. self.myLetterDoc.keepBendMarksFrame = \
  151. self.chkUseBendMarks.State != 0
  152. self.myLetterDoc.keepLetterSignsFrame = \
  153. self.chkUseSigns.State != 0
  154. self.myLetterDoc.keepSenderAddressRepeatedFrame = \
  155. self.chkUseAddressReceiver.State != 0
  156. if self.optBusinessLetter.State:
  157. if self.chkBusinessPaper.State != 0 \
  158. and self.chkCompanyReceiver.State != 0:
  159. self.myLetterDoc.keepSenderAddressRepeatedFrame = False
  160. if self.chkBusinessPaper.State != 0 \
  161. and self.chkPaperCompanyAddress.State != 0:
  162. self.myLetterDoc.keepAddressFrame = False
  163. self.myLetterDoc.killEmptyFrames()
  164. self.bSaveSuccess = \
  165. OfficeDocument.store(
  166. self.xMSF, self.myLetterDoc.xTextDocument,
  167. self.sPath, "writer8_template")
  168. if self.bSaveSuccess:
  169. self.saveConfiguration()
  170. xIH = self.xMSF.createInstance(
  171. "com.sun.star.comp.uui.UUIInteractionHandler")
  172. loadValues = list(range(4))
  173. loadValues[0] = uno.createUnoStruct( \
  174. 'com.sun.star.beans.PropertyValue')
  175. loadValues[0].Name = "AsTemplate"
  176. loadValues[1] = uno.createUnoStruct( \
  177. 'com.sun.star.beans.PropertyValue')
  178. loadValues[1].Name = "MacroExecutionMode"
  179. loadValues[1].Value = ALWAYS_EXECUTE
  180. loadValues[2] = uno.createUnoStruct( \
  181. 'com.sun.star.beans.PropertyValue')
  182. loadValues[2].Name = "UpdateDocMode"
  183. loadValues[2].Value = FULL_UPDATE
  184. loadValues[3] = uno.createUnoStruct( \
  185. 'com.sun.star.beans.PropertyValue')
  186. loadValues[3].Name = "InteractionHandler"
  187. loadValues[3].Value = xIH
  188. if self.bEditTemplate:
  189. loadValues[0].Value = False
  190. else:
  191. loadValues[0].Value = True
  192. oDoc = OfficeDocument.load(
  193. Desktop.getDesktop(self.xMSF),
  194. self.sPath, "_default", loadValues)
  195. oDoc.CurrentController.ViewSettings.ZoomType = OPTIMAL
  196. else:
  197. pass
  198. except Exception:
  199. traceback.print_exc()
  200. finally:
  201. if endWizard:
  202. self.xUnoDialog.endExecute()
  203. self.running = False
  204. return True;
  205. def closeDocument(self):
  206. try:
  207. xCloseable = self.myLetterDoc.xFrame
  208. xCloseable.close(False)
  209. except CloseVetoException:
  210. traceback.print_exc()
  211. def optBusinessLetterItemChanged(self):
  212. self.lstPrivateStylePos = None
  213. self.lstPrivOfficialStylePos = None
  214. self.xDialogModel.lblBusinessStyle.Enabled = True
  215. self.xDialogModel.lstBusinessStyle.Enabled = True
  216. self.xDialogModel.chkBusinessPaper.Enabled = True
  217. self.xDialogModel.lblPrivOfficialStyle.Enabled = False
  218. self.xDialogModel.lstPrivOfficialStyle.Enabled = False
  219. self.xDialogModel.lblPrivateStyle.Enabled = False
  220. self.xDialogModel.lstPrivateStyle.Enabled = False
  221. self.lstBusinessStyleItemChanged()
  222. self.enableSenderReceiver()
  223. self.setPossibleFooter(True)
  224. if self.myPathSelection.xSaveTextBox.Text.lower() == "":
  225. self.myPathSelection.initializePath()
  226. def optPrivOfficialLetterItemChanged(self):
  227. self.lstBusinessStylePos = None
  228. self.lstPrivateStylePos = None
  229. self.xDialogModel.lblBusinessStyle.Enabled = False
  230. self.xDialogModel.lstBusinessStyle.Enabled = False
  231. self.xDialogModel.chkBusinessPaper.Enabled = False
  232. self.xDialogModel.lblPrivOfficialStyle.Enabled = True
  233. self.xDialogModel.lstPrivOfficialStyle.Enabled = True
  234. self.xDialogModel.lblPrivateStyle.Enabled = False
  235. self.xDialogModel.lstPrivateStyle.Enabled = False
  236. self.lstPrivOfficialStyleItemChanged()
  237. self.disableBusinessPaper()
  238. self.disableSenderReceiver()
  239. self.setPossibleFooter(True)
  240. if self.myPathSelection.xSaveTextBox.Text.lower() == "":
  241. self.myPathSelection.initializePath()
  242. self.myLetterDoc.fillSenderWithUserData()
  243. def optPrivateLetterItemChanged(self):
  244. self.lstBusinessStylePos = None
  245. self.lstPrivOfficialStylePos = None
  246. self.xDialogModel.lblBusinessStyle.Enabled = False
  247. self.xDialogModel.lstBusinessStyle.Enabled = False
  248. self.xDialogModel.chkBusinessPaper.Enabled = False
  249. self.xDialogModel.lblPrivOfficialStyle.Enabled = False
  250. self.xDialogModel.lstPrivOfficialStyle.Enabled = False
  251. self.xDialogModel.lblPrivateStyle.Enabled = True
  252. self.xDialogModel.lstPrivateStyle.Enabled = True
  253. self.lstPrivateStyleItemChanged()
  254. self.disableBusinessPaper()
  255. self.disableSenderReceiver()
  256. self.setPossibleFooter(False)
  257. if self.myPathSelection.xSaveTextBox.Text.lower() == "":
  258. self.myPathSelection.initializePath()
  259. def optSenderPlaceholderItemChanged(self):
  260. self.xDialogModel.lblSenderName.Enabled = False
  261. self.xDialogModel.lblSenderStreet.Enabled = False
  262. self.xDialogModel.lblPostCodeCity.Enabled = False
  263. self.xDialogModel.txtSenderName.Enabled = False
  264. self.xDialogModel.txtSenderStreet.Enabled = False
  265. self.xDialogModel.txtSenderPostCode.Enabled = False
  266. self.xDialogModel.txtSenderState.Enabled = False
  267. self.xDialogModel.txtSenderCity.Enabled = False
  268. self.myLetterDoc.fillSenderWithUserData()
  269. def optSenderDefineItemChanged(self):
  270. self.xDialogModel.lblSenderName.Enabled = True
  271. self.xDialogModel.lblSenderStreet.Enabled = True
  272. self.xDialogModel.lblPostCodeCity.Enabled = True
  273. self.xDialogModel.txtSenderName.Enabled = True
  274. self.xDialogModel.txtSenderStreet.Enabled = True
  275. self.xDialogModel.txtSenderPostCode.Enabled = True
  276. self.xDialogModel.txtSenderState.Enabled = True
  277. self.xDialogModel.txtSenderCity.Enabled = True
  278. self.txtSenderNameTextChanged()
  279. self.txtSenderStreetTextChanged()
  280. self.txtSenderPostCodeTextChanged()
  281. self.txtSenderStateTextChanged()
  282. self.txtSenderCityTextChanged()
  283. def lstBusinessStyleItemChanged(self):
  284. selectedItemPos = self.lstBusinessStyle.SelectedItemPos
  285. if self.lstBusinessStylePos != selectedItemPos:
  286. self.lstBusinessStylePos = selectedItemPos
  287. self.myLetterDoc.loadAsPreview(
  288. self.BusinessFiles[1][selectedItemPos], False)
  289. self.initializeElements()
  290. self.chkBusinessPaperItemChanged()
  291. self.setElements(False)
  292. self.drawConstants()
  293. def lstPrivOfficialStyleItemChanged(self):
  294. selectedItemPos = self.lstPrivOfficialStyle.SelectedItemPos
  295. if self.lstPrivOfficialStylePos != selectedItemPos:
  296. self.lstPrivOfficialStylePos = selectedItemPos
  297. self.myLetterDoc.loadAsPreview(
  298. self.OfficialFiles[1][selectedItemPos], False)
  299. self.initializeElements()
  300. self.setPossibleSenderData(True)
  301. self.setElements(False)
  302. self.drawConstants()
  303. def lstPrivateStyleItemChanged(self):
  304. selectedItemPos = self.lstPrivateStyle.SelectedItemPos
  305. if self.lstPrivateStylePos != selectedItemPos:
  306. self.lstPrivateStylePos = selectedItemPos
  307. self.myLetterDoc.xTextDocument = \
  308. self.myLetterDoc.loadAsPreview(
  309. self.PrivateFiles[1][selectedItemPos], False)
  310. self.initializeElements()
  311. self.setElements(True)
  312. def numLogoHeightTextChanged(self):
  313. self.BusCompanyLogo.iHeight = int(self.numLogoHeight.Value * 1000)
  314. self.BusCompanyLogo.setFramePosition()
  315. def numLogoWidthTextChanged(self):
  316. self.BusCompanyLogo.iWidth = int(self.numLogoWidth.Value * 1000)
  317. self.BusCompanyLogo.setFramePosition()
  318. def numLogoXTextChanged(self):
  319. self.BusCompanyLogo.iXPos = int(self.numLogoX.Value * 1000)
  320. self.BusCompanyLogo.setFramePosition()
  321. def numLogoYTextChanged(self):
  322. self.BusCompanyLogo.iYPos = int(self.numLogoY.Value * 1000)
  323. self.BusCompanyLogo.setFramePosition()
  324. def numAddressWidthTextChanged(self):
  325. self.BusCompanyAddress.iWidth = int(self.numAddressWidth.Value * 1000)
  326. self.BusCompanyAddress.setFramePosition()
  327. def numAddressXTextChanged(self):
  328. self.BusCompanyAddress.iXPos = int(self.numAddressX.Value * 1000)
  329. self.BusCompanyAddress.setFramePosition()
  330. def numAddressYTextChanged(self):
  331. self.BusCompanyAddress.iYPos = int(self.numAddressY.Value * 1000)
  332. self.BusCompanyAddress.setFramePosition()
  333. def numAddressHeightTextChanged(self):
  334. self.BusCompanyAddress.iHeight = int(self.numAddressHeight.Value * 1000)
  335. self.BusCompanyAddress.setFramePosition()
  336. def numFooterHeightTextChanged(self):
  337. self.BusFooter.iHeight = int(self.numFooterHeight.Value * 1000)
  338. self.BusFooter.iYPos = \
  339. self.myLetterDoc.DocSize.Height - self.BusFooter.iHeight
  340. self.BusFooter.setFramePosition()
  341. def chkPaperCompanyLogoItemChanged(self):
  342. if self.chkPaperCompanyLogo.State != 0:
  343. if self.numLogoWidth.Value == 0:
  344. self.numLogoWidth.Value = 0.1
  345. if self.numLogoHeight.Value == 0:
  346. self.numLogoHeight.Value = 0.1
  347. self.BusCompanyLogo = BusinessPaperObject(
  348. self.myLetterDoc.xTextDocument, "Company Logo",
  349. int(self.numLogoWidth.Value * 1000),
  350. int(self.numLogoHeight.Value * 1000),
  351. int(self.numLogoX.Value * 1000),
  352. self.numLogoY.Value * 1000)
  353. self.xDialogModel.numLogoHeight.Enabled = True
  354. self.xDialogModel.numLogoWidth.Enabled = True
  355. self.xDialogModel.numLogoX.Enabled = True
  356. self.xDialogModel.numLogoY.Enabled = True
  357. self.setPossibleLogo(False)
  358. else:
  359. if self.BusCompanyLogo is not None:
  360. self.BusCompanyLogo.removeFrame()
  361. self.xDialogModel.numLogoHeight.Enabled = False
  362. self.xDialogModel.numLogoWidth.Enabled = False
  363. self.xDialogModel.numLogoX.Enabled = False
  364. self.xDialogModel.numLogoY.Enabled = False
  365. self.setPossibleLogo(True)
  366. def chkPaperCompanyAddressItemChanged(self):
  367. if self.chkPaperCompanyAddress.State != 0:
  368. if self.numAddressWidth.Value == 0:
  369. self.numAddressWidth.Value = 0.1
  370. if self.numAddressHeight.Value == 0:
  371. self.numAddressHeight.Value = 0.1
  372. self.BusCompanyAddress = BusinessPaperObject(
  373. self.myLetterDoc.xTextDocument, "Company Address",
  374. int(self.numAddressWidth.Value * 1000),
  375. int(self.numAddressHeight.Value * 1000),
  376. int(self.numAddressX.Value * 1000),
  377. int(self.numAddressY.Value * 1000))
  378. self.xDialogModel.numAddressHeight.Enabled = True
  379. self.xDialogModel.numAddressWidth.Enabled = True
  380. self.xDialogModel.numAddressX.Enabled = True
  381. self.xDialogModel.numAddressY.Enabled = True
  382. if self.myLetterDoc.hasElement("Sender Address"):
  383. self.myLetterDoc.switchElement(
  384. "Sender Address", False)
  385. if self.chkCompanyReceiver.State != 0:
  386. self.setPossibleSenderData(False)
  387. else:
  388. if self.BusCompanyAddress is not None:
  389. self.BusCompanyAddress.removeFrame()
  390. self.xDialogModel.numAddressHeight.Enabled = False
  391. self.xDialogModel.numAddressWidth.Enabled = False
  392. self.xDialogModel.numAddressX.Enabled = False
  393. self.xDialogModel.numAddressY.Enabled = False
  394. if self.myLetterDoc.hasElement("Sender Address"):
  395. self.myLetterDoc.switchElement("Sender Address", True)
  396. self.setPossibleSenderData(True)
  397. if self.optSenderDefine.State:
  398. self.optSenderDefineItemChanged()
  399. if self.optSenderPlaceholder.State:
  400. self.optSenderPlaceholderItemChanged()
  401. def chkCompanyReceiverItemChanged(self):
  402. xReceiverFrame = None
  403. if self.chkCompanyReceiver.State != 0:
  404. try:
  405. xReceiverFrame = self.myLetterDoc.getFrameByName(
  406. "Receiver Address", self.myLetterDoc.xTextDocument)
  407. iFrameWidth = int(xReceiverFrame.Width)
  408. iFrameX = int(xReceiverFrame.HoriOrientPosition)
  409. iFrameY = int(xReceiverFrame.VertOrientPosition)
  410. iReceiverHeight = int(0.5 * 1000)
  411. self.BusCompanyAddressReceiver = BusinessPaperObject(
  412. self.myLetterDoc.xTextDocument, " ", iFrameWidth, iReceiverHeight,
  413. iFrameX, iFrameY - iReceiverHeight)
  414. self.setPossibleAddressReceiver(False)
  415. except Exception:
  416. traceback.print_exc()
  417. if self.chkPaperCompanyAddress.State != 0:
  418. self.setPossibleSenderData(False)
  419. else:
  420. if self.BusCompanyAddressReceiver is not None:
  421. self.BusCompanyAddressReceiver.removeFrame()
  422. self.setPossibleAddressReceiver(True)
  423. self.setPossibleSenderData(True)
  424. if self.optSenderDefine.State:
  425. self.optSenderDefineItemChanged()
  426. if self.optSenderPlaceholder.State:
  427. self.optSenderPlaceholderItemChanged()
  428. def chkPaperFooterItemChanged(self):
  429. if self.chkPaperFooter.State != 0:
  430. if self.numFooterHeight.Value == 0:
  431. self.numFooterHeight.Value = 0.1
  432. self.BusFooter = BusinessPaperObject(
  433. self.myLetterDoc.xTextDocument, "Footer",
  434. self.myLetterDoc.DocSize.Width,
  435. int(self.numFooterHeight.Value * 1000), 0,
  436. int(self.myLetterDoc.DocSize.Height - \
  437. (self.numFooterHeight.Value * 1000)))
  438. self.xDialogModel.numFooterHeight.Enabled = True
  439. self.xDialogModel.lblFooterHeight.Enabled = True
  440. self.setPossibleFooter(False)
  441. else:
  442. if self.BusFooter is not None:
  443. self.BusFooter.removeFrame()
  444. self.xDialogModel.numFooterHeight.Enabled = False
  445. self.xDialogModel.lblFooterHeight.Enabled = False
  446. self.setPossibleFooter(True)
  447. def chkUseLogoItemChanged(self):
  448. try:
  449. if self.myLetterDoc.hasElement("Company Logo"):
  450. logostatus = \
  451. bool(self.xDialogModel.chkUseLogo.Enabled) \
  452. and (self.chkUseLogo.State != 0)
  453. self.myLetterDoc.switchElement(
  454. "Company Logo", logostatus)
  455. except Exception:
  456. traceback.print_exc()
  457. def chkUseAddressReceiverItemChanged(self):
  458. try:
  459. if self.myLetterDoc.hasElement("Sender Address Repeated"):
  460. rstatus = \
  461. bool(self.xDialogModel.chkUseAddressReceiver.Enabled) \
  462. and (self.chkUseAddressReceiver.State != 0)
  463. self.myLetterDoc.switchElement(
  464. "Sender Address Repeated", rstatus)
  465. except Exception:
  466. traceback.print_exc()
  467. def chkUseSignsItemChanged(self):
  468. if self.myLetterDoc.hasElement("Letter Signs"):
  469. self.myLetterDoc.switchElement(
  470. "Letter Signs", self.chkUseSigns.State != 0)
  471. def chkUseSubjectItemChanged(self):
  472. if self.myLetterDoc.hasElement("Subject Line"):
  473. self.myLetterDoc.switchElement(
  474. "Subject Line", self.chkUseSubject.State != 0)
  475. def chkUseBendMarksItemChanged(self):
  476. if self.myLetterDoc.hasElement("Bend Marks"):
  477. self.myLetterDoc.switchElement(
  478. "Bend Marks", self.chkUseBendMarks.State != 0)
  479. def chkUseFooterItemChanged(self):
  480. try:
  481. bFooterPossible = (self.chkUseFooter.State != 0) \
  482. and bool(self.xDialogModel.chkUseFooter.Enabled)
  483. if self.chkFooterNextPages.State != 0:
  484. self.myLetterDoc.switchFooter(
  485. "First Page", False, self.chkFooterPageNumbers.State != 0,
  486. self.txtFooter.Text)
  487. self.myLetterDoc.switchFooter("Standard", bFooterPossible,
  488. self.chkFooterPageNumbers.State != 0, self.txtFooter.Text)
  489. else:
  490. self.myLetterDoc.switchFooter(
  491. "First Page", bFooterPossible,
  492. self.chkFooterPageNumbers.State != 0, self.txtFooter.Text)
  493. self.myLetterDoc.switchFooter(
  494. "Standard", bFooterPossible,
  495. self.chkFooterPageNumbers.State != 0, self.txtFooter.Text)
  496. BPaperItem = \
  497. self.getRoadmapItemByID(LetterWizardDialogImpl.RM_FOOTER)
  498. BPaperItem.Enabled = bFooterPossible
  499. except Exception:
  500. traceback.print_exc()
  501. def chkFooterNextPagesItemChanged(self):
  502. self.chkUseFooterItemChanged()
  503. def chkFooterPageNumbersItemChanged(self):
  504. self.chkUseFooterItemChanged()
  505. def setPossibleFooter(self, bState):
  506. self.xDialogModel.chkUseFooter.Enabled = bState
  507. self.chkUseFooterItemChanged()
  508. def setPossibleAddressReceiver(self, bState):
  509. if self.myLetterDoc.hasElement("Sender Address Repeated"):
  510. self.xDialogModel.chkUseAddressReceiver.Enabled = bState
  511. self.chkUseAddressReceiverItemChanged()
  512. def setPossibleLogo(self, bState):
  513. if self.myLetterDoc.hasElement("Company Logo"):
  514. self.xDialogModel.chkUseLogo.Enabled = bState
  515. self.chkUseLogoItemChanged()
  516. def txtFooterTextChanged(self):
  517. self.chkUseFooterItemChanged()
  518. def txtSenderNameTextChanged(self):
  519. myFieldHandler = TextFieldHandler(
  520. self.myLetterDoc.xMSF, self.myLetterDoc.xTextDocument)
  521. myFieldHandler.changeUserFieldContent(
  522. "Company", self.txtSenderName.Text)
  523. def txtSenderStreetTextChanged(self):
  524. myFieldHandler = TextFieldHandler(
  525. self.myLetterDoc.xMSF, self.myLetterDoc.xTextDocument)
  526. myFieldHandler.changeUserFieldContent(
  527. "Street", self.txtSenderStreet.Text)
  528. def txtSenderCityTextChanged(self):
  529. myFieldHandler = TextFieldHandler(
  530. self.myLetterDoc.xMSF, self.myLetterDoc.xTextDocument)
  531. myFieldHandler.changeUserFieldContent(
  532. "City", self.txtSenderCity.Text)
  533. def txtSenderPostCodeTextChanged(self):
  534. myFieldHandler = TextFieldHandler(
  535. self.myLetterDoc.xMSF, self.myLetterDoc.xTextDocument)
  536. myFieldHandler.changeUserFieldContent(
  537. "PostCode", self.txtSenderPostCode.Text)
  538. def txtSenderStateTextChanged(self):
  539. myFieldHandler = TextFieldHandler(
  540. self.myLetterDoc.xMSF, self.myLetterDoc.xTextDocument)
  541. myFieldHandler.changeUserFieldContent(
  542. "State", self.txtSenderState.Text)
  543. def txtTemplateNameTextChanged(self):
  544. xDocProps = self.myLetterDoc.xTextDocument.DocumentProperties
  545. TitleName = self.txtTemplateName.Text
  546. xDocProps.Title = TitleName
  547. def chkUseSalutationItemChanged(self):
  548. self.myLetterDoc.switchUserField(
  549. "Salutation", self.lstSalutation.Text,
  550. self.chkUseSalutation.State != 0)
  551. self.xDialogModel.lstSalutation.Enabled = \
  552. self.chkUseSalutation.State != 0
  553. def lstSalutationItemChanged(self):
  554. self.myLetterDoc.switchUserField(
  555. "Salutation", self.lstSalutation.Text,
  556. self.chkUseSalutation.State != 0)
  557. def chkUseGreetingItemChanged(self):
  558. self.myLetterDoc.switchUserField(
  559. "Greeting", self.lstGreeting.Text, self.chkUseGreeting.State != 0)
  560. self.xDialogModel.lstGreeting.Enabled = \
  561. self.chkUseGreeting.State != 0
  562. def setDefaultForGreetingAndSalutation(self):
  563. if self.lstSalutation.Text:
  564. self.lstSalutation.Text = self.resources.SalutationLabels[0]
  565. if self.lstGreeting.Text:
  566. self.lstGreeting.Text = self.resources.GreetingLabels[0]
  567. def lstGreetingItemChanged(self):
  568. self.myLetterDoc.switchUserField(
  569. "Greeting", self.lstGreeting.Text, self.chkUseGreeting.State != 0)
  570. def chkBusinessPaperItemChanged(self):
  571. if self.chkBusinessPaper.State != 0:
  572. self.enableBusinessPaper()
  573. else:
  574. self.disableBusinessPaper()
  575. self.setPossibleSenderData(True)
  576. def setPossibleSenderData(self, bState):
  577. self.xDialogModel.optSenderDefine.Enabled = bState
  578. self.xDialogModel.optSenderPlaceholder.Enabled = bState
  579. self.xDialogModel.lblSenderAddress.Enabled = bState
  580. if not bState:
  581. self.xDialogModel.txtSenderCity.Enabled = bState
  582. self.xDialogModel.txtSenderName.Enabled = bState
  583. self.xDialogModel.txtSenderPostCode.Enabled = bState
  584. self.xDialogModel.txtSenderStreet.Enabled = bState
  585. self.xDialogModel.txtSenderCity.Enabled = bState
  586. self.xDialogModel.txtSenderState.Enabled = bState
  587. self.xDialogModel.lblSenderName.Enabled = bState
  588. self.xDialogModel.lblSenderStreet.Enabled = bState
  589. self.xDialogModel.lblPostCodeCity.Enabled = bState
  590. def enableSenderReceiver(self):
  591. BPaperItem = self.getRoadmapItemByID(
  592. LetterWizardDialogImpl.RM_SENDERRECEIVER)
  593. BPaperItem.Enabled = True
  594. def disableSenderReceiver(self):
  595. BPaperItem = self.getRoadmapItemByID(
  596. LetterWizardDialogImpl.RM_SENDERRECEIVER)
  597. BPaperItem.Enabled = False
  598. def enableBusinessPaper(self):
  599. try:
  600. BPaperItem = self.getRoadmapItemByID(
  601. LetterWizardDialogImpl.RM_BUSINESSPAPER)
  602. BPaperItem.Enabled = True
  603. self.chkPaperCompanyLogoItemChanged()
  604. self.chkPaperCompanyAddressItemChanged()
  605. self.chkPaperFooterItemChanged()
  606. self.chkCompanyReceiverItemChanged()
  607. except Exception:
  608. traceback.print_exc()
  609. def disableBusinessPaper(self):
  610. try:
  611. BPaperItem = self.getRoadmapItemByID(
  612. LetterWizardDialogImpl.RM_BUSINESSPAPER)
  613. BPaperItem.Enabled = False
  614. if self.BusCompanyLogo is not None:
  615. self.BusCompanyLogo.removeFrame()
  616. if self.BusCompanyAddress is not None:
  617. self.BusCompanyAddress.removeFrame()
  618. if self.BusFooter is not None:
  619. self.BusFooter.removeFrame()
  620. if self.BusCompanyAddressReceiver is not None:
  621. self.BusCompanyAddressReceiver.removeFrame()
  622. self.setPossibleAddressReceiver(True)
  623. self.setPossibleFooter(True)
  624. self.setPossibleLogo(True)
  625. if self.myLetterDoc.hasElement("Sender Address"):
  626. self.myLetterDoc.switchElement(
  627. "Sender Address", True)
  628. except Exception:
  629. traceback.print_exc()
  630. def initializeSalutation(self):
  631. self.xDialogModel.lstSalutation.StringItemList = \
  632. tuple(self.resources.SalutationLabels)
  633. def initializeGreeting(self):
  634. self.xDialogModel.lstGreeting.StringItemList = \
  635. tuple(self.resources.GreetingLabels)
  636. def initializeTemplates(self, xMSF):
  637. sLetterPath = self.sTemplatePath + "/wizard/letter"
  638. self.BusinessFiles = \
  639. FileAccess.getFolderTitles(
  640. xMSF, "bus", sLetterPath, self.resources.dictBusinessTemplate)
  641. self.OfficialFiles = \
  642. FileAccess.getFolderTitles(
  643. xMSF, "off", sLetterPath, self.resources.dictOfficialTemplate)
  644. self.PrivateFiles = \
  645. FileAccess.getFolderTitles(
  646. xMSF, "pri", sLetterPath, self.resources.dictPrivateTemplate)
  647. self.xDialogModel.lstBusinessStyle.StringItemList = \
  648. tuple(self.BusinessFiles[0])
  649. self.xDialogModel.lstPrivOfficialStyle.StringItemList = \
  650. tuple(self.OfficialFiles[0])
  651. self.xDialogModel.lstPrivateStyle.StringItemList = \
  652. tuple(self.PrivateFiles[0])
  653. self.xDialogModel.lstBusinessStyle.SelectedItems = (0,)
  654. self.xDialogModel.lstPrivOfficialStyle.SelectedItems = (0,)
  655. self.xDialogModel.lstPrivateStyle.SelectedItems = (0,)
  656. return True
  657. def initializeElements(self):
  658. self.xDialogModel.chkUseLogo.Enabled = \
  659. self.myLetterDoc.hasElement("Company Logo")
  660. self.xDialogModel.chkUseBendMarks.Enabled = \
  661. self.myLetterDoc.hasElement("Bend Marks")
  662. self.xDialogModel.chkUseAddressReceiver.Enabled = \
  663. self.myLetterDoc.hasElement("Sender Address Repeated")
  664. self.xDialogModel.chkUseSubject.Enabled = \
  665. self.myLetterDoc.hasElement("Subject Line")
  666. self.xDialogModel.chkUseSigns.Enabled = \
  667. self.myLetterDoc.hasElement("Letter Signs")
  668. self.myLetterDoc.updateDateFields()
  669. def setConfiguration(self):
  670. if self.optBusinessLetter.State:
  671. self.optBusinessLetterItemChanged()
  672. elif self.optPrivOfficialLetter.State:
  673. self.optPrivOfficialLetterItemChanged()
  674. elif self.optPrivateLetter.State:
  675. self.optPrivateLetterItemChanged()
  676. def optReceiverPlaceholderItemChanged(self):
  677. OfficeDocument.attachEventCall(
  678. self.myLetterDoc.xTextDocument, "OnNew", "StarBasic",
  679. "macro:///Template.Correspondence.Placeholder()")
  680. def optReceiverDatabaseItemChanged(self):
  681. OfficeDocument.attachEventCall(
  682. self.myLetterDoc.xTextDocument, "OnNew", "StarBasic",
  683. "macro:///Template.Correspondence.Database()")
  684. def setElements(self, privLetter):
  685. if self.optSenderDefine.State:
  686. self.optSenderDefineItemChanged()
  687. if self.optSenderPlaceholder.State:
  688. self.optSenderPlaceholderItemChanged()
  689. self.chkUseSignsItemChanged()
  690. self.chkUseSubjectItemChanged()
  691. self.chkUseSalutationItemChanged()
  692. self.chkUseGreetingItemChanged()
  693. self.chkUseBendMarksItemChanged()
  694. self.chkUseAddressReceiverItemChanged()
  695. self.txtTemplateNameTextChanged()
  696. if self.optReceiverDatabase.State and not privLetter:
  697. self.optReceiverDatabaseItemChanged()
  698. if self.optReceiverPlaceholder.State and not privLetter:
  699. self.optReceiverPlaceholderItemChanged()
  700. if self.optCreateLetter.State:
  701. self.optCreateFromTemplateItemChanged()
  702. if self.optMakeChanges.State:
  703. self.optMakeChangesItemChanged()
  704. def drawConstants(self):
  705. '''Localise the template'''
  706. constRangeList = self.myLetterDoc.searchFillInItems(1)
  707. for i in constRangeList:
  708. text = i.String.lower()
  709. aux = TextElement(i, self.resources.dictConstants[text])
  710. aux.write()
  711. def insertRoadmap(self):
  712. self.addRoadmap()
  713. self.insertRoadMapItems(
  714. self.resources.RoadmapLabels,
  715. [True, False, True, True, False, True])
  716. self.setRoadmapInteractive(True)
  717. self.setRoadmapComplete(True)
  718. self.setCurrentRoadmapItemID(1)
  719. def insertPathSelectionControl(self):
  720. self.myPathSelection = \
  721. PathSelection(self.xMSF, self, PathSelection.TransferMode.SAVE,
  722. PathSelection.DialogTypes.FILE)
  723. self.myPathSelection.insert(
  724. 6, 97, 70, 205, 45, self.resources.reslblTemplatePath_value,
  725. True, HelpIds.getHelpIdString(HID + 47),
  726. HelpIds.getHelpIdString(HID + 48))
  727. self.myPathSelection.sDefaultDirectory = self.sUserTemplatePath
  728. self.myPathSelection.sDefaultName = "myLetterTemplate.ott"
  729. self.myPathSelection.sDefaultFilter = "writer8_template"
  730. self.myPathSelection.addSelectionListener(self)
  731. def initConfiguration(self):
  732. try:
  733. root = Configuration.getConfigurationRoot(
  734. self.xMSF, "/org.openoffice.Office.Writer/Wizards/Letter",
  735. False)
  736. self.myConfig.readConfiguration(root, "cp_")
  737. RadioDataAware.attachRadioButtons(self.myConfig, "cp_LetterType",
  738. (self.optBusinessLetter, self.optPrivOfficialLetter,
  739. self.optPrivateLetter), True).updateUI()
  740. UnoDataAware.attachListBox(
  741. self.myConfig.cp_BusinessLetter, "cp_Style",
  742. self.lstBusinessStyle, True).updateUI()
  743. UnoDataAware.attachListBox(
  744. self.myConfig.cp_PrivateOfficialLetter, "cp_Style",
  745. self.lstPrivOfficialStyle, True).updateUI()
  746. UnoDataAware.attachListBox(
  747. self.myConfig.cp_PrivateLetter, "cp_Style",
  748. self.lstPrivateStyle, True).updateUI()
  749. UnoDataAware.attachCheckBox(
  750. self.myConfig.cp_BusinessLetter, "cp_BusinessPaper",
  751. self.chkBusinessPaper, True).updateUI()
  752. cgl = self.myConfig.cp_BusinessLetter
  753. cgpl = self.myConfig.cp_BusinessLetter.cp_CompanyLogo
  754. cgpa = self.myConfig.cp_BusinessLetter.cp_CompanyAddress
  755. UnoDataAware.attachCheckBox(
  756. cgpl, "cp_Display", self.chkPaperCompanyLogo, True).updateUI()
  757. UnoDataAware.attachNumericControl(
  758. cgpl, "cp_Width", self.numLogoWidth, True).updateUI()
  759. UnoDataAware.attachNumericControl(
  760. cgpl, "cp_Height", self.numLogoHeight, True).updateUI()
  761. UnoDataAware.attachNumericControl(
  762. cgpl, "cp_X", self.numLogoX, True).updateUI()
  763. UnoDataAware.attachNumericControl(
  764. cgpl, "cp_Y", self.numLogoY, True).updateUI()
  765. UnoDataAware.attachCheckBox(
  766. cgpa, "cp_Display", self.chkPaperCompanyAddress, True).updateUI()
  767. UnoDataAware.attachNumericControl(
  768. cgpa, "cp_Width", self.numAddressWidth, True).updateUI()
  769. UnoDataAware.attachNumericControl(
  770. cgpa, "cp_Height", self.numAddressHeight, True).updateUI()
  771. UnoDataAware.attachNumericControl(
  772. cgpa, "cp_X", self.numAddressX, True).updateUI()
  773. UnoDataAware.attachNumericControl(
  774. cgpa, "cp_Y", self.numAddressY, True).updateUI()
  775. UnoDataAware.attachCheckBox(
  776. cgl, "cp_PaperCompanyAddressReceiverField",
  777. self.chkCompanyReceiver, True).updateUI()
  778. UnoDataAware.attachCheckBox(
  779. cgl, "cp_PaperFooter", self.chkPaperFooter, True).updateUI()
  780. UnoDataAware.attachNumericControl(
  781. cgl, "cp_PaperFooterHeight", self.numFooterHeight, True).updateUI()
  782. UnoDataAware.attachCheckBox(
  783. cgl, "cp_PrintCompanyLogo", self.chkUseLogo, True).updateUI()
  784. UnoDataAware.attachCheckBox(
  785. cgl, "cp_PrintCompanyAddressReceiverField",
  786. self.chkUseAddressReceiver, True).updateUI()
  787. UnoDataAware.attachCheckBox(
  788. cgl, "cp_PrintLetterSigns", self.chkUseSigns, True).updateUI()
  789. UnoDataAware.attachCheckBox(
  790. cgl, "cp_PrintSubjectLine", self.chkUseSubject, True).updateUI()
  791. UnoDataAware.attachCheckBox(
  792. cgl, "cp_PrintSalutation", self.chkUseSalutation, True).updateUI()
  793. UnoDataAware.attachCheckBox(
  794. cgl, "cp_PrintBendMarks", self.chkUseBendMarks, True).updateUI()
  795. UnoDataAware.attachCheckBox(
  796. cgl, "cp_PrintGreeting", self.chkUseGreeting, True).updateUI()
  797. UnoDataAware.attachCheckBox(
  798. cgl, "cp_PrintFooter", self.chkUseFooter, True).updateUI()
  799. UnoDataAware.attachEditControl(
  800. cgl, "cp_Salutation", self.lstSalutation, True).updateUI()
  801. UnoDataAware.attachEditControl(
  802. cgl, "cp_Greeting", self.lstGreeting, True).updateUI()
  803. RadioDataAware.attachRadioButtons(
  804. cgl, "cp_SenderAddressType",
  805. (self.optSenderDefine, self.optSenderPlaceholder), True).updateUI()
  806. UnoDataAware.attachEditControl(
  807. cgl, "cp_SenderCompanyName", self.txtSenderName, True).updateUI()
  808. UnoDataAware.attachEditControl(
  809. cgl, "cp_SenderStreet", self.txtSenderStreet, True).updateUI()
  810. UnoDataAware.attachEditControl(
  811. cgl, "cp_SenderPostCode", self.txtSenderPostCode, True).updateUI()
  812. UnoDataAware.attachEditControl(
  813. cgl, "cp_SenderState", self.txtSenderState, True).updateUI()
  814. UnoDataAware.attachEditControl(
  815. cgl, "cp_SenderCity", self.txtSenderCity, True).updateUI()
  816. RadioDataAware.attachRadioButtons(
  817. cgl, "cp_ReceiverAddressType",
  818. (self.optReceiverDatabase, self.optReceiverPlaceholder),
  819. True).updateUI()
  820. UnoDataAware.attachEditControl(
  821. cgl, "cp_Footer", self.txtFooter, True).updateUI()
  822. UnoDataAware.attachCheckBox(
  823. cgl, "cp_FooterOnlySecondPage",
  824. self.chkFooterNextPages, True).updateUI()
  825. UnoDataAware.attachCheckBox(
  826. cgl, "cp_FooterPageNumbers",
  827. self.chkFooterPageNumbers, True).updateUI()
  828. RadioDataAware.attachRadioButtons(
  829. cgl, "cp_CreationType",
  830. (self.optCreateLetter, self.optMakeChanges), True).updateUI()
  831. UnoDataAware.attachEditControl(
  832. cgl, "cp_TemplateName", self.txtTemplateName, True).updateUI()
  833. UnoDataAware.attachEditControl(
  834. cgl, "cp_TemplatePath", self.myPathSelection.xSaveTextBox,
  835. True).updateUI()
  836. except Exception:
  837. traceback.print_exc()
  838. def saveConfiguration(self):
  839. try:
  840. root = Configuration.getConfigurationRoot(self.xMSF,
  841. "/org.openoffice.Office.Writer/Wizards/Letter", True)
  842. self.myConfig.writeConfiguration(root, "cp_")
  843. root.commitChanges()
  844. except Exception:
  845. traceback.print_exc()
  846. def validatePath(self):
  847. if self.myPathSelection.usedPathPicker:
  848. self.filenameChanged = True
  849. self.myPathSelection.usedPathPicker = False