hi!
How can i create a combo box which can contain widgets?
Cheers: Tamás
So, I tried it, but without success. My program runs without errors, but there isn't anyting in the ComboBox. I tried so: ... megjegyzese = GTK2.ComboBox(); megjegyzese->set_model(modell()); megjegyzese->set_active(0); ... GTK2.TreeModel modell() { GTK2.TreeStore store; GTK2.TreeIter iter;
iter = GTK2.TreeIter();
store = GTK2.TreeStore(({"int", "int"})); // az oszlopok típusa iter = store->append(); store->set_row(iter, ({1, 2}));
return store; } ...
I can't find out what can be the problem...
From: linuxlinux1@windowslive.com To: pike-devel@lists.lysator.liu.se Subject: gtk question Date: Mon, 2 Aug 2010 08:46:32 +0200
hi!
How can i create a combo box which can contain widgets?
Cheers: Tamás
From: Csürke Tamás linuxlinux1@windowslive.com To: pike lista pike-devel@lists.lysator.liu.se Sent: Mon, August 2, 2010 12:07:23 PM Subject: RE: gtk question
So, I tried it, but without success. My program runs without errors, but there isn't anyting in the ComboBox. I tried so:
... megjegyzese = GTK2.ComboBox(); megjegyzese->set_model(modell()); megjegyzese->set_active(0); ... GTK2.TreeModel modell() { GTK2.TreeStore store; GTK2.TreeIter iter;
iter = GTK2.TreeIter();
store = GTK2.TreeStore(({"int", "int"})); // az oszlopok típusa iter = store->append(); store->set_row(iter, ({1, 2}));
return store; } ...
I can't find out what can be the problem...
From: linuxlinux1@windowslive.com To: pike-devel@lists.lysator.liu.se Subject: gtk question Date: Mon, 2 Aug 2010 08:46:32 +0200
hi!
How can i create a combo box which can contain widgets?
Cheers: Tamás
Here is a test program that works, you can try it out:
#!/usr/bin/env pike
void fixed_toggled(object w, array data, object ts) { GTK2.TreePath path=GTK2.TreePath(data[0]); // write("path==%O\n",path); GTK2.TreeIter iter=ts->get_iter(path); int val=ts->get_value(iter,3); // write("val==%d\n",val); val=!val; ts->set_value(iter,3,val); }
int main(int argc, array argv) { GTK2.setup_gtk(); object w=GTK2.Window(GTK2.WINDOW_TOPLEVEL); object vb=GTK2.Vbox(0,8)->set_border_width(8); w->add(vb); vb->pack_start(GTK2.Label("Jonathan's Holiday Card Planning Sheet"),0,0,0); object sw=GTK2.ScrolledWindow(); sw->set_shadow_type(GTK2.SHADOW_ETCHED_IN) ->set_policy(GTK2.POLICY_AUTOMATIC,GTK2.POLICY_AUTOMATIC); vb->pack_start(sw,1,1,0);
GTK2.TreeStore ts=GTK2.TreeStore(({ "string","int","int","boolean","string" }) ); object iter=ts->append(); ts->set_row(iter,({ "foo",1,2,0,GTK2.STOCK_OPEN }) ); iter=ts->append(); ts->set_row(iter,({ "bar",3,47,1,GTK2.STOCK_CLOSE }) ); iter=ts->append(); ts->set_row(iter,({ "baz",124,97,0,GTK2.STOCK_DELETE }) ); GTK2.TreeView tree=GTK2.TreeView(ts); GTK2.CellRenderer gcr=GTK2.CellRendererText(); array(GTK2.TreeViewColumn) cols; cols=allocate(5); // write("gcr==%O\n",gcr); // write("family==%s\n",gcr->get_property("family")); /* cols[0]=GTK2.TreeViewColumn()->set_title("Name") ->pack_start(gcr,1) ->add_attribute(gcr,"text",0); */ cols[0]=GTK2.TreeViewColumn("Name",gcr,"text",0); gcr=GTK2.CellRendererText(); cols[1]=GTK2.TreeViewColumn("Val 1",gcr,"text",1); gcr=GTK2.CellRendererText(); cols[2]=GTK2.TreeViewColumn("Val 2",gcr,"text",2); gcr=GTK2.CellRendererToggle(); cols[3]=GTK2.TreeViewColumn("Active?",gcr,"active",3); gcr->signal_connect("toggled",fixed_toggled,ts); gcr=GTK2.CellRendererPixbuf(); cols[4]=GTK2.TreeViewColumn("Pic",gcr,"stock-id",4); tree->append_column(cols[0]) ->append_column(cols[1]) ->append_column(cols[2]) ->append_column(cols[3]) ->append_column(cols[4]); vb->add(tree); w->signal_connect("destroy",lambda() { exit(0); },0); w->show_all();
object path=GTK2.TreePath("1"); tree->set_cursor(path,cols[1],0); return -1; }
Thank you, it's very useful. And runs without problem, it creates the tree. But I even couldn't create a similar ComboBox. :(
I think based on your example that I should render the rows with a cellrenderer, but I don't know how or where...
Date: Mon, 2 Aug 2010 14:15:33 -0700 From: riffraff169@yahoo.com Subject: Re: gtk question To: pike-devel@lists.lysator.liu.se
From: Csürke Tamás linuxlinux1@windowslive.com To: pike lista pike-devel@lists.lysator.liu.se Sent: Mon, August 2, 2010 12:07:23 PM Subject: RE: gtk question
So, I tried it, but without success. My program runs without errors, but there isn't anyting in the ComboBox. I tried so: ... megjegyzese = GTK2.ComboBox(); megjegyzese->set_model(modell()); megjegyzese->set_active(0); ... GTK2.TreeModel modell() { GTK2.TreeStore store; GTK2.TreeIter iter;
iter = GTK2.TreeIter();
store = GTK2.TreeStore(({"int", "int"})); // az oszlopok típusa iter = store->append(); store->set_row(iter, ({1, 2}));
return store; } ...
I can't find out what can be the problem...
From: linuxlinux1@windowslive.com To: pike-devel@lists.lysator.liu.se Subject: gtk question Date: Mon, 2 Aug 2010 08:46:32 +0200
hi!
How can i create a combo box which can contain widgets?
Cheers: Tamás
Here is a test program that works, you can try it out:
#!/usr/bin/env pike
void fixed_toggled(object w, array data, object ts) { GTK2.TreePath path=GTK2.TreePath(data[0]); // write("path==%O\n",path); GTK2.TreeIter iter=ts->get_iter(path); int val=ts->get_value(iter,3); // write("val==%d\n",val); val=!val; ts->set_value(iter,3,val); }
int main(int argc, array argv) { GTK2.setup_gtk(); object w=GTK2.Window(GTK2.WINDOW_TOPLEVEL); object vb=GTK2.Vbox(0,8)->set_border_width(8); w->add(vb);
vb->pack_start(GTK2.Label("Jonathan's Holiday Card Planning Sheet"),0,0,0); object sw=GTK2.ScrolledWindow(); sw->set_shadow_type(GTK2.SHADOW_ETCHED_IN) ->set_policy(GTK2.POLICY_AUTOMATIC,GTK2.POLICY_AUTOMATIC); vb->pack_start(sw,1,1,0);
GTK2.TreeStore ts=GTK2.TreeStore(({ "string","int","int","boolean","string" }) ); object iter=ts->append(); ts->set_row(iter,({ "foo",1,2,0,GTK2.STOCK_OPEN }) ); iter=ts->append(); ts->set_row(iter,({ "bar",3,47,1,GTK2.STOCK_CLOSE }) ); iter=ts->append(); ts->set_row(iter,({ "baz",124,97,0,GTK2.STOCK_DELETE }) ); GTK2.TreeView tree=GTK2.TreeView(ts); GTK2.CellRenderer gcr=GTK2.CellRendererText(); array(GTK2.TreeViewColumn) cols; cols=allocate(5); // write("gcr==%O\n",gcr); // write("family==%s\n",gcr->get_property("family")); /* cols[0]=GTK2.TreeViewColumn()->set_title("Name") ->pack_start(gcr,1) ->add_attribute(gcr,"text",0); */ cols[0]=GTK2.TreeViewColumn("Name",gcr,"text",0); gcr=GTK2.CellRendererText(); cols[1]=GTK2.TreeViewColumn("Val 1",gcr,"text",1); gcr=GTK2.CellRendererText(); cols[2]=GTK2.TreeViewColumn("Val 2",gcr,"text",2); gcr=GTK2.CellRendererToggle(); cols[3]=GTK2.TreeViewColumn("Active?",gcr,"active",3); gcr->signal_connect("toggled",fixed_toggled,ts); gcr=GTK2.CellRendererPixbuf(); cols[4]=GTK2.TreeViewColumn("Pic",gcr,"stock-id",4); tree->append_column(cols[0])
->append_column(cols[1]) ->append_column(cols[2]) ->append_column(cols[3]) ->append_column(cols[4]); vb->add(tree); w->signal_connect("destroy",lambda() { exit(0); },0); w->show_all();
object path=GTK2.TreePath("1"); tree->set_cursor(path,cols[1],0); return -1; }
From: Csürke Tamás linuxlinux1@windowslive.com To: pike lista pike-devel@lists.lysator.liu.se Sent: Tue, August 3, 2010 11:38:47 AM Subject: RE: gtk question
Thank you, it's very useful. And runs without problem, it creates the tree. But I even couldn't create a similar ComboBox. :(
I think based on your example that I should render the rows with a cellrenderer, but I don't know how or where...
#!/usr/bin/env pike
void get_text(GTK2.ComboBox w, mixed data) { // string text=w->get_active_text(); int index=w->get_active();
// write("You chose: %s\n",text); object tm=w->get_property("model"); // write("tm==%O\n",tm); object iter=tm->get_iter(GTK2.TreePath((string)index)); mixed val=tm->get_value(iter,0); write("val==%O\n",val); }
int main(int argc, array argv) { GTK2.setup_gtk(); object w=GTK2.Window(GTK2.WINDOW_TOPLEVEL); // GTK2.ListStore ls=GTK2.ListStore(({ "string" })); object cb=GTK2.ComboBox("string"); cb->append_text("test 1"); cb->append_text("foo"); cb->append_text("fred"); cb->append_text("scooby"); w->add(cb); w->show_all(); cb->signal_connect("changed",get_text,0); w->signal_connect("destroy",lambda(){ exit(0); },0); return -1; }
Just modify it to add specific cell renderers as per the previous example.
pike-devel@lists.lysator.liu.se