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

Xisco Fauli xfauli at kemper.freedesktop.org
Fri Jun 17 16:18:51 PDT 2011


 wizards/com/sun/star/wizards/common/ConfigGroup.py      |   49 ++++-----
 wizards/com/sun/star/wizards/common/Configuration.py    |   85 +++-------------
 wizards/com/sun/star/wizards/common/FileAccess.py       |   21 +--
 wizards/com/sun/star/wizards/document/OfficeDocument.py |    8 -
 wizards/com/sun/star/wizards/fax/FaxDocument.py         |    4 
 wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py |   36 +++---
 wizards/com/sun/star/wizards/text/TextDocument.py       |    6 +
 wizards/com/sun/star/wizards/ui/PathSelection.py        |    6 -
 wizards/com/sun/star/wizards/ui/WizardDialog.py         |    2 
 9 files changed, 84 insertions(+), 133 deletions(-)

New commits:
commit f97b301d2df41b4347cc058bfcd00847b91839eb
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Sat Jun 18 01:16:37 2011 +0200

    First attempt to create the document

diff --git a/wizards/com/sun/star/wizards/common/ConfigGroup.py b/wizards/com/sun/star/wizards/common/ConfigGroup.py
index d8675f4..2cd2618 100644
--- a/wizards/com/sun/star/wizards/common/ConfigGroup.py
+++ b/wizards/com/sun/star/wizards/common/ConfigGroup.py
@@ -1,4 +1,5 @@
 from ConfigNode import *
+from Configuration import Configuration
 import traceback
 
 class ConfigGroup(ConfigNode):
@@ -13,16 +14,17 @@ class ConfigGroup(ConfigNode):
                     traceback.print_exc()
 
     def writeField(self, field, configView, prefix):
-        propertyName = field.getName().substring(prefix.length())
-        fieldType = field.getType()
-        if ConfigNode.isAssignableFrom(fieldType):
-            childView = Configuration.addConfigNode(configView, propertyName)
-            child = field.get(this)
-            child.writeConfiguration(childView, prefix)
-        elif fieldType.isPrimitive():
-            Configuration.set(convertValue(field), propertyName, configView)
-        elif isinstance(fieldType,str):
-            Configuration.set(field.get(this), propertyName, configView)
+        propertyName = field[len(prefix):]
+        field = getattr(self,field)
+        fieldType = type(field)
+        if isinstance(field, ConfigNode):
+            pass
+            #COMMENTED
+            #childView = Configuration.addConfigNode(configView, propertyName)
+            #self.writeConfiguration(childView, prefix)
+        else:
+            Configuration.Set(self.convertValue(field), propertyName,
+                configView)
 
     '''
     convert the primitive type value of the
@@ -34,22 +36,19 @@ class ConfigGroup(ConfigNode):
     '''
 
     def convertValue(self, field):
-        if field.getType().equals(Boolean.TYPE):
-            return field.getBoolean(this)
-
-        if field.getType().equals(Integer.TYPE):
-            return field.getInt(this)
-
-        if field.getType().equals(Short.TYPE):
-            return field.getShort(this)
+        if isinstance(field,bool):
+            return bool(field)
+        elif isinstance(field,int):
+            return int(field)
 
-        if field.getType().equals(Float.TYPE):
-            return field.getFloat(this)
-
-        if (field.getType().equals(Double.TYPE)):
-            return field.getDouble(this)
-        return None
-        #and good luck with it :-) ...
+    def readConfiguration(self, configurationView, param):
+        for i in dir(self):
+            if i.startswith(param):
+                try:
+                    self.readField( i, configurationView, param)
+                except Exception, ex:
+                    print "Error reading field: " + i
+                    traceback.print_exc()
 
     def readConfiguration(self, configurationView, param):
         for i in dir(self):
