[Libreoffice-commits] .: 3 commits - wizards/com

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 3 14:02:16 PDT 2012


 wizards/com/sun/star/wizards/common/FileAccess.py            |   59 ++--------
 wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py      |   29 ++---
 wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py |   63 ++++++-----
 3 files changed, 68 insertions(+), 83 deletions(-)

New commits:
commit 60211510d3a1c2f96bb6f6e96895f003d6beef74
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Wed Oct 3 22:59:03 2012 +0200

    pywizard: localise listbox at runtime
    
    Change-Id: I667976f7f76776cc3ef76abe9935271a7a0c2923

diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py
index a213b7e..0364a0d 100644
--- a/wizards/com/sun/star/wizards/common/FileAccess.py
+++ b/wizards/com/sun/star/wizards/common/FileAccess.py
@@ -307,7 +307,7 @@ class FileAccess(object):
             return False
 
     @classmethod
-    def getFolderTitles(self, xMSF, FilterName, FolderName):
+    def getFolderTitles(self, xMSF, FilterName, FolderName, resDict):
         #Returns and ordered dict containing the template's name and path
         
         LocLayoutFiles = {}
@@ -321,12 +321,17 @@ class FileAccess(object):
                 FilterName = None
             else:
                 FilterName += "-"
-                
+            
             for i in nameList:
                 fileName = self.getFilename(i)
                 if FilterName is None or fileName.startswith(FilterName):
                     xDocInterface.loadFromMedium(i, tuple())
-                    LocLayoutFiles[xDocInterface.Title] = i
+                    if xDocInterface.Title in resDict:
+                        # localise string at runtime
+                        title = resDict[xDocInterface.Title]
+                    else:
+                        title = xDocInterface.Title
+                    LocLayoutFiles[title] = i
 
         except Exception, exception:
             traceback.print_exc()
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
index b128a95..ae73800 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
@@ -299,9 +299,9 @@ class FaxWizardDialogImpl(FaxWizardDialog):
                 "/wizard/fax")
             self.sWorkPath = FileAccess.getOfficePath2(xMSF, "Work", "", "")
             self.BusinessFiles = FileAccess.getFolderTitles(xMSF, "bus",
-                self.sFaxPath)
+                self.sFaxPath, self.resources.dictBusinessTemplate)
             self.PrivateFiles = FileAccess.getFolderTitles(xMSF, "pri",
-                self.sFaxPath)
+                self.sFaxPath, self.resources.dictPrivateTemplate)
             
             self.setControlProperty("lstBusinessStyle", "StringItemList",
                 tuple(self.BusinessFiles.keys()))
@@ -327,17 +327,17 @@ class FaxWizardDialogImpl(FaxWizardDialog):
         self.myFaxDoc.updateDateFields()
 
     def initializeSalutation(self):
-        #'Saludation' dropdown list
+        #'Saludation' listbox
         self.setControlProperty("lstSalutation", "StringItemList",
             tuple(self.resources.SalutationLabels))
 
     def initializeGreeting(self):
-        #'Complimentary Close' dropdown list
+        #'Complimentary Close' listbox
         self.setControlProperty("lstGreeting", "StringItemList",
             tuple(self.resources.GreetingLabels))
 
     def initializeCommunication(self):
-        #'Type of message' dropdown list
+        #'Type of message' listbox
         self.setControlProperty("lstCommunicationType", "StringItemList",
             tuple(self.resources.CommunicationLabels))
 
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
index 33bda56..7cf3703 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
@@ -140,6 +140,26 @@ class FaxWizardDialogResources(Resource):
             FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 47),
         FaxWizardDialogResources.resConsist3PlaceHolder : self.getResText(
             FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 48)}
+
+        #Create a dictionary for localising the private template
+        self.dictPrivateTemplate = {
+        "Bottle" : self.getResText(
+            FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 49),
+        "Lines" : self.getResText(
+            FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 50),
+        "Marine" : self.getResText(
+            FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 51)}
+
+        #Create a dictionary for localising the business template
+        self.dictBusinessTemplate = {
+        "Classic Fax" : self.getResText(
+            FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 52),
+        "Classic Fax from Private" : self.getResText(
+            FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 53),
+        "Modern Fax" : self.getResText(
+            FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 54),
+        "Modern Fax from Private" : self.getResText(
+            FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 55)}
         
         #Common Resources
         self.resOverwriteWarning = self.getResText(
commit 789c48251add484f3c912b700b418a733385181d
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Wed Oct 3 22:04:16 2012 +0200

    pyfax: cleanup ugly code
    
    Change-Id: I6141e544391c6723e7d2949771be1bd5a1768163

diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py
index 6b91bc4..a213b7e 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 b678f38..b128a95 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()
 
commit ee70864a632e2abf219fe514b8736d887aba2602
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Wed Oct 3 20:53:37 2012 +0200

    pyfax: Cleanup resources
    
    Change-Id: I68059a9ae31d22be3f1390eb065f13f98df8116b

diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
index 249c249..b678f38 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
@@ -327,25 +327,28 @@ class FaxWizardDialogImpl(FaxWizardDialog):
         self.myFaxDoc.updateDateFields()
 
     def initializeSalutation(self):
+        #'Saludation' dropdown list
         self.setControlProperty("lstSalutation", "StringItemList",
-            self.resources.SalutationLabels)
+            tuple(self.resources.SalutationLabels))
 
     def initializeGreeting(self):
