Forum: Ruby-Gnome 2 Disable Button while Thread does some work.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
35f0e7653d7404ac987b0383e1d76e2e?d=identicon&s=25 Martin Portman (Guest)
on 2007-02-09 12:09
(Received via mailing list)
Hi,

I want a button to kick off processing, and for the button to be
disabled
while processing is going on.  The code below does this.  However,
I can't click the button twice in a row, I need to click elsewhere
(within the
larger app, or outside it)  and then come back to the button
for the click to work.

Why is this so?  What am i missing?  Or is there a better way to do
this?

Ruby 1.8.4, gtk-win32-2-8-18-rc1, ruby-gtk2-0-14-1

Thanks,
Martin

Here's the code:
===
require 'gtk2'
Gtk.init
win = Gtk::Window.new

button = Gtk::Button.new( "Do it" )

win.add( button )

button.signal_connect("clicked"){
   if( button.sensitive? )

     button.sensitive=false

     Thread.new{
       puts "running process"
       sleep 2
       button.sensitive=true
     }
   end
}

win.show_all

Gtk.main
===


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your job
easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709...
8e6374c0ef7b66942f34798e31edf014?d=identicon&s=25 Dobai-Pataky Bálint (Guest)
on 2007-02-09 12:24
(Received via mailing list)
Martin Portman wrote:
>
try the modified one i attached, you might get the idea from it.
while the button is insensitive it wont accept your clicks.

balint
35f0e7653d7404ac987b0383e1d76e2e?d=identicon&s=25 Martin Portman (Guest)
on 2007-02-09 16:54
(Received via mailing list)
Dobai-Pataky Bálint wrote:
>> Why is this so?  What am i missing?  Or is there a better way to do this?
>
> try the modified one i attached, you might get the idea from it.
> while the button is insensitive it wont accept your clicks.

Thanks, but I didn't explain myself clearly!  That is exactly the
behaviour I
want!

However, once the processing is done, and the button becomes sensitive
again,
the button only responds to clicks once the app has lost focus.  If I
click on the button, leave the mouse where it is, wait for the
processing to
finish and the button to become sensitive, and I click again, that click
and
all following clicks are ignored until I move the focus to another
window,
and then come back to the app and try to click again, which works.

I guess it's a problem with threads and what button.sensitive=true does,
and when it does it, which I don't understand (yet!).

Martin

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your job
easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709...
8e6374c0ef7b66942f34798e31edf014?d=identicon&s=25 Dobai-Pataky Bálint (Guest)
on 2007-02-09 17:35
(Received via mailing list)
Martin Portman wrote:
> However, once the processing is done, and the button becomes sensitive again,
> the button only responds to clicks once the app has lost focus.  If I
> click on the button, leave the mouse where it is, wait for the processing to
> finish and the button to become sensitive, and I click again, that click and
> all following clicks are ignored until I move the focus to another window,
> and then come back to the app and try to click again, which works.
>
> I guess it's a problem with threads and what button.sensitive=true does,
> and when it does it, which I don't understand (yet!).
>
the example script we shared works as expected here.
dev-ruby/ruby-gtk2-0.16.0
dev-lang/ruby-1.8.5_p12
Gentoo Base System release 1.12.9
35f0e7653d7404ac987b0383e1d76e2e?d=identicon&s=25 Martin Portman (Guest)
on 2007-02-12 09:45
(Received via mailing list)
Dobai-Pataky Bálint wrote:
> the example script we shared works as expected here.
> dev-ruby/ruby-gtk2-0.16.0
> dev-lang/ruby-1.8.5_p12
> Gentoo Base System release 1.12.9

Ok, looks like I need to upgrade.
Thanks for your help,
Martin.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your job
easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709...
This topic is locked and can not be replied to.