[Libreoffice-commits] .: Branch 'feature/gsoc2011_wizards' - wizards/com

Xisco Fauli xfauli at kemper.freedesktop.org
Sun Jun 19 17:45:09 PDT 2011


 wizards/com/sun/star/wizards/common/ConfigGroup.py      |    5 +-
 wizards/com/sun/star/wizards/common/FileAccess.py       |   10 ----
 wizards/com/sun/star/wizards/common/Helper.py           |   17 ++-----
 wizards/com/sun/star/wizards/common/NumberFormatter.py  |    1 
 wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py |   38 ++++++----------
 wizards/com/sun/star/wizards/text/TextDocument.py       |    7 ++
 wizards/com/sun/star/wizards/text/TextFieldHandler.py   |   33 ++++++-------
 wizards/com/sun/star/wizards/ui/PathSelection.py        |    2 
 wizards/com/sun/star/wizards/ui/UnoDialog.py            |    2 
 wizards/com/sun/star/wizards/ui/WizardDialog.py         |    7 +-
 10 files changed, 50 insertions(+), 72 deletions(-)

New commits:
commit cf6868c5064ef9adce34e45c9653ac138e790e6f
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Mon Jun 20 02:42:24 2011 +0200

    a bit of optimitation

diff --git a/wizards/com/sun/star/wizards/common/ConfigGroup.py b/wizards/com/sun/star/wizards/common/ConfigGroup.py
index 2cd2618..a5824e8 100644
--- a/wizards/com/sun/star/wizards/common/ConfigGroup.py
+++ b/wizards/com/sun/star/wizards/common/ConfigGroup.py
@@ -16,13 +16,14 @@ class ConfigGroup(ConfigNode):
     def writeField(self, field, configView, prefix):
         propertyName = field[len(prefix):]
         field = getattr(self,field)
-        fieldType = type(field)
+
         if isinstance(field, ConfigNode):
             pass
-            #COMMENTED
+            #print configView
             #childView = Configuration.addConfigNode(configView, propertyName)
             #self.writeConfiguration(childView, prefix)
         else:
+            #print type(field)
             Configuration.Set(self.convertValue(field), propertyName,
                 configView)
 
diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py
index 6f8e16b..8c58091 100644
--- a/wizards/com/sun/star/wizards/common/FileAccess.py
+++ b/wizards/com/sun/star/wizards/common/FileAccess.py
@@ -109,15 +109,9 @@ class FileAccess(object):
             Template_user = xPathInterface.getPropertyValue(
                 sPath + "_user")
             if type(Template_internal) is not types.InstanceType:
-                if isinstance(Template_internal,tuple):
-                    ReadPaths = ReadPaths + Template_internal
-                else:
-                    ReadPaths = ReadPaths + (Template_internal,)
+                ReadPaths = ReadPaths + Template_internal
             if type(Template_user) is not types.InstanceType:
-                if isinstance(Template_user,tuple):
-                    ReadPaths = ReadPaths + Template_user
-                else:
-                    ReadPaths = ReadPaths + (Template_internal,)
+                ReadPaths = ReadPaths + Template_user
             ReadPaths = ReadPaths + (Template_writable,)
             if sType.lower() == "user":
                 ResultPath = Template_writable
diff --git a/wizards/com/sun/star/wizards/common/Helper.py b/wizards/com/sun/star/wizards/common/Helper.py
index 32cdb72..f2c6d69 100644
--- a/wizards/com/sun/star/wizards/common/Helper.py
+++ b/wizards/com/sun/star/wizards/common/Helper.py
@@ -42,14 +42,11 @@ class Helper(object):
 
     @classmethod
     def getPropertyValue(self, CurPropertyValue, PropertyName):
-        MaxCount = len(CurPropertyValue)
-        i = 0
-        while i < MaxCount:
-            if CurPropertyValue[i] is not None:
-                if CurPropertyValue[i].Name.equals(PropertyName):
-                    return CurPropertyValue[i].Value
-
-            i += 1
+        for i in  CurPropertyValue:
+            if i is not None:
+                if i.Name == PropertyName:
+                    return i.Value
+
         raise RuntimeException()
 
     @classmethod
