# HScale stops changing when running code in on\_change\_value

**URL:** <https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336>\
**Category:** Ruby-Gnome 2\
**Created:** [August 7, 2009, 2:00am UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336 "2009-08-07T02:00:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [August 7, 2009, 2:00am UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336/1 "2009-08-07T02:00:55Z")

</div>

Hello

While trying to write a test application for the pixels= method I  
found that when doing too much work in on\_change\_value the value stops  
changing.

The update method is called from the on\_change\_value. When everything  
in that method is commented out it is possible to change the scale  
value but since the update method is where this value is used it makes  
the application somewhat pointless.

Any ideas how to do a “preview” that updates along with the changing  
value as the user drags the scale?

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [September 23, 2009, 1:39am UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336/2 "2009-09-23T01:39:36Z")

</div>

Anybody has advice on this issue?

I simplified the application so that it has only two hscales and a  
toggle which breaks sliding of the scales. It is written in ruby +  
gtk2 + glade.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [September 23, 2009, 1:40am UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336/3 "2009-09-23T01:40:47Z")

</div>

Le mardi 22 septembre 2009 à 15:49 +0200, Michal S. a écrit :

> Anybody has advice on this issue?
> 
> I simplified the application so that it has only two hscales and a  
> toggle which breaks sliding of the scales. It is written in ruby +  
> gtk2 + glade.

Why do you call glade[‘update’].queue\_draw ?

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [September 23, 2009, 1:56am UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336/4 "2009-09-23T01:56:36Z")

</div>

2009/9/22 Pascal T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Le mardi 22 septembre 2009 Ã 15:49 +0200, Michal S. a Ã©crit :
> 
> > Anybody has advice on this issue?
> > 
> > I simplified the application so that it has only two hscales and a  
> > toggle which breaks sliding of the scales. It is written in ruby +  
> > gtk2 + glade.
> 
> Why do you call glade[‘update’].queue\_draw ?

Because in my original application I changed the pixes of an image and  
it won’t update unless I tell it to (or hide the window and show it  
again or something like that).

Calling queue\_draw on anything seems to break ruby-gtk2 so I do not  
need to ship a picture with the sample code.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [September 23, 2009, 11:14am UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336/5 "2009-09-23T11:14:04Z")

</div>

Michal S. wrote:

> Anybody has advice on this issue?
> 
> I simplified the application so that it has only two hscales and a  
> toggle which breaks sliding of the scales. It is written in ruby +  
> gtk2 + glade.
> 
> Thanks
> 
> Michal

I tried your example, but I don’t see what’s wrong.

Is it supposed to demonstrate the problem ?

Simon

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [September 23, 2009, 12:41pm UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336/6 "2009-09-23T12:41:18Z")

</div>

2009/9/23 Simon A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I tried your example, but I don’t see what’s wrong.
> 
> Is it supposed to demonstrate the problem ?

Yes, when you check the update checkbox the hscales are no longer  
movable.

Perhaps I should have make it checked it to start with.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [September 23, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336/7 "2009-09-23T17:22:10Z")

</div>

Michal S. wrote:

> 2009/9/23 Simon A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > I tried your example, but I don’t see what’s wrong.
> > 
> > Is it supposed to demonstrate the problem ?
> 
> Yes, when you check the update checkbox the hscales are no longer  
> movable.
> 
> Perhaps I should have make it checked it to start with.

I think ‘on\_xxxx\_change\_value’ should return false/nil if you want the  
scale to update, or true otherwise.

change ‘update min, max’ to :

def update min,max  
if @update then  
STDERR.puts “returning false, scale will move”  
return false  
else  
STDERR.puts “returning true, scale will NOT move”  
return true  
end  
end

Since ruby returns your last statement, it returns max for you, which is  
always true. However, when you call queue\_draw, it returns false, so,  
you on\_xxx\_change\_value returns false.

Hope it helps

Simon

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [September 25, 2009, 3:18pm UTC](https://www.ruby-forum.com/t/hscale-stops-changing-when-running-code-in-on-change-value/173336/8 "2009-09-25T15:18:37Z")

</div>

2009/9/23 Simon A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > Perhaps I should have make it checked it to start with.  
> > Â Â else  
> > Â Â Â STDERR.puts “returning true, scale will NOT move”  
> > Â Â Â return true  
> > Â Â end  
> > Â end
> 
> Since ruby returns your last statement, it returns max for you, which is  
> always true. However, when you call queue\_draw, it returns false, so,  
> you on\_xxx\_change\_value returns false.

Indeed, moving the handler to value\_changed handler resolves the  
problem.

Unfortunately, this is not documented for ruby-gnome2.

Thanks

Michal
