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

Xisco Fauli xfauli at kemper.freedesktop.org
Fri Jul 29 09:40:54 PDT 2011


 wizards/com/sun/star/wizards/agenda/AgendaTemplate.py |   20 +--
 wizards/com/sun/star/wizards/agenda/TopicsControl.py  |   70 ++++++------
 wizards/com/sun/star/wizards/ui/ControlScroller.py    |   98 +++++++++---------
 3 files changed, 92 insertions(+), 96 deletions(-)

New commits:
commit b62e278a4e28713bbcfeb0b79e530d2d066185ae
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Fri Jul 29 18:39:55 2011 +0200

    add listeners to the agenda items

diff --git a/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py b/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py
index 7199c11..ab8e9b0 100644
--- a/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py
+++ b/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py
@@ -991,8 +991,8 @@ class Topics(object):
     '''
 
     def isWritten(self, topic):
-        return (AgendaTemplate.writtenTopics.size() > topic \
-            and AgendaTemplate.writtenTopics.get(topic) != None)
+        return (len(AgendaTemplate.writtenTopics) > topic \
+            and AgendaTemplate.writtenTopics[topic] is not None)
 
     '''rewrites a single cell containing.
     This is used in order to refresh the topic/responsible/duration data
@@ -1010,28 +1010,28 @@ class Topics(object):
 
     def writeCell(self, topic, what, data):
         # if the whole row should be written...
-        if not isWritten(topic):
-            write(topic, data)
+        if not self.isWritten(topic):
+            self.write(topic, data)
             # write only the "what" cell.
         else:
             # calculate the table row.
             firstRow = 1 + (topic * Topics.rowsPerTopic) + 1
             # go to the first cell of this topic.
-            cursor = Topics.table.createCursorByCellName("A" + firstRow)
+            cursor = Topics.table.createCursorByCellName("A" + str(firstRow))
             te = None
             cursorMoves = 0
             tmp_switch_var1 = what
             if tmp_switch_var1 == 0:
-                te = setItemText(Topics.numCell, data[0].Value)
+                te = self.setItemText(Topics.numCell, data[0].Value)
                 cursorMoves = Topics.numCell
             elif tmp_switch_var1 == 1:
-                te = setItemText(Topics.topicCell, data[1].Value)
+                te = self.setItemText(Topics.topicCell, data[1].Value)
                 cursorMoves = Topics.topicCell
             elif tmp_switch_var1 == 2:
-                te = setItemText(Topics.responsibleCell, data[2].Value)
+                te = self.setItemText(Topics.responsibleCell, data[2].Value)
                 cursorMoves = Topics.responsibleCell
             elif tmp_switch_var1 == 3:
-                te = setItemText(Topics.timeCell, data[3].Value)
+                te = self.setItemText(Topics.timeCell, data[3].Value)
                 cursorMoves = Topics.timeCell
 
             # move the cursor to the needed cell...
@@ -1039,7 +1039,7 @@ class Topics(object):
             xc = Topics.table.getCellByName(cursor.RangeName)
             # and write it !
             te.write(xc)
-            (Topics.topicCellFormats.get(cursorMoves)).format(xc)
+            Topics.topicCellFormats[cursorMoves].format(xc)
 
     '''writes the given topic.
     if the first topic was involved, reformat the
diff --git a/wizards/com/sun/star/wizards/agenda/TopicsControl.py b/wizards/com/sun/star/wizards/agenda/TopicsControl.py
index 7a48802..fdcbd1b 100644
--- a/wizards/com/sun/star/wizards/agenda/TopicsControl.py
+++ b/wizards/com/sun/star/wizards/agenda/TopicsControl.py
@@ -133,6 +133,7 @@ class TopicsControl(ControlScroller):
     end, which enables the user to enter data...
     '''
 
+    @classmethod
     def insertRowAtEnd(self):
         l = len(ControlScroller.scrollfields)
         self.registerControlGroup(self.newRow(l), l)
@@ -304,6 +305,7 @@ class TopicsControl(ControlScroller):
     @return
     '''
 
+    @classmethod
     def newRow(self, i):
         pv = [None] * 4
         pv[0] = Properties.createProperty(
@@ -338,11 +340,11 @@ class TopicsControl(ControlScroller):
     @return true if empty. false if not.
     '''
 
