from qt import *

_QObject = QObject

class QObject(_QObject):
    def _is_signal_or_slot(x):
        try:
            return x[0].isdigit()
        except:
            return False

    _is_signal_or_slot = staticmethod(_is_signal_or_slot)

    def _make_signal(signal):
        if not QObject._is_signal_or_slot(signal):
            try:
                if signal.find('(') >= 0:
                    signal = SIGNAL(signal)
                else:
                    signal = PYSIGNAL(signal)
            except AttributeError:
                pass
        return signal

    _make_signal = staticmethod(_make_signal)

    def connect(self, signal, slot):
        signal = self._make_signal(signal)
        if not self._is_signal_or_slot(slot):
            try:
                if slot.find('(') >= 0:
                    slot = SLOT(slot)
                else:
                    slot = PYSIGNAL(slot)
            except AttributeError:
                pass
        return _QObject.connect(self, signal, slot)

    def emit(self, signal, *args):
        return _QObject.emit(self, self._make_signal(signal), args)

if __name__ == '__main__':
    class Test(QObject):
        def __init__(self):
            QObject.__init__(self)
            self.connect('spam', self.spammed)

        def spammed(self, *args):
            print "I've been spammed with", args

    t = Test()
    t.emit('spam')
    t.emit('spam', 7, 'eggs')
