[PyQt] Can't disable key strokes while flashing matching brackets

Edward K. Ream edreamleo at gmail.com
Wed Jan 28 14:27:00 GMT 2009


Hello all,

I would like to have my app flash matching brackets in a QTextEdit.  But I
am having problems locking out key events while the flashing happens. I have
tried all the obvious things.  For example, in the my code (see the Post
Script), w is a QTextEdit, and the calls to

    w.blockSignals(False)
    w.setDisabled(False)

don't do the job. Alas, key events during the flashing can replace the
selected text (a bracket) with the incoming key.

Is there native support for flashing that I am overlooking?

Is there example code somewhere that would show how to lock out key strokes
until flashing is complete?

Is there some other recommended approach other than the code below?

Thanks.

Edward

P.S.  Here is my present code::

def flashCharacter(self,i,bg='white',fg='red',flashes=3,delay=75):

    w = self.widget

    def after(func):
        QtCore.QTimer.singleShot(delay,func)

    def addFlashCallback(self=self,w=w):
        n,i = self.flashCount,self.flashIndex
        self.setSelectionRange(i,i+1)  # = w.setSelection(i,i+1)
        self.flashCount -= 1
        after(removeFlashCallback)

    def removeFlashCallback(self=self,w=w):
        n,i = self.flashCount,self.flashIndex

        if n > 0:
            self.setSelectionRange(i,i)
            after(addFlashCallback)
        else:
            w.blockSignals(False)
            w.setDisabled(False)
            i = self.afterFlashIndex
            self.setSelectionRange(i,i,insert=i) # =
w.textCursor().setPosition(i)
            w.setFocus()

    self.flashCount = flashes
    self.flashIndex = i
    self.afterFlashIndex = self.getInsertPoint()
    w.setDisabled(True)
    w.blockSignals(True)
    addFlashCallback()

EKR
--------------------------------------------------------------------
Edward K. Ream email: edreamleo at gmail.com
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090128/c5028bbb/attachment.html


More information about the PyQt mailing list