diff --git a/wizards/com/sun/star/wizards/common/Configuration.py b/wizards/com/sun/star/wizards/common/Configuration.py
index c73dec9..88f853b 100644
--- a/wizards/com/sun/star/wizards/common/Configuration.py
+++ b/wizards/com/sun/star/wizards/common/Configuration.py
@@ -20,59 +20,11 @@ in hierarchy form from the root of the registry.
 class Configuration(object):
 
     @classmethod
-    def getInt(self, name, parent):
-        o = getNode(name, parent)
-        if AnyConverter.isVoid(o):
-            return 0
-
-        return AnyConverter.toInt(o)
-
-    @classmethod
-    def getShort(self, name, parent):
-        o = getNode(name, parent)
-        if AnyConverter.isVoid(o):
-            return 0
-
-        return AnyConverter.toShort(o)
-
-    @classmethod
-    def getFloat(self, name, parent):
-        o = getNode(name, parent)
-        if AnyConverter.isVoid(o):
-            return 0
-
-        return AnyConverter.toFloat(o)
-
-    @classmethod
-    def getDouble(self, name, parent):
-        o = getNode(name, parent)
-        if AnyConverter.isVoid(o):
-            return 0
-
-        return AnyConverter.toDouble(o)
-
-    @classmethod
-    def getString(self, name, parent):
-        o = getNode(name, parent)
-        if AnyConverter.isVoid(o):
-            return ""
-
-        return o
-
-    @classmethod
-    def getBoolean(self, name, parent):
-        o = getNode(name, parent)
-        if AnyConverter.isVoid(o):
-            return False
-
-        return AnyConverter.toBoolean(o)
-
-    @classmethod
     def getNode(self, name, parent):
         return parent.getByName(name)
 
     @classmethod
-    def set(self, value, name, parent):
+    def Set(self, value, name, parent):
         parent.setHierarchicalPropertyValue(name, value)
 
     '''
@@ -90,24 +42,25 @@ class Configuration(object):
     def getConfigurationRoot(self, xmsf, sPath, updateable):
         oConfigProvider = xmsf.createInstance(
             "com.sun.star.configuration.ConfigurationProvider")
-        if updateable:
-            sView = "com.sun.star.configuration.ConfigurationUpdateAccess"
-        else:
-            sView = "com.sun.star.configuration.ConfigurationAccess"
+        args = []
 
         aPathArgument = uno.createUnoStruct(
             'com.sun.star.beans.PropertyValue')
         aPathArgument.Name = "nodepath"
         aPathArgument.Value = sPath
-        aModeArgument = uno.createUnoStruct(
-            'com.sun.star.beans.PropertyValue')
+
+        args.append(aPathArgument)
         if updateable:
+            sView = "com.sun.star.configuration.ConfigurationUpdateAccess"
+            aModeArgument = uno.createUnoStruct(
+                'com.sun.star.beans.PropertyValue')
             aModeArgument.Name = "lazywrite"
             aModeArgument.Value = False
+            args.append(aModeArgument)
+        else:
+            sView = "com.sun.star.configuration.ConfigurationAccess"
 
-
-        return oConfigProvider.createInstanceWithArguments(sView,
-            (aPathArgument,aModeArgument,))
+        return oConfigProvider.createInstanceWithArguments(sView, tuple(args))
 
     @classmethod
     def getChildrenNames(self, configView):
@@ -176,14 +129,16 @@ class Configuration(object):
 
     @classmethod
     def addConfigNode(self, configView, name):
-        if configView == None:
+        if configView is None:
             return configView.getByName(name)
         else:
-            # the new element is the result !
-            newNode = configView.createInstance()
+            print configView
             # insert it - this also names the element
-            xNameContainer.insertByName(name, newNode)
-            return newNode
+            try:
+                configView.insertByName(name, configView.createInstance())
+            except Exception,e:
+                traceback.print_exc()
+            #return newNode
 
     @classmethod
     def removeNode(self, configView, name):
@@ -197,14 +152,14 @@ class Configuration(object):
 
     @classmethod
     def updateConfiguration(self, xmsf, path, name, node, param):
-        view = Configuration.self.getConfigurationRoot(xmsf, path, True)
+        view = self.getConfigurationRoot(xmsf, path, True)
         addConfigNode(path, name)
         node.writeConfiguration(view, param)
         view.commitChanges()
 
     @classmethod
     def removeNode(self, xmsf, path, name):
-        view = Configuration.self.getConfigurationRoot(xmsf, path, True)
+        view = self.getConfigurationRoot(xmsf, path, True)
         removeNode(view, name)
         view.commitChanges()
 
diff --git a/wizards/com/sun/star/wizards/common/FileAccess.py b/wizards/com/sun/star/wizards/common/FileAccess.py
index 5af66d8..6f8e16b 100644
--- a/wizards/com/sun/star/wizards/common/FileAccess.py
+++ b/wizards/com/sun/star/wizards/common/FileAccess.py
@@ -4,6 +4,7 @@ from com.sun.star.ucb import CommandAbortedException
 from com.sun.star.uno import Exception as UnoException
 from com.sun.star.awt.VclWindowPeerAttribute import OK, YES_NO
 import types
+from os import path as osPath
 
 '''
 This class delivers static convenience methods