+    @classmethod
     def isRowEmpty(self, row):
-        data = getTopicData(row)
+        data = self.getTopicData(row)
         # now - is this row empty?
-        return data[1].Value.equals("") and data[2].Value.equals("") \
-                and data[3].Value.equals("")
+        return data[1].Value and data[2].Value and data[3].Value
 
     '''
     update the preview document and
@@ -350,34 +352,26 @@ class TopicsControl(ControlScroller):
     @param guiRow
     @param column
     '''
+    oldData = []
 
+    @classmethod
     def fieldChanged(self, guiRow, column):
         with TopicsControl.lock:
             try:
                 # First, I update the document
-                data = getTopicData(guiRow + TopicsControl.nscrollvalue)
-                if data == None:
+                data = self.getTopicData(guiRow + TopicsControl.nscrollvalue)
+                if data is None:
                     return
 
-                equal = True
-                if self.oldData != None:
-                    i = 0
-                    while i < data.length and equal:
-                        equal = equal & data[i].Value == self.oldData[i]
-                        i += 1
-                    if equal:
-                        return
-
+                dataValue = [i.Value for i in data]
+                if dataValue == TopicsControl.oldData:
+                    return
                 else:
-                    self.oldData = range(4)
+                    TopicsControl.oldData = dataValue
 
