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

Xisco Fauli xfauli at kemper.freedesktop.org
Thu Jun 16 08:50:29 PDT 2011


 wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py |    4 
 wizards/com/sun/star/wizards/text/TextFieldHandler.py   |   80 ++++++------
 wizards/com/sun/star/wizards/ui/UnoDialog.py            |   10 -
 wizards/com/sun/star/wizards/ui/WizardDialog.py         |  101 ++++++----------
 wizards/com/sun/star/wizards/ui/event/CommonListener.py |    5 
 wizards/com/sun/star/wizards/ui/event/EventNames.py     |   15 --
 6 files changed, 93 insertions(+), 122 deletions(-)

New commits:
commit 8e94dc8172af22a86ddbb52c8c9504eca0575ae0
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Thu Jun 16 17:41:29 2011 +0200

    Add listeners and optimize.
    
    - Add listeners to the steps on the left.
    - The wizard dialog is loaded much faster ( ~5 second faster than before )

diff --git a/wizards/com/sun/star/wizards/RemoteFaxWizard b/wizards/com/sun/star/wizards/RemoteFaxWizard
old mode 100644
new mode 100755
diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
index 9ffade4..1905ae6 100644
--- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
+++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py
@@ -65,7 +65,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
         self.running = True
         try:
             #Number of steps on WizardDialog:
-            self.setMaxStep(5)
+            self.nMaxStep = 5
 
             #instatiate The Document Frame for the Preview
             self.myFaxDoc = FaxDocument(xMSF, self)
@@ -133,7 +133,7 @@ class FaxWizardDialogImpl(FaxWizardDialog):
         self.running = False
 
     def finishWizard(self):
-        self.switchToStep(self.getCurrentStep(), self.getMaxStep())
+        self.switchToStep(self.getCurrentStep(), self.nMaxStep)
         self.myFaxDoc.setWizardTemplateDocInfo( \
             self.resources.resFaxWizardDialog_title,
             self.resources.resTemplateDescription)
diff --git a/wizards/com/sun/star/wizards/text/TextFieldHandler.py b/wizards/com/sun/star/wizards/text/TextFieldHandler.py
index c492674..d9e3ed8 100644
--- a/wizards/com/sun/star/wizards/text/TextFieldHandler.py
+++ b/wizards/com/sun/star/wizards/text/TextFieldHandler.py
@@ -4,6 +4,8 @@ from com.sun.star.util import DateTime
 from common.PropertyNames import PropertyNames
 import unicodedata
 
+import inspect
+
 class TextFieldHandler(object):
     '''
     Creates a new instance of TextFieldHandler
@@ -11,9 +13,16 @@ class TextFieldHandler(object):
     @param xTextDocument
     '''
 
+    xTextFieldsSupplierAux = None
+    dictTextFields = None
+
     def __init__(self, xMSF, xTextDocument):
         self.xMSFDoc = xMSF
         self.xTextFieldsSupplier = xTextDocument
+        if TextFieldHandler.xTextFieldsSupplierAux is not \
+                self.xTextFieldsSupplier:
+            self.__getTextFields()
+            TextFieldHandler.xTextFieldsSupplierAux = self.xTextFieldsSupplier
 
     def refreshTextFields(self):
         xUp = self.xTextFieldsSupplier.TextFields
@@ -40,9 +49,9 @@ class TextFieldHandler(object):
             xField = self.xMSFDoc.createInstance(
                 "com.sun.star.text.TextField.User")
 
