@@ -23,6 +23,23 @@ class XLPythonObject(object):
23
23
_public_methods_ = []
24
24
def __init__ (self , obj ):
25
25
self .obj = obj
26
+
27
+ class XLPythonIterator (object ):
28
+ _public_methods_ = [ "MoveNext" , "Current" ]
29
+
30
+ def __init__ (self , obj ):
31
+ self .iter = obj .__iter__ ()
32
+ self .current = None
33
+
34
+ def MoveNext (self ):
35
+ try :
36
+ self .current = self .iter .next ()
37
+ return True
38
+ except StopIteration :
39
+ return False
40
+
41
+ def Current (self ):
42
+ return ToVariant (self .current )
26
43
27
44
def FromVariant (var ):
28
45
try :
@@ -34,7 +51,7 @@ def ToVariant(obj):
34
51
return win32com .server .util .wrap (XLPythonObject (obj ))
35
52
36
53
class XLPython (object ):
37
- _public_methods_ = [ 'Module' , 'Tuple' , 'Dict' , 'List' , 'Obj' , 'Str' , 'Var' , 'Call' , 'GetItem' , 'SetItem' , 'GetAttr' , 'SetAttr' , 'Eval' , 'Exec' , 'ShowConsole' , 'Reload' , 'AddPath' ]
54
+ _public_methods_ = [ 'Module' , 'Tuple' , 'Dict' , 'List' , 'Obj' , 'Str' , 'Var' , 'Call' , 'GetItem' , 'SetItem' , 'GetAttr' , 'SetAttr' , 'HasAttr' , ' Eval' , 'Exec' , 'ShowConsole' , 'Reload' , 'AddPath' , 'Builtins' , 'Len' , 'GetIter ' ]
38
55
39
56
def ShowConsole (self ):
40
57
import ctypes
@@ -117,6 +134,14 @@ def Call(self, obj, *args):
117
134
else :
118
135
return ToVariant (getattr (obj , method )(* pargs , ** kwargs ))
119
136
137
+ def Len (self , obj ):
138
+ obj = FromVariant (obj )
139
+ return len (obj )
140
+
141
+ def Builtins (self ):
142
+ import __builtin__
143
+ return ToVariant (__builtin__ )
144
+
120
145
def GetItem (self , obj , key ):
121
146
obj = FromVariant (obj )
122
147
key = FromVariant (key )
@@ -139,6 +164,15 @@ def SetAttr(self, obj, attr, value):
139
164
value = FromVariant (value )
140
165
setattr (obj , attr , value )
141
166
167
+ def HasAttr (self , obj , attr ):
168
+ obj = FromVariant (obj )
169
+ attr = FromVariant (attr )
170
+ return hasattr (obj , attr )
171
+
172
+ def GetIter (self , obj ):
173
+ obj = FromVariant (obj )
174
+ return win32com .server .util .wrap (XLPythonIterator (obj ))
175
+
142
176
def Eval (self , expr , * args ):
143
177
globals = None
144
178
locals = None
0 commit comments