@@ -117,11 +114,9 @@ class Helper(object):
                 uno.invoke(xMultiPSetLst, "setPropertyValues",
                     (PropertyNames, PropertyValues))
             else:
-                i = 0
-                while i < len(PropertyNames):
+                for i in xrange(len(PropertyNames)):
                     self.setUnoPropertyValue(xMultiPSetLst, PropertyNames[i],
                         PropertyValues[i])
-                    i += 1
 
         except Exception, e:
             traceback.print_exc()
diff --git a/wizards/com/sun/star/wizards/common/NumberFormatter.py b/wizards/com/sun/star/wizards/common/NumberFormatter.py
index eff9f16..a3deb17 100644
--- a/wizards/com/sun/star/wizards/common/NumberFormatter.py
+++ b/wizards/com/sun/star/wizards/common/NumberFormatter.py
@@ -59,7 +59,6 @@ class NumberFormatter(object):
             Type, Locale())
 
     def convertNumberToString(self, _nkey, _dblValue, _xNumberFormatter=None):
-        print "yepa"
         if _xNumberFormatter is None:
             return self.xNumberFormatter.convertNumberToString(
                 _nkey, _dblValue)
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
index 58ee5ac..32ce4b8 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
@@ -523,6 +523,9 @@ class FaxWizardDialogImpl(FaxWizardDialog):
             PropertyNames.PROPERTY_ENABLED, True)
         self.setControlProperty("txtSenderFax",
             PropertyNames.PROPERTY_ENABLED, True)
+
+        self.myFieldHandler = TextFieldHandler(self.myFaxDoc.xMSF,
+            self.xTextDocument)
         self.txtSenderNameTextChanged()
         self.txtSenderStreetTextChanged()
         self.txtSenderPostCodeTextChanged()
@@ -545,39 +548,28 @@ class FaxWizardDialogImpl(FaxWizardDialog):
         self.bEditTemplate = True
 
     def txtSenderNameTextChanged(self):
-        myFieldHandler = TextFieldHandler(self.myFaxDoc.xMSF,
-            self.xTextDocument)
-        myFieldHandler.changeUserFieldContent("Company",
-            self.txtSenderName.Text)
+        self.myFieldHandler.changeUserFieldContent(
+            "Company", self.txtSenderName.Text)
 
     def txtSenderStreetTextChanged(self):
-        myFieldHandler = TextFieldHandler(self.myFaxDoc.xMSF,
-            self.xTextDocument)
-        myFieldHandler.changeUserFieldContent("Street",
-            self.txtSenderStreet.Text)
+        self.myFieldHandler.changeUserFieldContent(
+            "Street", self.txtSenderStreet.Text)
 
     def txtSenderCityTextChanged(self):
-        myFieldHandler = TextFieldHandler(self.myFaxDoc.xMSF,
-            self.xTextDocument)
-        myFieldHandler.changeUserFieldContent("City",
-            self.txtSenderCity.Text)
+        self.myFieldHandler.changeUserFieldContent(
+            "City", self.txtSenderCity.Text)
 
     def txtSenderPostCodeTextChanged(self):
-        myFieldHandler = TextFieldHandler(self.myFaxDoc.xMSF,
-            self.xTextDocument)
-        myFieldHandler.changeUserFieldContent("PostCode",
-            self.txtSenderPostCode.Text)
+        self.myFieldHandler.changeUserFieldContent(
+            "PostCode", self.txtSenderPostCode.Text)
 
     def txtSenderStateTextChanged(self):
-        myFieldHandler = TextFieldHandler(self.myFaxDoc.xMSF,
-            self.xTextDocument)
-        myFieldHandler.changeUserFieldContent(PropertyNames.PROPERTY_STATE,
-            self.txtSenderState.Text)
+        self.myFieldHandler.changeUserFieldContent(
+            PropertyNames.PROPERTY_STATE, self.txtSenderState.Text)
 
     def txtSenderFaxTextChanged(self):
