]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/activex/activex.py
Moved config.py to the root because if wxPython hasn't been built yet
[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 #---------------------------------------------------------------------------
9
10 class 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
50 class 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
59 class 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
78 class 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
85 class 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
95 class 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
102 class 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
116 class 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
123 class 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
140 class 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
147 class 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
164 class 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
171 class 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
188 class 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
197 class 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
340 class 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
350 def 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)
357 class 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 _preCallInit(*args, **kwargs):
371 """_preCallInit(PyObject pyself)"""
372 return _activex.ActiveXEvent__preCallInit(*args, **kwargs)
373
374 def _postCallCleanup(*args, **kwargs):
375 """_postCallCleanup(PyObject pyself)"""
376 return _activex.ActiveXEvent__postCallCleanup(*args, **kwargs)
377
378
379 class ActiveXEventPtr(ActiveXEvent):
380 def __init__(self, this):
381 self.this = this
382 if not hasattr(self,"thisown"): self.thisown = 0
383 self.__class__ = ActiveXEvent
384 _activex.ActiveXEvent_swigregister(ActiveXEventPtr)
385
386 #---------------------------------------------------------------------------
387
388 class IEHtmlWindowBase(ActiveXWindow):
389 def __repr__(self):
390 return "<%s.%s; proxy of C++ wxIEHtmlWindowBase instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
391 def __init__(self, *args, **kwargs):
392 newobj = _activex.new_IEHtmlWindowBase(*args, **kwargs)
393 self.this = newobj.this
394 self.thisown = 1
395 del newobj.thisown
396 def SetCharset(*args, **kwargs): return _activex.IEHtmlWindowBase_SetCharset(*args, **kwargs)
397 def LoadString(*args, **kwargs): return _activex.IEHtmlWindowBase_LoadString(*args, **kwargs)
398 def LoadStream(*args, **kwargs): return _activex.IEHtmlWindowBase_LoadStream(*args, **kwargs)
399 def GetStringSelection(*args, **kwargs): return _activex.IEHtmlWindowBase_GetStringSelection(*args, **kwargs)
400 def GetText(*args, **kwargs): return _activex.IEHtmlWindowBase_GetText(*args, **kwargs)
401
402 class IEHtmlWindowBasePtr(IEHtmlWindowBase):
403 def __init__(self, this):
404 self.this = this
405 if not hasattr(self,"thisown"): self.thisown = 0
406 self.__class__ = IEHtmlWindowBase
407 _activex.IEHtmlWindowBase_swigregister(IEHtmlWindowBasePtr)
408
409 #---------------------------------------------------------------------------
410 # Some helper and utility functions for ActiveX
411
412
413 t4 = " " * 4
414 t8 = " " * 8
415
416 def GetAXInfo(ax):
417 """
418 Returns a printable summary of the TypeInfo from the ActiveX instance
419 passed in.
420 """
421
422 def ProcessFuncX(f, out, name):
423 out.append(name)
424 out.append(t4 + "retType: %s" % f.retType.vt_type)
425 if f.params:
426 out.append(t4 + "params:")
427 for p in f.params:
428 out.append(t8 + p.name)
429 out.append(t8+t4+ "in:%s out:%s optional:%s type:%s" % (p.isIn, p.isOut, p.isOptional, p.vt_type))
430 out.append('')
431
432 def ProcessPropX(p, out):
433 out.append(GernerateAXModule.trimPropName(p.name))
434 out.append(t4+ "type:%s arg:%s canGet:%s canSet:%s" % (p.type.vt_type, p.arg.vt_type, p.canGet, p.canSet))
435 out.append('')
436
437 out = []
438
439 out.append("PROPERTIES")
440 out.append("-"*20)
441 for p in ax.GetAXProperties():
442 ProcessPropX(p, out)
443 out.append('\n\n')
444
445 out.append("METHODS")
446 out.append("-"*20)
447 for m in ax.GetAXMethods():
448 ProcessFuncX(m, out, GernerateAXModule.trimMethodName(m.name))
449 out.append('\n\n')
450
451 out.append("EVENTS")
452 out.append("-"*20)
453 for e in ax.GetAXEvents():
454 ProcessFuncX(e, out, GernerateAXModule.trimEventName(e.name))
455 out.append('\n\n')
456
457 return "\n".join(out)
458
459
460
461 class GernerateAXModule:
462 def __init__(self, ax, className, modulePath, moduleName=None, verbose=False):
463 """
464 Make a Python module file with a class that has been specialized
465 for the AcitveX object.
466
467 ax An instance of the ActiveXWindow class
468 className The name to use for the new class
469 modulePath The path where the new module should be written to
470 moduleName The name of the .py file to create. If not given
471 then the className will be used.
472 """
473 import os
474 if moduleName is None:
475 moduleName = className + '.py'
476 filename = os.path.join(modulePath, moduleName)
477 if verbose:
478 print "Creating module in:", filename
479 print " ProgID: ", ax.GetCLSID().GetProgIDString()
480 print " CLSID: ", ax.GetCLSID().GetCLSIDString()
481 print
482 self.mf = file(filename, "w")
483 self.WriteFileHeader(ax)
484 self.WriteEvents(ax)
485 self.WriteClassHeader(ax, className)
486 self.WriteMethods(ax)
487 self.WriteProperties(ax)
488 self.WriteDocs(ax)
489 self.mf.close()
490 del self.mf
491
492
493 def WriteFileHeader(self, ax):
494 self.write("# This module was generated by the wx.activex.GernerateAXModule class\n"
495 "# (See also the genaxmodule script.)\n")
496 self.write("import wx")
497 self.write("import wx.activex\n")
498 self.write("clsID = '%s'\nprogID = '%s'\n"
499 % (ax.GetCLSID().GetCLSIDString(), ax.GetCLSID().GetProgIDString()))
500 self.write("\n")
501
502
503 def WriteEvents(self, ax):
504 events = ax.GetAXEvents()
505 if events:
506 self.write("# Create eventTypes and event binders")
507 for e in events:
508 self.write("wxEVT_%s = wx.activex.RegisterActiveXEvent('%s')"
509 % (self.trimEventName(e.name), e.name))
510 self.write()
511 for e in events:
512 n = self.trimEventName(e.name)
513 self.write("EVT_%s = wx.PyEventBinder(wxEVT_%s, 1)" % (n,n))
514 self.write("\n")
515
516
517 def WriteClassHeader(self, ax, className):
518 self.write("# Derive a new class from ActiveXWindow")
519 self.write("""\
520 class %s(wx.activex.ActiveXWindow):
521 def __init__(self, parent, ID=-1, pos=wx.DefaultPosition,
522 size=wx.DefaultSize, style=0, name='%s'):
523 wx.activex.ActiveXWindow.__init__(self, parent,
524 wx.activex.CLSID('%s'),
525 ID, pos, size, style, name)
526 """ % (className, className, ax.GetCLSID().GetCLSIDString()) )
527
528
529 def WriteMethods(self, ax):
530 methods = ax.GetAXMethods()
531 if methods:
532 self.write(t4, "# Methods exported by the ActiveX object")
533 for m in methods:
534 name = self.trimMethodName(m.name)
535 self.write(t4, "def %s(self%s):" % (name, self.getParameters(m, True)))
536 self.write(t8, "return self.CallAXMethod('%s'%s)" % (m.name, self.getParameters(m, False)))
537 self.write()
538
539
540 def WriteProperties(self, ax):
541 props = ax.GetAXProperties()
542 if props:
543 self.write(t4, "# Getters, Setters and properties")
544 for p in props:
545 getterName = setterName = "None"
546 if p.canGet:
547 getterName = "_get_" + p.name
548 self.write(t4, "def %s(self):" % getterName)
549 self.write(t8, "return self.GetAXProp('%s')" % p.name)
550 if p.canSet:
551 setterName = "_set_" + p.name
552 self.write(t4, "def %s(self, %s):" % (setterName, p.arg.name))
553 self.write(t8, "self.SetAXProp('%s', %s)" % (p.name, p.arg.name))
554
555 self.write(t4, "%s = property(%s, %s)" %
556 (self.trimPropName(p.name), getterName, setterName))
557 self.write()
558
559
560 def WriteDocs(self, ax):
561 self.write()
562 doc = GetAXInfo(ax)
563 for line in doc.split('\n'):
564 self.write("# ", line)
565
566
567
568 def write(self, *args):
569 for a in args:
570 self.mf.write(a)
571 self.mf.write("\n")
572
573
574 def trimEventName(name):
575 if name.startswith("On"):
576 name = name[2:]
577 return name
578 trimEventName = staticmethod(trimEventName)
579
580
581 def trimPropName(name):
582 #name = name[0].lower() + name[1:]
583 name = name.lower()
584 import keyword
585 if name in keyword.kwlist: name += '_'
586 return name
587 trimPropName = staticmethod(trimPropName)
588
589
590 def trimMethodName(name):
591 import keyword
592 if name in keyword.kwlist: name += '_'
593 return name
594 trimMethodName = staticmethod(trimMethodName)
595
596
597 def getParameters(self, m, withDefaults):
598 import keyword
599 st = ""
600 # collect the input parameters, if both isIn and isOut are
601 # False then assume it is an input paramater
602 params = []
603 for p in m.params:
604 if p.isIn or (not p.isIn and not p.isOut):
605 params.append(p)
606 # did we get any?
607 for p in params:
608 name = p.name
609 if name in keyword.kwlist: name += '_'
610 st += ", "
611 st += name
612 if withDefaults and p.isOptional:
613 st += '=None'
614 return st
615
616
617 #---------------------------------------------------------------------------
618
619