[PyKDE] PyQt4 custom widgets

Andreas Pakulat apaku at gmx.de
Mon Jan 9 23:44:47 GMT 2006


On 09.01.06 23:42:06, Andreas Pakulat wrote:
> On 09.01.06 22:24:57, Phil Thompson wrote:
> > On Monday 09 January 2006 9:19 pm, Andreas Pakulat wrote:
> > > As you can see pyuic4 generates totally nonsense import statements (or
> > > is python able to parse C++ header files?). I guess Phil you didn't
> > > invest much time on pyuic4 regarding this, did you?
> > 
> > Not a lot - seeing as Torsten wrote it. I'm sure he'll appreciate a patch to 
> > fix it.
> 
> Hmm, haven't read Torsten since mid-december... 
> 
> Maybe I have some time to get familiar with pyuic at the weekend. I'll
> let you know...

Couldn't let it lie around ;-)

So here's a small patch which makes empty extends-Elements work and also
"corrects" the import statements by simply transforming whatever is in
the header-element to a pythonic module-path. 

The latter means that a string like

widgets/mycustomwidget.h

gets transformed into

widgets.mycustomwidget

I think you can't get much better than this, except maybe provide a way
to override this with a custom module path (like -m
mycustomwidget.module). However that is beyond my scope for now.

Phil, maybe you can put this into the next snapshot of PyQt4 so I don't
have to patch myself.

Andreas

-- 
You will never know hunger.
-------------- next part --------------
--- compiling/pyqt/PyQt4-gpl-snapshot-20060106/pyuic/uic/uiparser.py	2006-01-07 04:31:40.000000000 +0100
+++ python2.4/lib/python2.4/site-packages/PyQt4/uic/uiparser.py	2006-01-10 00:25:29.851379584 +0100
@@ -1,5 +1,6 @@
 import sys
 import logging
+import re
 from itertools import count
 
 try:
@@ -345,10 +346,15 @@
             classname = custom_widget.findtext("class")
             if classname.startswith("Q3"):
                 raise NoSuchWidgetError, classname
-            self.wdb.addCustomWidget(classname,
-                                     custom_widget.findtext("extends"),
-                                     custom_widget.findtext("header"))
-
+	    header = custom_widget.findtext("header") 
+	    extends = custom_widget.findtext("extends")
+	    if extends == '' or extends is None:
+	    	extends = 'QObject'
+
+	    header = re.sub('\/', '.', header)
+	    header = re.sub('.h', '', header)
+            self.wdb.addCustomWidget(classname, extends, header)
+                                     
 
     def createToplevelWidget(*args):
         raise NotImplementedError, "must be overwritten"


More information about the PyQt mailing list