Re: Problem with Gtk.ListStore



Have you tried

this.store.set_value(iter, 0, ''+items[0]);

It does sound like it's an implementation problem in gjs, as it works fine in seed (as I spent some time fixing it a long while ago...)

Regards
Alan


On Wednesday, July 18, 2012 03:55 PM, Peter Verthez wrote:
Follow-up with some more experimentation...

It seems that ListStore.set_value works if you pass a string (literal) value, but fails when you pass a String (Object) value.

The following works:
        this.store.set_value(iter, 0, "test");

but the following fails (and even causes gjs-console to abort with SIGSEGV):
        this.store.set_value(iter, 0, new String("test"));

Since literal values are converted to a String object when passed to a method, that causes the behavior mentioned in my previous mail. This makes that a ListStore with String values is currently not usable.

I'll submit a bug report (version info: gjs-1.32.0-1.fc17.rpm).

Best regards,
Peter.


On 07/17/2012 06:26 PM, Peter Verthez wrote:
Hi,

I'm trying to write a gnome shell extension. As part of that I'm making a preference page for which one of the preferences is a file list. I'm modelling this as a TreeView, with an Add button next to it that opens a FileChooserDialog, and adds the selected file name in the list when OK is pressed.

I have however a problem with inserting values in that treeview. The treeview is created like this:

        this.actor = new Gtk.TreeView({headers_visible: false});
        this.store = new Gtk.ListStore();
        this.store.set_column_types([GObject.TYPE_STRING]);
        this.actor.set_model(this.store);

        this.column = new Gtk.TreeViewColumn();
        this.cell = new Gtk.CellRendererText();
        this.column.pack_start(this.cell, true);
        this.column.add_attribute(this.cell, "text", 0);
        this.actor.append_column(this.column);

this.actor.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
        ...

And when I add literal values, it works:

        this.store.clear();
        let iter = this.store.append();
        this.store.set_value(iter, 0, "test");

But string values passed on from somewhere else don't work (I'm simplifying here, I want to do a loop on items of course):

        update_all: function() {
           this.update(["test"]);
        },

        update: function(items) {
           this.store.set_value(iter, 0, items[0]);
           ...
        }

with as error:
Error: Could not guess unspecified GValue type

When the 'items' variable is a local array in the method, it works and is indeed shown in the treeview:

// items is an array of string passed to the surrounding function
        update: function() {
           let items = ["test"];
           this.store.set_value(iter, 0, items[0]);
           ...
        }

I've also tried creating a GObject.Value explicitly to pass to set_value (I'm assuming that this is the correct way to construct a GObject.Value, because if I try it in lg at least get_string() returns the proper value):

        let v = new GObject.Value();
        v.init(GObject.TYPE_STRING);
        v.set_string(items[0]);
        this.store.set_value(iter, 0, v);

But that gave me the same error message.

I suppose this is a bug in the javascript binding?

Best regards,
Peter.






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]