Leo Body Widget / Events Question

23 views
Skip to first unread message

Adrian

unread,
Jul 4, 2017, 6:43:47 PM7/4/17
to leo-editor
Hello,

After some code searching (Use the Source Luke), I determined how to finally hook in my own kepressevent handlers for the body pane in a reliable fashion.  But I had to put in a hack in the EventFilter system, to pass on every key press event to global dispatcher that I created.  Otherwise, no matter what I did, I would not get consistently called event handlers.

Sure it works, but I am not sure if there is a way for me to reliably capture keypress events in the body pane without this hack?

Here is what I did:

In the eventFilter method, of the LeoQtEventFilter class:


       
if self.keyIsActive:
           
#2017-07-04: change made by me under this comment
           
try:
                g
.user_dict['my_key_dispatcher'](event)
           
except Exception as e:
                g
.red(e)
                g
.red("My Key Dispatcher has not been instantiated, qt_events.py")
           
#--

g.user_dict['my_key_dispatcher'] is a function defined at startup in myLeoSettings.  It runs through a list of handlers I can add or remove at anytime.

Yes, it works, but ugly.

Is there a non-hack way to get all key press events from the body pane?

Thanks,
Adrian

Edward K. Ream

unread,
Jul 5, 2017, 9:59:47 AM7/5/17
to leo-e...@googlegroups.com
On Tue, Jul 4, 2017 at 5:43 PM, Adrian <develope...@gmail.com> wrote:

Is there a non-hack way to get all key press events from the body pane?

​Yes and no.

Yes: could assign your own Qt event filter to the body widget.

No: By default, your custom event filter would have to make sure it does what the default event filter does.

Edward
Reply all
Reply to author
Forward
0 new messages