-                i = 0
-                while i < data.length:
-                    self.oldData[i] = data[i].Value
-                    i += 1
-                updateDocumentCell(
+                self.updateDocumentCell(
                     guiRow + TopicsControl.nscrollvalue, column, data)
-                if isRowEmpty(guiRow + TopicsControl.nscrollvalue):
+                if self.isRowEmpty(guiRow + TopicsControl.nscrollvalue):
                     '''
                     if this is the row before the last one
                     (the last row is always empty)
@@ -407,10 +401,10 @@ class TopicsControl(ControlScroller):
                     # is this the last row?
                     if (guiRow + TopicsControl.nscrollvalue + 1) \
                             == len(ControlScroller.scrollfields):
-                        insertRowAtEnd()
+                        self.insertRowAtEnd()
 
-            except Exception, e:
-                e.printStackTrace()
+            except Exception:
+                traceback.print_exc()
 
     '''
     return the corresponding row data for the given index.
@@ -418,9 +412,10 @@ class TopicsControl(ControlScroller):
     @return a PropertyValue array with the data for the given topic.
     '''
 
+    @classmethod
     def getTopicData(self, topic):
         if topic < len(ControlScroller.scrollfields):
-            return ControlScroller.scrollfields.get(topic)
+            return ControlScroller.scrollfields[topic]
         else:
             return None
 
@@ -709,6 +704,7 @@ class TopicsControl(ControlScroller):
     @param data the data of the entire row.
     '''
 
+    @classmethod
     def updateDocumentCell(self, row, column, data):
         try:
             ControlScroller.CurUnoDialog.agendaTemplate.topics.writeCell(
@@ -789,11 +785,11 @@ class ControlRow(object):
     def topicTextChanged(self):
         try:
             # update the data model
-            fieldInfo(self.offset, 1)
+            ControlScroller.fieldInfo(self.offset, 1)
             # update the preview document
-            fieldChanged(self.offset, 1)
-        except Exception, ex:
-            ex.printStackTrace()
+            TopicsControl.fieldChanged(self.offset, 1)
+        except Exception:
+            traceback.print_exc()
 
     '''
     called through an event listener when the
@@ -804,11 +800,11 @@ class ControlRow(object):
     def responsibleTextChanged(self):
         try:
             # update the data model
-            fieldInfo(self.offset, 2)
+            ControlScroller.fieldInfo(self.offset, 2)
             # update the preview document
-            fieldChanged(self.offset, 2)
-        except Exception, ex:
-            ex.printStackTrace()
+            TopicsControl.fieldChanged(self.offset, 2)
+        except Exception:
+            traceback.print_exc()
 
     '''
     called through an event listener when the
@@ -819,11 +815,11 @@ class ControlRow(object):
     def timeTextChanged(self):
         try:
             # update the data model
-            fieldInfo(self.offset, 3)
+            ControlScroller.fieldInfo(self.offset, 3)
             # update the preview document
-            fieldChanged(self.offset, 3)
-        except Exception, ex:
-            ex.printStackTrace()
+            TopicsControl.fieldChanged(self.offset, 3)
+        except Exception:
+            traceback.print_exc()
 
     '''
     enables/disables the row.
diff --git a/wizards/com/sun/star/wizards/ui/ControlScroller.py b/wizards/com/sun/star/wizards/ui/ControlScroller.py
index 4a21193..0f0ba5a 100644
--- a/wizards/com/sun/star/wizards/ui/ControlScroller.py
+++ b/wizards/com/sun/star/wizards/ui/ControlScroller.py
@@ -17,11 +17,12 @@ class ControlScroller(object):
     iStep = None
     curHelpIndex = None
 
+
     # TODO add parameters for tabindices and helpindex
     def __init__(self, _CurUnoDialog, _xMSF, _iStep, _iCompPosX, _iCompPosY,
             _iCompWidth, _nblockincrement, _nlinedistance, _firsthelpindex):
         self.xMSF = _xMSF
-        self.nblockincrement = _nblockincrement
+        ControlScroller.nblockincrement = _nblockincrement
         ControlScroller.CurUnoDialog = _CurUnoDialog
         ControlScroller.iStep = _iStep
         ControlScroller.curHelpIndex = _firsthelpindex
@@ -31,7 +32,7 @@ class ControlScroller(object):
         self.iCompPosY = _iCompPosY
         self.iCompWidth = _iCompWidth
         self.iCompHeight = 2 * ControlScroller.SORELFIRSTPOSY + \
-                self.nblockincrement * self.linedistance
+                ControlScroller.nblockincrement * self.linedistance
         self.iStartPosY = self.iCompPosY + ControlScroller.SORELFIRSTPOSY
         ScrollHeight = self.iCompHeight - 2
         self.nlineincrement = 1
@@ -50,7 +51,7 @@ class ControlScroller(object):
         self.oImgControl = ControlScroller.CurUnoDialog.xUnoDialog.getControl(
             "imgBackground" + self.sincSuffix)
         self.setComponentMouseTransparent()
-        self.xScrollBar = ControlScroller.CurUnoDialog.insertScrollBar(
+        ControlScroller.xScrollBar = ControlScroller.CurUnoDialog.insertScrollBar(
             "TitleScrollBar" + self.sincSuffix,
             ("Border", PropertyNames.PROPERTY_ENABLED,
                 PropertyNames.PROPERTY_HEIGHT,
@@ -65,10 +66,10 @@ class ControlScroller(object):
                     ControlScroller.iScrollBarWidth - 1,
                 self.iCompPosY + 1, ControlScroller.iStep,
                 ControlScroller.iScrollBarWidth), 0, self)
-        self.nscrollvalue = 0
-        self.ControlGroupVector = []
+        ControlScroller.nscrollvalue = 0
+        ControlScroller.ControlGroupVector = []
         ypos = self.iStartPosY + ControlScroller.SORELFIRSTPOSY
-        for i in xrange(self.nblockincrement):
+        for i in xrange(ControlScroller.nblockincrement):
             self.insertControlGroup(i, ypos)
             ypos += self.linedistance
 
@@ -77,7 +78,7 @@ class ControlScroller(object):
             setPeerProperties(self.oImgControl, "MouseTransparent", True)
 
     def setScrollBarOrientationHorizontal(self):
-        Helper.setUnoPropertyValue(self.xScrollBar, "Orientation",HORIZONTAL)
+        Helper.setUnoPropertyValue(ControlScroller.xScrollBar, "Orientation",HORIZONTAL)
 
     '''
     @author bc93774
@@ -89,29 +90,29 @@ class ControlScroller(object):
         try:
             self.ntotfieldcount = _ntotfieldcount
             self.setCurFieldCount()
-            self.nscrollvalue = 0
+            ControlScroller.nscrollvalue = 0
             Helper.setUnoPropertyValue(
-                self.xScrollBar.Model, "ScrollValue", self.nscrollvalue)
-            if self.ntotfieldcount > self.nblockincrement:
+                ControlScroller.xScrollBar.Model, "ScrollValue", ControlScroller.nscrollvalue)
+            if self.ntotfieldcount > ControlScroller.nblockincrement:
                 Helper.setUnoPropertyValues(
-                    self.xScrollBar.Model, (PropertyNames.PROPERTY_ENABLED,
+                    ControlScroller.xScrollBar.Model, (PropertyNames.PROPERTY_ENABLED,
                         "BlockIncrement", "LineIncrement",
                         "ScrollValue", "ScrollValueMax"),
-                    (True, self.nblockincrement, self.nlineincrement,
-                        self.nscrollvalue,
-                        self.ntotfieldcount - self.nblockincrement))
+                    (True, ControlScroller.nblockincrement, self.nlineincrement,
+                        ControlScroller.nscrollvalue,
+                        self.ntotfieldcount - ControlScroller.nblockincrement))
             else:
                 Helper.setUnoPropertyValues(
-                    self.xScrollBar.Model,
+                    ControlScroller.xScrollBar.Model,
                     (PropertyNames.PROPERTY_ENABLED, "ScrollValue"),
-                    (False, self.nscrollvalue))
+                    (False, ControlScroller.nscrollvalue))
 
             self.fillupControls(True)
         except Exception:
             traceback.print_exc()
 
     def fillupControls(self, binitialize):