-        myFieldHandler = TextFieldHandler(self.myFaxDoc.xMSF,
-            self.xTextDocument)
-        myFieldHandler.changeUserFieldContent("Fax", self.txtSenderFax.Text)
+        self.myFieldHandler.changeUserFieldContent(
+            "Fax", self.txtSenderFax.Text)
 
     #switch Elements on/off --------------------------------------------------
 
diff --git a/wizards/com/sun/star/wizards/text/TextDocument.py b/wizards/com/sun/star/wizards/text/TextDocument.py
index c432ee7..fb97048 100644
--- a/wizards/com/sun/star/wizards/text/TextDocument.py
+++ b/wizards/com/sun/star/wizards/text/TextDocument.py
@@ -124,12 +124,15 @@ class TextDocument(object):
         mode in order to avoid the 'do u want to save' box'''
         if self.xTextDocument is not None:
             try:
-                self.xTextDocument.setModified(False)
+                self.xTextDocument.Modified = False
             except PropertyVetoException, e1:
                 traceback.print_exc()
+
         self.xTextDocument = OfficeDocument.load(
             self.xFrame, sDefaultTemplate, "_self", loadValues)
+
         self.DocSize = self.getPageSize()
+
         myViewHandler = ViewHandler(self.xTextDocument, self.xTextDocument)
         try:
             myViewHandler.setViewSetting(
@@ -142,7 +145,7 @@ class TextDocument(object):
 
     def getPageSize(self):
         try:
-            xNameAccess = self.xTextDocument.getStyleFamilies()
+            xNameAccess = self.xTextDocument.StyleFamilies
             xPageStyleCollection = xNameAccess.getByName("PageStyles")
             xPageStyle = xPageStyleCollection.getByName("First Page")
             return Helper.getUnoPropertyValue(xPageStyle, "Size")
diff --git a/wizards/com/sun/star/wizards/text/TextFieldHandler.py b/wizards/com/sun/star/wizards/text/TextFieldHandler.py
index d9e3ed8..22f94a3 100644
--- a/wizards/com/sun/star/wizards/text/TextFieldHandler.py
+++ b/wizards/com/sun/star/wizards/text/TextFieldHandler.py
@@ -14,6 +14,7 @@ class TextFieldHandler(object):
     '''
 
     xTextFieldsSupplierAux = None
+    arrayTextFields = None
     dictTextFields = None
 
     def __init__(self, xMSF, xTextDocument):
@@ -73,10 +74,12 @@ class TextFieldHandler(object):
         try:
             if self.xTextFieldsSupplier.TextFields.hasElements():
                 TextFieldHandler.dictTextFields = {}
+                TextFieldHandler.arrayTextFields = []
                 xEnum = \
                     self.xTextFieldsSupplier.TextFields.createEnumeration()
                 while xEnum.hasMoreElements():
                     oTextField = xEnum.nextElement()
+                    TextFieldHandler.arrayTextFields.append(oTextField)
                     xPropertySet = oTextField.TextFieldMaster
                     if len(xPropertySet.Name) is not 0:
                         TextFieldHandler.dictTextFields[xPropertySet.Name] = \
@@ -118,47 +121,41 @@ class TextFieldHandler(object):
 
     def updateDocInfoFields(self):
         try:
