Re: ItemFactory Callback

"Jonathan Pelletier" wrote:

Does anybody know how to specify parameters for a callback function using
the ItemFactory structure ???

You can always use closures as callbacks, e.g.:

my @menu_items = ( { path     => '/_File',
                     type     => '<Branch>' },
                   { path        => '/File/_New',
                     accelerator => '<control>N',
                     callback    => sub { print_hello (['test']) }

This way you can pass any data to your callback functions, even if Gtk 
has no mechanism for providing parameters like e.g. signal_connect has.
It's even possible to pass dynamically lexically scoped variables here,
because closures keep this scope for every pass at runtime.

You can find details about closures in the perlref manpage.



sub i($){print$_[0]}*j=*ENV;sub w($){sleep$_[0]}sub _($){i"$p$c > ",w
1,$_=$_[0],tr;i-za-h,;a-hi-z ;,i$_,w 1,i"\n"}$|=1;$f='HO';($c=$j{PWD}
)=~s/$j{$f."ME"}/~/;$p="$j{USER}\ $j{HOSTNAME}:";_"kl",$c='~',_"zu,".
"-zn,*",_"#,epg,lw,gwc,mfmkcbm,cvsvwev,uiqt,kwvbmvb?",i"$p$c > ";w 99

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