-            if self.xTextFieldsSupplier.getTextFieldMasters().hasByName(
+            if self.xTextFieldsSupplier.TextFieldMasters.hasByName(
                 "com.sun.star.text.FieldMaster.User." + FieldName):
-                oMaster = self.xTextFieldsSupplier.getTextFieldMasters().getByName( \
+                oMaster = self.xTextFieldsSupplier.TextFieldMasters.getByName( \
                     "com.sun.star.text.FieldMaster.User." + FieldName)
                 oMaster.dispose()
 
@@ -60,55 +69,52 @@ class TextFieldHandler(object):
         xPSet.setPropertyValue("Content", FieldTitle)
         return xPSet
 
-    def __getTextFieldsByProperty(
-            self, _PropertyName, _aPropertyValue, _TypeName):
+    def __getTextFields(self):
         try:
             if self.xTextFieldsSupplier.TextFields.hasElements():
+                TextFieldHandler.dictTextFields = {}
                 xEnum = \
                     self.xTextFieldsSupplier.TextFields.createEnumeration()
-                xDependentVector = []
                 while xEnum.hasMoreElements():
                     oTextField = xEnum.nextElement()
                     xPropertySet = oTextField.TextFieldMaster
-                    if xPropertySet.PropertySetInfo.hasPropertyByName(
-                        _PropertyName):
-                        oValue = xPropertySet.getPropertyValue(_PropertyName)
-                        if isinstance(oValue,unicode):
-                            if _TypeName == "String":
-                                sValue = unicodedata.normalize(
-                                    'NFKD', oValue).encode('ascii','ignore')
-                                if sValue == _aPropertyValue:
-                                    xDependentVector.append(oTextField)
-                        #COMMENTED
-                        '''elif AnyConverter.isShort(oValue):
-                            if _TypeName.equals("Short"):
-                                iShortParam = (_aPropertyValue).shortValue()
-                                ishortValue = AnyConverter.toShort(oValue)
-                                if ishortValue == iShortParam:
-                                    xDependentVector.append(oTextField) '''
-                if xDependentVector:
-                    return xDependentVector
-            else:
-                return None
-
+                    if len(xPropertySet.Name) is not 0:
+                        TextFieldHandler.dictTextFields[xPropertySet.Name] = \
+                            oTextField
         except Exception, e:
             #TODO Auto-generated catch block
             traceback.print_exc()
 
-        return None
+    def __getTextFieldsByProperty(
+            self, _PropertyName, _aPropertyValue, _TypeName):
+        try:
+            xProperty = TextFieldHandler.dictTextFields[_aPropertyValue]
+            xPropertySet = xProperty.TextFieldMaster
+            if xPropertySet.PropertySetInfo.hasPropertyByName(
+                    _PropertyName):
+                oValue = xPropertySet.getPropertyValue(_PropertyName)
+                if _TypeName == "String":
+                    sValue = unicodedata.normalize(
+                        'NFKD', oValue).encode('ascii','ignore')
+                    if sValue == _aPropertyValue:
+                        return xProperty
+            #COMMENTED
+            '''elif AnyConverter.isShort(oValue):
+                        if _TypeName.equals("Short"):
+                            iShortParam = (_aPropertyValue).shortValue()
+                            ishortValue = AnyConverter.toShort(oValue)
+                            if ishortValue == iShortParam:
+                                xDependentVector.append(oTextField) '''
+            return None
+        except KeyError, e:
+            return None
 
     def changeUserFieldContent(self, _FieldName, _FieldContent):
-        try:
-            xDependentTextFields = self.__getTextFieldsByProperty(
+        DependentTextFields = self.__getTextFieldsByProperty(
                 PropertyNames.PROPERTY_NAME, _FieldName, "String")
-            if xDependentTextFields != None:
-                for i in xDependentTextFields:
-                    i.getTextFieldMaster().setPropertyValue(
-                        "Content", _FieldContent)
-                self.refreshTextFields()
-
-        except Exception, e:
-            traceback.print_exc()
+        if DependentTextFields is not None:
+            DependentTextFields.TextFieldMaster.setPropertyValue("Content", _FieldContent)
+            self.refreshTextFields()
 
     def updateDocInfoFields(self):
         try:
diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog.py b/wizards/com/sun/star/wizards/ui/UnoDialog.py
index 32ac6e5..551d0e3 100644
--- a/wizards/com/sun/star/wizards/ui/UnoDialog.py
+++ b/wizards/com/sun/star/wizards/ui/UnoDialog.py
@@ -502,7 +502,7 @@ class UnoDialog(object):
     '''
 
     def executeDialogFromParent(self, parent):
-        return self.executeDialog(parent.xWindow.getPosSize())
+        return self.executeDialog(parent.xWindow.PosSize)
 
     '''
     @param XComponent
@@ -511,10 +511,10 @@ class UnoDialog(object):
     '''
 
     def executeDialogFromComponent(self, xComponent):
-        if xComponent != None:
-            w = xComponent.getComponentWindow()
-            if w != None:
-                return self.executeDialog(w.getPosSize())
+        if xComponent is not None:
+            w = xComponent.ComponentWindow
+            if w is not None:
+                return self.executeDialog(w.PosSize)
 
         return self.executeDialog( Rectangle (0, 0, 640, 400))
 
diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.py b/wizards/com/sun/star/wizards/ui/WizardDialog.py
index 23c099e..4ed4fe3 100644
--- a/wizards/com/sun/star/wizards/ui/WizardDialog.py
+++ b/wizards/com/sun/star/wizards/ui/WizardDialog.py
@@ -37,9 +37,9 @@ class WizardDialog(UnoDialog2):
         super(WizardDialog,self).__init__(xMSF)
         self.__hid = hid_
         self.__iButtonWidth = 50
-        self.__nNewStep = 1
-        self.__nOldStep = 1
-        self.__nMaxStep = 1
+        self.nNewStep = 1
+        self.nOldStep = 1
+        self.nMaxStep = 1
         self.__bTerminateListenermustberemoved = True
         self.__oWizardResource = Resource(xMSF, "dbw")
         self.sMsgEndAutopilot = self.__oWizardResource.getResText(
@@ -59,35 +59,14 @@ class WizardDialog(UnoDialog2):
             pass
             # do nothing;
 
-    def setMaxStep(self, i):
-        self.__nMaxStep = i
-
-    def getMaxStep(self):
-        return self.__nMaxStep
-
-    def setOldStep(self, i):
-        self.__nOldStep = i
-
-    def getOldStep(self):
-        return self.__nOldStep
-
-    def setNewStep(self, i):
-        self.__nNewStep = i
-
-    def getNewStep(self):
-        return self.__nNewStep
-
-    def vetoableChange(self, arg0):
-        self.__nNewStep = self.__nOldStep
-
     def itemStateChanged(self, itemEvent):
         try:
-            self.__nNewStep = itemEvent.ItemId
-            self.__nOldStep = int(Helper.getUnoPropertyValue(
+            self.nNewStep = itemEvent.ItemId
+            self.nOldStep = int(Helper.getUnoPropertyValue(
                 self.xDialogModel,
                 PropertyNames.PROPERTY_STEP))
-            if self.__nNewStep != self.__nOldStep:
-                switchToStep()
+            if self.nNewStep != self.nOldStep:
+                self.switchToStep()
 
         except IllegalArgumentException, exception:
             traceback.print_exc()
@@ -142,10 +121,10 @@ class WizardDialog(UnoDialog2):
             self.oRoadmap.setPropertyValue(
                 PropertyNames.PROPERTY_NAME, "rdmNavi")
 
-            mi = MethodInvocation("itemStateChanged", self)
             self.xRoadmapControl = self.xUnoDialog.getControl("rdmNavi")
+            method = getattr(self, "itemStateChanged")
             self.xRoadmapControl.addItemListener(
-                ItemListenerProcAdapter(None))
+                ItemListenerProcAdapter(method))
 
             Helper.setUnoPropertyValue(
                 self.oRoadmap, "Text",
@@ -157,17 +136,15 @@ class WizardDialog(UnoDialog2):
 
     def setRMItemLabels(self, _oResource, StartResID):
         self.sRMItemLabels = _oResource.getResArray(
-            StartResID, self.__nMaxStep)
+            StartResID, self.nMaxStep)
 
     def getRMItemLabels(self):
         return self.sRMItemLabels
 
-    def insertRoadmapItem(self, _Index, _bEnabled, _LabelID, _CurItemID):
-        return insertRoadmapItem(
-            _Index, _bEnabled, self.sRMItemLabels(_LabelID), _CurItemID)
-
     def insertRoadmapItem(self, Index, _bEnabled, _sLabel, _CurItemID):
         try:
+            if isinstance(_sLabel, int):
+                _sLabel = self.sRMItemLabels(_sLabel)
             oRoadmapItem = self.oRoadmap.createInstance()
             Helper.setUnoPropertyValue(oRoadmapItem,
                 PropertyNames.PROPERTY_LABEL, _sLabel)
@@ -201,12 +178,12 @@ class WizardDialog(UnoDialog2):
 
     def switchToStep(self,_nOldStep=None, _nNewStep=None):
         if _nOldStep is not None and _nNewStep is not None:
-            self.__nOldStep = _nOldStep
-            self.__nNewStep = _nNewStep
+            self.nOldStep = _nOldStep
+            self.nNewStep = _nNewStep
 
-        self.leaveStep(self.__nOldStep, self.__nNewStep)
-        if self.__nNewStep != self.__nOldStep:
-            if self.__nNewStep == self.__nMaxStep:
+        self.leaveStep(self.nOldStep, self.nNewStep)
+        if self.nNewStep != self.nOldStep:
+            if self.nNewStep == self.nMaxStep:
                 self.setControlProperty(
                     "btnWizardNext", "DefaultButton", False)
                 self.setControlProperty(
@@ -217,8 +194,8 @@ class WizardDialog(UnoDialog2):
                 self.setControlProperty(
                     "btnWizardFinish", "DefaultButton", False)
 
-            self.changeToStep(self.__nNewStep)
-            self.enterStep(self.__nOldStep, self.__nNewStep)
+            self.changeToStep(self.nNewStep)
+            self.enterStep(self.nOldStep, self.nNewStep)
             return True
 
         return False
@@ -382,16 +359,16 @@ class WizardDialog(UnoDialog2):
                 PropertyNames.PROPERTY_ENABLED, bEnabled)
 
     def enablefromStep(self, _iStep, _bDoEnable):
-        if _iStep <= self.__nMaxStep:
+        if _iStep <= self.nMaxStep:
             i = _iStep
-            while i <= self.__nMaxStep:
+            while i <= self.nMaxStep:
                 setStepEnabled(i, _bDoEnable)
                 i += 1
             enableFinishButton(_bDoEnable)
             if not _bDoEnable:
                 enableNextButton(_iStep > getCurrentStep() + 1)
             else:
-                enableNextButton(not (getCurrentStep() == self.__nMaxStep))
+                enableNextButton(not (getCurrentStep() == self.nMaxStep))
 
     def isStepEnabled(self, _nStep):
         try:
@@ -408,17 +385,17 @@ class WizardDialog(UnoDialog2):
 
     def gotoPreviousAvailableStep(self):
         try:
-            if self.__nNewStep > 1:
-                self.__nOldStep = self.__nNewStep
-                self.__nNewStep -= 1
-                while self.__nNewStep > 0:
-                    bIsEnabled = self.isStepEnabled(self.__nNewStep)
+            if self.nNewStep > 1:
+                self.nOldStep = self.nNewStep
+                self.nNewStep -= 1
+                while self.nNewStep > 0:
+                    bIsEnabled = self.isStepEnabled(self.nNewStep)
                     if bIsEnabled:
                         break;
 
-                    self.__nNewStep -= 1
-                if (self.__nNewStep == 0):
-                    self.__nNewStep = self.__nOldStep
+                    self.nNewStep -= 1
+                if (self.nNewStep == 0):
+                    self.nNewStep = self.nOldStep
                 self.switchToStep()
         except Exception, e:
             traceback.print_exc()
@@ -427,8 +404,8 @@ class WizardDialog(UnoDialog2):
 
     def getNextAvailableStep(self):
         if self.isRoadmapComplete():
-            i = self.__nNewStep + 1
-            while i <= self.__nMaxStep:
+            i = self.nNewStep + 1
+            while i <= self.nMaxStep:
                 if self.isStepEnabled(i):
                     return i
 
@@ -438,9 +415,9 @@ class WizardDialog(UnoDialog2):
 
     def gotoNextAvailableStep(self):
         try:
-            self.__nOldStep = self.__nNewStep
-            self.__nNewStep = self.getNextAvailableStep()
-            if self.__nNewStep > -1:
+            self.nOldStep = self.nNewStep
+            self.nNewStep = self.getNextAvailableStep()
+            if self.nNewStep > -1:
                 self.switchToStep()
         except Exception, e:
             traceback.print_exc()
@@ -467,7 +444,7 @@ class WizardDialog(UnoDialog2):
              traceback.print_exc()
 
     def getMaximalStep(self):
-        return self.__nMaxStep
+        return self.nMaxStep
 
     def getCurrentStep(self):
         try:
@@ -478,15 +455,15 @@ class WizardDialog(UnoDialog2):
             return -1
 
     def setCurrentStep(self, _nNewstep):
-        self.__nNewStep = _nNewstep
-        changeToStep(self.__nNewStep)
+        self.nNewStep = _nNewstep
+        changeToStep(self.nNewStep)
 
     def setRightPaneHeaders(self, _oResource, StartResID, _nMaxStep):
         self.sRightPaneHeaders = _oResource.getResArray(StartResID, _nMaxStep)
         setRightPaneHeaders(self.sRightPaneHeaders)
 
     def setRightPaneHeaders(self, _sRightPaneHeaders):
-        self.__nMaxStep = _sRightPaneHeaders.length
+        self.nMaxStep = _sRightPaneHeaders.length
         self.sRightPaneHeaders = _sRightPaneHeaders
         oFontDesc = FontDescriptor.FontDescriptor()
         oFontDesc.Weight = com.sun.star.awt.FontWeight.BOLD
diff --git a/wizards/com/sun/star/wizards/ui/event/CommonListener.py b/wizards/com/sun/star/wizards/ui/event/CommonListener.py
index 24ff521..73a52c9 100644
--- a/wizards/com/sun/star/wizards/ui/event/CommonListener.py
+++ b/wizards/com/sun/star/wizards/ui/event/CommonListener.py
@@ -75,7 +75,10 @@ class ItemListenerProcAdapter( unohelper.Base, XItemListener ):
     # oItemEvent is a com.sun.star.awt.ItemEvent struct.
     def itemStateChanged( self, oItemEvent ):
         if callable( self.oProcToCall ):
-            apply( self.oProcToCall )
+            try:
+                apply( self.oProcToCall)
+            except:
+                apply( self.oProcToCall, (oItemEvent,) + self.tParams )
 
 
 #--------------------------------------------------
diff --git a/wizards/com/sun/star/wizards/ui/event/EventNames.py b/wizards/com/sun/star/wizards/ui/event/EventNames.py
deleted file mode 100644
index 49845ce..0000000
--- a/wizards/com/sun/star/wizards/ui/event/EventNames.py
+++ /dev/null
@@ -1,15 +0,0 @@
-EVENT_ACTION_PERFORMED = "APR"
-EVENT_ITEM_CHANGED = "ICH"
-EVENT_TEXT_CHANGED = "TCH"    #window events (XWindow)
-EVENT_WINDOW_RESIZED = "WRE"
-EVENT_WINDOW_MOVED = "WMO"
-EVENT_WINDOW_SHOWN = "WSH"
-EVENT_WINDOW_HIDDEN = "WHI"    #focus events (XWindow)
-EVENT_FOCUS_GAINED = "FGA"
-EVENT_FOCUS_LOST = "FLO"    #keyboard events
-EVENT_KEY_PRESSED = "KPR"
-EVENT_KEY_RELEASED = "KRE"    #mouse events
-EVENT_MOUSE_PRESSED = "MPR"
-EVENT_MOUSE_RELEASED = "MRE"
-EVENT_MOUSE_ENTERED = "MEN"
-EVENT_MOUSE_EXITED = "MEX"


More information about the Libreoffice-commits mailing list