thefinn has asked for the wisdom of the Perl Monks concerning the following question:

I wished to create a tab frame under a menu system. The menu system would create tabs as users began jobs and then push external program output to the tab as the job runs in background. It will also be saving much of the output to database for querying later.

I have a bit of perl experience, but am not neat or as efficient as many others (self taught) so sorry or any non-perfect code you might find. Also I've worked on this maybe 10 hours and much of it isn't written as I seem to be stuck at the point where I am trying to create a tab from the menu selection.

I will be putting the propper module headers and such in later (I was testing the implementation of modules when I was doing this for instance). So, once again not much point digressing to "OMG, You aren't using strict?!?!" etc..

Thanks a lot,
Peter.

console.pl starts here:

#!/usr/bin/perl use Tk; use Tk::LabFrame; use Tk::NoteBook; my $Version = "1.0"; sub mainmenu { $main = MainWindow->new(); $main->minsize( qw(640 480)); $main->title( "Rasputin"); $main->configure(-background => 'black'); $menu_bar = $main->Frame(-relief => 'groove', -borderwidth=> 3, -background=> 'black')->pack(-side =>top, -fill +=> 'x', -anchor=>'n'); $scan_menu=$menu_bar->Menubutton(-text => 'Scans', -background => 'black', -foreground => '#00ff00', -activebackground => '#00ff00', -activeforeground => 'black')->pack(-side => 'left'); $bruteforce_menu=$menu_bar->Menubutton(-text => 'Bruteforce', -background => 'black', -foreground => '#00ff00', -activebackground => '#00ff00', -activeforeground => 'black')->pack(-side => 'left'); $search_menu=$menu_bar->Menubutton(-text => 'Searches', -background => 'black', -foreground => '#00FF00', -activebackground => '#00ff00', -activeforeground => 'black')->pack(-side => 'left'); $configuration_menu=$menu_bar->Menubutton(-text => 'Configuration' +, -background => 'black', -foreground => '#00ff00', -activebackground => '#00ff00', -activeforeground => 'black')->pack(-side => 'left'); $help_menu=$menu_bar->Menubutton(-text => 'Help', -background => 'black', -foreground => '#00ff00', -activebackground => '#00ff00', -activeforeground => 'black')->pack(-side => 'right'); $tab_dialog=$main->Frame(-background=> 'black', -relief => 'groove +', -borderwidth=> '3', -foreground => '#00ff00')->pack(-side=> 'bottom', -fill => 'both') +; $tab_dialog->pack(); $tabsinside=$tab_dialog->NoteBook(); $tabsinside->pack(-fill => 'x'); } sub startup { load_modules(); } sub load_modules { foreach $module (<*.module.pl>) { require "$module"; push (@modules_loaded, $module); } } mainmenu(); startup(); MainLoop();

And now nmap.module.pl:

sub begin_menus{ $scan_menu->command(-label => 'Nmap Scan', -background=>'black', -foreground=>'#00ff00', -activebackground=>'#00ff00', -activeforeground=>'black', -command => sub { &nmap_scan_dialog() } ); $search_menu->command(-label => 'Nmap Database Search', -background =>'black', -foreground =>'#00ff00', -activebackground=>'#00ff00', -activeforeground=>'black', -command => sub { &nmap_search_dialog() } ); $configuration_menu->command(-label => 'Nmap Configuration', -background=>'black', -foreground=>'#00ff00', -activebackground=>'#00ff00', -activeforeground=>'black', -command => sub { &nmap_configuration_dialog() } ); } sub nmap_search_dialog { return 1; } sub nmap_scan_dialog { $tabsinside->add("nmap", -label => "Nmap Scan")->pack(); } sub nmap_configuration_dialog { return 1; } sub nmap_start { if ( begin_menus() ) { return 1; } } nmap_start();

Replies are listed 'Best First'.
Re: Tk::NoteBook issue with creating tabs under a menu
by zentara (Cardinal) on Jul 15, 2008 at 13:58 UTC
    Your example was unrunable by me, but here is a working snippet that adds tabs to a notebook from a menu. You may be looking for the Resize fix.
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::NoteBook; my %nbframes; my $top = MainWindow->new; $top->geometry("300x300"); my $menu = $top->Menu( -type => 'menubar' ); $top->configure( -menu => $menu ); $menu->Cascade( -label => '~Selections', -tearoff => 1, -menuitems => [ [ Button => 'dir', -command => [ \&addtab, 'dir' ] ], [ Button => 'time', -command => [ \&addtab, 'time' ] ], [ Button => 'ls', -command => [ \&addtab, 'ls' ] ], ], ); my $nb = $top->NoteBook->pack(qw/-side top -fill both -expand 1/); MainLoop; sub addtab { my $choice = shift; print $choice, "\n"; $nbframes{$choice}{'frame'} = $nb->add($choice, -label => $choice, -raisecmd => sub{ $top->update; }, -createcmd => sub{ $top->update; }, ); $nbframes{$choice}{'text'} = $nbframes{$choice}{'frame'}->Scrolled('Text',-bg=>'white')->pack( +); $nbframes{$choice}{'text'}->insert('end',time); $nbframes{$choice}{'text'}->focus(); $nb->Resize; #bug workaround }

    I'm not really a human, but I play one on earth CandyGram for Mongo
      I'm trying to make sense of the following code snippet from the example above by zentara.

      At present I'm really quite unsure how to access frame elements of dynamically created tabs.

      $nbframes{$choice}{'frame'}

      Any help appreciated.
      Peter.

        Well, Tk::Notebook->add returns a frame
        $nbframes{$choice}{'frame'} = $nb->add(...
        zentara stored it in $nbframes{$choice}{'frame'}, and later accessed it with
        $nbframes{$choice}{'frame'}->Scrolled('Text',-bg=>'white')
        so it sounds like you need to read perldsc, references quick reference
Re: Tk::NoteBook issue with creating tabs under a menu
by jethro (Monsignor) on Jul 15, 2008 at 14:13 UTC
    Your code isn't working and you don't want advice like using -w and strict? -w and strict are recommended exactly BECAUSE you find many bugs with them a lot faster.

    Clearly using strict is more effort and one might be tempted to not use it while rapid prototyping, but invariably in the debug phase you pay the price for that. There is no such excuse for -w

    Also it might be easier to help you if you tell us how the output of this program differs from what you want. It might be obvious to someone who downloads and starts it, but not everyone will do that.

    A reply falls below the community's threshold of quality. You may see it by logging in.