event handling

P

Peter Nemeth

Hi ,


I am working on a stellar spectral analysis pipeline in Python. My OS is
Suse 10.0, and i use Python 2.5 . I have found difficulties with keyboard
event handling. My code communicates with the user through an xterm window
and shows graphs in a Gnuplot window. At a certain point i start an
infinite loop in order to select multiple spectral regions by mouse-clicks
over the Gnuplot graph. I would like to terminate this loop by a single
keystroke, but i can not get it done. I use 'thread' to run this process
in the background waiting for a keystroke. I don't want to use tkinter,
widgets or pygame because those require a popup surface to work in and i
already have the gnuplot window.

I tried a C like getch() function, but that pauses the code waiting for
key press instead of scanning the event queue.

Is there any other means for general event handling in Python?

Any help would be greatly appreciated.


Sincerely,
Peter
 
M

Mike Driscoll

Hi ,

I am working on a stellar spectral analysis pipeline in Python. My OS is
Suse 10.0, and i use Python 2.5 . I have found difficulties with keyboard
event handling. My code communicates with the user through an xterm window
and shows graphs in a Gnuplot window. At a certain point i start an
infinite loop in order to select multiple spectral regions by mouse-clicks
over the Gnuplot graph. I would like to terminate this loop by a single
keystroke, but i can not get it done. I use 'thread' to run this process
in the background waiting for a keystroke. I don't want to use tkinter,
widgets or pygame because those require a popup surface to work in and i
already have the gnuplot window.

I tried a C like getch() function, but that pauses the code waiting for
key press instead of scanning the event queue.

Is there any other means for general event handling in Python?

Any help would be greatly appreciated.

Sincerely,
Peter

I would use wxPython, but since you seem against that, here's what I
found using Google-fu:

http://www.freenetpages.co.uk/hp/alan.gauld/tutevent.htm

It sounds very similar to what you are doing and it shows how to do it
in both Windows and Linux.

Threads are annoying buggers. You'll probably want to have one thread
catching key-presses and storing them in a file or "file-like" object
and have your other thread read from it periodically. I'm not sure
that the link above mentions that.

Hope that helps!

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top