Stephen Waterbury <golux@comcast.net> writes:
Joe Brown wrote:
Python has it's own socket library, so there isn't a need the
wxWidgets portation.
Depending on what your needs are you might want to look at twisted.
... but if you are going to use Twisted, you will
want to run it in a separate thread from the wx event
loop -- the two don't play nice.
As Stephen alludes to, there _is_ a need for the wxWidgets port
because the MainLoop method of wxApp blocks.
The problem isn't with Python's socket library,
the problem is with wxApp; either I have to mess around
with timers for polling or mess around with threads.
Tkinter's approach (at least for sockets) makes so much more sense
because input coming from a socket (or any file descriptor)
_is_ another event when execution is trapped in a wxApp MainLoop.
With threading, extra hassles crop up such as locks to protect data.
If wxPython has a user-triggered event, then a seperate thread
could have the data in an indeterminate state. At least with timers,
the events will be properly _serialized_. But with timers,
there is the inefficiency of polling.
Essentially, I have to use either the kludge of threads or the kludge of
polling timers when, in contrast, wxSockets gives clean, elegant
serialization of _both_ user events and file/socket events.
After all, there is a reason that this functionality
was built into the X Window System
Besides, why does wxSockets have to work at cross-purposes
to the existing socket library?
That is, wxSockets should be a wrapper _around_ Python's socket
library instead of some entirely disjoint object.
In particular, wxSocket methods should include, as a parameter,
a Python socket object; or a socket object should be a field
within a wxSocket object.
Tsk, this omission from wxPython is strange given
it's apparent superiority to Tkinter in most other ways.
...
Actually, I just had an idea which should be reasonably clean
(even if not as clean as the correct approach of wxSocket).
Have one thread block on a socket and, then, trigger an event
in the thread with the wxApp MainLoop. Is it possible to trigger
some kind of wxPython notification events across threads?