Well, the best thing is to take it one step at a time. First, get used to how Net::Oscar works by itself. Then once you have a good feel for it, try adding the Tk front end. Things are greatly complicated by using threads with Tk, further compounded by your novice status with both Tk and threads. You might want to try looking thru the results of a perlmonk's searchbox search for "Tk threads". It's all been discussed before, and you should be able to get some sample tk-w-thread code to experiment with. I don't know if you need threads at all (being unfamiliar with Net::Oscar.) You may be able to do it with some other easier method, like in your
while(1) {
$oscar->do_one_loop();
# Do stuff
#update your Tk widgets here
$mw->DoOneEvent( DONT_WAIT |
ALL_EVENTS );
}
The above is just an idea, since you are using a while(1) loop, which will interfere with Tk's mainloop. You can call DoOneEvent to keep Tk going and responding to events.All in all, you are asking for us to give you a simple code example, for a fairly complex program..... not gonna happen. I did see there is a POE component module for Net::Oscar, maybe you would want to look at that? As far as simple sending of a message goes, there is an "oscartest" script contained in the module distribution, I would start with that. Sorry, I don't have AIM going so I'm not able to try it. Maybe post a another topnode question.... "How do I use Net::Oscar"? Or Net::OSCAR: Having trouble getting started
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] |
I managed to get it to do what I wanted it to do without a GUI -- do_one_loop() doesn't do what I thought it did. It simply checks for waiting events and messages and acts accordingly. I took your advice and made a thread that sits and waits to send a message when activated by a shared variable. That did the trick.
This should help me translate it into a GUI -- I'll look at the DoOneEvent function too, and see if I can do something with that.
Thanks very much for your help and your patience with a perl newbie.
| [reply] |
Great! I mentioned the DoOneEvent method, because in your code, it seemed that you needed to do a while(1){}, or run a second event loop. When you try to run 2 (or more) event-loop based programs, only 1 event loop can be in control, and you need to manually "pump" the othe loop(s) with DoOneEvent (or whatever their system calls it).In Tk the MainLoop is
sub MainLoop
unless ($inMainLoop) {
local $inMainLoop = 1;
while (Tk::MainWindow->Count) {
DoOneEvent(0);
}
}
}
So if you can't use Tk::MainLoop in your program to be the controlling event loop, you can place the DoOneEvent in a timer, or a while(1) loop and effectively keep Tk active and responding.But it sounds like you are on your way with threads, and that is your best option.
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] |