+        #'Complimentary Close' dropdown list
         self.setControlProperty("lstGreeting", "StringItemList",
-            self.resources.GreetingLabels)
+            tuple(self.resources.GreetingLabels))
 
     def initializeCommunication(self):
+        #'Type of message' dropdown list
         self.setControlProperty("lstCommunicationType", "StringItemList",
-            self.resources.CommunicationLabels)
+            tuple(self.resources.CommunicationLabels))
 
     def __setDefaultForGreetingAndSalutationAndCommunication(self):
-        if self.lstSalutation.Text == "":
+        if not self.lstSalutation.Text:
             self.lstSalutation.setText(self.resources.SalutationLabels[0])
 
-        if self.lstGreeting.Text == "":
+        if not self.lstGreeting.Text:
             self.lstGreeting.setText(self.resources.GreetingLabels[0])
 
-        if self.lstCommunicationType.Text == "":
+        if not self.lstCommunicationType.Text:
             self.lstCommunicationType.setText( \
                 self.resources.CommunicationLabels[0])
 
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
index ef60232..33bda56 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogResources.py
@@ -35,17 +35,13 @@ class FaxWizardDialogResources(Resource):
     resConsist2PlaceHolder = "#consist2#"
     resConsist3PlaceHolder = "#consist3#"
 
-
     def __init__(self, xmsf):
         super(FaxWizardDialogResources,self).__init__(xmsf,
             FaxWizardDialogResources.MODULE_NAME)
-        self.RoadmapLabels = ()
-        self.SalutationLabels = ()
-        self.GreetingLabels = ()
-        self.CommunicationLabels = ()
-
-        #Delete the String, uncomment the self.getResText method
-
+        self.RoadmapLabels = []
+        self.SalutationLabels = []
+        self.GreetingLabels = []
+        self.CommunicationLabels = []
 
         self.resFaxWizardDialog_title = self.getResText(
             FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 1)
@@ -145,40 +141,37 @@ class FaxWizardDialogResources(Resource):
         FaxWizardDialogResources.resConsist3PlaceHolder : self.getResText(
             FaxWizardDialogResources.RID_FAXWIZARDDIALOG_START + 48)}
         
-        self.loadRoadmapResources()
-        self.loadSalutationResources()
-        self.loadGreetingResources()
-        self.loadCommunicationResources()
-        self.loadCommonResources()
-
-    def loadCommonResources(self):
+        #Common Resources
         self.resOverwriteWarning = self.getResText(
             FaxWizardDialogResources.RID_RID_COMMON_START + 19)
         self.resTemplateDescription = self.getResText(
             FaxWizardDialogResources.RID_RID_COMMON_START + 20)
+        
+        self.loadRoadmapResources()
+        self.loadSalutationResources()
+        self.loadGreetingResources()
+        self.loadCommunicationResources()
 
     def loadRoadmapResources(self):
         for i in xrange(5):
-            self.RoadmapLabels = self.RoadmapLabels + ((self.getResText(
+            self.RoadmapLabels.append(self.getResText(
                 FaxWizardDialogResources.RID_FAXWIZARDROADMAP_START + \
-                + i + 1)),)
+                + i + 1))
 
     def loadSalutationResources(self):
-        i = 1
         for i in xrange(4):
-            self.SalutationLabels = self.SalutationLabels + ((self.getResText(
+            self.SalutationLabels.append(self.getResText(
                 FaxWizardDialogResources.RID_FAXWIZARDSALUTATION_START + \
-                i + 1)),)
+                i + 1))
 
     def loadGreetingResources(self):
         for i in xrange(4):
-            self.GreetingLabels = self.GreetingLabels + ((self.getResText(
+            self.GreetingLabels.append(self.getResText(
                 FaxWizardDialogResources.RID_FAXWIZARDGREETING_START + \
-                i +1 )),)
+                i + 1))
 
     def loadCommunicationResources(self):
         for i in xrange(3):
-            self.CommunicationLabels = \
-            self.CommunicationLabels + ((self.getResText(
+            self.CommunicationLabels.append(self.getResText(
                 FaxWizardDialogResources.RID_FAXWIZARDCOMMUNICATION_START + \
-                i + 1)),)
+                i + 1))


More information about the Libreoffice-commits mailing list