Chankey Pathak
Chankey Pathak

Reputation: 21676

Keeping the window in dialog

#!/usr/bin/perl
use warnings;
#WINDOW 1
system ("dialog --keep-window --menu Customize 10 70 50 'Flush rules' 'Clear all the rules' 2> /tmp/customize.txt ");
open FILE4, "/tmp/customize.txt" or die $!;
     chomp(my $customize = <FILE4>);
           if($customize =~ /Flush rules/){
           `iptables -F`;
           system ("dialog --infobox 'All tables have been flushed.' 05 35");
           }
           else{
               exit;
           }

When the above code is executed then a dialog box appears which shows an option to flush rules. When I press Enter the command iptables -F executes and it flushes all the iptables rules. After that the program terminates. I want that after flushing all the rules the window which came in starting i.e which gives the option to flush rules should not close. The program should not terminate after flushing the rules. It should come back to the window1.

Upvotes: 2

Views: 546

Answers (2)

tripleee
tripleee

Reputation: 189679

While dialog makes this very easy, it is not the most flexible solution. A proper GUI application would have a single window whose appearance changes in response to user interactions via callbacks. There are plenty of tools to do this from Perl; if you are on GTK, look at gtkperl. Or look at http://perl-begin.org/uses/GUI/

Upvotes: 0

Friek
Friek

Reputation: 1541

How about surrounding it with:

while (1)
{
     #WINDOW 1
     ... rest of program
}

You could add an exit option to the dialog box and have break the while loop when that option is chosen.

Upvotes: 3

Related Questions