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

pywizards: simplify paths handling

Change-Id: I436ca81e180d595e018811823e8b77c8b675bef5
üst ebb26385
......@@ -81,7 +81,8 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
self.agenda.readConfiguration(root, "cp_")
self.templateConsts = TemplateConsts
self.initializePaths()
# initialize the agenda template
self.agendaTemplate = AgendaDocument(
self.xMSF, self.agenda, self.resources,
......@@ -103,7 +104,6 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
self.topicsControl = TopicsControl(self, self.xMSF, self.agenda)
self.initializePaths()
#special Control for setting the save Path:
self.insertPathSelectionControl()
......@@ -143,15 +143,6 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
self.myPathSelection.sDefaultFilter = "writer8_template"
self.myPathSelection.addSelectionListener(self)
def initializePaths(self):
try:
self.sTemplatePath = FileAccess.getOfficePath2(
self.xMSF, "Template", "share", "/wizard")
self.sUserTemplatePath = FileAccess.getOfficePath2(
self.xMSF, "Template", "user", "")
except NoValidPathException:
traceback.print_exc()
'''
bind controls to the agenda member (DataAware model)
'''
......@@ -227,10 +218,7 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
def initializeTemplates(self):
try:
self.sTemplatePath = FileAccess.getOfficePath2(
self.xMSF, "Template", "share", "/wizard")
sAgendaPath = FileAccess.combinePaths(
self.xMSF, self.sTemplatePath, "/wizard/agenda")
sAgendaPath = self.sTemplatePath + "/wizard/agenda"
self.agendaTemplates = FileAccess.getFolderTitles(
self.xMSF, "aw", sAgendaPath)
return True
......
......@@ -16,10 +16,6 @@
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
import traceback
from .NoValidPathException import NoValidPathException
from com.sun.star.ucb import CommandAbortedException
from com.sun.star.awt.VclWindowPeerAttribute import OK, YES_NO
'''
This class delivers static convenience methods
......@@ -40,109 +36,6 @@ class FileAccess(object):
self.filenameConverter = xmsf.createInstance(
"com.sun.star.ucb.FileContentProvider")
@classmethod
def deleteLastSlashfromUrl(self, _sPath):
if _sPath.endswith("/"):
return _sPath[:-1]
else:
return _sPath
'''
Further information on arguments value see in OO Developer Guide,
chapter 6.2.7
@param xMSF
@param sPath
@param xSimpleFileAccess
@return the respective path of the office application.
A probable following "/" at the end is trimmed.
'''
@classmethod
def getOfficePath(self, xMSF, sPath, xSimpleFileAccess):
try:
ResultPath = ""
xInterface = xMSF.createInstance("com.sun.star.util.PathSettings")
ResultPath = str(Helper.getUnoPropertyValue(xInterface, sPath))
ResultPath = self.deleteLastSlashfromUrl(ResultPath)
return ResultPath
except Exception:
traceback.print_exc()
return ""
'''
Further information on arguments value see in OO Developer Guide,
chapter 6.2.7
@param xMSF
@param sPath
@param sType use "share" or "user". Set to ""
f not needed eg for the WorkPath;
In the return Officepath a possible slash at the end is cut off
@param sSearchDir
@return
@throws NoValidPathException
'''
@classmethod
def getOfficePath2(self, xMSF, sPath, sType, sSearchDir):
#This method currently only works with sPath="Template"
bexists = False
try:
xPathInterface = xMSF.createInstance(
"com.sun.star.util.PathSettings")
ResultPath = ""
ReadPaths = ()
xUcbInterface = xMSF.createInstance(
"com.sun.star.ucb.SimpleFileAccess")
Template_writable = xPathInterface.getPropertyValue(
sPath + "_writable")
Template_internal = xPathInterface.getPropertyValue(
sPath + "_internal")
Template_user = xPathInterface.getPropertyValue(
sPath + "_user")
if not hasattr(Template_internal, '__dict__'):
ReadPaths = ReadPaths + Template_internal
if not hasattr(Template_user, '__dict__'):
ReadPaths = ReadPaths + Template_user
ReadPaths = ReadPaths + (Template_writable,)
if sType.lower() == "user":
ResultPath = Template_writable
bexists = True
else:
#find right path using the search sub path
for i in ReadPaths:
tmpPath = i + sSearchDir
if xUcbInterface.exists(tmpPath):
ResultPath = i
bexists = True
break
ResultPath = self.deleteLastSlashfromUrl(ResultPath)
except Exception:
traceback.print_exc()
ResultPath = ""
if not bexists:
raise NoValidPathException (xMSF, "");
return ResultPath
@classmethod
def combinePaths(self, xMSF, _sFirstPath, _sSecondPath):
bexists = False
ReturnPath = ""
try:
xUcbInterface = xMSF.createInstance(
"com.sun.star.ucb.SimpleFileAccess")
ReturnPath = _sFirstPath + _sSecondPath
bexists = xUcbInterface.exists(ReturnPath)
except Exception:
traceback.print_exc()
return ""
if not bexists:
raise NoValidPathException (xMSF, "");
return ReturnPath
@classmethod
def getFolderTitles(self, xMSF, FilterName, FolderName, resDict=None):
#Returns and ordered dict containing the template's name and path
......@@ -221,35 +114,22 @@ class FileAccess(object):
'''
return the filename out of a system-dependent path
@param path
@return
'''
@classmethod
def getPathFilename(self, path):
return self.getFilename(path, File.separator)
'''
@author rpiterman
@param path
@param pathSeparator
@return
'''
@classmethod
def getFilename(self, path, pathSeparator = "/"):
return path.split(pathSeparator)[-1]
'''
@param url
@return the parent dir of the given url.
if the path points to file, gives the directory in which the file is.
'''
@classmethod
def getParentDir(self, url):
while url[-1] == "/":
url = hello[:-1]
return url[:url.rfind("/")]
@classmethod
......
......@@ -59,8 +59,6 @@ class FaxWizardDialogImpl(FaxWizardDialog):
self.lstPrivateStylePos = None
self.bSaveSuccess = False
self.filenameChanged = False
self.UserTemplatePath = ""
self.sTemplatePath = ""
@classmethod
def main(self):
......@@ -97,7 +95,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
self.initializeSalutation()
self.initializeGreeting()
self.initializeCommunication()
self.__initializePaths()
self.initializePaths()
#special Control for setting the save Path:
self.insertPathSelectionControl()
......@@ -251,25 +249,14 @@ class FaxWizardDialogImpl(FaxWizardDialog):
5, 97, 70, 205, 45, self.resources.reslblTemplatePath_value,
True, HelpIds.getHelpIdString(HID + 34),
HelpIds.getHelpIdString(HID + 35))
self.myPathSelection.sDefaultDirectory = self.UserTemplatePath
self.myPathSelection.sDefaultDirectory = self.sUserTemplatePath
self.myPathSelection.sDefaultName = "myFaxTemplate.ott"
self.myPathSelection.sDefaultFilter = "writer8_template"
self.myPathSelection.addSelectionListener(self)
def __initializePaths(self):
try:
self.sTemplatePath = FileAccess.getOfficePath2(self.xMSF,
"Template", "share", "/wizard")
self.UserTemplatePath = FileAccess.getOfficePath2(self.xMSF,
"Template", "user", "")
except NoValidPathException:
traceback.print_exc()
def initializeTemplates(self, xMSF):
try:
self.sFaxPath = FileAccess.combinePaths(xMSF, self.sTemplatePath,
"/wizard/fax")
self.sWorkPath = FileAccess.getOfficePath2(xMSF, "Work", "", "")
self.sFaxPath = self.sTemplatePath + "/wizard/fax"
self.BusinessFiles = FileAccess.getFolderTitles(xMSF, "bus",
self.sFaxPath, self.resources.dictBusinessTemplate)
self.PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri",
......
......@@ -99,7 +99,8 @@ class LetterWizardDialogImpl(LetterWizardDialog):
self.buildStep4()
self.buildStep5()
self.buildStep6()
self.__initializePaths()
self.initializePaths()
self.initializeSalutation()
self.initializeGreeting()
......@@ -768,19 +769,8 @@ class LetterWizardDialogImpl(LetterWizardDialog):
else:
return None
def __initializePaths(self):
try:
self.sTemplatePath = \
FileAccess.getOfficePath2(
self.xMSF, "Template", "share", "/wizard")
self.sUserTemplatePath = \
FileAccess.getOfficePath2(self.xMSF, "Template", "user", "")
except NoValidPathException:
traceback.print_exc()
def initializeTemplates(self, xMSF):
sLetterPath = FileAccess.combinePaths(
xMSF, self.sTemplatePath, "/../common/wizard/letter")
sLetterPath = self.sTemplatePath + "/../common/wizard/letter"
self.BusinessFiles = \
FileAccess.getFolderTitles(
xMSF, "bus", sLetterPath, self.resources.dictBusinessTemplate)
......
......@@ -148,7 +148,7 @@ class TextDocument(object):
myFieldHandler = TextFieldHandler(self.xMSF, self.xTextDocument)
myFieldHandler.updateDocInfoFields()
return self.xTextDocument
def getPageSize(self):
try:
xNameAccess = self.xTextDocument.StyleFamilies
......
......@@ -102,6 +102,15 @@ class WizardDialog(UnoDialog2):
traceback.print_exc()
return -1
def initializePaths(self):
xPropertySet = \
self.xMSF.createInstance("com.sun.star.util.PathSettings")
self.sTemplatePath = \
xPropertySet.getPropertyValue("Template_user")[0]
self.sUserTemplatePath = \
xPropertySet.getPropertyValue("Template_writable")
def addRoadmap(self):
try:
iDialogHeight = self.xDialogModel.Height
......@@ -353,8 +362,6 @@ class WizardDialog(UnoDialog2):
except Exception:
traceback.print_exc()
#TODO discuss with rp
def getNextAvailableStep(self):
if self.isRoadmapComplete():
i = self.nNewStep + 1
......
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