Hi Monks,
I have written the following code. In this code in the 'XY Co-Ordinates and Metal to trace' block, we are rewriting similar code over and over (4 times). I want the user to have a + button, which user can click to add a new X, Y, Metal options pane. This way, user can enter how many ever X, Y, Metal options he wants by clicking the plus button and not be restricted by the 4 X,Y options I have provided.
But note that whatever value he types in, has to be retrieved when I press the push button. You can see that I am printing the values in the text bar based on the input values provided by the user. Is there a way to modify this code to achieve the required functionality?
#!/usr/local/bin/perl
use Tk;
use Tk::widgets qw(LabFrame);
use File::Spec::Functions qw(canonpath);
use Tk::Optionmenu;
use Scalar::Util qw(looks_like_number);
use Cwd 'abs_path';
my $o_xco_ordinate;
my $o_yco_ordinate;
my $o_metal_layer="";
my $o_processoption = "180nm";
my $o_gdsname;
my $o_mw = MainWindow->new;
# File Entry and Getting File from location.
my $o_file_lf = $o_mw->LabFrame(
-label => 'File Name',
-labelside => 'acrosstop',
-foreground => 'blue',
);
$o_file_lf->pack(
-expand => 0,
-fill => 'x',
);
my $o_ent = $o_file_lf->Entry(
-width => 35,
)->grid(
-row => 0, -column => 0,
-padx => 5,
-pady => 5,
);
my $o_file_btn = $o_file_lf->Button(
-text => 'Select',
-command => sub { o_get_file() },
)->grid(
-row => 0, -column => 1,
-padx => 5,
-pady => 5,
);
#Entering the metal stack options and metal lines
my $o_metaloption_lf = $o_mw->LabFrame(
-label => 'XY Co-Ordinates and Metal to trace',
-labelside => 'acrosstop',
-foreground => 'blue',
);
$o_metaloption_lf->pack(
-expand => 0,
-fill => 'x',
);
my $o_frm_metalOption =$o_metaloption_lf ->Frame()->pack; # just for c
+entering the buuton row
#######################################SETTING DEFAULT################
+################################################
my $o_default_metal = "NONE";
my $o_default_x = "";
my $o_default_y = "";
##########################################Co-ordinate and metal option
+: Row 1 ####################################################
#my $o_f_metal = $o_mw->Frame->pack;
my $o_f_coord = $o_mw->Frame->pack;
#my $o_f_coord = $o_mw->Frame->pack;
$o_f_coord->Label(-text => 'X1:')-> grid(-row=>0,-column=>0)->pack(-si
+de => 'left');
# Setting the default entry values.
my $o_e_x = $o_f_coord->Entry(-textvariable => \(my $o_x = $o_default_
+x))
-> grid(-row=>0,-column=>1)->pack(-side => 'l
+eft');
$o_f_coord->Label(-text => 'Y1:')-> grid(-row=>0,-column=>2)->pack(-si
+de => 'left');
my $o_e_y = $o_f_coord->Entry(-textvariable => \(my $o_y = $o_default_
+y))
-> grid(-row=>0,-column=>3) ->pack(-side => '
+left');
my $o_o_metal = $o_f_coord->Optionmenu(
-options => [[M1=>"M1"], [M2=>"M2"], [M3=>"M3"], [M4=>"M4"],[
+M5=>"M5"],[M6=>"M6"],[M7=>"M7"], [M8=>"M8"],[B1=>"B1"],[B2=>"B2"],[B3
+=>"B3"],[B4=>"B4"],[BA=>"BA"],[BB=>"BB"], [BD=>"BD"], [BE=>"BE"], [FA
+=>"FA"], [FB=>"FB"], [L1=>"L1"], [L2=>"L2"], [L3 =>"L3"],[EA=>"EA"],
+[EB=>"EB"], [LB=>"LB"],[NONE=>" "]],
-variable => \ my $o_metal,
-textvariable => \ my $o_t_metal,
)-> grid(-row=>0,-column=>4) ->pack;
# Set the default option.
#$o_metal = $o_default_metal;
$o_t_metal = $o_default_metal;
##########################################Co-ordinate and metal option
+: Row 2 ####################################################
my $o_f_coord2 = $o_mw->Frame->pack;
#my $o_f_coord = $o_mw->Frame->pack;
$o_f_coord2->Label(-text => 'X2:')-> grid(-row=>0,-column=>0)->pack(-s
+ide => 'left');
# Setting the default entry values.
my $o_e_x2 = $o_f_coord2->Entry(-textvariable => \(my $o_x2 = $o_defau
+lt_x))
-> grid(-row=>0,-column=>1)->pack(-side => 'l
+eft');
$o_f_coord2->Label(-text => 'Y2:')-> grid(-row=>0,-column=>2)->pack(-s
+ide => 'left');
my $o_e_y2 = $o_f_coord2->Entry(-textvariable => \(my $o_y2 = $o_defau
+lt_y))
-> grid(-row=>0,-column=>3) ->pack(-side => '
+left');
my $o_o_metal2 = $o_f_coord2->Optionmenu(
-options => [[M1=>"M1"], [M2=>"M2"], [M3=>"M3"], [M4=>"M4"],[
+M5=>"M5"],[M6=>"M6"],[M7=>"M7"], [M8=>"M8"],[B1=>"B1"],[B2=>"B2"],[B3
+=>"B3"],[B4=>"B4"],[BA=>"BA"],[BB=>"BB"], [BD=>"BD"], [BE=>"BE"], [FA
+=>"FA"], [FB=>"FB"], [L1=>"L1"], [L2=>"L2"], [L3 =>"L3"],[EA=>"EA"],
+[EB=>"EB"], [LB=>"LB"],[NONE=>" "]],
-variable => \ my $o_metal2,
-textvariable => \ my $o_t_metal2,
)-> grid(-row=>0,-column=>4) ->pack;
# Set the default option.
#$o_metal = $o_default_metal;
$o_t_metal2 = $o_default_metal;
##########################################Co-ordinate and metal option
+: Row 3 ####################################################
my $o_f_coord3 = $o_mw->Frame->pack;
#my $o_f_coord = $o_mw->Frame->pack;
$o_f_coord3->Label(-text => 'X3:')-> grid(-row=>0,-column=>0)->pack(-s
+ide => 'left');
# Setting the default entry values.
my $o_e_x3 = $o_f_coord3->Entry(-textvariable => \(my $o_x3 = $o_defau
+lt_x))
-> grid(-row=>0,-column=>1)->pack(-side => 'l
+eft');
$o_f_coord3->Label(-text => 'Y3:')-> grid(-row=>0,-column=>2)->pack(-s
+ide => 'left');
my $o_e_y3 = $o_f_coord3->Entry(-textvariable => \(my $o_y3 = $o_defau
+lt_y))
-> grid(-row=>0,-column=>3) ->pack(-side => '
+left');
my $o_o_metal3 = $o_f_coord3->Optionmenu(
-options => [[M1=>"M1"], [M2=>"M2"], [M3=>"M3"], [M4=>"M4"],[
+M5=>"M5"],[M6=>"M6"],[M7=>"M7"], [M8=>"M8"],[B1=>"B1"],[B2=>"B2"],[B3
+=>"B3"],[B4=>"B4"],[BA=>"BA"],[BB=>"BB"], [BD=>"BD"], [BE=>"BE"], [FA
+=>"FA"], [FB=>"FB"], [L1=>"L1"], [L2=>"L2"], [L3 =>"L3"],[EA=>"EA"],
+[EB=>"EB"], [LB=>"LB"],[NONE=>" "]],
-variable => \ my $o_metal3,
-textvariable => \ my $o_t_metal3,
)-> grid(-row=>0,-column=>4) ->pack;
# Set the default option.
#$o_metal = $o_default_metal;
$o_t_metal3 = $o_default_metal;
######################################################################
+############################################################
#Entering the metal stack options and metal lines
##########################################Co-ordinate and metal option
+: Row 4 ####################################################
my $o_f_coord4 = $o_mw->Frame->pack;
#my $o_f_coord = $o_mw->Frame->pack;
$o_f_coord4->Label(-text => 'X4:')-> grid(-row=>0,-column=>0)->pack(-s
+ide => 'left');
# Setting the default entry values.
my $o_e_x4 = $o_f_coord4->Entry(-textvariable => \(my $o_x4 = $o_defau
+lt_x))
-> grid(-row=>0,-column=>1)->pack(-side => 'l
+eft');
$o_f_coord4->Label(-text => 'Y4:')-> grid(-row=>0,-column=>2)->pack(-s
+ide => 'left');
my $o_e_y4 = $o_f_coord4->Entry(-textvariable => \(my $o_y4 = $o_defau
+lt_y))
-> grid(-row=>0,-column=>3) ->pack(-side => '
+left');
my $o_o_metal4 = $o_f_coord4->Optionmenu(
-options => [[M1=>"M1"], [M2=>"M2"], [M3=>"M3"], [M4=>"M4"],[
+M5=>"M5"],[M6=>"M6"],[M7=>"M7"], [M8=>"M8"],[B1=>"B1"],[B2=>"B2"],[B3
+=>"B3"],[B4=>"B4"],[BA=>"BA"],[BB=>"BB"], [BD=>"BD"], [BE=>"BE"], [FA
+=>"FA"], [FB=>"FB"], [L1=>"L1"], [L2=>"L2"], [L3 =>"L3"],[EA=>"EA"],
+[EB=>"EB"], [LB=>"LB"],[NONE=>" "]],
-variable => \ my $o_metal4,
-textvariable => \ my $o_t_metal4,
)-> grid(-row=>0,-column=>4) ->pack;
# Set the default option.
#$o_metal = $o_default_metal;
$o_t_metal4 = $o_default_metal;
######################################################################
+############################################################
#Running the file
my $o_run_lf = $o_mw->LabFrame(
-label => 'Run',
-labelside => 'acrosstop',
-foreground => 'blue',
);
$o_run_lf->pack(
-expand => 1,
-fill => 'both',
);
my $o_but = $o_run_lf->Button(
-text => "Go!",
-command => \&o_push_button,
)->pack;
# clear
my $o_but_clear = $o_run_lf->Button(
-text => "Clear Text Box",
-command => \&o_clearme,
)->pack;
#Text Box
my $o_txt = $o_run_lf->Scrolled(
'Text',
-width => 40,
-height => 15,
-wrap => 'word',
-scrollbars => 'e',
-background => 'white',
);
$o_txt->pack(
-expand => 1,
-fill => 'both',
-padx => 5,
-pady => 5,
);
MainLoop;
#SUB PROCEDURES
sub o_get_dir {
# JFileDialog works better on Windows XP ;)
#my @a_types = (["Layout files", [qw/.gds .oas .oas.gz .gds.gz/]]);
my $o_dir_dlg = $o_mw->chooseDirectory(-initialdir => '~',
-title => 'Choose a directory');
print "$o_dir_dlg selected as directory\n";
#return($o_file_dlg);
# Use getOpenFile if that's not important
# my $o_file_dlg = $o_mw->JFileDialog(
# -Title => 'File name',
# -Create => 0,
# -Path => File::HomeDir->my_documents,
# -FPat => '*.txt',
# -ShowAll => 'NO'
# );
# my $o_file = $o_file_dlg->Show(-Horiz => 1);
my $o_dir = $o_dir_dlg;
unless ($o_dir) {
print "cancelled...\n";
return;
}
$o_dir = canonpath($o_dir);
o_update_dir($o_dir);
return($o_dir);
}
sub o_update_dir {
my $o_value_dir = shift;
$o_entdir->delete( 0, 'end' );
$o_entdir->insert( 0, $o_value_dir ) if defined $o_value_dir;
return;
}
sub o_clearme {
$o_txt-> delete("1.0",'end');
}
sub o_push_button {
if (($o_x eq "") || ($o_y eq "") || ($o_metal eq "")) {
$o_metal = "";
$o_x = "";
$o_y = "";
}
if (($o_x2 eq "") || ($o_y2 eq "") || ($o_metal2 eq "")) {
$o_metal2 = "";
$o_x2 = "";
$o_y2 = "";
}
if (($o_x3 eq "") || ($o_y3 eq "") || ($o_metal3 eq "")) {
$o_metal3 = "";
$o_x3 = "";
$o_y3 = "";
}
if (($o_x4 eq "") || ($o_y4 eq "") || ($o_metal4 eq "")) {
$o_metal4 = "";
$o_x4 = "";
$o_y4 = "";
}
if (($o_x5 eq "") || ($o_y5 eq "") || ($o_metal5 eq "")) {
$o_metal5 = "";
$o_x5 = "";
$o_y5 = "";
}
if (($o_x6 eq "") || ($o_y6 eq "") || ($o_metal6 eq "")) {
$o_metal6 = "";
$o_x6 = "";
$o_y6 = "";
}
if (($o_x7 eq "") || ($o_y7 eq "") || ($o_metal7 eq "")) {
$o_metal7 = "";
$o_x7 = "";
$o_y7 = "";
}
$o_txt->insert( 'end', "$o_x $o_y $o_metal\n" );
$o_txt->insert( 'end',"$o_x2 $o_y2 $o_metal2 \n");
$o_txt->insert( 'end',"$o_x3 $o_y3 $o_metal3 \n");
$o_txt->insert( 'end',"$o_x4 $o_y4 $o_metal4 \n");
$o_txt->update();
}
sub o_get_file {
my @o_types =
(["Layout files", [qw/.gds .oas .oas.gz .gds.gz/]]
);
my $o_file_dlg = $o_mw->getOpenFile(-filetypes => \@o_types) or retu
+rn();
print "$o_file_dlg selected\n";
my $o_file = $o_file_dlg;
unless ($o_file) {
print "cancelled...\n";
return;
}
$o_file = canonpath($o_file);
o_update_file($o_file);
return($o_file);
}
sub o_update_file {
my $o_value = shift;
$o_ent->delete( 0, 'end' );
$o_ent->insert( 0, $o_value ) if defined $o_value;
return;
}
thanks,