[PyKDE] PyQt4 custom widgets

Torsten Marek shlomme at gmx.net
Tue Jan 10 09:42:03 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andreas Pakulat schrieb:
> 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
> 
> 
> 
> ------------------------------------------------------------------------
> 
> --- 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"

Hi,

I'm kind of in a general rush right now since I'm moving back to Germany right
now. The patch should be okay for now.

greetings

Torsten

- --
Torsten Marek <shlomme at gmx.net>
ID: A244C858 -- FP: 1902 0002 5DFC 856B F146  894C 7CC5 451E A244 C858
Keyserver: subkeys.pgp.net

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDw4FrfMVFHqJEyFgRApSuAKCDyDp/NblEBefTkOwUetCUeU7z5wCfUZ7O
agW2KLK75ih74OK6OFbltlc=
=LKoj
-----END PGP SIGNATURE-----




More information about the PyQt mailing list