-        for i in xrange(0, self.nblockincrement):
+        for i in xrange(0, ControlScroller.nblockincrement):
             if i < self.ncurfieldcount:
                 self.fillupControl(i)
 
@@ -121,7 +122,7 @@ class ControlScroller(object):
     @classmethod
     def fillupControl(self, guiRow):
         nameProps = ControlScroller.scrollfields[guiRow]
-        valueProps = ControlScroller.scrollfields[guiRow + self.nscrollvalue]
+        valueProps = ControlScroller.scrollfields[guiRow + ControlScroller.nscrollvalue]
         for i in nameProps:
             if ControlScroller.CurUnoDialog.xDialogModel.hasByName(i.Name):
                 self.setControlData(i.Name, i.Value)
@@ -133,30 +134,32 @@ class ControlScroller(object):
             setTotalFieldCount(_ntotfieldcount)
         if _nscrollvalue >= 0:
             Helper.setUnoPropertyValue(
-                self.xScrollBar.Model, "ScrollValue", _nscrollvalue)
+                ControlScroller.xScrollBar.Model, "ScrollValue", _nscrollvalue)
             scrollControls()
 
+    @classmethod
     def setCurFieldCount(self):
-        if self.ntotfieldcount > self.nblockincrement:
-            self.ncurfieldcount = self.nblockincrement
+        if self.ntotfieldcount > ControlScroller.nblockincrement:
+            self.ncurfieldcount = ControlScroller.nblockincrement
         else:
             self.ncurfieldcount = self.ntotfieldcount
 
+    @classmethod
     def setTotalFieldCount(self, _ntotfieldcount):
         self.ntotfieldcount = _ntotfieldcount
         self.setCurFieldCount()
-        if self.ntotfieldcount > self.nblockincrement:
+        if self.ntotfieldcount > ControlScroller.nblockincrement:
             Helper.setUnoPropertyValues(
-                self.xScrollBar.Model,
+                ControlScroller.xScrollBar.Model,
                 (PropertyNames.PROPERTY_ENABLED, "ScrollValueMax"),
-                (True, self.ntotfieldcount - self.nblockincrement))
+                (True, self.ntotfieldcount - ControlScroller.nblockincrement))
         else:
