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 @@ ...@@ -17,6 +17,7 @@
# #
import traceback import traceback
import types import types
from collections import OrderedDict
from os import path as osPath from os import path as osPath
from .NoValidPathException import NoValidPathException from .NoValidPathException import NoValidPathException
...@@ -36,11 +37,6 @@ These Convenince methods include mainly Exception-handling. ...@@ -36,11 +37,6 @@ These Convenince methods include mainly Exception-handling.
''' '''
class FileAccess(object): class FileAccess(object):
'''
@param xMSF
@param sPath
@param sAddPath
'''
@classmethod @classmethod
def addOfficePath(self, xMSF, sPath, sAddPath): def addOfficePath(self, xMSF, sPath, sAddPath):
...@@ -312,62 +308,30 @@ class FileAccess(object): ...@@ -312,62 +308,30 @@ class FileAccess(object):
@classmethod @classmethod
def getFolderTitles(self, xMSF, FilterName, FolderName): def getFolderTitles(self, xMSF, FilterName, FolderName):
LocLayoutFiles = [[2],[]] #Returns and ordered dict containing the template's name and path
LocLayoutFiles = {}
try: try:
xDocInterface = xMSF.createInstance( xDocInterface = xMSF.createInstance(
"com.sun.star.document.DocumentProperties") "com.sun.star.document.DocumentProperties")
xInterface = xMSF.createInstance( xInterface = xMSF.createInstance(
"com.sun.star.ucb.SimpleFileAccess") "com.sun.star.ucb.SimpleFileAccess")
nameList = xInterface.getFolderContents(FolderName, False) nameList = xInterface.getFolderContents(FolderName, False)
TitleVector = []
NameVector = []
if FilterName is None or FilterName == "": if FilterName is None or FilterName == "":
FilterName = None FilterName = None
else: else:
FilterName = FilterName + "-" FilterName += "-"
fileName = ""
NameVectorAppend = NameVector.append
TitleVectorAppend = TitleVector.append
for i in nameList: for i in nameList:
fileName = self.getFilename(i) fileName = self.getFilename(i)
if FilterName is None or fileName.startswith(FilterName): if FilterName is None or fileName.startswith(FilterName):
xDocInterface.loadFromMedium(i, tuple()) xDocInterface.loadFromMedium(i, tuple())
NameVectorAppend(i) LocLayoutFiles[xDocInterface.Title] = i
TitleVectorAppend(xDocInterface.Title)
LocLayoutFiles[1] = NameVector
LocLayoutFiles[0] = TitleVector
except Exception, exception: except Exception, exception:
traceback.print_exc() traceback.print_exc()
return self.__bubblesortList(LocLayoutFiles) return OrderedDict(sorted(LocLayoutFiles.items(), key=lambda t: t[0]))
'''
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
'''
@classmethod @classmethod
def addPath(self, _sPath, _sPath2): def addPath(self, _sPath, _sPath2):
......
...@@ -302,15 +302,15 @@ class FaxWizardDialogImpl(FaxWizardDialog): ...@@ -302,15 +302,15 @@ class FaxWizardDialogImpl(FaxWizardDialog):
self.sFaxPath) self.sFaxPath)
self.PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri", self.PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri",
self.sFaxPath) self.sFaxPath)
self.setControlProperty("lstBusinessStyle", "StringItemList", self.setControlProperty("lstBusinessStyle", "StringItemList",
tuple(self.BusinessFiles[0])) tuple(self.BusinessFiles.keys()))
self.setControlProperty("lstPrivateStyle", "StringItemList", self.setControlProperty("lstPrivateStyle", "StringItemList",
tuple(self.PrivateFiles[0])) tuple(self.PrivateFiles.keys()))
self.setControlProperty("lstBusinessStyle", "SelectedItems", (0,)) self.setControlProperty("lstBusinessStyle", "SelectedItems", (0,))
self.setControlProperty("lstPrivateStyle", "SelectedItems" , (0,)) self.setControlProperty("lstPrivateStyle", "SelectedItems" , (0,))
return True return True
except NoValidPathException, e: except NoValidPathException, e:
# TODO Auto-generated catch block
traceback.print_exc() traceback.print_exc()
return False return False
...@@ -457,7 +457,7 @@ class FaxWizardDialogImpl(FaxWizardDialog): ...@@ -457,7 +457,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
if FaxWizardDialogImpl.lstBusinessStylePos is not selectedItemPos: if FaxWizardDialogImpl.lstBusinessStylePos is not selectedItemPos:
FaxWizardDialogImpl.lstBusinessStylePos = selectedItemPos FaxWizardDialogImpl.lstBusinessStylePos = selectedItemPos
TextDocument.xTextDocument = self.myFaxDoc.loadAsPreview( TextDocument.xTextDocument = self.myFaxDoc.loadAsPreview(
self.BusinessFiles[1][selectedItemPos], False) self.BusinessFiles.values()[selectedItemPos], False)
self.initializeElements() self.initializeElements()
self.setElements() self.setElements()
self.drawConstants() self.drawConstants()
...@@ -482,7 +482,7 @@ class FaxWizardDialogImpl(FaxWizardDialog): ...@@ -482,7 +482,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
if FaxWizardDialogImpl.lstPrivateStylePos is not selectedItemPos: if FaxWizardDialogImpl.lstPrivateStylePos is not selectedItemPos:
FaxWizardDialogImpl.lstPrivateStylePos = selectedItemPos FaxWizardDialogImpl.lstPrivateStylePos = selectedItemPos
TextDocument.xTextDocument = self.myFaxDoc.loadAsPreview( TextDocument.xTextDocument = self.myFaxDoc.loadAsPreview(
self.PrivateFiles[1][selectedItemPos], False) self.PrivateFiles.values()[selectedItemPos], False)
self.initializeElements() self.initializeElements()
self.setElements() 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