In Python 2.4, the signal decorator provides a convenient way of defining the signature of a a slot method or function.

from qt import * 

def qt_signal_signature(signature):
    split_pos = signature.find('(')
    signal_name, args = signature[:split_pos], signature[split_pos:]
    def set_slot_sig(method):
        method.slot_signature = signature
        method.signal_name = signal_name
        function = getattr(method, 'im_func', method)

        method.signal = SIGNAL(signal_name+args)
        method.slot   = SLOT(function.func_name+args)
        return method
    return set_slot_sig

The usage is as follows:

class SignalHandler(object): 
    def __init__(self):
        f = self._widget_pressed
        QObject.connect(SOME_WIDGET, f.signal, f)

    @qt_signal_signature("pressed(QIconViewItem*, const QPoint&)")
    def _widget_pressed(self, other_item, position):
        # do something here ...

Currently, there is no support in PyQT that could ask for "f.signal" itself, but it would be easy to integrate that into the connect method. It could accept two arguments, a QObject and a method or function and then check if the function carries a "signal" or "slot" attribute. Since current code does not use this signature, this change should not break anything.

SignalDecorator (last edited 2005-05-14 08:57:19 by p5498AE20)