Hi, yeah, that example was not the best, it is unecessarily complex, which may be a turn off. I'm working on a "general recipe list example" which contains all the various customcellrenderers in a simple manner, so they can be easily setup. I'm stuck right now, on getting the spinbutton cell renderer to work right, but below is a simple example of doing the combotext. Notice there are 2 ways to do a combo .... with entry and dropdown list, and a non-editable popup. I post a better example later in the snippets section, when I figure it out. :-)
#!/usr/bin/perl use warnings; use strict; use Gtk2 -init; use Glib qw/TRUE FALSE/; my $window = Gtk2::Window->new( "toplevel" ); $window->signal_connect( "destroy", sub { Gtk2->main_quit(); } ); $window->set_default_size(600,200); my $vbox = Gtk2::VBox->new( 0, 5 ); $vbox->set_size_request(0,0); my $model = Gtk2::ListStore->new( "Glib::String", "Glib::String", "Glib::String", # easy to use string for ints "Glib::String", "Glib::String", "Glib::Boolean", "Glib::Double", 'Gtk2::Gdk::Pixbuf', ); my $pixbuf = Gtk2::Button->new->render_icon ('gtk-home', 'large-toolba +r'); $model->set( $model->append, 0 => 'Joe', 1 => 'Schmoe', 2 => 1, 3 => 'two', 4 => 'foo', 5 => 1, 6 => 42.42 , 7 => $pixbuf ); $model->set( $model->append, 0 => 'Billy', 1 => 'Bobo', 2 => 3, 3 => 'five', 4 => 'bar', 5 => 0, 6 => 24.42, 7 => $pixbuf ); ############ Column0 setup ########################################### +### ###################################################################### +##### my $col0 = 0; my $renderer_0 = Gtk2::CellRendererText->new; $renderer_0->set( editable => TRUE ); $renderer_0->signal_connect( edited => sub { &process_editing( @_, $co +l0 ); } ); ###################################################################### +###### my $column_0 = Gtk2::TreeViewColumn->new_with_attributes( " Text1 ", $renderer_0, 'text' => $col0 ); ###################################################################### +##### #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@ ############ Column1 setup ########################################### +### my $col1 = 1; my $renderer_1 = Gtk2::CellRendererText->new; $renderer_1->set( editable => TRUE ); $renderer_1->signal_connect( edited => sub { &process_editing( @_, $co +l1 ); } ); ###################################################################### +#### my $column_1 = Gtk2::TreeViewColumn->new_with_attributes( " Text2 ", $renderer_1, 'text' => $col1 ); ###################################################################### +####### #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@ ############ Column2 setup ########################################### +### ###################################################################### +####### my $col2 = 2; my $combo_model = Gtk2::ListStore->new( "Glib::String" ); foreach my $choice (1,2,3,4,5,){ $combo_model->set($combo_model->append,0,$choice ); } my $renderer_2 = Gtk2::CellRendererCombo->new; $renderer_2->set( editable => TRUE, text_column => 0, has_entry => TRUE, model => $combo_model ); $renderer_2->signal_connect( edited => sub { &process_editing( @_, $co +l2 ); } ); my $column_2 = Gtk2::TreeViewColumn->new_with_attributes( "Combo Drop", $renderer_2, text => $col2 ); ###################################################################### +####### #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@ ############ Column3 setup ########################################### +### my $col3 = 3; my $combo_model1 = Gtk2::ListStore->new( "Glib::String" ); foreach my $choice ('one','two','three','four','five'){ $combo_model1->set($combo_model1->append,0,$choice ); } my $renderer_3 = Gtk2::CellRendererCombo->new; $renderer_3->set( editable => TRUE, text_column => 0, has_entry => TRUE, model => $combo_model1 ); $renderer_3->signal_connect( edited => sub { &process_editing( @_, $co +l3 ); } ); my $column_3 = Gtk2::TreeViewColumn->new_with_attributes( "Combo Drop", $renderer_3, text => $col3 ); ###################################################################### +############# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@ ############ Column4 setup ########################################### +### my $col4 = 4; my $combo_model2 = Gtk2::ListStore->new( "Glib::String" ); foreach my $choice ('foo','bar','baz','buz','fum'){ $combo_model2->set($combo_model2->append,0,$choice ); } my $renderer_4 = Gtk2::CellRendererCombo->new; $renderer_4->set( editable => TRUE, text_column => 0, has_entry => FALSE, #makes a pure popup model => $combo_model2 ); $renderer_4->signal_connect( edited => sub { &process_editing( @_, $co +l4 ); } ); my $column_4 = Gtk2::TreeViewColumn->new_with_attributes( "Combo PoP", $renderer_4, text => $col4 ); ###################################################################### +############# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@ ############ Column5 setup ########################################### +### my $col5 = 5; my $togglemodel = Gtk2::ListStore -> new(qw(Glib::Boolean)); my $renderer_5 = Gtk2::CellRendererToggle->new(); $renderer_5->set( activatable => 1 ); $renderer_5->signal_connect( toggled => sub { &process_toggle(@_, $col5) } ); my $column_5 = Gtk2::TreeViewColumn->new_with_attributes ( ' On/Off ', $renderer_5, ); $column_5->set_resizable (TRUE); # set initial value on display $column_5->set_cell_data_func( $renderer_5, sub { &render_toggle_cell( + @_, $col5 ); } ); ###################################################################### +######### ###################################################################### +######## # main program starts my $treeview = Gtk2::TreeView->new( $model ); # a TreeSelection $treeview->get_selection->set_mode ('extended'); $treeview->set_rules_hint( TRUE ); $treeview->append_column( $column_0 ); $treeview->append_column( $column_1 ); $treeview->append_column( $column_2 ); $treeview->append_column( $column_3 ); $treeview->append_column( $column_4 ); $treeview->append_column( $column_5 ); my $sw = Gtk2::ScrolledWindow->new( undef, undef ); $sw->set_shadow_type( "etched-in" ); $sw->set_policy( "never", "always" ); $sw->add( $treeview ); $vbox->pack_start( $sw, 1, 1, 0 ); my $button = Gtk2::Button->new( "Dump Values" ); $button->signal_connect( "clicked" => sub { &dump_values(@_); } ); $vbox->pack_start( $button, 0, 0, 0 ); $window->add( $vbox ); $window->show_all; Gtk2->main; ###################################################################### +###### sub process_editing { my ( $renderer, $text_path, $new_text, $column ) = @_; my $path = Gtk2::TreePath->new_from_string ($text_path); my $iter = $model->get_iter ($path); #update the underlying model $model->set( $iter, $column, $new_text); } ###################################################################### +######## sub process_toggle{ my ($cell, $row_num, $column) = @_; my $path = Gtk2::TreePath->new_from_string ($row_num); # get toggled iter my $iter = $model->get_iter($path); my ($toggle_item) = $model->get ($iter,$column); # flip the value $toggle_item ^= 1; # set new value in underlying model $model->set ($iter, $column, $toggle_item); } ###################################################################### +######### sub render_toggle_cell { my($tcolview,$cell,$model,$iter, $column) = @_; # print "$tcolview, $cell, $model, $iter, $column\n"; my ($toggle_item) = $model->get ($iter, $column); if($toggle_item){ $cell->set_active(1); }else{$cell->set_active(0)} } ###################################################################### +######## sub dump_values { my $treeselection = $treeview->get_selection; # print "$treeselection\n"; #for a single selection mode # my $iter = $treeselection->get_selected; # my $iter = $model->get_iter_first; #for multiple selection mode my @selpaths = $treeselection->get_selected_rows; # read perldoc Gtk2::Tree::Model Gtk2::Tree::Selection foreach my $tpath(@selpaths){ my $iter = $model->get_iter($tpath); print $model->get( $iter, 0 ) . '--'; print $model->get( $iter, 1 ) . '--'; print $model->get( $iter, 2 ) . '--'; print $model->get( $iter, 3 ) . '--'; print $model->get( $iter, 4 ) . '--'; print $model->get( $iter, 5 ) . '--'; print "\n"; } }

I'm not really a human, but I play one on earth. flash japh

In reply to Re^3: popup menu in Gtk2::SimpleList by zentara
in thread popup menu in Gtk2::SimpleList by cas2006

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.