def normalize_signal(signal):
    """
    normalize whitespace in signal string, which should be SIGNAL(xx) or (untested) PYSIGNAL(xx)
    """
    try:
        # this fails with AttributeError: normalizeSignalSlot [bruce 050921]
        return QObject.normalizeSignalSlot(signal)
        # (this should call a static method on QObject)
    except AttributeError:
        # Use my own hacked-up kluge, until the above lost method gets found.
        # I think it doesn't matter if this has same output as Qt version,
        # as long as it makes some canonical form with the same equivalence classes
        # as the Qt version, since it's only used to prepare keys for my own dicts.
        words = signal[1:].split(
        )  # this ignores whitespace at start or end of signal[1:]

        def need_space_between(w1, w2):
            def wordchar(c):
                return c in "_" or c.isalnum()  #k guess

            return wordchar(w1[-1]) and wordchar(w2[0])

        res = signal[0] + words[0]
        for w1, w2 in zip(words[:-1], words[1:]):
            # for every pair of words; w1 has already been appended to res
            if need_space_between(w1, w2):
                res += ' '
            res += w2
##        if signal != res and DEBUG_PRINT_UNDO and 0:
##            print "hack converted %r to %r" % (signal, res) # they all look ok
        return res
    pass
Example #2
0
def normalize_signal(signal):
    """
    normalize whitespace in signal string, which should be SIGNAL(xx) or (untested) PYSIGNAL(xx)
    """
    try:
        # this fails with AttributeError: normalizeSignalSlot [bruce 050921]
        return QObject.normalizeSignalSlot(signal)
            # (this should call a static method on QObject)
    except AttributeError:
        # Use my own hacked-up kluge, until the above lost method gets found.
        # I think it doesn't matter if this has same output as Qt version,
        # as long as it makes some canonical form with the same equivalence classes
        # as the Qt version, since it's only used to prepare keys for my own dicts.
        words = signal[1:].split() # this ignores whitespace at start or end of signal[1:]
        def need_space_between(w1, w2):
            def wordchar(c):
                return c in "_" or c.isalnum() #k guess
            return wordchar(w1[-1]) and wordchar(w2[0])
        res = signal[0] + words[0]
        for w1, w2 in zip(words[:-1],words[1:]):
            # for every pair of words; w1 has already been appended to res
            if need_space_between(w1, w2):
                res += ' '
            res += w2
##        if signal != res and DEBUG_PRINT_UNDO and 0:
##            print "hack converted %r to %r" % (signal, res) # they all look ok
        return res
    pass