]> git.saurik.com Git - wxWidgets.git/blame - wxPython/contrib/activex/activex.py
Lindsay Mathieson's newest wxActiveX class has been wrapped into a new
[wxWidgets.git] / wxPython / contrib / activex / activex.py
CommitLineData
b7c75283
RD
1# This file was created automatically by SWIG.
2# Don't modify this file, modify the SWIG interface instead.
3
4import _activex
5
6import core
7wx = core
8#---------------------------------------------------------------------------
9
10class CLSID(object):
11 """
12 This class wraps the Windows CLSID structure and is used to
13 specify the class of the ActiveX object that is to be created. A
14 CLSID can be constructed from either a ProgID string, (such as
15 'WordPad.Document.1') or a classID string, (such as
16 '{CA8A9783-280D-11CF-A24D-444553540000}').
17 """
18 def __repr__(self):
19 return "<%s.%s; proxy of C++ CLSID instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
20 def __init__(self, *args, **kwargs):
21 """
22 __init__(String id) -> CLSID
23
24 This class wraps the Windows CLSID structure and is used to
25 specify the class of the ActiveX object that is to be created. A
26 CLSID can be constructed from either a ProgID string, (such as
27 'WordPad.Document.1') or a classID string, (such as
28 '{CA8A9783-280D-11CF-A24D-444553540000}').
29 """
30 newobj = _activex.new_CLSID(*args, **kwargs)
31 self.this = newobj.this
32 self.thisown = 1
33 del newobj.thisown
34 def __del__(self, destroy=_activex.delete_CLSID):
35 """__del__()"""
36 try:
37 if self.thisown: destroy(self)
38 except: pass
39
40 def GetCLSIDString(*args, **kwargs):
41 """GetCLSIDString() -> String"""
42 return _activex.CLSID_GetCLSIDString(*args, **kwargs)
43
44 def GetProgIDString(*args, **kwargs):
45 """GetProgIDString() -> String"""
46 return _activex.CLSID_GetProgIDString(*args, **kwargs)
47
48 def __str__(self): return self.GetCLSIDString()
49
50class CLSIDPtr(CLSID):
51 def __init__(self, this):
52 self.this = this
53 if not hasattr(self,"thisown"): self.thisown = 0
54 self.__class__ = CLSID
55_activex.CLSID_swigregister(CLSIDPtr)
56
57#---------------------------------------------------------------------------
58
59class ParamX(object):
60 def __init__(self): raise RuntimeError, "No constructor defined"
61 def __repr__(self):
62 return "<%s.%s; proxy of C++ wxParamX instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
63 flags = property(_activex.ParamX_flags_get)
64 isPtr = property(_activex.ParamX_isPtr_get)
65 isSafeArray = property(_activex.ParamX_isSafeArray_get)
66 isOptional = property(_activex.ParamX_isOptional_get)
67 vt = property(_activex.ParamX_vt_get)
68 name = property(_activex.ParamX_name_get)
69 vt_type = property(_activex.ParamX_vt_type_get)
70
71 isIn = property(_activex.ParamX_IsIn)
72
73 isOut = property(_activex.ParamX_IsOut)
74
75 isRetVal = property(_activex.ParamX_IsRetVal)
76
77
78class ParamXPtr(ParamX):
79 def __init__(self, this):
80 self.this = this
81 if not hasattr(self,"thisown"): self.thisown = 0
82 self.__class__ = ParamX
83_activex.ParamX_swigregister(ParamXPtr)
84
85class FuncX(object):
86 def __init__(self): raise RuntimeError, "No constructor defined"
87 def __repr__(self):
88 return "<%s.%s; proxy of C++ wxFuncX instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
89 name = property(_activex.FuncX_name_get)
90 memid = property(_activex.FuncX_memid_get)
91 hasOut = property(_activex.FuncX_hasOut_get)
92 retType = property(_activex.FuncX_retType_get)
93 params = property(_activex.FuncX_params_get)
94
95class FuncXPtr(FuncX):
96 def __init__(self, this):
97 self.this = this
98 if not hasattr(self,"thisown"): self.thisown = 0
99 self.__class__ = FuncX
100_activex.FuncX_swigregister(FuncXPtr)
101
102class PropX(object):
103 def __init__(self): raise RuntimeError, "No constructor defined"
104 def __repr__(self):
105 return "<%s.%s; proxy of C++ wxPropX instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
106 name = property(_activex.PropX_name_get)
107 memid = property(_activex.PropX_memid_get)
108 type = property(_activex.PropX_type_get)
109 arg = property(_activex.PropX_arg_get)
110 putByRef = property(_activex.PropX_putByRef_get)
111 canGet = property(_activex.PropX_CanGet)
112
113 canSet = property(_activex.PropX_CanSet)
114
115
116class PropXPtr(PropX):
117 def __init__(self, this):
118 self.this = this
119 if not hasattr(self,"thisown"): self.thisown = 0
120 self.__class__ = PropX
121_activex.PropX_swigregister(PropXPtr)
122
123class ParamXArray(object):
124 def __init__(self): raise RuntimeError, "No constructor defined"
125 def __repr__(self):
126 return "<%s.%s; proxy of C++ wxParamXArray instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
127 def __nonzero__(*args, **kwargs):
128 """__nonzero__() -> bool"""
129 return _activex.ParamXArray___nonzero__(*args, **kwargs)
130
131 def __len__(*args, **kwargs):
132 """__len__() -> int"""
133 return _activex.ParamXArray___len__(*args, **kwargs)
134
135 def __getitem__(*args, **kwargs):
136 """__getitem__(int idx) -> ParamX"""
137 return _activex.ParamXArray___getitem__(*args, **kwargs)
138
139
140class ParamXArrayPtr(ParamXArray):
141 def __init__(self, this):
142 self.this = this
143 if not hasattr(self,"thisown"): self.thisown = 0
144 self.__class__ = ParamXArray
145_activex.ParamXArray_swigregister(ParamXArrayPtr)
146
147class FuncXArray(object):
148 def __init__(self): raise RuntimeError, "No constructor defined"
149 def __repr__(self):
150 return "<%s.%s; proxy of C++ wxFuncXArray instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
151 def __nonzero__(*args, **kwargs):
152 """__nonzero__() -> bool"""
153 return _activex.FuncXArray___nonzero__(*args, **kwargs)
154
155 def __len__(*args, **kwargs):
156 """__len__() -> int"""
157 return _activex.FuncXArray___len__(*args, **kwargs)
158
159 def __getitem__(*args, **kwargs):
160 """__getitem__(int idx) -> FuncX"""
161 return _activex.FuncXArray___getitem__(*args, **kwargs)
162
163
164class FuncXArrayPtr(FuncXArray):
165 def __init__(self, this):
166 self.this = this
167 if not hasattr(self,"thisown"): self.thisown = 0
168 self.__class__ = FuncXArray
169_activex.FuncXArray_swigregister(FuncXArrayPtr)
170
171class PropXArray(object):
172 def __init__(self): raise RuntimeError, "No constructor defined"
173 def __repr__(self):
174 return "<%s.%s; proxy of C++ wxPropXArray instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
175 def __nonzero__(*args, **kwargs):
176 """__nonzero__() -> bool"""
177 return _activex.PropXArray___nonzero__(*args, **kwargs)
178
179 def __len__(*args, **kwargs):
180 """__len__() -> int"""
181 return _activex.PropXArray___len__(*args, **kwargs)
182
183 def __getitem__(*args, **kwargs):
184 """__getitem__(int idx) -> PropX"""
185 return _activex.PropXArray___getitem__(*args, **kwargs)
186
187
188class PropXArrayPtr(PropXArray):
189 def __init__(self, this):
190 self.this = this
191 if not hasattr(self,"thisown"): self.thisown = 0
192 self.__class__ = PropXArray
193_activex.PropXArray_swigregister(PropXArrayPtr)
194
195#---------------------------------------------------------------------------
196
197class ActiveXWindow(core.Window):
198 """
199 ActiveXWindow derives from wxWindow and the constructor accepts a
200 CLSID for the ActiveX Control that should be created. The
201 ActiveXWindow class simply adds methods that allow you to query
202 some of the TypeInfo exposed by the ActiveX object, and also to
203 get/set properties or call methods by name. The Python
204 implementation automatically handles converting parameters and
205 return values to/from the types expected by the ActiveX code as
206 specified by the TypeInfo.
207
208 """
209 def __repr__(self):
210 return "<%s.%s; proxy of C++ wxActiveXWindow instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
211 def __init__(self, *args, **kwargs):
212 """
213 __init__(Window parent, CLSID clsId, int id=-1, Point pos=DefaultPosition,
214 Size size=DefaultSize, long style=0,
215 String name=PanelNameStr) -> ActiveXWindow
216
217 Creates an ActiveX control from the clsID given and makes it act
218 as much like a regular wx.Window as possible.
219 """
220 newobj = _activex.new_ActiveXWindow(*args, **kwargs)
221 self.this = newobj.this
222 self.thisown = 1
223 del newobj.thisown
224 self._setOORInfo(self)
225
226 def GetCLSID(*args, **kwargs):
227 """
228 GetCLSID() -> CLSID
229
230 Return the CLSID used to construct this ActiveX window
231 """
232 return _activex.ActiveXWindow_GetCLSID(*args, **kwargs)
233
234 def GetAXEventCount(*args, **kwargs):
235 """
236 GetAXEventCount() -> int
237
238 Number of events defined for this control
239 """
240 return _activex.ActiveXWindow_GetAXEventCount(*args, **kwargs)
241
242 def GetAXEventDesc(*args, **kwargs):
243 """
244 GetAXEventDesc(int idx) -> FuncX
245
246 Returns event description by index
247 """
248 return _activex.ActiveXWindow_GetAXEventDesc(*args, **kwargs)
249
250 def GetAXPropCount(*args, **kwargs):
251 """
252 GetAXPropCount() -> int
253
254 Number of properties defined for this control
255 """
256 return _activex.ActiveXWindow_GetAXPropCount(*args, **kwargs)
257
258 def GetAXPropDesc(*args):
259 """
260 GetAXPropDesc(int idx) -> PropX
261 GetAXPropDesc(String name) -> PropX
262 """
263 return _activex.ActiveXWindow_GetAXPropDesc(*args)
264
265 def GetAXMethodCount(*args, **kwargs):
266 """
267 GetAXMethodCount() -> int
268
269 Number of methods defined for this control
270 """
271 return _activex.ActiveXWindow_GetAXMethodCount(*args, **kwargs)
272
273 def GetAXMethodDesc(*args):
274 """
275 GetAXMethodDesc(int idx) -> FuncX
276 GetAXMethodDesc(String name) -> FuncX
277 """
278 return _activex.ActiveXWindow_GetAXMethodDesc(*args)
279
280 def GetAXEvents(*args, **kwargs):
281 """
282 GetAXEvents() -> FuncXArray
283
284 Returns a sequence of FuncX objects describing the events
285 available for this ActiveX object.
286 """
287 return _activex.ActiveXWindow_GetAXEvents(*args, **kwargs)
288
289 def GetAXMethods(*args, **kwargs):
290 """
291 GetAXMethods() -> FuncXArray
292
293 Returns a sequence of FuncX objects describing the methods
294 available for this ActiveX object.
295 """
296 return _activex.ActiveXWindow_GetAXMethods(*args, **kwargs)
297
298 def GetAXProperties(*args, **kwargs):
299 """
300 GetAXProperties() -> PropXArray
301
302 Returns a sequence of PropX objects describing the properties
303 available for this ActiveX object.
304 """
305 return _activex.ActiveXWindow_GetAXProperties(*args, **kwargs)
306
307 def SetAXProp(*args, **kwargs):
308 """
309 SetAXProp(String name, PyObject value)
310
311 Set a property of the ActiveX object by name.
312 """
313 return _activex.ActiveXWindow_SetAXProp(*args, **kwargs)
314
315 def GetAXProp(*args, **kwargs):
316 """
317 GetAXProp(String name) -> PyObject
318
319 Get the value of an ActiveX property by name.
320 """
321 return _activex.ActiveXWindow_GetAXProp(*args, **kwargs)
322
323 def _CallAXMethod(*args):
324 """
325 _CallAXMethod(String name, PyObject args) -> PyObject
326
327 The implementation for CallMethod. Calls an ActiveX method, by
328 name passing the parameters given in args.
329 """
330 return _activex.ActiveXWindow__CallAXMethod(*args)
331
332 def CallAXMethod(self, name, *args):
333 """
334 Front-end for _CallMethod. Simply passes all positional args
335 after the name as a single tuple to _CallMethod.
336 """
337 return self._CallAXMethod(name, args)
338
339
340class ActiveXWindowPtr(ActiveXWindow):
341 def __init__(self, this):
342 self.this = this
343 if not hasattr(self,"thisown"): self.thisown = 0
344 self.__class__ = ActiveXWindow
345_activex.ActiveXWindow_swigregister(ActiveXWindowPtr)
346
347#---------------------------------------------------------------------------
348
349
350def RegisterActiveXEvent(*args, **kwargs):
351 """
352 RegisterActiveXEvent(String eventName) -> wxEventType
353
354 Creates a standard wx event ID for the given eventName.
355 """
356 return _activex.RegisterActiveXEvent(*args, **kwargs)
357class ActiveXEvent(core.CommandEvent):
358 """
359 An instance of ActiveXEvent is sent to the handler for all bound
360 ActiveX events. Any event parameters from the ActiveX cntrol are
361 turned into attributes of the Python proxy for this event object.
362 Additionally, there is a property called eventName that will
363 return (suprizingly <wink>) the name of the ActiveX event.
364 """
365 def __init__(self): raise RuntimeError, "No constructor defined"
366 def __repr__(self):
367 return "<%s.%s; proxy of C++ wxActiveXEvent instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
368 eventName = property(_activex.ActiveXEvent_EventName)
369
370 def _preInit(*args, **kwargs):
371 """
372 _preInit(PyObject pyself)
373
374 This is called by the EventThunker before calling the handler.
375 We'll convert and load the ActiveX event parameters into
376 attributes of the Python event object.
377 """
378 return _activex.ActiveXEvent__preInit(*args, **kwargs)
379
380
381class ActiveXEventPtr(ActiveXEvent):
382 def __init__(self, this):
383 self.this = this
384 if not hasattr(self,"thisown"): self.thisown = 0
385 self.__class__ = ActiveXEvent
386_activex.ActiveXEvent_swigregister(ActiveXEventPtr)
387
388#---------------------------------------------------------------------------
389
390class IEHtmlWindowBase(ActiveXWindow):
391 def __repr__(self):
392 return "<%s.%s; proxy of C++ wxIEHtmlWindowBase instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
393 def __init__(self, *args, **kwargs):
394 newobj = _activex.new_IEHtmlWindowBase(*args, **kwargs)
395 self.this = newobj.this
396 self.thisown = 1
397 del newobj.thisown
398 def SetCharset(*args, **kwargs): return _activex.IEHtmlWindowBase_SetCharset(*args, **kwargs)
399 def LoadString(*args, **kwargs): return _activex.IEHtmlWindowBase_LoadString(*args, **kwargs)
400 def LoadStream(*args, **kwargs): return _activex.IEHtmlWindowBase_LoadStream(*args, **kwargs)
401 def GetStringSelection(*args, **kwargs): return _activex.IEHtmlWindowBase_GetStringSelection(*args, **kwargs)
402 def GetText(*args, **kwargs): return _activex.IEHtmlWindowBase_GetText(*args, **kwargs)
403
404class IEHtmlWindowBasePtr(IEHtmlWindowBase):
405 def __init__(self, this):
406 self.this = this
407 if not hasattr(self,"thisown"): self.thisown = 0
408 self.__class__ = IEHtmlWindowBase
409_activex.IEHtmlWindowBase_swigregister(IEHtmlWindowBasePtr)
410
411#---------------------------------------------------------------------------
412# Some helper and utility functions for ActiveX
413
414
415t4 = " " * 4
416t8 = " " * 8
417
418def GetAXInfo(ax):
419 """
420 Returns a printable summary of the TypeInfo from the ActiveX instance
421 passed in.
422 """
423
424 def ProcessFuncX(f, out, name):
425 out.append(name)
426 out.append(t4 + "retType: %s" % f.retType.vt_type)
427 if f.params:
428 out.append(t4 + "params:")
429 for p in f.params:
430 out.append(t8 + p.name)
431 out.append(t8+t4+ "in:%s out:%s optional:%s type:%s" % (p.isIn, p.isOut, p.isOptional, p.vt_type))
432 out.append('')
433
434 def ProcessPropX(p, out):
435 out.append(GernerateAXModule.trimPropName(p.name))
436 out.append(t4+ "type:%s arg:%s canGet:%s canSet:%s" % (p.type.vt_type, p.arg.vt_type, p.canGet, p.canSet))
437 out.append('')
438
439 out = []
440
441 out.append("PROPERTIES")
442 out.append("-"*20)
443 for p in ax.GetAXProperties():
444 ProcessPropX(p, out)
445 out.append('\n\n')
446
447 out.append("METHODS")
448 out.append("-"*20)
449 for m in ax.GetAXMethods():
450 ProcessFuncX(m, out, GernerateAXModule.trimMethodName(m.name))
451 out.append('\n\n')
452
453 out.append("EVENTS")
454 out.append("-"*20)
455 for e in ax.GetAXEvents():
456 ProcessFuncX(e, out, GernerateAXModule.trimEventName(e.name))
457 out.append('\n\n')
458
459 return "\n".join(out)
460
461
462
463class GernerateAXModule:
464 def __init__(self, ax, className, modulePath, moduleName=None, verbose=False):
465 """
466 Make a Python module file with a class that has been specialized
467 for the AcitveX object.
468
469 ax An instance of the ActiveXWindow class
470 className The name to use for the new class
471 modulePath The path where the new module should be written to
472 moduleName The name of the .py file to create. If not given
473 then the className will be used.
474 """
475 import os
476 if moduleName is None:
477 moduleName = className + '.py'
478 filename = os.path.join(modulePath, moduleName)
479 if verbose:
480 print "Creating module in:", filename
481 print " ProgID: ", ax.GetCLSID().GetProgIDString()
482 print " CLSID: ", ax.GetCLSID().GetCLSIDString()
483 print
484 self.mf = file(filename, "w")
485 self.WriteFileHeader(ax)
486 self.WriteEvents(ax)
487 self.WriteClassHeader(ax, className)
488 self.WriteMethods(ax)
489 self.WriteProperties(ax)
490 self.WriteDocs(ax)
491 self.mf.close()
492 del self.mf
493
494
495 def WriteFileHeader(self, ax):
496 self.write("# This module was generated by the wx.activex.GernerateAXModule class\n"
497 "# (See also the genaxmodule script.)\n")
498 self.write("import wx")
499 self.write("import wx.activex\n")
500 self.write("clsID = '%s'\nprogID = '%s'\n"
501 % (ax.GetCLSID().GetCLSIDString(), ax.GetCLSID().GetProgIDString()))
502 self.write("\n")
503
504
505 def WriteEvents(self, ax):
506 events = ax.GetAXEvents()
507 if events:
508 self.write("# Create eventTypes and event binders")
509 for e in events:
510 self.write("wxEVT_%s = wx.activex.RegisterActiveXEvent('%s')"
511 % (self.trimEventName(e.name), e.name))
512 self.write()
513 for e in events:
514 n = self.trimEventName(e.name)
515 self.write("EVT_%s = wx.PyEventBinder(wxEVT_%s, 1)" % (n,n))
516 self.write("\n")
517
518
519 def WriteClassHeader(self, ax, className):
520 self.write("# Derive a new class from ActiveXWindow")
521 self.write("""\
522class %s(wx.activex.ActiveXWindow):
523 def __init__(self, parent, ID=-1, pos=wx.DefaultPosition,
524 size=wx.DefaultSize, style=0, name='%s'):
525 wx.activex.ActiveXWindow.__init__(self, parent,
526 wx.activex.CLSID('%s'),
527 ID, pos, size, style, name)
528 """ % (className, className, ax.GetCLSID().GetCLSIDString()) )
529
530
531 def WriteMethods(self, ax):
532 methods = ax.GetAXMethods()
533 if methods:
534 self.write(t4, "# Methods exported by the ActiveX object")
535 for m in methods:
536 name = self.trimMethodName(m.name)
537 self.write(t4, "def %s(self%s):" % (name, self.getParameters(m, True)))
538 self.write(t8, "return self.CallAXMethod('%s'%s)" % (m.name, self.getParameters(m, False)))
539 self.write()
540
541
542 def WriteProperties(self, ax):
543 props = ax.GetAXProperties()
544 if props:
545 self.write(t4, "# Getters, Setters and properties")
546 for p in props:
547 getterName = setterName = "None"
548 if p.canGet:
549 getterName = "_get_" + p.name
550 self.write(t4, "def %s(self):" % getterName)
551 self.write(t8, "return self.GetAXProp('%s')" % p.name)
552 if p.canSet:
553 setterName = "_set_" + p.name
554 self.write(t4, "def %s(self, %s):" % (setterName, p.arg.name))
555 self.write(t8, "self.SetAXProp('%s', %s)" % (p.name, p.arg.name))
556
557 self.write(t4, "%s = property(%s, %s)" %
558 (self.trimPropName(p.name), getterName, setterName))
559 self.write()
560
561
562 def WriteDocs(self, ax):
563 self.write()
564 doc = GetAXInfo(ax)
565 for line in doc.split('\n'):
566 self.write("# ", line)
567
568
569
570 def write(self, *args):
571 for a in args:
572 self.mf.write(a)
573 self.mf.write("\n")
574
575
576 def trimEventName(name):
577 if name.startswith("On"):
578 name = name[2:]
579 return name
580 trimEventName = staticmethod(trimEventName)
581
582
583 def trimPropName(name):
584 #name = name[0].lower() + name[1:]
585 name = name.lower()
586 import keyword
587 if name in keyword.kwlist: name += '_'
588 return name
589 trimPropName = staticmethod(trimPropName)
590
591
592 def trimMethodName(name):
593 import keyword
594 if name in keyword.kwlist: name += '_'
595 return name
596 trimMethodName = staticmethod(trimMethodName)
597
598
599 def getParameters(self, m, withDefaults):
600 import keyword
601 st = ""
602 # collect the input parameters, if both isIn and isOut are
603 # False then assume it is an input paramater
604 params = []
605 for p in m.params:
606 if p.isIn or (not p.isIn and not p.isOut):
607 params.append(p)
608 # did we get any?
609 for p in params:
610 name = p.name
611 if name in keyword.kwlist: name += '_'
612 st += ", "
613 st += name
614 if withDefaults and p.isOptional:
615 st += '=None'
616 return st
617
618
619#---------------------------------------------------------------------------
620
621