Django
Django

Reputation: 415

Listening to network event and keyboard input at the same time in Python

I want to write an (GUI) application that listens both to keyboard events (client side generated events) and to a network port (server side generated events). I could use some high level advice on how to do this. Some additional info: - I am using the wxPython module for the GUI - I could set the socket in non-blocking mode, but this way I have to keep polling the socket by keeping executing the recv() command. I did this earlier and I can recall that this used considerable resources - I could use the thread module, but since I am not familiar with it, I try to avoid this, but maybe I can't Advice would be appreciated.

Upvotes: 1

Views: 842

Answers (3)

Mike Driscoll
Mike Driscoll

Reputation: 33081

wxPython does have key events. Here are the wxPython docs page on the subject: http://www.wxpython.org/docs/api/wx.KeyEvent-class.html

wxPython doesn't wrap every single thing in wxWidgets. The developers didn't think that they needed to wrap stuff that already had great support in Python itself. Thus, see Python for its socket support

And if you want to get really heavy, look into the Twisted framework. There are several articles on using it with wxPython:

Upvotes: 1

Stefano Mtangoo
Stefano Mtangoo

Reputation: 6560

There is wxKeyEvent in Docs. Use that to catch the keys and Socket to send it via a network or do whatever you want to do! For socket see this sticky. It is C++ but it will give you a better Idea!

Upvotes: 0

David Poole
David Poole

Reputation: 3510

I am not a wx expert. Could you use wx's native event driven mechanisms? The keypress would certainly have an event. Wx has a socket class wxSocketClient() that could translate the low level socket events (data ready, closed, etc) into a wx event.

Upvotes: 0

Related Questions