]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/activex/_activex_ex.py
3 #---------------------------------------------------------------------------
4 # Some helper and utility functions for ActiveX
12 Returns a printable summary of the TypeInfo from the ActiveX instance
16 def ProcessFuncX(f
, out
, name
):
18 out
.append(t4
+ "retType: %s" % f
.retType
.vt_type
)
20 out
.append(t4
+ "params:")
22 out
.append(t8
+ p
.name
)
23 out
.append(t8
+t4
+ "in:%s out:%s optional:%s type:%s" % (p
.isIn
, p
.isOut
, p
.isOptional
, p
.vt_type
))
26 def ProcessPropX(p
, out
):
27 out
.append(GernerateAXModule
.trimPropName(p
.name
))
28 out
.append(t4
+ "type:%s arg:%s canGet:%s canSet:%s" % (p
.type.vt_type
, p
.arg
.vt_type
, p
.canGet
, p
.canSet
))
33 out
.append("PROPERTIES")
35 for p
in ax
.GetAXProperties():
41 for m
in ax
.GetAXMethods():
42 ProcessFuncX(m
, out
, GernerateAXModule
.trimMethodName(m
.name
))
47 for e
in ax
.GetAXEvents():
48 ProcessFuncX(e
, out
, GernerateAXModule
.trimEventName(e
.name
))
55 class GernerateAXModule
:
56 def __init__(self
, ax
, className
, modulePath
, moduleName
=None, verbose
=False):
58 Make a Python module file with a class that has been specialized
59 for the AcitveX object.
61 ax An instance of the ActiveXWindow class
62 className The name to use for the new class
63 modulePath The path where the new module should be written to
64 moduleName The name of the .py file to create. If not given
65 then the className will be used.
68 if moduleName
is None:
69 moduleName
= className
+ '.py'
70 filename
= os
.path
.join(modulePath
, moduleName
)
72 print "Creating module in:", filename
73 print " ProgID: ", ax
.GetCLSID().GetProgIDString()
74 print " CLSID: ", ax
.GetCLSID().GetCLSIDString()
76 self
.mf
= file(filename
, "w")
77 self
.WriteFileHeader(ax
)
79 self
.WriteClassHeader(ax
, className
)
81 self
.WriteProperties(ax
)
87 def WriteFileHeader(self
, ax
):
88 self
.write("# This module was generated by the wx.activex.GernerateAXModule class\n"
89 "# (See also the genaxmodule script.)\n")
90 self
.write("import wx")
91 self
.write("import wx.activex\n")
92 self
.write("clsID = '%s'\nprogID = '%s'\n"
93 % (ax
.GetCLSID().GetCLSIDString(), ax
.GetCLSID().GetProgIDString()))
97 def WriteEvents(self
, ax
):
98 events
= ax
.GetAXEvents()
100 self
.write("# Create eventTypes and event binders")
102 self
.write("wxEVT_%s = wx.activex.RegisterActiveXEvent('%s')"
103 % (self
.trimEventName(e
.name
), e
.name
))
106 n
= self
.trimEventName(e
.name
)
107 self
.write("EVT_%s = wx.PyEventBinder(wxEVT_%s, 1)" % (n
,n
))
111 def WriteClassHeader(self
, ax
, className
):
112 self
.write("# Derive a new class from ActiveXWindow")
114 class %s(wx.activex.ActiveXWindow):
115 def __init__(self, parent, ID=-1, pos=wx.DefaultPosition,
116 size=wx.DefaultSize, style=0, name='%s'):
117 wx.activex.ActiveXWindow.__init__(self, parent,
118 wx.activex.CLSID('%s'),
119 ID, pos, size, style, name)
120 """ % (className
, className
, ax
.GetCLSID().GetCLSIDString()) )
123 def WriteMethods(self
, ax
):
124 methods
= ax
.GetAXMethods()
126 self
.write(t4
, "# Methods exported by the ActiveX object")
128 name
= self
.trimMethodName(m
.name
)
129 self
.write(t4
, "def %s(self%s):" % (name
, self
.getParameters(m
, True)))
130 self
.write(t8
, "return self.CallAXMethod('%s'%s)" % (m
.name
, self
.getParameters(m
, False)))
134 def WriteProperties(self
, ax
):
135 props
= ax
.GetAXProperties()
137 self
.write(t4
, "# Getters, Setters and properties")
139 getterName
= setterName
= "None"
141 getterName
= "_get_" + p
.name
142 self
.write(t4
, "def %s(self):" % getterName
)
143 self
.write(t8
, "return self.GetAXProp('%s')" % p
.name
)
145 setterName
= "_set_" + p
.name
146 self
.write(t4
, "def %s(self, %s):" % (setterName
, p
.arg
.name
))
147 self
.write(t8
, "self.SetAXProp('%s', %s)" % (p
.name
, p
.arg
.name
))
149 self
.write(t4
, "%s = property(%s, %s)" %
150 (self
.trimPropName(p
.name
), getterName
, setterName
))
154 def WriteDocs(self
, ax
):
157 for line
in doc
.split('\n'):
158 self
.write("# ", line
)
162 def write(self
, *args
):
168 def trimEventName(name
):
169 if name
.startswith("On"):
172 trimEventName
= staticmethod(trimEventName
)
175 def trimPropName(name
):
176 #name = name[0].lower() + name[1:]
179 if name
in keyword
.kwlist
: name
+= '_'
181 trimPropName
= staticmethod(trimPropName
)
184 def trimMethodName(name
):
186 if name
in keyword
.kwlist
: name
+= '_'
188 trimMethodName
= staticmethod(trimMethodName
)
191 def getParameters(self
, m
, withDefaults
):
194 # collect the input parameters, if both isIn and isOut are
195 # False then assume it is an input paramater
198 if p
.isIn
or (not p
.isIn
and not p
.isOut
):
203 if name
in keyword
.kwlist
: name
+= '_'
206 if withDefaults
and p
.isOptional
:
211 #---------------------------------------------------------------------------