-            xEnum = self.xTextFieldsSupplier.TextFields.createEnumeration()
-            while xEnum.hasMoreElements():
-                oTextField = xEnum.nextElement()
-                if oTextField.supportsService(
+            for i in TextFieldHandler.arrayTextFields:
+                if i.supportsService(
                     "com.sun.star.text.TextField.ExtendedUser"):
-                    oTextField.update()
+                    i.update()
 
-                if oTextField.supportsService(
+                if i.supportsService(
                     "com.sun.star.text.TextField.User"):
-                    oTextField.update()
+                    i.update()
 
         except Exception, e:
             traceback.print_exc()
 
     def updateDateFields(self):
         try:
-            xEnum = self.xTextFieldsSupplier.TextFields.createEnumeration()
             now = time.localtime(time.time())
             dt = DateTime()
             dt.Day = time.strftime("%d", now)
             dt.Year = time.strftime("%Y", now)
             dt.Month = time.strftime("%m", now)
             dt.Month += 1
-            while xEnum.hasMoreElements():
-                oTextField = xEnum.nextElement()
-                if oTextField.supportsService(
+            for i in TextFieldHandler.arrayTextFields:
+                if i.supportsService(
                     "com.sun.star.text.TextField.DateTime"):
-                    oTextField.setPropertyValue("IsFixed", False)
-                    oTextField.setPropertyValue("DateTimeValue", dt)
+                    i.setPropertyValue("IsFixed", False)
+                    i.setPropertyValue("DateTimeValue", dt)
 
         except Exception, e:
             traceback.print_exc()
 
     def fixDateFields(self, _bSetFixed):
         try:
-            xEnum = self.xTextFieldsSupplier.TextFields.createEnumeration()
-            while xEnum.hasMoreElements():
-                oTextField = xEnum.nextElement()
-                if oTextField.supportsService(
+            for i in TextFieldHandler.arrayTextFields:
+                if i.supportsService(
                     "com.sun.star.text.TextField.DateTime"):
-                    oTextField.setPropertyValue("IsFixed", _bSetFixed)
+                    i.setPropertyValue("IsFixed", _bSetFixed)
 
         except Exception, e:
             traceback.print_exc()
diff --git a/wizards/com/sun/star/wizards/ui/PathSelection.py b/wizards/com/sun/star/wizards/ui/PathSelection.py
index b848799..b7ea23c 100644
--- a/wizards/com/sun/star/wizards/ui/PathSelection.py
+++ b/wizards/com/sun/star/wizards/ui/PathSelection.py
@@ -89,8 +89,6 @@ class PathSelection(object):
 
     def triggerPathPicker(self):
         try:
-            print self.iTransferMode
-            print self.TransferMode.SAVE
             if self.iTransferMode == self.TransferMode.SAVE:
                 if self.iDialogType == self.DialogTypes.FOLDER:
                     #TODO: write code for picking a folder for saving
diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog.py b/wizards/com/sun/star/wizards/ui/UnoDialog.py
index baacd58..fc63ddb 100644
--- a/wizards/com/sun/star/wizards/ui/UnoDialog.py
+++ b/wizards/com/sun/star/wizards/ui/UnoDialog.py
@@ -47,7 +47,7 @@ class UnoDialog(object):
     def setControlProperty(self, ControlName, PropertyName, PropertyValue):
         try:
             if PropertyValue is not None:
-                if self.xDialogModel.hasByName(ControlName) == False:
+                if not self.xDialogModel.hasByName(ControlName):
                     return
                 xPSet = self.xDialogModel.getByName(ControlName)
                 if isinstance(PropertyValue,bool):
diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.py b/wizards/com/sun/star/wizards/ui/WizardDialog.py
index 874f540..377cffd 100644
--- a/wizards/com/sun/star/wizards/ui/WizardDialog.py
+++ b/wizards/com/sun/star/wizards/ui/WizardDialog.py
@@ -161,14 +161,13 @@ class WizardDialog(UnoDialog2):
 
     def getRoadmapItemByID(self, _ID):
         try:
-            i = 0
-            while i < self.oRoadmap.Count:
-                CurRoadmapItem = self.oRoadmap.getByIndex(i)
+            getByIndex = self.oRoadmap.getByIndex
+            for i in xrange(self.oRoadmap.Count):
+                CurRoadmapItem = getByIndex(i)
                 CurID = int(Helper.getUnoPropertyValue(CurRoadmapItem, "ID"))
                 if CurID == _ID:
                     return CurRoadmapItem
 
-                i += 1
             return None
         except UnoException, exception:
             traceback.print_exc()


More information about the Libreoffice-commits mailing list