From: Frank v W. <fv...@va...> - 2005-01-23 08:39:38
|
I'm writing a small application that uses LWP::UserAgent with a callback function to retrieve streaming data from a server, and I want to display this data in a Wx gui. I made two threads, one running the LWP::UserAgent::request, and one doing the wxPerl GUI. As I understand it, I'm not allowed to touch the GUI from the LWP thread, so I'm trying to get some interthread communication going by calling=20 AddPendingEvent on my Wx::App.=20 This obviously takes an event object as a parameter, yet I can't find out how to construct a Wx::Event: There isn't a Wx::Event->new() by the looks of it. Could someone suggest how to handle this? (Suggestions for other approaches are most welcome too, my experience with GUI programming is limited.) --=20 Frank v Waveren Fingerprint: BDD7 D61E fvw@[var.cx|stack.nl] ICQ#10074100 5D39 CF05 4BFC F57A Public key: hkp://wwwkeys.pgp.net/468D62C8 FA00 7D51 468D 62C8 |
From: Mattia B. <mat...@li...> - 2005-01-23 16:35:07
|
On Sun, 23 Jan 2005 09:39:46 +0100 Frank v Waveren <fv...@va...> wrote: Hello, > I'm writing a small application that uses LWP::UserAgent with a > callback function to retrieve streaming data from a server, and I want > to display this data in a Wx gui. I made two threads, one running the > LWP::UserAgent::request, and one doing the wxPerl GUI. As I understand > it, I'm not allowed to touch the GUI from the LWP thread, so I'm > trying to get some interthread communication going by calling > AddPendingEvent on my Wx::App. This is the correct approach. You could look to demo/wxThread.pm in the souce and/or samples package. > This obviously takes an event object as a parameter, yet I can't find > out how to construct a Wx::Event: There isn't a Wx::Event->new() by > the looks of it. No, there isn't, but if there was it would not work for your purpose: Wx::PostEvent/Wx::EvtHandler->AddPendingEvent requires the event object to implement the Clone method (in C++) to clone the event object. To do this in Perl you could derive from Wx::PlEvent/Wx::PlCommandEvent and override Clone in your class. For what you want to achieve Wx::PlThreadEvent is much simpler: you pass a shared structure to its constructor/SetData method and in the receiving thread you can read it using Wx::GetData; demo/wxThread.pm shows this approach. > Could someone suggest how to handle this? (Suggestions for other > approaches are most welcome too, my experience with GUI programming is > limited.) HTH Mattia |
From: Frank v W. <fv...@va...> - 2005-01-24 02:34:29
|
On Sun, Jan 23, 2005 at 04:17:08PM +0100, Mattia Barbon wrote: > No, there isn't, but if there was it would not work for your purpose: > Wx::PostEvent/Wx::EvtHandler->AddPendingEvent requires the event object > to implement the Clone method (in C++) to clone the event object. To do > this in Perl you could derive from Wx::PlEvent/Wx::PlCommandEvent and > override Clone in your class. For what you want to achieve Wx::PlThreadEv= ent > is much simpler: you pass a shared structure to its constructor/SetData m= ethod > and in the receiving thread you can read it using Wx::GetData; demo/wxThr= ead.pm > shows this approach. >=20 > HTH > Mattia Thank you, that was incredibly helpful (I'd overlooked the fact that there were separate wxPerl demos). Also, thanks for the wonderful job you've done at WxPerl! --=20 Frank v Waveren Fingerprint: BDD7 D61E fvw@[var.cx|stack.nl] ICQ#10074100 5D39 CF05 4BFC F57A Public key: hkp://wwwkeys.pgp.net/468D62C8 FA00 7D51 468D 62C8 |