Forum: wxRuby Application focus

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E5aa0dcf094f3c59b0f454d7b8843e5a?d=identicon&s=25 Médéric H. (freaxmind)
on 2010-04-29 22:54
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
Mario Steele (Guest)
on 2010-04-29 23:27
(Received via mailing list)
Hello Hurier,

There is two ways in which you can do this.  The first method, is to use
Wx::Timer and Threads.  It depends on if you are using Ruby 1.9 or Ruby
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
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
you, as Ruby 1.9 uses native threads, instead of Soft Threads, as with
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
in your initialization method for your Window class, which will call the
method that handles the Xmppr processing, and occasionally checks for
to be generated by the wxWidgets, by using Wx::App.pending?  Which
true if events are pending, otherwise false.

Idle events are generated once for entering an Idle state.  So, if you
nothing with your app for a second, it will generate an idle event,
will execute once, and then it will wait for new events to occur.  When
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
events occur.


E5aa0dcf094f3c59b0f454d7b8843e5a?d=identicon&s=25 Médéric H. (freaxmind)
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.
This topic is locked and can not be replied to.