I have used a boxsizer example and a commandline chatclient.py to
create a customized chat application. I am having a problem receiving
the socket data and appending it to a wx.TextCtrl. I can send
messages fine. I run a command line server and a command line client,
then start the wx application. I can send fine using the application
buttons but if the command line client sends a message it never shows
up in my recieve_message panel and if I close the wx application after
the command line client sends a message the socket does not get
closed. I expect this is because it is hung somewhere in my trying to
receive the message. So, the vital question is how can I monitor the
socket and post that data to the panel, I can't use the socket listen
and run the server on the same machine - I have tried that. Any help
would be appreciated.
Looks like you are falling into the trap of blocking the GUI with a long running task (your socket communications.) The GUI works in an event-driven manner, and if you prevent the events from being dispatched then nothing works. Events are dispatched from the MainLoop, and only one at a time is dispatched. So when you get into a loop like "while self.keeprunning:" you are preventing control from returning to the MainLoop and so no events can be delivered (like paint events, etc.)
Thanks, this was a big help and today I received my _wxPython IN
ACTION_ book I ordered overnight from amazon yesterday. I used
wx.Timer to "get" socket data and have adjusted the timer to get
results but not real good. It seems that at some point it is waiting
for data and not freeing up the gui until it gets that data. I am
going to look at that this weekend. I looked at the example in your
book which was slightly different and am working on a copy using
something more like the book example.
Thanks again,
Thomas
···
On 4/9/08, Robin Dunn <robin@alldunn.com> wrote:
Thomas Bennett wrote:
> I have used a boxsizer example and a commandline chatclient.py to
> create a customized chat application. I am having a problem receiving
> the socket data and appending it to a wx.TextCtrl. I can send
> messages fine. I run a command line server and a command line client,
> then start the wx application. I can send fine using the application
> buttons but if the command line client sends a message it never shows
> up in my recieve_message panel and if I close the wx application after
> the command line client sends a message the socket does not get
> closed. I expect this is because it is hung somewhere in my trying to
> receive the message. So, the vital question is how can I monitor the
> socket and post that data to the panel, I can't use the socket listen
> and run the server on the same machine - I have tried that. Any help
> would be appreciated.
>
Looks like you are falling into the trap of blocking the GUI with a long
running task (your socket communications.) The GUI works in an event-driven
manner, and if you prevent the events from being dispatched then nothing
works. Events are dispatched from the MainLoop, and only one at a time is
dispatched. So when you get into a loop like "while self.keeprunning:" you
are preventing control from returning to the MainLoop and so no events can
be delivered (like paint events, etc.)
Seems I read on a WEB page that there are issues with MS Windows and
the asyncore library, the problem being that MS windows does something
different unless you use the Twisted library. This app will
eventually be running on MS Win PCs. I am using wx.Timer to get
socket data though and have tried polling also. I think I need to
look at my source in more detail to see where I have probably not told
it to stop looking if there are no packets, I think this is pausing
access through the program gui.
Thanks,
Thomas
···
On 4/10/08, Mark Guagenti <mgenti@gentiweb.com> wrote:
What I would recommend doing is using asyncore or asynchat (part of
the standard python library) so you don't have to start up a thread
for the socket and the GUI. Then you can setup a continuous wx timer
to call asyncore's poll method.
--Mark
On Wed, Apr 9, 2008 at 8:48 PM, Robin Dunn <robin@alldunn.com> wrote:
> Thomas Bennett wrote:
>
> > I have used a boxsizer example and a commandline chatclient.py to
> > create a customized chat application. I am having a problem receiving
> > the socket data and appending it to a wx.TextCtrl. I can send
> > messages fine. I run a command line server and a command line client,
> > then start the wx application. I can send fine using the application
> > buttons but if the command line client sends a message it never shows
> > up in my recieve_message panel and if I close the wx application after
> > the command line client sends a message the socket does not get
> > closed. I expect this is because it is hung somewhere in my trying to
> > receive the message. So, the vital question is how can I monitor the
> > socket and post that data to the panel, I can't use the socket listen
> > and run the server on the same machine - I have tried that. Any help
> > would be appreciated.
> >
>
> Looks like you are falling into the trap of blocking the GUI with a long
> running task (your socket communications.) The GUI works in an event-driven
> manner, and if you prevent the events from being dispatched then nothing
> works. Events are dispatched from the MainLoop, and only one at a time is
> dispatched. So when you get into a loop like "while self.keeprunning:" you
> are preventing control from returning to the MainLoop and so no events can
> be delivered (like paint events, etc.)
>
> See: LongRunningTasks - wxPyWiki for solutions.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwidgets.org
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org http://lists.wxwidgets.org/mailman/listinfo/wxpython-users