Hi there, I'm developping an application based on xmpp4r and WxRuby to download file between contacts. My application must handle incoming request and manage all the file upload proccess. Unfortunately, all proccess in Wx::App are active only if the application has the focus or receive an event. For example, I must move my cursor on the main window or click on it if I want the user interface to be refreshed (contact go online/offline). Is there a way to set that the Wx application must continue its actions allthough it has not the focus ? Thank you
on 2010-04-29 22:54
on 2010-04-29 23:27
Hello Hurier, There is two ways in which you can do this. The first method, is to use a Wx::Timer and Threads. It depends on if you are using Ruby 1.9 or Ruby 1.8 in the method in which you can execute this. If you are using Ruby 1.8 You create a Thread that will do your Xmppr processing, and then you setup a timer, that will after so many seconds or Milliseconds, does a Thread switch, to allow other ruby threads to run. You can find an example of this in my Sockets examples distributed with wxRuby. If you are using Ruby 1.9 You can simply just create the Thread, and it will auto-context switch for you, as Ruby 1.9 uses native threads, instead of Soft Threads, as with Ruby 1.8, hence for the work around provided in the sockets demo. The second method in which to implement this, is to use the evt_idle method in your initialization method for your Window class, which will call the method that handles the Xmppr processing, and occasionally checks for Events to be generated by the wxWidgets, by using Wx::App.pending? Which returns true if events are pending, otherwise false. Idle events are generated once for entering an Idle state. So, if you do nothing with your app for a second, it will generate an idle event, evt_idle will execute once, and then it will wait for new events to occur. When a new event occurs for anything, the event will fire, then it will wait for a second then generate another idle event. The timing in the above explination is only an example, and does not expressly garuntee that the idle event will execute 1 second after no other events occur. hth, Mario
on 2010-05-03 22:09
Thanks Mario, it's exacly that's I need ! I've used the Timer class and set it in my main windows. It's work perfectly ! Thanks again for your accurate answer.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.