[PyKDE] SIP: adding code to methods?
rasky at develer.com
Wed Mar 22 13:47:33 GMT 2006
Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
>> - I was thinking of defining a common utility function with %TypeCode,
>> then calling it for each method. How can I define C++ code which is
>> executed after the method invokation? I don't want to use %MethodCode
>> because I don't want to rewrite the method invokation code itself, since
>> the default is perfectly fine.
> You might be able to use the PostHook annotation. Generally though, SIP
> wraps an API - if you don't like the API then change it.
I can't use PostHook as it can't get any argument. Maybe a %PostCode and a
%PreCode (in which users might call sipCallHook, if they need) would be more
>> - How can I make my module export a custom Python exception class (the
>> equivalent of "class MyException(Exception): pass") which has no match in
>> the C++ code?
> You just need to define a new type/class in C++ and add it to the module
> dictionary - probably using %PostInitialisationCode.
Would exec work for this? And once it's in the module dictionary, how do I
access its type from a %MethodCode so to call PyErr_Format()?
[sorry, I'm pretty newbie at Python API].
More information about the PyQt