[PyKDE] Adding things to Qt classes

Boudewijn Rempt boud at valdyas.org
Tue Apr 30 22:59:00 BST 2002


One of the things I like to do is stuff extra data in QApplication, like this:

Python 2.2.1 (#1, Apr 12 2002, 22:26:33)
[GCC 2.95.3 20010315 (SuSE)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import qt, sys
>>> qapp = qt.QApplication(sys.argv)
>>> qapp.field = "bla"
>>> qapp.field
'bla'
>>>

I've finally found some time for experimenting with QTable, and I wanted
to associate data with QTableItems without going to the length of
subclassing them, and without keeping a dictionary mapping items to data. So 
I did the following:

...
            for f in rec:
                if f[0].inList:
                    c += 1
                    self.setText(r, c, f[1])
                    self.item.field = f
...

And that doesn't work, because you can create classes with read-only 
attributes nowadays:

Traceback (most recent call last):
  File "kuragui/guitable.py", line 85, in ?
    main(sys.argv)
  File "kuragui/guitable.py", line 77, in main
    mainwin.refresh(app.createObject('lng_lex', form="adan"))
  File "kuragui/guitable.py", line 54, in refresh
    self.item.field = f
TypeError: 'builtin_function_or_method' object has only read-only attributes 
(assign to .field)

Is this behavious intentional? Necessary? Or would it be just as easy to 
simply allow it?

-- 
Boudewijn Rempt | http://www.valdyas.org




More information about the PyQt mailing list