Hi, i'm a little rusty, but I think you will have to either make a separate menu for each item, or dynamically load the menu items from a hash or something. Gtk2 is very good about cleaning up menus that are self contained in a sub.... so don't feel bad about using the menu once then letting it be discarded....here is a cheap fast example

what I would do if I had more time to play around, is to have a hash containing your values( or maybe pulled from a db)..... then as you build your menu, plug in the values you need. Another thing to try is $menu->destroy your menu after each use, so the old global dosn't get left laying around..... watch for memory gains too as you run alot of menu calls.

As you can see from the code, you can get the button the menu is being called from, from the callback arguments being passed in..... so that gives you your way of loading a custom menu for the button in question.

One last point, I didn't use a treeview for my example, but what might be happening, is that your menu is attached to the treeview itself, not the elements. Remember, labels( common in treeview), don't respond to events.... you may need event boxes for each label to signal_connect to.

#!/usr/bin/perl use warnings; use strict; use Glib ':constants'; use Gtk2 'init'; my $w = Gtk2::Window->new('toplevel'); $w->signal_connect(destroy => sub { Gtk2->main_quit() }); $w->set_border_width(12); $w->show(); my $vbox = Gtk2::VBox->new( FALSE, 6 ); $w->add($vbox); my $b = Gtk2::Button->new_from_stock('gtk-ok'); $vbox->pack_start( $b, FALSE, FALSE, 0 ); $b->signal_connect(clicked => sub { $w->destroy() }); my $b1 = Gtk2::Button->new_from_stock('gtk-cancel'); $vbox->pack_start( $b1, FALSE, FALSE, 0 ); $b1->signal_connect(clicked => sub { }); $b->signal_connect(button_release_event => sub { my ($button, $event) = @_; return FALSE if $event->button != 3; my $item; my $menu = Gtk2::Menu->new(); $item = Gtk2::MenuItem->new_with_mnemonic('Item _1'); $menu->append($item); $item->show(); $item = Gtk2::MenuItem->new_with_mnemonic('Item _2'); $menu->append($item); $item->show(); $item = Gtk2::SeparatorMenuItem->new(); $menu->append($item); $item->show(); $item = Gtk2::MenuItem->new_with_mnemonic('Item _3'); $menu->append($item); $item->show(); $menu->popup(undef, undef, undef, undef, $event->button, $event->time); return TRUE; }); $b1->signal_connect(button_release_event => sub { my ($button, $event) = @_; return FALSE if $event->button != 3; my $item; my $menu = Gtk2::Menu->new(); $item = Gtk2::MenuItem->new_with_mnemonic('Z_1'); $menu->append($item); $item->show(); $item = Gtk2::MenuItem->new_with_mnemonic('Z_2'); $menu->append($item); $item->show(); $item = Gtk2::SeparatorMenuItem->new(); $menu->append($item); $item->show(); $item = Gtk2::MenuItem->new_with_mnemonic('Z_3'); $menu->append($item); $item->show(); $menu->popup(undef, undef, undef, undef, $event->button, $event->time); return TRUE; }); $w->show_all; Gtk2->main(); 0;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

In reply to Re: TreeView popup issue by zentara
in thread TreeView popup issue by Anonymous Monk

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.