in reply to using the send_im function in Net::OSCAR in Tk outside of a Net::OSCAR callback

I don't have Net::Oscar installed, but I can tell you that you will probably have trouble using this with Tk, the way you have it written. The first big problem is that you start your thread after Tk has been started. "Tk is NOT thread-safe" means that you can only mix threads and Tk with certain strict rules. The first rule is that the thread must be created before you invoke any Tk statements. Why? Because when the thread gets created, it gets a copy of the main process. If any Tk widgets are in existence, the thread gets a copy of them. Since Tk is not thread-safe, there will be unpredictable behavior as Tk tries to figure out which thread-widget to use.

So you need to setup a design where you create the aimbot thread BEFORE you start writing any Tk code. Then you can use shared-variables to communicate between the main Tk thread, and the aimbot running in the thread. Additionally, you will probably need a timer in the main Tk thread to constantly read the shared variables to see if they have changed.... Tk will NOT be auto-notified if something in the aimbot-thread changes, so you need a timer to constantly scan the shared variables.

So, it probably can be done, with a well thought out combination of shared-variables, timers, threads, and Tk, but it is sure to be a bit of work. My first prototype would be to create the thread first, and put it into a "sleep loop" waiting for a shared variable from main to start it. Then set up the Tk stuff, with buttons to signal the thread. Then in the thread, when you get a signal to start, create your aimbot, and read/write the shared variables. Then in the Tk main thread, display the reads, and send to the aimbot thread thru shared variables.


I'm not really a human, but I play one on earth. flash japh
  • Comment on Re: using the send_im function in Net::OSCAR in Tk outside of a Net::OSCAR callback

Replies are listed 'Best First'.
Hrm
by fridayjones85 (Novice) on Jun 27, 2006 at 15:34 UTC

    Thanks greatly for your reply -- I've started fiddling with things per your suggestion, but with limited results.

    I can't even figure out how to send a message out of the blue when I'm not using a GUI like Tk. Any thoughts there? If I could figure out using send_im outside of callbacks by itself, I might be able to figure out the GUI part later.

    Thanks again.

      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
        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.