wizards/source/access2base/Python.xba     |   18 +++++++++++----
 wizards/source/access2base/access2base.py |   36 ++++++++++++++++++++++--------
 2 files changed, 41 insertions(+), 13 deletions(-)

New commits:
commit 54b47a81fdba4fb42f7f5eaee65292014567cd29
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Fri Aug 23 13:08:12 2019 +0200
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Fri Aug 23 13:12:17 2019 +0200

    Access2Base - Implement Find and ProcOfLine
    
    Find and ProcOfLine are methods of the MODULE class
    They return a value (as usual) but also parameters
    passed by reference, which is not supported by Python
    As a workaround, specific properties are set after
    their execution
    
    Change-Id: I70ed3646a6d701a4853d071d4ca6eb213276d5e9

diff --git a/wizards/source/access2base/Python.xba 
b/wizards/source/access2base/Python.xba
index 45144ec7c8d3..0ef8a7e96fbc 100644
--- a/wizards/source/access2base/Python.xba
+++ b/wizards/source/access2base/Python.xba
@@ -88,7 +88,7 @@ Public Function PythonWrapper(ByVal pvCallType As Variant _
 &apos;                         [0] =&gt; 0 = scalar or array returned by the 
method
 &apos;                                 =&gt; 1 = basic object returned by the 
method
 &apos;                                 =&gt; 2 = a null value
-&apos;                         [1] =&gt; the object reference or the returned 
value or Null
+&apos;                         [1] =&gt; the object reference or the returned 
value (complemented with arguments passed by reference, if any) or Null
 &apos;                         [2] =&gt; the object type or Null
 &apos;                         [3] =&gt; the object name, if any
 &apos;                 or, when pvCallType == vbUNO, as the UNO object 
returned by the property
@@ -222,6 +222,10 @@ Const vbGet = 2, vbLet = 4, vbMethod = 1, vbSet = 8, vbUNO 
= 16
                                        If vObject._Type = 
&quot;COLLECTION&quot; And vObject._CollType = COLLTABLEDEFS Then vArgs = 
Array(_A2B_.PythonCache(vArgs(0)))
                                Case &quot;Close&quot;
                                        sSCript = &quot;mClose&quot;
+                               Case &quot;Find&quot;
+                                       For i = 0 To UBound(vArgs)
+                                               If IsNull(vArgs(i)) Then 
vArgs(i) = Empty
+                                       Next i
                                Case &quot;Type&quot;
                                        sScript = &quot;pType&quot;
                                Case Else
@@ -294,9 +298,15 @@ Const vbGet = 2, vbLet = 4, vbMethod = 1, vbSet = 8, vbUNO 
= 16
                                Case &quot;Close&quot;, &quot;Dispose&quot;, 
&quot;Terminate&quot;
                                        Set _A2B_.PythonCache(pvObject) = 
Nothing
                                Case &quot;Move&quot;, &quot;MoveFirst&quot;, 
&quot;MoveLast&quot;, &quot;MoveNext&quot;, &quot;MovePrevious&quot;      
&apos;  Pass the new BOF, EOF values (binary format)
-                                               If vObject._Type = 
&quot;RECORDSET&quot; Then
-                                                       vReturn = 
(Iif(vObject.BOF, 1, 0) * 2 + Iif(vObject.EOF, 1, 0)) * Iif(vReturn, 1, -1)
-                                               End If
+                                       If vObject._Type = 
&quot;RECORDSET&quot; Then
+                                               vReturn = (Iif(vObject.BOF, 1, 
0) * 2 + Iif(vObject.EOF, 1, 0)) * Iif(vReturn, 1, -1)
+                                       End If
+                               Case &quot;Find&quot;                           
&apos;  Store in array the arguments passed by reference
+                                       If vObject._Type = &quot;MODULE&quot; 
And vReturn = True Then
+                                               vReturn = Array(vReturn, 
vArgs(1), vArgs(2), vArgs(3), vArgs(4))
+                                       End If
+                               Case &quot;ProcOfLine&quot;             &apos;  
Store in array the arguments passed by reference
+                                       vReturn = Array(vReturn, vArgs(1))
                                Case Else
                        End Select
        End Select
diff --git a/wizards/source/access2base/access2base.py 
b/wizards/source/access2base/access2base.py
index e58f1cce9f14..ca4a2b64bd19 100644
--- a/wizards/source/access2base/access2base.py
+++ b/wizards/source/access2base/access2base.py
@@ -985,16 +985,17 @@ class _BasicObject(object):
         5. Setting a property value is done via a Basic call, except if 
self.internal == True
     """
     W = _A2B.invokeWrapper
-    internal_attributes = ('objectreference', 'objecttype', 'name', 'count', 
'index', 'internal')
+    internal_attributes = ('objectreference', 'objecttype', 'name', 'internal')
 
     def __init__(self, reference = -1, objtype = None, name = ''):
         self.objectreference = reference    # reference in the cache managed 
by Basic
         self.objecttype = objtype           # ('DATABASE', 'COLLECTION', ...)
         self.name = name                    # '' when no name
         self.internal = False               # True to exceptionally allow 
assigning a new value to a read-only property
+        self.localProperties = ()
 
     def __getattr__(self, name):
-        if name == 'classProperties':
+        if name in ('classProperties', 'localProperties'):
             pass
         elif name in self.classProperties:
             # Get Property from Basic
@@ -1003,7 +1004,7 @@ class _BasicObject(object):
         return super(_BasicObject, self).__getattribute__(name)
 
     def __setattr__(self, name, value):
-        if name == 'classProperties':
+        if name in ('classProperties', 'localProperties'):
             pass
         elif name in self.classProperties:
             if self.internal:       # internal = True forces property setting 
even if property is read-only
@@ -1012,7 +1013,7 @@ class _BasicObject(object):
                 self.W(_vbLet, self.objectreference, name, value)
             else:
                 raise AttributeError("type object '" + self.objecttype + "' 
has no editable attribute '" + name + "'")
-        elif name[0:2] == '__' or name in self.internal_attributes:
+        elif name[0:2] == '__' or name in self.internal_attributes or name in 
self.localProperties:
             pass
         else:
             raise AttributeError("type object '" + self.objecttype + "' has no 
attribute '" + name + "'")
@@ -1069,6 +1070,7 @@ class _Collection(_BasicObject):
     classProperties = dict(Count = False)
     def __init__(self, reference = -1, objtype = None):
         super().__init__(reference, objtype)
+        self.localProperties = ('count', 'index')
         self.count = self.Count
         self.index = 0
     def __iter__(self):
@@ -1325,19 +1327,35 @@ class _Module(_BasicObject):
     classProperties = dict(CountOfDeclarationLines = False, CountOfLines = 
False
                         , ProcStartLine = False, Type = False
                         )
+    def __init__(self, reference = -1, objtype = None, name = ''):
+        super().__init__(reference, objtype, name)
+        self.localProperties = ('startline', 'startcolumn', 'endline', 
'endcolumn', 'prockind')
 
-    """ def Find(self, target, startline, startcolumn, endline, endcolumn, 
wholeword = False
+    def Find(self, target, startline, startcolumn, endline, endcolumn, 
wholeword = False
         , matchcase = False, patternsearch = False):
-        return self.W(_vbMethod, self.objectreference, 'Find', target, 
startline, startcolumn, endline
-                      , endcolumn, wholeword, matchcase, patternsearch) """
+        Returned = self.W(_vbMethod, self.objectreference, 'Find', target, 
startline, startcolumn, endline
+                      , endcolumn, wholeword, matchcase, patternsearch)
+        if isinstance(Returned, tuple):
+            if Returned[0] == True and len(Returned) == 5:
+                self.startline = Returned[1]
+                self.startcolumn = Returned[2]
+                self.endline = Returned[3]
+                self.endcolumn = Returned[4]
+            return Returned[0]
+        return Returned
     def Lines(self, line, numlines):
         return self.W(_vbMethod, self.objectreference, 'Lines', line, numlines)
     def ProcBodyLine(self, procname, prockind):
         return self.W(_vbMethod, self.objectreference, 'ProcBodyLine', 
procname, prockind)
     def ProcCountLines(self, procname, prockind):
         return self.W(_vbMethod, self.objectreference, 'ProcCountLines', 
procname, prockind)
-    """ def ProcOfLine(self, line, prockind):
-        return self.W(_vbMethod, self.objectreference, 'ProcOfLine', line, 
prockind) """
+    def ProcOfLine(self, line, prockind):
+        Returned = self.W(_vbMethod, self.objectreference, 'ProcOfLine', line, 
prockind)
+        if isinstance(Returned, tuple):
+            if len(Returned) == 2:
+                self.prockind = Returned[1]
+                return Returned[0]
+        return Returned
     def ProcStartLine(self, procname, prockind):
         return self.W(_vbMethod, self.objectreference, 'ProcStartLine', 
procname, prockind)
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to