-            Helper.setUnoPropertyValue(self.xScrollBar.Model,
+            Helper.setUnoPropertyValue(ControlScroller.xScrollBar.Model,
                 PropertyNames.PROPERTY_ENABLED, False)
 
     def toggleComponent(self, _bdoenable):
         bdoenable = _bdoenable and \
-            (self.ntotfieldcount > self.nblockincrement)
+            (self.ntotfieldcount > ControlScroller.nblockincrement)
         ControlScroller.CurUnoDialog.setControlProperty(
                 "TitleScrollBar" + self.sincSuffix,
                 PropertyNames.PROPERTY_ENABLED, bdoenable)
@@ -176,27 +179,27 @@ class ControlScroller(object):
     def setLineIncrementation(self, _nlineincrement):
         self.nlineincrement = _nlineincrement
         Helper.setUnoPropertyValue(
-            self.xScrollBar.Model, "LineIncrement", self.nlineincrement)
+            ControlScroller.xScrollBar.Model, "LineIncrement", self.nlineincrement)
 
     def getLineIncrementation(self):
         return self.nlineincrement
 
     def setBlockIncrementation(self, _nblockincrement):
-        self.nblockincrement = _nblockincrement
+        ControlScroller.nblockincrement = _nblockincrement
         Helper.setUnoPropertyValues(
-            self.xScrollBar.Model,
+            ControlScroller.xScrollBar.Model,
             (PropertyNames.PROPERTY_ENABLED, "BlockIncrement",
                 "ScrollValueMax"),
-            (self.ntotfieldcount > self.nblockincrement, self.nblockincrement,
-                self.ntotfieldcount - self.nblockincrement))
+            (self.ntotfieldcount > ControlScroller.nblockincrement, ControlScroller.nblockincrement,
+                self.ntotfieldcount - ControlScroller.nblockincrement))
 
     def scrollControls(self):
         try:
             scrollRowsInfo()
-            self.nscrollvalue = int(Helper.getUnoPropertyValue(
-                    self.xScrollBar.Model, "ScrollValue"))
-            if self.nscrollvalue + self.nblockincrement >= self.ntotfieldcount:
-                self.nscrollvalue = self.ntotfieldcount - self.nblockincrement
+            ControlScroller.nscrollvalue = int(Helper.getUnoPropertyValue(
+                    ControlScroller.xScrollBar.Model, "ScrollValue"))
+            if ControlScroller.nscrollvalue + ControlScroller.nblockincrement >= self.ntotfieldcount:
+                ControlScroller.nscrollvalue = self.ntotfieldcount - ControlScroller.nblockincrement
 
             fillupControls(False)
         except java.lang.Exception, ex:
@@ -225,27 +228,23 @@ class ControlScroller(object):
     this control.
     '''
 
+    @classmethod
     def fieldInfo(self, guiRow, column):
-        if guiRow + self.nscrollvalue < ControlScroller.scrollfields.size():
-            pv = fieldInfo(
-                (ControlScroller.scrollfields.elementAt(
-                    guiRow + self.nscrollvalue))[column],
-                (ControlScroller.scrollfields.elementAt(guiRow))[column])
-            return pv
+        if guiRow + ControlScroller.nscrollvalue < len(ControlScroller.scrollfields):
+            valueProp = (ControlScroller.scrollfields[guiRow + ControlScroller.nscrollvalue])[column]
+            nameProp = (ControlScroller.scrollfields[guiRow])[column]
+            if ControlScroller.CurUnoDialog.xDialogModel.hasByName(nameProp.Name):
+                valueProp.Value = self.getControlData(nameProp.Name)
+            else:
+                valueProp.Value = nameProp.Value
+            return valueProp
         else:
             return None
 
-    def fieldInfo(self, valueProp, nameProp):
-        if ControlScroller.CurUnoDialog.xDialogModel.hasByName(nameProp.Name):
-            valueProp.Value = getControlData(nameProp.Name)
-        else:
-            valueProp.Value = nameProp.Value
-
-        return valueProp
-
     def unregisterControlGroup(self, _index):
         ControlScroller.scrollfields.remove(_index)
 
+    @classmethod
     def registerControlGroup(self, _currowproperties, _i):
         if _i == 0:
             del ControlScroller.scrollfields[:]
@@ -267,6 +266,7 @@ class ControlScroller(object):
             ControlScroller.CurUnoDialog.setControlProperty(
                 controlname, propertyname, newvalue)
 
+    @classmethod
     def getControlData(self, controlname):
         oControlModel = ControlScroller.CurUnoDialog.xUnoDialog.getControl(
             controlname).Model


More information about the Libreoffice-commits mailing list