[PyKDE] Dictionary thru new Signal/Slot mechanism

V. Armando Sole sole at esrf.fr
Wed Feb 1 12:48:56 GMT 2006


Hi!

I'm maintaining a fairly large amount of code where most of the former 
PYSIGNALS were implemented by sending a dictionary. Unless I'm missing 
something, I did not found other way to keep the code working than to make 
a derivative class of a supported type and make it behave as a dictionary 
without being one. For instance:

class MyDict(QObject):
     def __init__(self, dict0=None):
         QObject.__init__(self)
         if dict0 is None:
             self.dict = {}
         else:
             self.dict = dict0

     def findkey(self, item):
         return self.dict[key]

     def __setitem__(self, item, value):             # setting a keyword
         self.dict[item] = value

     def __getitem__(self, item):
         return self.dict[item]

     def __delitem__(self, item):                # deleting a keyword
         del self.dict[item]

     def has_key(self, item):
         return self.dict.has_key(item)           # does the key exist

     def __contains__(self, item):
         return self.dict.has_key(item)           # does the key exist

     def __del__(self):                                 #is this method 
really needed?
         del self.dict

Signals can be emited as "your_own_signal(QObject)" and everything seems to 
work (at least I did not have to change my slots).

I know it is an awful patch, but till a generic PyObject is implemented (or 
anything else) it may allow to keep working.

Regards,

Armando




More information about the PyQt mailing list