analyze text and produce popup

4 views
Skip to first unread message

Suresh

unread,
Sep 28, 2010, 4:52:17 PM9/28/10
to peppy-dev

Hello,

I have a very specific need at the moment: I would like to
continuously analyze the typed text from the user and output a list of
output words (these will serve to remind the user of a list of
possible keywords that she can use). The output will be in some sort
of window that is separate from the text area.

I am not a python or wxPython pro, but I am fairly experienced with
scientific programming in C/Matlab. Is this something that I can
easily hack into Peppy ? Would something else perhaps be a better
solution ? I use Mac OS 10.6

Thanks, Suresh

Rob McMullen

unread,
Sep 28, 2010, 5:53:21 PM9/28/10
to pepp...@googlegroups.com
There are probably two places you could insert your algorithm to
analyze the words -- using the idle handler (see idlePostHook in
peppy/fundamental.py), or attach onto the EVT_STC_CHANGE event (see
OnChanged in peppy/buffers.py).

There's no single place to intercept input since input can come from
many places (typing, repeat inserts ['ESC 43 X' inserts 43 x's],
cut/paste, middle mouse paste, macro insertion, etc) so it's not as
easy as just looking at keystrokes.

The spell checker does something like what you want in the idle
handler; keeps a list of regions that it has already checked and
updates stuff based regions that have not been checked yet. You might
be able to take a look at that and make it more general.

The EVT_STC_CHANGE event would be called after every
insertion/deletion to the buffer, so your algorithm probably couldn't
take too long or the user would notice a slowdown.

Rob

> --
> You received this message because you are subscribed to the Google Groups "peppy-dev" group.
> To post to this group, send email to pepp...@googlegroups.com.
> To unsubscribe from this group, send email to peppy-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/peppy-dev?hl=en.
>
>

Suresh Krishna

unread,
Sep 28, 2010, 11:59:00 PM9/28/10
to pepp...@googlegroups.com

Hi Rob,

Thank you very much for your very useful reply. Indeed, the EVT_STC_CHANGE
seems like what I want.. I will have to play with it. I also found the STC
documentation at yellowbrain.com and went through it a bit.

My algorithm basically searches for the most recently used keyword
(searching backwards from the cursor location) within a stream of words
(the text content) and then pops up a window with the list of the possibly
valid keywords that can follow the most recent one used. Keywords and
regular words will be delimited by spaces. So for example, if the user
types "I want to use the fileslist named" then the program can detect the
keyword "fileslist" and popup a list of possible followups to that, as
defined by my code.

Using the EVT_STC_CHANGE, I imagine that I could wait until the character
before the cursor was a valid separator (whitespace) and then scan the
text backwards for a valid keyword and then use that to construct the list
of valid followups.

Ideally, it could be great if I could use the STC lexer to return a list
of keywords (matching my predefined list) that I could then analyze and
use to trigger the popup. But I could not find a way to do this from the
STC documentation: the lexer features seem to be designed especially for
text coloring. Am I wrong ?

Could you easily think of a better way to do this ?

Very best, Suresh

On Tue, 28 Sep 2010 22:53:21 +0100, Rob McMullen <rob.mc...@gmail.com>
wrote:

Reply all
Reply to author
Forward
0 new messages