Sign up

Is Value.d's constructor for bool value missing?

When I try to pass some boolean values to Liststore constructor it was giving a warning message.

        auto model = new ListStore([GType.STRING, GType.BOOLEAN, GType.BOOLEAN]);

        void addOs(string isim, bool toggle, bool radio)
        {
            TreeIter iterator = model.createIter();
            model.setValue(iterator, 0, isim);
            model.setValue(iterator, 1, new Value(toggle));
            model.setValue(iterator, 2, new Value(radio));
        }

        addOs("Debian", false, true);
        addOs("Ubuntu", true, false);
        addOs("Bodhi linux", false, false);

So I added a constructor to the /gobject/Value.d file for bool values like this.

    this(bool value)
    {
        this();
        init(GType.BOOLEAN);
        setBoolean(value);
    }

Re: Is Value.d's constructor for bool value missing?

On Wed, 15 Feb 2017 19:55:55 GMT, Erdem wrote:

When I try to pass some boolean values to Liststore constructor it was giving a warning message.

Still I get the same warning:

Gtk-WARNING **: gtk unable to convert from gint to gboolean

Re: Is Value.d's constructor for bool value missing?

On 02/15/2017 09:04 PM, Erdem wrote:

On Wed, 15 Feb 2017 19:55:55 GMT, Erdem wrote:

When I try to pass some boolean values to Liststore constructor it was giving a warning message.

Still I get the same warning:

Gtk-WARNING **: gtk unable to convert from gint to gboolean

I don't see anything wrong at first hand. Do you have a more complete
example to test with?

Re: Is Value.d's constructor for bool value missing?

On Wed, 15 Feb 2017 23:09:01 +0100, Mike Wey wrote:

I don't see anything wrong at first hand. Do you have a more complete
example to test with?

Ok. Here is the complete example. I simply want to toggle the button in a cell.

import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.ListStore;
import gtk.TreeIter;
import gtk.TreeViewColumn;
import gtk.TreeView;
import gtk.CellRendererToggle;
import gtk.CellRendererText;
import gtk.TreePath;

import gobject.Value;


class MyWindow: MainWindow
{

    this()
    {
        super("CellRendererToggle Example");
        setDefaultSize(200, 200);

        auto model = new ListStore([GType.STRING, GType.BOOLEAN, GType.BOOLEAN]);

        void addOs(string name, bool toggle, bool radio)
        {
            TreeIter iter = model.createIter();
            model.setValue(iter, 0, name);
            model.setValue(iter, 1, new Value(toggle));
            model.setValue(iter, 2, new Value(radio));
        }

        addOs("Debian", false, true);
        addOs("Ubuntu", true, false);
        addOs("Bodhi linux", false, false);

        auto view = new TreeView(model);

        auto rendererText = new CellRendererText();
        auto columnText = new TreeViewColumn("Text", rendererText, "text", 0);
        view.appendColumn(columnText);

        auto rendererToggle = new CellRendererToggle();
        rendererToggle.addOnToggled((path, renderer)
                                   {onCellToggled(path, renderer, model);});
        auto columnToggle = new TreeViewColumn("Toggle", rendererToggle, "active", 1);
        view.appendColumn(columnToggle);

        add(view);

        showAll();
    }
    void onCellToggled(string path, CellRendererToggle renderer, ListStore model)
    {
        auto path_ = new TreePath(path);
        auto iter = new TreeIter(model, path_);
        auto status = model.getValue(iter, 1).getBoolean();

        status = (!status);
        model.setValue(iter, 1, status);
    }
}

void main(string[] args)
{
    Main.init(args);
    auto myWindow = new MyWindow();
    Main.run();
}

Re: Is Value.d's constructor for bool value missing?

On 02/16/2017 07:45 AM, Erdem wrote:

On Wed, 15 Feb 2017 23:09:01 +0100, Mike Wey wrote:

I don't see anything wrong at first hand. Do you have a more complete
example to test with?

Ok. Here is the complete example. I simply want to toggle the button in a cell.

...

I don't have any issues with this example, either with or without the
bool constructor for gobject.Value.

Which version of Gtk are you using?

Re: Is Value.d's constructor for bool value missing?

On Thu, 16 Feb 2017 20:27:22 +0100, Mike Wey wrote:

I don't have any issues with this example, either with or without the
bool constructor for gobject.Value.

Which version of Gtk are you using?

I use Gtk version 3.5.1

After your post I recognised my error.

        model.setValue(iter, 1, status);

I changed this line to take a Value

        model.setValue(iter, 1, new Value(status));

So it works as expected. Thanks.