Kaydet (Commit) 74e4137c authored tarafından Xisco Fauli's avatar Xisco Fauli

pyfax: Translate the template at run-time

Change-Id: Ied94eaeb33dcfab582ac1d4702b736cf81c5d7ca
üst 0e66cce3
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed
# with this work for additional information regarding copyright
# ownership. The ASF licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
import traceback
from .Helper import Helper
from com.sun.star.text.PlaceholderType import TEXT
class TextElement(object):
def __init__(self, item, placeHolderText, hint, xmsf):
self.item = item
self.placeHolderText = placeHolderText
self.xmsf = xmsf
self.paraStyle = Helper.getUnoPropertyValue(
item.Start, "ParaStyleName")
def write(self):
try:
if self.item is not None:
self.item.String = ""
cursor = self.item.Text.createTextCursorByRange(
self.item.Start)
cursor.String = self.placeHolderText
Helper.setUnoPropertyValue(
cursor, "ParaStyleName", self.paraStyle)
except Exception, e:
traceback.print_exc()
......@@ -30,7 +30,6 @@ class CallWizard(unohelper.Base, XJobExecutor):
self.ctx = ctx
def trigger(self, args):
print "hello"
try:
fw = FaxWizardDialogImpl(self.ctx.ServiceManager)
fw.startWizard(self.ctx.ServiceManager)
......
......@@ -15,9 +15,9 @@
# except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
from ..text.TextDocument import TextDocument, traceback, Helper,\
TextFieldHandler, Configuration
from ..text.TextDocument import *
#TextDocument, traceback, Helper,\
#TextFieldHandler, Configuration
from ..text.TextSectionHandler import TextSectionHandler
from ..common.PropertyNames import PropertyNames
......@@ -51,8 +51,8 @@ class FaxDocument(TextDocument):
def switchFooter(self, sPageStyle, bState, bPageNumber, sText):
if TextDocument.xTextDocument is not None:
TextDocument.xTextDocument.lockControllers()
try:
TextDocument.xTextDocument.lockControllers()
xPageStyleCollection = \
TextDocument.xTextDocument.StyleFamilies.getByName("PageStyles")
xPageStyle = xPageStyleCollection.getByName(sPageStyle)
......@@ -84,6 +84,7 @@ class FaxDocument(TextDocument):
TextDocument.xTextDocument.unlockControllers()
except Exception:
TextDocument.xTextDocument.lockControllers()
traceback.print_exc()
def hasElement(self, sElement):
......
......@@ -32,6 +32,7 @@ from ..common.NoValidPathException import NoValidPathException
from ..common.HelpIds import HelpIds
from ..common.FileAccess import FileAccess
from ..common.Desktop import Desktop
from ..common.TextElement import TextElement
from ..document.OfficeDocument import OfficeDocument
from com.sun.star.awt.VclWindowPeerAttribute import YES_NO, DEF_NO
......@@ -67,15 +68,17 @@ class FaxWizardDialogImpl(FaxWizardDialog):
@classmethod
def main(self, args):
#only being called when starting wizard remotely
#Call the wizard remotely
try:
ConnectStr = \
"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
xLocMSF = Desktop.connect(ConnectStr)
lw = FaxWizardDialogImpl(xLocMSF)
lw.startWizard(xLocMSF)
except Exception, e:
traceback.print_exc()
except Exception as e:
print ("Wizard failure exception " + str(type(e)) +
" message " + str(e) + " args " + str(e.args) +
traceback.format_exc())
def startWizard(self, xMSF):
self.running = True
......@@ -232,6 +235,30 @@ class FaxWizardDialogImpl(FaxWizardDialog):
except CloseVetoException, e:
traceback.print_exc()
def drawConstants(self):
'''Localise the template'''
constRangeList = self.searchFillInItems(1)
for i in xrange(constRangeList.Count):
item = constRangeList.getByIndex(i)
text = item.String.lower()
aux = TextElement(item, self.resources.dictConstants[text],
"hint", self.xMSF)
aux.write()
def searchFillInItems(self, typeSearch):
sd = TextDocument.xTextDocument.createSearchDescriptor()
if typeSearch == 0:
sd.setSearchString("<[^>]+>")
elif typeSearch == 1:
sd.setSearchString("#[^#]+#")
sd.setPropertyValue("SearchRegularExpression", True)
sd.setPropertyValue("SearchWords", True)
return TextDocument.xTextDocument.findAll(sd)
def insertRoadmap(self):
self.addRoadmap()
self.insertRoadMapItems(
......@@ -430,6 +457,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
self.BusinessFiles[1][selectedItemPos], False)
self.initializeElements()
self.setElements()
self.drawConstants()
def optPrivateFaxItemChanged(self):
FaxWizardDialogImpl.lstBusinessStylePos = None
......
......@@ -25,6 +25,15 @@ class FaxWizardDialogResources(Resource):
RID_FAXWIZARDSALUTATION_START = 3290
RID_FAXWIZARDROADMAP_START = 3300
RID_RID_COMMON_START = 500
resToPlaceHolder = "#to#"
resFromPlaceHolder = "#from#"
resFaxconstPlaceHolder = "#faxconst#"
resTelconstPlaceHolder = "#telconst#"
resEmailconstPlaceHolder = "#emailconst#"
resConsist1PlaceHolder = "#consist1#"
resConsist2PlaceHolder = "#consist2#"
resConsist3PlaceHolder = "#consist3#"
def __init__(self, xmsf):
......@@ -40,8 +49,6 @@ class FaxWizardDialogResources(Resource):
self.resFaxWizardDialog_title = self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 1)
self.resLabel9_value = self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 2)
self.resoptBusinessFax_value = self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 3)
self.resoptPrivateFax_value = self.getResText(
......@@ -118,6 +125,26 @@ class FaxWizardDialogResources(Resource):
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 39)
self.resLabel2_value = self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 40)
#Create a Dictionary for the constants values.
self.dictConstants = {
FaxWizardDialogResources.resToPlaceHolder : self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 41),
FaxWizardDialogResources.resFromPlaceHolder : self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 42),
FaxWizardDialogResources.resFaxconstPlaceHolder : self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 43),
FaxWizardDialogResources.resTelconstPlaceHolder : self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 44),
FaxWizardDialogResources.resEmailconstPlaceHolder : self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 45),
FaxWizardDialogResources.resConsist1PlaceHolder : self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 46),
FaxWizardDialogResources.resConsist2PlaceHolder : self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 47),
FaxWizardDialogResources.resConsist3PlaceHolder : self.getResText(
FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 48)}
self.loadRoadmapResources()
self.loadSalutationResources()
self.loadGreetingResources()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment