Dazed and confused about menus
- From: David Sword <gdsword williamsword co uk>
- To: gtk-perl list <gtk-perl-list gnome org>
- Subject: Dazed and confused about menus
- Date: 06 Nov 2003 14:38:29 +0000
Hi
I am writing a menu system which will run other programs I will write
(if I ever get to grips with this!). Details of each menu item are
stored in a database and are specific for each user i.e. some users will
get different sets of menu options from others.
There are a series of optionmenus used to cover different areas of work,
and to simplify navigation around a large set of options.
Everything works fine, except for attaching the callback to run the
programs - it always contains the details of the last menuitem created,
as opposed to the one selected, and I don't understand how to make this
work (or even if it CAN work!)
The offending subroutine is detailed below.
Any pointers or examples would be gratefully accepted!
####### code starts here
sub LoadMenus{
my @data;
my @data1;
$sql3->execute($userid,$dbname) or die ("Error Reading Menu Files");
while((@data1) = $sql3->fetchrow_array()) {
push(@data,[ data1]);
$number++;
}
for($cntr=0;$cntr < $number ;$cntr++){
$menu_name = $data[$cntr][0];
$title = $data[$cntr][2];
$subname = $data[$cntr][3];
$recordno = $data[$cntr][4];
# if the menu is already defined, do nothing, otherwise define a new
menu
if( !defined($menus{$menu_name})){
$menus{$menu_name} = Gtk2::Menu->new;
}
# Add a new item - connect the RunProg callback if a type P, or a
# submenu if a type S
$MenuItem[$cntr] = Gtk2::MenuItem->new($title);
if($data[$cntr][1] eq 'P'){
$progname = $subname;
$MenuItem[$cntr]->signal_connect('activate' => sub{
\&RunProg(@_,$progname)} );
}else{
$MenuItem[$cntr]->set_submenu ($menus{$subname});
}
$MenuItem[$cntr]->show;
$menus{$menu_name}->append($MenuItem[$cntr]);
}
$sql3->finish;
$opt_salesteam->set_menu($menus{salesteam});
$opt_sales->set_menu($menus{'sales'});
$opt_sal_rep->set_menu($menus{sal_rep});
$opt_stk_stores->set_menu($menus{stk_stores});
$opt_stk_finish->set_menu($menus{stk_finish});
}
sub RunProg{
print Dumper(@_);
my ($widget,$progname) = @_;
print "prog is $progname\n";
$file2run = $AB1WRKDIR.'/'.$progname;
# if($pid=fork){
# return 0;
# }elsif(defined $pid){
# exec $file2run;
# }else{
# die "Cannot fork new process1";
# }
}
#### end of code
TIA
--
Regards
David Sword
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]