diff options
author | Xisco Fauli <anistenis@gmail.com> | 2013-02-11 22:01:25 +0100 |
---|---|---|
committer | Xisco Fauli <anistenis@gmail.com> | 2013-02-11 22:03:14 +0100 |
commit | 57041602e2e0c5d1035359108ff1237a324c39d6 (patch) | |
tree | e21d0c4e34caa6c8e0decc81bd0132f2309e225e | |
parent | ebb263856c40d019c6aa9f5c281b33d26578004e (diff) |
pywizards: simplify paths handling
Change-Id: I436ca81e180d595e018811823e8b77c8b675bef5
6 files changed, 19 insertions, 167 deletions
diff --git a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py index 2c3e288bba87..72f3b753d33a 100644 --- a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py +++ b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py @@ -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 diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py index fd7a97cd9ca5..409c15c4c267 100644 --- a/wizards/com/sun/star/wizards/common/FileAccess.py +++ b/wizards/com/sun/star/wizards/common/FileAccess.py @@ -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 @@ -41,109 +37,6 @@ class FileAccess(object): "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 diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py index 0c5ed84d422c..ead90e178806 100644 --- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py +++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py @@ -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", diff --git a/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py b/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py index a7ff8f668275..f3b55fe5b00e 100644 --- a/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py +++ b/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py @@ -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) diff --git a/wizards/com/sun/star/wizards/text/TextDocument.py b/wizards/com/sun/star/wizards/text/TextDocument.py index 550297825d01..aae3d5981fe3 100644 --- a/wizards/com/sun/star/wizards/text/TextDocument.py +++ b/wizards/com/sun/star/wizards/text/TextDocument.py @@ -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 diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.py b/wizards/com/sun/star/wizards/ui/WizardDialog.py index 52597a15d5d9..534122afac49 100644 --- a/wizards/com/sun/star/wizards/ui/WizardDialog.py +++ b/wizards/com/sun/star/wizards/ui/WizardDialog.py @@ -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 |