[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] Can't disable key strokes while flashing matching brackets
From:       "Edward K. Ream" <edreamleo () gmail ! com>
Date:       2009-01-28 14:27:00
Message-ID: ffb592890901280627ud9b2481r37fe71941b3a8bee () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@gmail.com
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------

[Attachment #5 (text/html)]

Hello all,<br><br>I would like to have my app flash matching brackets in a \
QTextEdit.&nbsp; But I am having problems locking out key events while the flashing \
happens. I have tried all the obvious things.&nbsp; For example, in the my code (see \
the Post Script), w is a QTextEdit, and the calls to<br> <br>&nbsp;&nbsp;&nbsp; \
w.blockSignals(False)<br> &nbsp;&nbsp;&nbsp; w.setDisabled(False)<br><br>don&#39;t do \
the job. Alas, key events during the flashing can replace the selected text (a \
bracket) with the incoming key.&nbsp; <br><br>Is there native support for flashing \
that I am overlooking?<br> <br>Is there example code somewhere that would show how to \
lock out key strokes until flashing is complete?<br><br>Is there some other \
recommended approach other than the code \
below?<br><br>Thanks.<br><br>Edward<br><br>P.S.&nbsp; Here is my present code::<br> \
<br>def flashCharacter(self,i,bg=&#39;white&#39;,fg=&#39;red&#39;,flashes=3,delay=75):<br><br>&nbsp;&nbsp;&nbsp; \
w = self.widget<br><br>&nbsp;&nbsp;&nbsp; def \
after(func):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
QtCore.QTimer.singleShot(delay,func)<br><br>&nbsp;&nbsp;&nbsp; def \
addFlashCallback(self=self,w=w):<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; n,i = \
self.flashCount,self.flashIndex<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.setSelectionRange(i,i+1)&nbsp; # = \
w.setSelection(i,i+1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.flashCount \
-= 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
after(removeFlashCallback)<br><br>&nbsp;&nbsp;&nbsp; def \
removeFlashCallback(self=self,w=w):<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
n,i = self.flashCount,self.flashIndex<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
if n &gt; 0:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.setSelectionRange(i,i)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
after(addFlashCallback)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
w.blockSignals(False)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
w.setDisabled(False)<br> \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = \
self.afterFlashIndex<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.setSelectionRange(i,i,insert=i) # = \
w.textCursor().setPosition(i)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
w.setFocus()<br><br>&nbsp;&nbsp;&nbsp; self.flashCount = \
flashes<br>&nbsp;&nbsp;&nbsp; self.flashIndex = i<br>&nbsp;&nbsp;&nbsp; \
self.afterFlashIndex = self.getInsertPoint()<br> &nbsp;&nbsp;&nbsp; \
w.setDisabled(True)<br>&nbsp;&nbsp;&nbsp; w.blockSignals(True)<br>&nbsp;&nbsp;&nbsp; \
addFlashCallback()<br><br>EKR<br>--------------------------------------------------------------------<br>Edward \
                K. Ream email: <a \
                href="mailto:edreamleo@gmail.com">edreamleo@gmail.com</a><br>
Leo: <a href="http://webpages.charter.net/edreamleo/front.html">http://webpages.charte \
r.net/edreamleo/front.html</a><br>--------------------------------------------------------------------<br><br>




_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic