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

pyfax: cleanup ugly code

Change-Id: I6141e544391c6723e7d2949771be1bd5a1768163
üst ee70864a
......@@ -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):
......
......@@ -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()
......
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