@@ -412,11 +413,9 @@ class FileAccess(object):
                     NameVectorAppend(i)
                     TitleVectorAppend(xDocInterface.Title)
 
-            LocLayoutFiles[1] = NameVector
-            LocLayoutFiles[0] = TitleVector
+            LocLayoutFiles[1] = sorted(NameVector)
+            LocLayoutFiles[0] = sorted(TitleVector)
 
-            #COMMENTED
-            #JavaTools.bubblesortList(LocLayoutFiles)
         except Exception, exception:
             traceback.print_exc()
 
@@ -557,7 +556,7 @@ class FileAccess(object):
             f = open(path)
 
         r = self.filenameConverter.getFileURLFromSystemPath(path,
-            f.getAbsolutePath())
+             osPath.abspath(path))
         return r
 
     def getPath(self, parentURL, childURL):
@@ -737,15 +736,9 @@ class FileAccess(object):
 
     @classmethod
     def getParentDir(self, url):
-        if url.endsWith("/"):
-            return getParentDir(url.substring(0, url.length() - 1))
-
-        pos = url.indexOf("/", pos + 1)
-        lastPos = 0
-        while pos > -1:
-            lastPos = pos
-            pos = url.indexOf("/", pos + 1)
-        return url.substring(0, lastPos)
+        while url[-1] == "/":
+            url = hello[:-1]
+        return url[:url.rfind("/")]
 
     def createNewDir(self, parentDir, name):
         s = getNewFile(parentDir, name, "")
diff --git a/wizards/com/sun/star/wizards/document/OfficeDocument.py b/wizards/com/sun/star/wizards/document/OfficeDocument.py
index 0647d32..a14f42b 100644
--- a/wizards/com/sun/star/wizards/document/OfficeDocument.py
+++ b/wizards/com/sun/star/wizards/document/OfficeDocument.py
@@ -174,7 +174,7 @@ class OfficeDocument(object):
     @classmethod
     def store(self, xMSF, xComponent, StorePath, FilterName, bStoreToUrl):
         try:
-            if FilterName.length() > 0:
+            if len(FilterName):
                 oStoreProperties = range(2)
                 oStoreProperties[0] = uno.createUnoStruct(
                     'com.sun.star.beans.PropertyValue')
@@ -188,10 +188,10 @@ class OfficeDocument(object):
             else:
                 oStoreProperties = range(0)
 
-            if bStoreToUrl == True:
-                xComponent.storeToURL(StorePath, oStoreProperties)
+            if bStoreToUrl:
+                xComponent.storeToURL(StorePath, tuple(oStoreProperties))
             else:
-                xStoreable.storeAsURL(StorePath, oStoreProperties)
+                xComponent.storeAsURL(StorePath, tuple(oStoreProperties))
 
             return True
         except Exception, exception:
diff --git a/wizards/com/sun/star/wizards/fax/FaxDocument.py b/wizards/com/sun/star/wizards/fax/FaxDocument.py
index f07917d..8ff2e64 100644
--- a/wizards/com/sun/star/wizards/fax/FaxDocument.py
+++ b/wizards/com/sun/star/wizards/fax/FaxDocument.py
@@ -115,13 +115,13 @@ class FaxDocument(TextDocument):
     def killEmptyFrames(self):
         try:
             if not self.keepLogoFrame:
-                xTF = TextFrameHandler.getFrameByName("Company Logo",
+                xTF = self.getFrameByName("Company Logo",
                 self.xTextDocument)
                 if xTF is not None:
                     xTF.dispose()
 
             if not self.keepTypeFrame:
-                xTF = TextFrameHandler.getFrameByName("Communication Type",
+                xTF = self.getFrameByName("Communication Type",
                 self.xTextDocument)
                 if xTF is not None:
                     xTF.dispose()
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
index 5cae6d6..4d1119d 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
@@ -9,6 +9,7 @@ from ui.XPathSelectionListener import XPathSelectionListener
 from common.Configuration import *
 from document.OfficeDocument import OfficeDocument
 from text.TextFieldHandler import TextFieldHandler
+from com.sun.star.awt.VclWindowPeerAttribute import YES_NO, DEF_NO
 
 from common.NoValidPathException import *
 from com.sun.star.uno import RuntimeException
@@ -133,17 +134,16 @@ class FaxWizardDialogImpl(FaxWizardDialog):
         self.running = False
 
     def finishWizard(self):
-        self.switchToStep(self.CurrentStep, self.nMaxStep)
+        self.switchToStep(self.getCurrentStep(), self.nMaxStep)
         self.myFaxDoc.setWizardTemplateDocInfo( \
             self.resources.resFaxWizardDialog_title,
             self.resources.resTemplateDescription)
         try:
             fileAccess = FileAccess(self.xMSF)
-            self.sPath = self.myPathSelection.SelectedPath
-            if self.sPath == "":
+            self.sPath = self.myPathSelection.getSelectedPath()
+            if self.sPath is "":
                 self.myPathSelection.triggerPathPicker()
-                self.sPath = self.myPathSelection.SelectedPath
-            print self.sPath
+                self.sPath = self.myPathSelection.getSelectedPath()
 
             self.sPath = fileAccess.getURL(self.sPath)
             #first, if the filename was not changed, thus
@@ -151,12 +151,10 @@ class FaxWizardDialogImpl(FaxWizardDialog):
             # file exists and warn the user.
             if not self.__filenameChanged:
                 if fileAccess.exists(self.sPath, True):
-                    answer = SystemDialog.showMessageBox( \
-                        xMSF, xControl.Peer, "MessBox",
-                        VclWindowPeerAttribute.YES_NO + \
-                        VclWindowPeerAttribute.DEF_NO,
-                        self.resources.resOverwriteWarning)
-                    if (answer == 3): # user said: no, do not overwrite...
+                    answer = SystemDialog.showMessageBox(
+                        self.xMSF, self.xUnoDialog.Peer, "MessBox",
+                        YES_NO + DEF_NO, self.resources.resOverwriteWarning)
+                    if answer == 3: # user said: no, do not overwrite...
                         return False
 
 
@@ -168,13 +166,13 @@ class FaxWizardDialogImpl(FaxWizardDialog):
             self.myFaxDoc.keepTypeFrame = \
                 (self.chkUseCommunicationType.State is not 0)
             self.myFaxDoc.killEmptyFrames()
-            self.bSaveSuccess = OfficeDocument.store(xMSF, self.xTextDocument,
+            self.bSaveSuccess = OfficeDocument.store(self.xMSF, self.xTextDocument,
                 self.sPath, "writer8_template", False)
             if self.bSaveSuccess:
-                saveConfiguration()
-                xIH = xMSF.createInstance( \
+                self.saveConfiguration()
+                xIH = self.xMSF.createInstance( \
                     "com.sun.star.comp.uui.UUIInteractionHandler")
-                loadValues = range(3)
+                loadValues = range(4)
                 loadValues[0] = uno.createUnoStruct( \
                     'com.sun.star.beans.PropertyValue')
                 loadValues[0].Name = "AsTemplate"
@@ -196,10 +194,10 @@ class FaxWizardDialogImpl(FaxWizardDialog):
                 else:
                     loadValues[0].Value = True
 
-                oDoc = OfficeDocument.load(Desktop.getDesktop(xMSF),
+                oDoc = OfficeDocument.load(Desktop.getDesktop(self.xMSF),
                     self.sPath, "_default", loadValues)
-                myViewHandler = oDoc.CurrentController.ViewSettings
-                myViewHandler.setPropertyValue("ZoomType",
+                myViewHandler = ViewHandler(self.xMSF, oDoc)
+                myViewHandler.setViewSetting("ZoomType",
                     uno.Any("short",OPTIMAL))
             else:
                 pass
@@ -415,7 +413,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
 
     def saveConfiguration(self):
         try:
-            root = Configuration.getConfigurationRoot(xMSF,
+            root = Configuration.getConfigurationRoot(self.xMSF,
                 "/org.openoffice.Office.Writer/Wizards/Fax", True)
             self.myConfig.writeConfiguration(root, "cp_")
             Configuration.commit(root)
diff --git a/wizards/com/sun/star/wizards/text/TextDocument.py b/wizards/com/sun/star/wizards/text/TextDocument.py
index 7c564d5..c6ff211 100644
--- a/wizards/com/sun/star/wizards/text/TextDocument.py
+++ b/wizards/com/sun/star/wizards/text/TextDocument.py
@@ -262,6 +262,12 @@ class TextDocument(object):
         xPC.jumpToLastPage()
         return xPC.getPage()
 
+    def getFrameByName(self, sFrameName, xTD):
+        if xTD.TextFrames.hasByName(sFrameName):
+            return xTD.TextFrames.getByName(sFrameName)
+
+        return None
+
     '''
     Possible Values for "OptionString" are: "LoadCellStyles",
     "LoadTextStyles", "LoadFrameStyles",
diff --git a/wizards/com/sun/star/wizards/ui/PathSelection.py b/wizards/com/sun/star/wizards/ui/PathSelection.py
index aa7231e..ef5f6e4 100644
--- a/wizards/com/sun/star/wizards/ui/PathSelection.py
+++ b/wizards/com/sun/star/wizards/ui/PathSelection.py
@@ -102,11 +102,11 @@ class PathSelection(object):
                         self.sDefaultName, self.sDefaultFilter)
                     sStorePath = myFilePickerDialog.sStorePath
                     if sStorePath is not None:
-                        myFA = FileAccess(xMSF);
-                        xSaveTextBox.setText(myFA.getPath(sStorePath, None))
+                        myFA = FileAccess(self.xMSF);
+                        self.xSaveTextBox.Text = myFA.getPath(sStorePath, None)
                         self.sDefaultDirectory = \
                             FileAccess.getParentDir(sStorePath)
-                        self.sDefaultName = myFA.getFilename(sStorePath)
+                        self.sDefaultName = myFA.getFilename(self.sStorePath)
                     return
             elif iTransferMode == TransferMode.LOAD:
                 if iDialogType == DialogTypes.FOLDER:
diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.py b/wizards/com/sun/star/wizards/ui/WizardDialog.py
index b8f1236..d39e6d1 100644
--- a/wizards/com/sun/star/wizards/ui/WizardDialog.py
+++ b/wizards/com/sun/star/wizards/ui/WizardDialog.py
@@ -431,7 +431,7 @@ class WizardDialog(UnoDialog2):
                     self.enableFinishButton(True)
 
             if success:
-                removeTerminateListener()
+                self.removeTerminateListener()
         except Exception, e:
              traceback.print_exc()
 


More information about the Libreoffice-commits mailing list