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