在文本框

时间:2016-10-31 22:22:46

标签: perl hash textbox tk

我一直在尝试编写一个perl脚本,该脚本应该读取文件,解析它,显示内容的简短摘要(以设置开头和特定模式结束打印)并将其显示在报告区域中当用户选择某个集合的摘要时。我逐行读取文件,查找开始和结束字符,将其保存在哈希中,并使用我用来构建摘要的其他元数据。然后我尝试创建一个Textbox / ROText / Pane。但是,当我尝试使用insert命令填充完整内容时,数字之间的所有间距都将丢失。当我将相同的行打印到文件或屏幕上时,不会发生这种情况,保留了间距。有人可以说明为什么会在GUI中发生这种情况吗?以下是我尝试阅读的文件示例:

Assume that the file to be read looks as follows:

Starting report1
----------------------------------------
A B                   0.46    1.00  4.79
C                             2.00  8.54
DEF                   0.72          7.38
GH                            6.97  8.88
IJK                   7.46 8  6.98  4.32
End of report1


The GUI displays it randomly like this:

Starting report1
----------------------------------------
A B    0.46  1.00  4.79
C      2.00  8.54
DEF  0.72 7.38
GH     6.97 8.88
IJK   7.46 8  6.98  4.32
End of report1

这是代码:

my $summary_list = $summary_box->Scrolled("Listbox", -height => 5,-width => 120,-font => "7x13bold",-scrollbars => "ose", -exportselection => 1, -background => "black", -foreground => "white", -selectmode=>'single', -relief => 'groove')->pack(-side => 'left', -fill => "both", -expand =>1);
$summary_list->bind('<Button-1>', [\&retrieveReport] );

# Create the detailed text area, bind it to the summary list, configure the highlight text and disable editing
#my $report_area = $display_frame -> Frame()->pack(-side => 'top', -expand => 1, -fill =>'both');
my $report_area = $display_frame -> LabFrame(-label => 'Selected Path', -labelside => 'acrosstop')->pack(-side => 'top', -expand => 1, -fill =>'both');
my $report_entry = $report_area->Scrolled("ROText", -height => 30,-width => 120, -font => "5x5",-scrollbars => "se", -exportselection => 1, -wrap => "none")->pack(-fill => "both", -expand =>1);
$report_entry->tagConfigure( 'highlight', -background => 'lightgreen', -foreground => 'black', -font => "Arial 15 bold" );

sub retrieveReport {
my @sel = $summary_list->curselection;  
$report_entry->delete("0.0",'end');
$report_entry->insert('end',$display_paths{$sel[0]}{report});
#print "$display_paths{$sel[0]}{report}\n";

#Debug
my @lines = split("\n",$display_paths{$sel[0]}{report});
foreach (@lines) {
    #$report_entry->insert('end',$_);
    #$report_entry->insert('end',"\n");
    #print "$_\n";
}

# Highlight text
my @includes = $include_list->get(0, 'end');
foreach (@includes) {
    $_ =~ s/([\/\]\[])/\\$1/g;
    while ($display_paths{$sel[0]}{report} =~ /$_/gi) {
        $report_entry->tagAdd('highlight',"1.0 + $-[0] chars","1.0 + $+[0] chars");
    }
}
}

0 个答案:

没有答案