diff options
author | Xisco Fauli <anistenis@gmail.com> | 2012-10-03 22:04:16 +0200 |
---|---|---|
committer | Xisco Fauli <anistenis@gmail.com> | 2012-10-03 23:01:30 +0200 |
commit | 789c48251add484f3c912b700b418a733385181d (patch) | |
tree | 47783e6d21544ec450cc72c19b2e9c3b10c1950d /wizards | |
parent | pyfax: Cleanup resources (diff) | |
download | core-789c48251add484f3c912b700b418a733385181d.tar.gz core-789c48251add484f3c912b700b418a733385181d.zip |
pyfax: cleanup ugly code
Change-Id: I6141e544391c6723e7d2949771be1bd5a1768163
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/com/sun/star/wizards/common/FileAccess.py | 52 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py | 10 |
2 files changed, 13 insertions, 49 deletions
diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py index 6b91bc4cbf48..a213b7e4f444 100644 --- a/wizards/com/sun/star/wizards/common/FileAccess.py +++ b/wizards/com/sun/star/wizards/common/FileAccess.py @@ -17,6 +17,7 @@ # import traceback import types +from collections import OrderedDict from os import path as osPath from .NoValidPathException import NoValidPathException @@ -36,11 +37,6 @@ These Convenince methods include mainly Exception-handling. ''' class FileAccess(object): - ''' - @param xMSF - @param sPath - @param sAddPath - ''' @classmethod def addOfficePath(self, xMSF, sPath, sAddPath): @@ -312,62 +308,30 @@ class FileAccess(object): @classmethod def getFolderTitles(self, xMSF, FilterName, FolderName): - LocLayoutFiles = [[2],[]] + #Returns and ordered dict containing the template's name and path + + LocLayoutFiles = {} try: xDocInterface = xMSF.createInstance( "com.sun.star.document.DocumentProperties") xInterface = xMSF.createInstance( "com.sun.star.ucb.SimpleFileAccess") nameList = xInterface.getFolderContents(FolderName, False) - TitleVector = [] - NameVector = [] if FilterName is None or FilterName == "": FilterName = None else: - FilterName = FilterName + "-" - fileName = "" - NameVectorAppend = NameVector.append - TitleVectorAppend = TitleVector.append + FilterName += "-" + for i in nameList: fileName = self.getFilename(i) if FilterName is None or fileName.startswith(FilterName): xDocInterface.loadFromMedium(i, tuple()) - NameVectorAppend(i) - TitleVectorAppend(xDocInterface.Title) - - LocLayoutFiles[1] = NameVector - LocLayoutFiles[0] = TitleVector + LocLayoutFiles[xDocInterface.Title] = i except Exception, exception: traceback.print_exc() - return self.__bubblesortList(LocLayoutFiles) - - ''' - This function bubble sorts an array of with 2 dimensions. - The default sorting order is the first dimension - Only if sort2ndValue is True the second dimension is - the relevant for the sorting order - ''' - - @classmethod - def __bubblesortList(self, SortList): - SortCount = len(SortList[0]) - DimCount = len(SortList) - for i in xrange(SortCount): - for t in xrange(SortCount - i - 1): - if SortList[0][t] > SortList[0][t + 1]: - for k in xrange(DimCount): - DisplayDummy = SortList[k][t]; - SortList[k][t] = SortList[k][t + 1]; - SortList[k][t + 1] = DisplayDummy - return SortList - ''' - We search in all given path for a given file - @param _sPath - @param _sPath2 - @return - ''' + return OrderedDict(sorted(LocLayoutFiles.items(), key=lambda t: t[0])) @classmethod def addPath(self, _sPath, _sPath2): diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py index b678f38a0dce..b128a95ceab0 100644 --- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py +++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py @@ -302,15 +302,15 @@ class FaxWizardDialogImpl(FaxWizardDialog): self.sFaxPath) self.PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri", self.sFaxPath) + self.setControlProperty("lstBusinessStyle", "StringItemList", - tuple(self.BusinessFiles[0])) + tuple(self.BusinessFiles.keys())) self.setControlProperty("lstPrivateStyle", "StringItemList", - tuple(self.PrivateFiles[0])) + tuple(self.PrivateFiles.keys())) self.setControlProperty("lstBusinessStyle", "SelectedItems", (0,)) self.setControlProperty("lstPrivateStyle", "SelectedItems" , (0,)) return True except NoValidPathException, e: - # TODO Auto-generated catch block traceback.print_exc() return False @@ -457,7 +457,7 @@ class FaxWizardDialogImpl(FaxWizardDialog): if FaxWizardDialogImpl.lstBusinessStylePos is not selectedItemPos: FaxWizardDialogImpl.lstBusinessStylePos = selectedItemPos TextDocument.xTextDocument = self.myFaxDoc.loadAsPreview( - self.BusinessFiles[1][selectedItemPos], False) + self.BusinessFiles.values()[selectedItemPos], False) self.initializeElements() self.setElements() self.drawConstants() @@ -482,7 +482,7 @@ class FaxWizardDialogImpl(FaxWizardDialog): if FaxWizardDialogImpl.lstPrivateStylePos is not selectedItemPos: FaxWizardDialogImpl.lstPrivateStylePos = selectedItemPos TextDocument.xTextDocument = self.myFaxDoc.loadAsPreview( - self.PrivateFiles[1][selectedItemPos], False) + self.PrivateFiles.values()[selectedItemPos], False) self.initializeElements() self.setElements() |