[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyKDE] PyQt4 and SIP-4.4.5 issues
From:       Gerard Vermeulen <gerard.vermeulen () grenoble ! cnrs ! fr>
Date:       2006-09-16 10:52:34
Message-ID: 20060916125234.2974b74c.gerard.vermeulen () grenoble ! cnrs ! fr
[Download RAW message or body]

Phil,

The attached PyQt4.pyqwt.patch (a bit hardwired, but IMO not worth a more general
solution) makes it possible to use the Qwt5 designer plugin with pyuic4 without
editing the generated Python code (it is impossible to infer the PyQwt module
from the header filenames returned by the plugin).


In porting PyQwt3D to PyQt-4, I found problems with the SIP DECLARATIONS
below (the code runs when built against Qt3 but not against Qt4,
because qRegisterMetaType does not work with abstract classes).

The private copy constructors are only partial solutions, because the the
classes can still be instantianated from Python.

The documentation for the /Abstract/ annotation feels a bit out of date:
some time ago /Abstract/ really indicated an abstract class, but nowadays
it means a class that cannot be instantianated *and* cannot be subclassed.



DECLARATION 1:

// GridMapping is a normal base class

class Function: GridMapping
{
%TypeHeaderCode
#include <qwt3d_function.h>
%End // %TypeHeaderCode

public:
    Function();
    virtual ~Function();

    // SIP-4.4.5 parses the pure virtual operator,
    // but does not treat Function as an abstract class

    virtual double operator()(double, double) = 0;

    ...

private:
    // ?? SIP-bug: a regression with respect to SIP-4.3.x ??
    // This class is not recognized as abstract
    // The code for Qt-4 does not compile unless a private copy constructor
    Function(const Function&);

}; // class Function


DECLARATION 2:

class Drawable
{
%TypeHeaderCode
#include <qwt3d_drawable.h>
%End // %TypeHeaderCode

public:

    // In C++ the destructor is declared as pure virtual.
    // There are no other virtual functions,
    // but SIP does not parse the pure specifier "= 0"
    virtual ~Drawable() /* = 0 */;

    ...

private:
    // I do not know how to get this class recognized as abstract
    // The code for Qt-4 does not compile unless a private copy constructor
    Drawable(const Drawable&);

}; // class Drawable


Gerard

["PyQt4.pyqwt.patch" (application/octet-stream)]

--- PyQt-x11-gpl-4.0.1/pyuic/uic/uiparser.py.pyqwt	2006-09-16 11:51:43.000000000 +0200
+++ PyQt-x11-gpl-4.0.1/pyuic/uic/uiparser.py	2006-09-16 12:14:11.000000000 +0200
@@ -1,3 +1,4 @@
+import os
 import sys
 import logging
 import re
@@ -414,9 +415,17 @@
             classname = custom_widget.findtext("class")
             if classname.startswith("Q3"):
                 raise NoSuchWidgetError, classname
-            self.wdb.addCustomWidget(classname,
-                                     custom_widget.findtext("extends") or "QWidget",
-                                     header2module(custom_widget.findtext("header")))
+            if classname.startswith("Qwt"):
+                # use a fake header to import the Qwt widgets from PyQt4.Qwt5 
+                self.wdb.addCustomWidget(
+                    classname,
+                    custom_widget.findtext("extends") or "QWidget",
+                    header2module(os.path.join("PyQt4", "Qwt5.h")))
+            else:
+                self.wdb.addCustomWidget(
+                    classname,
+                    custom_widget.findtext("extends") or "QWidget",
+                    header2module(custom_widget.findtext("header")))
                                      
 
     def createToplevelWidget(*args):


_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic