Thread overview
GTK Scale/Volume Buttons Show Muted Icon on Startup
Apr 25, 2019
Ron Tarrant
Apr 25, 2019
number
Apr 25, 2019
Ron Tarrant
Apr 25, 2019
Mike Wey
Apr 25, 2019
Ron Tarrant
Apr 26, 2019
Russel Winder
Apr 26, 2019
Ron Tarrant
April 25, 2019
I've scoured the docs, the wrapper code, the Internet, but can't come up with an explanation...

When running this example of a VolumeButton, no matter what the initial value of the slider, the icon showing is audio-volume-muted.

I wrote up a second test using the parent, a ScaleButton, passing a list of icons to the constructor. The order of the icons in the string array is correct, but the result was the same as with the VolumeButton. The muted icon shows on startup despite the initial value.

After fiddling with either one of these, moving the value up or down, the icons behave as described in the docs.

I've put both buttons in this one sample code file below.

Another odd thing...

If I run this example repeatedly, sometimes it doesn't find the icon set for one of the buttons. When it can't find the icons, and which button it can't find them for, seems to be random. This also happens if only one of these buttons is present in the code.


```
// Test Rig Foundation for Learning GtkD Coding

import std.stdio;

import gtk.MainWindow;
import gtk.Main;
import gtk.Box;
import gtk.Widget;
import gtk.VolumeButton;
import gtk.ScaleButton;
import gtk.Adjustment;
import gtk.c.types;

void main(string[] args)
{
	Main.init(args);

	TestRigWindow myTestRig = new TestRigWindow("Test Rig with VolumeButton");
	
	Main.run();
	
} // main()


class TestRigWindow : MainWindow
{
	int borderWidth = 10;
	int width = 250;
	int height = 175;
	AppBox appBox;
	
	this(string title)
	{
		super(title);
		addOnDestroy(&quitApp);
		setBorderWidth(borderWidth);
		setSizeRequest(width, height);
		
		appBox = new AppBox();
		add(appBox);
		
		showAll();

	} // this() CONSTRUCTOR
	
		
	void quitApp(Widget widget)
	{
		writeln("Bye.");
		Main.quit();
		
	} // quitApp()

} // class myAppWindow


class AppBox : Box
{
	MyVolumeButton myVolumeButton;
	MyScaleButton myScaleButton;
	
	this()
	{
		super(Orientation.VERTICAL, 10);
		
		myVolumeButton = new MyVolumeButton();
		packStart(myVolumeButton, false, false, 0);

		myScaleButton = new MyScaleButton();
		packStart(myScaleButton, false, false, 0);
		
	} // this()

} // class AppBox


class MyScaleButton : ScaleButton
{
	double minimum = 0;
	double maximum = 10;
	double step = 1;

	Adjustment adjustment;
	double initialValue = 0;
	double pageIncrement = 1;
	double pageSize = 0;
	
	string[] icons = ["audio-volume-muted", "audio-volume-high", "audio-volume-low", "audio-volume-medium"];
//	string[] icons = ["audio-volume-low", "audio-volume-high"];
	
	this()
	{
		super(IconSize.BUTTON, minimum, maximum, step, icons);
		
		adjustment = new Adjustment(initialValue, minimum, maximum, step, pageIncrement, pageSize);
		setAdjustment(adjustment);
		addOnValueChanged(&valueChanged);
		
	} // this()
	
	
	void valueChanged(double value, ScaleButton sb)
	{
		writeln(getValue());
		
	} // valueChanged()


} // class MyScaleButton


class MyVolumeButton : VolumeButton
{
	double minimum = 0;
	double maximum = 10;
	double step = 1;

	Adjustment adjustment;
	double initialValue = 7;
	double pageIncrement = 1;
	double pageSize = 1;
	
	this()
	{
		super();
		
		adjustment = new Adjustment(initialValue, minimum, maximum, step, pageIncrement, pageSize);
		setAdjustment(adjustment);
		addOnValueChanged(&valueChanged);
		
	} // this()
	
	
	void valueChanged(double value, ScaleButton sb)
	{
		writeln(getValue());
		
	} // valueChanged()


} // class MyVolumeButton

```

April 25, 2019
On Thursday, 25 April 2019 at 11:36:26 UTC, Ron Tarrant wrote:
> When running this example of a VolumeButton, ...

When using `setValue(initialValue)` after `setAdjustment()` the scale seems have the correct value. If in addition the Adjustment is created with an initial value different from the `initialValue` used with `setValue()` then the icons are also correct on startup. Though I don't know why that is. The loading issue doesn't happen here (on linux).
April 25, 2019
On Thursday, 25 April 2019 at 12:40:00 UTC, number wrote:
> On Thursday, 25 April 2019 at 11:36:26 UTC, Ron Tarrant wrote:
>> When running this example of a VolumeButton, ...
>
> When using `setValue(initialValue)` after `setAdjustment()` the scale seems have the correct value. If in addition the Adjustment is created with an initial value different from the `initialValue` used with `setValue()` then the icons are also correct on startup. Though I don't know why that is. The loading issue doesn't happen here (on linux).

Must be a Windows thing, then.

And even explicitly setting it with setValue() doesn't help. The icon is still wrong on startup.

April 25, 2019
On 25-04-2019 15:19, Ron Tarrant wrote:
> On Thursday, 25 April 2019 at 12:40:00 UTC, number wrote:
>> On Thursday, 25 April 2019 at 11:36:26 UTC, Ron Tarrant wrote:
>>> When running this example of a VolumeButton, ...
>>
>> When using `setValue(initialValue)` after `setAdjustment()` the scale seems have the correct value. If in addition the Adjustment is created with an initial value different from the `initialValue` used with `setValue()` then the icons are also correct on startup. Though I don't know why that is. The loading issue doesn't happen here (on linux).
> 
> Must be a Windows thing, then.
> 
> And even explicitly setting it with setValue() doesn't help. The icon is still wrong on startup.
> 

This looks like an issue with GTK, the icon is not updated when changing the Adjustment, only when the value changes.

Using setValue after setting the ajustment should work, only you have to use a different value than the initial value of the adjustment or GTK doesn't see it as a change.

-- 
Mike Wey
April 25, 2019
On Thursday, 25 April 2019 at 17:57:25 UTC, Mike Wey wrote:
> On 25-04-2019 15:19, Ron Tarrant wrote:

> This looks like an issue with GTK, the icon is not updated when changing the Adjustment, only when the value changes.

So, it should be reported directly to the GTK people rather than... well... you?

> Using setValue after setting the ajustment should work, only you have to use a different value than the initial value of the adjustment or GTK doesn't see it as a change.

Thanks, Mike. That does the trick. I guess the world loves a gludge, eh? :)

April 26, 2019
On Thu, 2019-04-25 at 11:36 +0000, Ron Tarrant via Digitalmars-d-learn wrote:
> I've scoured the docs, the wrapper code, the Internet, but can't come up with an explanation...
> 
> When running this example of a VolumeButton, no matter what the initial value of the slider, the icon showing is audio-volume-muted.

Experience with Me TV in D/GtkD/GStreamerD and Rust/gtk-rs/gstreamer-rs indicates that volume buttons and adjustments in GTK+ have issues, this is not a GtkD or gtk-rs thing it seems to be a GTK+ thing.

If I remember correctly, you have to set up the volume button, set the initial
volume, then set up and add the adjustment, and then reset the initial value
via the adjustment to get the icon correct. Memory on this is hazy as it was a
while ago, I got it working and then left it alone, untouched.

-- 
Russel.
===========================================
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



April 26, 2019
On Friday, 26 April 2019 at 09:36:04 UTC, Russel Winder wrote:

> If I remember correctly, you have to set up the volume button, set the initial
> volume, then set up and add the adjustment, and then reset the initial value
> via the adjustment to get the icon correct. Memory on this is hazy...

Actually, you're memory on this point is fine, Russell.

My solution—in an effort to keep is as clear as possible—was to do the initial setting of the new Adjustment to (initialValue + 1), and then do setValue(initialValue).