[PyQt] VirtualCatcherCode and abstract methods

2007-05-11 Thread James Emerton
I have an interface declaring some abstract methods: class IUnknown { public: virtual int AddRef() = 0; virtual int Release() = 0; }; When I am implementing that interface in Python, I don't want to be bothered with the mechanics of reference counting, so I abuse Python's own ref count. (I be

Re: [PyQt] Getting mouse and key event with a qtablewidget

2007-03-15 Thread James Emerton
There are two methods to accomplish this: 1. Subclass QTable and reimplement contentsKeyPressEvent() and contentsContextMenuEvent() 2. Add an eventFilter to the viewport of your table. Of the two methods, the first is generally preferred. Have a look at the Qt docs for more. James On 3/15

[PyKDE] SIP Leak during exception

2006-01-03 Thread James Emerton
Method calling code produced by SIP fails to delete temporary varibles created by user defined conversion routines. I've attached some generated code that demonstrates this. Note the a0 and a1 are not cleaned up before NULL is returned from the exception. Attached is a patch which corrects the p

[PyKDE] Re: Python script dependancy

2005-12-05 Thread James Emerton
I am very sorry. It must be Monday; I sent this to the wrong list. =( James ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

[PyKDE] Python script dependancy

2005-12-05 Thread James Emerton
I'm using scons in a project with a rather intricate build process. I am trying to eliminate manual steps from the build process, and integrate external sources directly into the build tree. So far, this has gone quite well. The building of external dependancies is done with several batch script

Re: [PyKDE] QString in PyQt4 - Request for Comments

2005-10-21 Thread James Emerton
> Maybe I wasn't clear. What I was proposing was *not* to create a full Qt > wrapper, but to introduce *helpers* to manage normal Qt objects in a more > Python way. If you look into the examples I wrote down yesterday, you'll see > it's mostly about creating or accessing Qt objects in more pythonic

Re: [PyKDE] QString in PyQt4 - Request for Comments

2005-10-21 Thread James Emerton
On 10/20/05, Giovanni Bajo <[EMAIL PROTECTED]> wrote: > James Emerton <[EMAIL PROTECTED]> wrote: > > > That's a valid point, but I don't think it needs to be a 'totally > > separate project.' I understand the potential for incompatibility &

Re: [PyKDE] QString in PyQt4 - Request for Comments

2005-10-20 Thread James Emerton
> Yes, I believe it would good to have two libraries. It's orthogonal to this > string issue though, but I wouldn't mind a more Pythonic way to use Qt. I'm > sure there are dozen of things that could be done easily in Python and are > harder in Qt because of C++. Of course, this is a totally differ

Re: [PyKDE] PyQt C API

2005-10-19 Thread James Emerton
> This is the inner loop of the rendering code for a custom graph widget. The > optimisation target isnt the PyQt code itself, but rather the next layer up, > which calls PyQt. It will be much more convenient for this C (or C++, or > pyrex) code to call the Qt C++ API directly. Now, I've never tou

Re: [PyKDE] QString in PyQt4 - Request for Comments

2005-10-19 Thread James Emerton
I'm very in favour of the automatic conversion of QStrings into native Python strings. I always thought that multiple string types was an annoyance exclusive to C++. I'm also not convinced that performance is a compelling argument for the preservation of QString in Python. See performance data:

Re: [PyKDE] Disappearing Layout Widget

2005-08-15 Thread James Emerton
On 8/11/05, Chad Brantly <[EMAIL PROTECTED]> wrote: > This kind of works, but not exactly. > self.SearchCriteriaGroupBox.layout() is a QVBoxLayout, not the > QGridLayout. I need to get to the QGridLayout created in the ui file > and insert another widget into it. I tried changing the last line of

Re: [PyKDE] Disappearing Layout Widget

2005-08-10 Thread James Emerton
The answer is in the ui code you posted: self.SearchCriteriaGroupBox.layout() http://doc.trolltech.com/3.3/qwidget.html#layout James ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

[PyKDE] C++ signature/undefined types

2005-07-28 Thread James Emerton
Given the following sip fragment... class Foo { virtual void bar( SIP_PYOBJECT ) [void (UnwrappedType)]; %MethodCode // ... %End %VirtualCatcherCode // ... %End }; Sip will compain about UnwrappedType not being defined. I don't believe it should need to be defined in the presence of the %V

Re: [PyKDE] Issue with QDialog and lifetime

2005-06-23 Thread James Emerton
On 6/23/05, Giovanni Bajo <[EMAIL PROTECTED]> wrote: > > Does anyone see a potential problem with exec_loop() transferring > > ownership of the dialog instance back to Python? > > Well, which C++ API would you intend to call to achieve this? We still need > the > QDialog to keep its parent widge

Re: [PyKDE] Issue with QDialog and lifetime

2005-06-22 Thread James Emerton
Sorry to be digging up such an old thread, but my mind keeps coming back to this one. Does anyone see a potential problem with exec_loop() transferring ownership of the dialog instance back to Python? James On 5/25/05, Giovanni Bajo <[EMAIL PROTECTED]> wrote: > Hello, > > while the QObject obje

Re: [PyKDE] Hi, help format QTables

2005-06-19 Thread James Emerton
On 6/19/05, Julian Ramos Marrero <[EMAIL PROTECTED]> wrote: > Hi list, > > I have a problem, I do not know as to implement format mask on items > QTables, somebody could orient to me. You'll need to subclass QTableItem and implement createEditor(), to set the format mask for editing. Jam

Re: [PyKDE] Handling exceptions in SIP

2005-06-18 Thread James Emerton
On 6/18/05, Denis S. Otkidach <[EMAIL PROTECTED]> wrote: > 2) You overwrite virtual method of wrapped class in Python, so that > other methods (implemented in C++) use it instead of base. This is more > interesting case, but I believe SIP can't handle it too. Please correct > me if I'm wrong. Bi

[PyKDE] SIP parse error

2005-06-17 Thread James Emerton
There is a small issue with the parsing code in SIP. I get a parse error whenever a %MethodCode section contains a %, such as a printf() format string. My workaround right now is to use something like this... const char fmt[] = { 37, '0', '4', 'd', 37, '0', '2', 'd', 37, '0', '2', 'd', 0 }; Jame

Re: [PyKDE] Handling exceptions in SIP

2005-06-09 Thread James Emerton
On 6/7/05, Phil Thompson <[EMAIL PROTECTED]> wrote: > So if I introduce something like... > > %ExceptionType MyException > %TypeHeaderCode > #include > %End > %ConvertFromTypeCode > // C++ code to return a PyObject instance of the exception. > // sipCpp (the C++ poiter) and sipException_M

Re: [PyKDE] Re: QString vs PyString

2005-06-05 Thread James Emerton
I am very pleased with the amount of discussion this topic has garnered! mutability: Strings in python are immutable for good reason. One being that they are considered a low-level data type that should behave like it's passed by value. (To modify a python string in some function, you have to re

Re: [PyKDE] Re: QString vs PyString

2005-06-03 Thread James Emerton
On 6/3/05, Jim Bublitz <[EMAIL PROTECTED]> wrote: > On Friday 03 June 2005 11:40, Matej Cepl wrote: > > And why do you have to use QString at all? Cannot you just use Python's > > native strings/unicode strings? Read more about the relationship between > > Python's and Qt-string machinery read > >

[PyKDE] QString vs PyString

2005-06-03 Thread James Emerton
I am using PyQt as a way to provide UI to scriptable plugins for a C++/Qt application. The business end of this app is written in standard C++ with some usage of boost libraries. Qt is used _strictly_ for the UI. This means that strings in the business logic are std::string objects (Unicode is n

[PyKDE] Re: Using SIP to call Python from C++

2005-05-19 Thread James Emerton
I am in the process of instrumenting a large C++ API with hooks that allow plugins to handle specific events. This is simply a sophistication of the snippet that I sent you. The principle is to create an abstract base class in C++ and implement the concrete class in Python. You need to handle th

Re: [PyKDE] SIP vs Boost.Python?

2005-05-12 Thread James Emerton
Here's the most maintainable way of calling Python from C++. This method keeps your C++ out of your Python and your Python out of your C++. As a bonus feature, if the Python implementation gets too slow, you can rewrite in C++ without needing to touch any client code. // // iface.h struct IFoo {

Re: [PyKDE] SIP vs Boost.Python?

2005-05-12 Thread James Emerton
There is no need for SIP to be enhanced to handle this. (I don't think boost::python has anything special here either.) The Python API can be made available by linking your application to the correct library and calling Py_Initialize(). What you are describing is exactly what I am doing with Pyt

[PyKDE] protected const method wrappers

2005-04-29 Thread James Emerton
When SIP generates the virtual wrapper classes, protected methods get a public sipProtect_foo() method. These methods do not inherit const-ness from their corresponding protected method. If you have a class where the method signature of two protected methods differs only in that one is const and

[PyKDE] Leaking in virtual handler

2005-04-20 Thread James Emerton
I have found a memory leak owing to how SIP handles virtual methods. If a type conversion is done by sipParseResult(), a new object is allocated but never deleted. I have an interface that returns a QString. If I implement this in python and return a python string, a conversion to QString is per

Re: [PyKDE] Using QDataStream

2005-04-06 Thread James Emerton
You may be able to exploit the Qt properties system to retrieve the most interesting members. (Provided that the parts interesting to you are actually properties.) # Saving... props = { } for p in obj.metaClass().propertyNames( True ): props[ p ] = obj.property( p ) # Loading... for p, v in

[PyKDE] SIP with debug Qt

2005-04-01 Thread James Emerton
In the interest of not having two different Qt source trees, I perpetrate small hack that creates qt-mtNNNd.dll as the debug version. (I do this by building normally to get a release build, then rerunning configure with -debug -lean -no-qmake and manually tweaking TARGET in the generated Makef

Re: [PyKDE] Abstract annotation and deleting objects

2005-03-25 Thread James Emerton
On 25-Mar-05, at 9:47 AM, Phil Thompson wrote: The effect of the CLASS_CANNOT_CREATE bit is to set td_init AND td_dealloc to 0 in the generated sipTypeDef. This causes factory methods returning pointers to abstract interfaces to leak memory. I am going to attempt to patch this, but I still don't k

[PyKDE] Abstract annotation and deleting objects

2005-03-23 Thread James Emerton
If a sip specification marks a class with the 'Abstract' annotation, the CLASS_CANNOT_CREATE bit is set. This can also be caused by the inclusion of pure virtual methods. The effect of the CLASS_CANNOT_CREATE bit is to set td_init AND td_dealloc to 0 in the generated sipTypeDef. This causes f

Re: [PyKDE] boost::shared_ptr

2005-03-22 Thread James Emerton
On 22-Mar-05, at 12:34 PM, Jim Bublitz wrote: It appears that when passing Python instances back into C++ you are creating a second, unrelated smart pointer. Unless KSharedPtr is maintaining a mapping of C++ pointers, the pointer that gets passed in is getting an extra reference added to it that w

Re: [PyKDE] boost::shared_ptr

2005-03-22 Thread James Emerton
On 22-Mar-05, at 12:23 AM, Jim Bublitz wrote: It seems to me Python is taking care of all of the ref counting in this case - there might be pathological cases where either the C++ instance of the template type or the Python instance get orphaned (no corresponding object on "the other side"). Mos

[PyKDE] boost::shared_ptr

2005-03-21 Thread James Emerton
I am rather new to PyQt/SIP and looking for a hint or two. The application in which I am embedding Python has a fairly extensive (non-Qt) API, with a Qt UI sitting on top. The API makes extensive use of refcounted smart pointers (boost::shared_ptr) to abstract interface classes. So far, I beli