diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2019-08-23 13:08:12 +0200 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2019-08-23 13:12:17 +0200 |
commit | 54b47a81fdba4fb42f7f5eaee65292014567cd29 (patch) | |
tree | 35aa7ce48fcc018aa409b5e7db4dd65ef8d28109 /wizards | |
parent | 5c2c08f635c30b732df48faca7ba3d411074e05a (diff) |
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
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/access2base/Python.xba | 18 | ||||
-rw-r--r-- | wizards/source/access2base/access2base.py | 36 |
2 files changed, 41 insertions, 13 deletions
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 _ ' [0] => 0 = scalar or array returned by the method ' => 1 = basic object returned by the method ' => 2 = a null value -' [1] => the object reference or the returned value or Null +' [1] => the object reference or the returned value (complemented with arguments passed by reference, if any) or Null ' [2] => the object type or Null ' [3] => the object name, if any ' 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 = "COLLECTION" And vObject._CollType = COLLTABLEDEFS Then vArgs = Array(_A2B_.PythonCache(vArgs(0))) Case "Close" sSCript = "mClose" + Case "Find" + For i = 0 To UBound(vArgs) + If IsNull(vArgs(i)) Then vArgs(i) = Empty + Next i Case "Type" sScript = "pType" Case Else @@ -294,9 +298,15 @@ Const vbGet = 2, vbLet = 4, vbMethod = 1, vbSet = 8, vbUNO = 16 Case "Close", "Dispose", "Terminate" Set _A2B_.PythonCache(pvObject) = Nothing Case "Move", "MoveFirst", "MoveLast", "MoveNext", "MovePrevious" ' Pass the new BOF, EOF values (binary format) - If vObject._Type = "RECORDSET" Then - vReturn = (Iif(vObject.BOF, 1, 0) * 2 + Iif(vObject.EOF, 1, 0)) * Iif(vReturn, 1, -1) - End If + If vObject._Type = "RECORDSET" Then + vReturn = (Iif(vObject.BOF, 1, 0) * 2 + Iif(vObject.EOF, 1, 0)) * Iif(vReturn, 1, -1) + End If + Case "Find" ' Store in array the arguments passed by reference + If vObject._Type = "MODULE" And vReturn = True Then + vReturn = Array(vReturn, vArgs(1), vArgs(2), vArgs(3), vArgs(4)) + End If + Case "ProcOfLine" ' 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) |