#!/usr/bin/env perl

#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#             G-language Manager
#
#     Copyright (C) 2001-2007 Keio University
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
#   $Id: G.pm,v 1.58 2001/11/23 03:43:18 t98901ka Exp $
#
# G-language System is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# G-language System is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with G-language System -- see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#END_HEADER
#
# written by Kazuharu Arakawa <gaou@g-language.org>,
# modified by Atsuko Kishi <uran@g-language.org> at
# G-language Project, Institute for Advanced Biosciences, Keio University.
#

use G;
use Getopt::Std;
use File::ShareDir ':ALL';
use G::Messenger;

&getopts('chvg:s:');

# GSB
if ($opt_c){
    my $filename = './default.gcf';
    my ($engine, $configure);

    $filename = $opt_g if (length $opt_g);
    
    open(FILE,"$filename") 
	|| die ("G-language Manager: $filename: No such file or directory\n");
    while(<FILE>){
	$engine = $1.'_engine' if(/>Engine:\s(.+)/);
	$configurator = $1.'_configurator' if(/>Configure:\s(.+)/);
    }
    close(FILE);

    &{$engine}("$filename",-src=>"$opt_s");

    exit;
}elsif ($opt_h || $opt_v){
    print "\n G-language Genome Analysis Environment\n";
    print " Copyright (C) 2001-2007 G-language Project, \n";
    print " Institute for Advanced Biosciences, Keio University\n\n";
    print "  Usage:   bash\$ glang system.gcf\n";
    print "           If no GCF is supplied, default.gcf will be selected.\n";
    print "  Options: -c command line mode (without GUI)\n";
    print "           -g specifies the GCF for the command line mode\n";
    print "           -s specifies the file name to generate perl script\n";
    print "           -h prints this message\n\n";
    exit;
}

use Cwd;
use G::Messenger;
use Wx;

my $browser = "konqueror";
$browser = "explorer" if ('MSWin32' eq $^O);
my $gcfpath = dist_file('g-language', 'gcf/default.gcf');
my $script = "none";
my $hsGCF;
my $cwd = getcwd();

use vars qw($engine $configure $load_script $converter_script $configurator $timer $panel 
            $editpanel $midpanel $odysseypanel $console $text);
($load_script,$converter_script,$execute, $generate,$configure) = (1024..1028);

msg_interface('Wx');

if (lstat 'default.gcf'){
    $script = $cwd . '/default.gcf';

    open(FILE,"$script");
    while(<FILE>){
    	$engine=$1 if(/>Engine:\s(.+)/);
    	$configure=$1 if(/>Configure:\s(.+)/);
    }
    close(FILE);

}elsif($ARGV[0] eq ''){
    unless(lstat $ENV{HOME} . "/.glang/default.gcf"){
	system("cp $gcfpath $ENV{HOME}/.glang/");
    }

    $script = $ENV{HOME} . "/.glang/default.gcf";

    open(FILE, $script);
    while(<FILE>){
    	$engine=$1 if(/>Engine:\s(.+)/);
    	$configure=$1 if(/>Configure:\s(.+)/);
    }
    close(FILE);

}else{
    $script = $cwd . '/' . $ARGV[0];

    open(FILE,"$script");
    while(<FILE>){
    	$engine=$1 if(/>Engine:\s(.+)/);
    	$configure=$1 if(/>Configure:\s(.+)/);
    }
    close(FILE);
}

# hack for wxMotif compatibility
if( $Wx::_platform == $Wx::_motif ) { 
  eval 'sub Wx::Window::SetToolTip {}';
  eval 'sub Wx::ToolTip::new {}';
};


package MyApp;

use strict;
use vars qw(@ISA);

@ISA = qw(Wx::App);

use Wx qw(wxMENU_TEAROFF);

sub OnInit {
    my( $this ) = @_;

    my( $frame ) = MyFrame->new( undef, -1, "G-language Manager",
                                 [-1, -1], [495, 152] );

    $frame->Show( 1 );
    $this->SetTopWindow( $frame );

    $main::configurator = Configurator->new(undef, -1, "Configurator",
					   [-1,-1], [477,452] );

    $main::console = Console->new(undef, -1, "Console", [-1,-1], [240,80]);
    $main::text = TextOutput->new(undef, -1, "Text Output", [-1,-1], [240,80]);

    G::Messenger::msg_error("Starting up G-language Manager.\n\n");

    if ($script eq 'none'){
	$main::configurator->Show( 0 );
    }else{
	$main::configurator->Show( 1 );
        G::Messenger::msg_error("read gcf done.\n");
    }

    $main::console->Show(1);
    $main::text->Show(0);

    1;
}


package MyFrame;

use File::ShareDir ':ALL';
use strict;
use vars qw(@ISA);

use Wx qw(wxTheApp wxMENU_TEAROFF);

use Wx qw(wxBLUE wxBITMAP_TYPE_BMP wxNOT_FOUND wxDefaultSize wxSAVE);
use Wx::Event qw(EVT_SIZE EVT_BUTTON EVT_TEXT EVT_TEXT_ENTER);

@ISA = qw(Wx::Panel);
@ISA = qw(Wx::Frame);

sub new {
    my $class = shift;
    my( $this ) = $class->SUPER::new( @_ );

    $main::panel = Wx::Panel->new( $this, -1);

    EVT_MENU( $this, $main::load_script, \&LoadFile );
    EVT_MENU( $this, $main::converter_script, \&ConvertFile);

    Wx::StaticBox->new( $main::panel, -1, "", [0, 0], [492, 123] );

    $this->{txt} = Wx::StaticText->new( $main::panel,
                                        1, 
                                        "G-language System", 
                                        [50, 10]
					);


    my @path = split(/\//, $script);
    my $last = pop @path;

    $this->{LABEL} = Wx::StaticText->new( $main::panel,
                                        1, 
                                        "Script: $last", 
                                        [230, 10]
					);

    Wx::StaticBox->new( $main::panel, -1, "Progress:", [10, 35], [360, 44] );

    use Wx qw(wxGA_HORIZONTAL wxNO_BORDER wxWHITE wxBLUE wxSL_LABELS);

    $this->{GAUGE} = Wx::Gauge->new( $main::panel, -1, 1, [18, 50],
                                     [342, 20], wxGA_HORIZONTAL|wxNO_BORDER );
    $this->{GAUGE}->SetBackgroundColour( wxWHITE );
    $this->{GAUGE}->SetForegroundColour( wxBLUE );

    my( $b3 ) = Wx::Button->new( $main::panel, $main::configure, 
	"      Configure      ", [15, 90] );
    my( $b3 ) = Wx::Button->new( $main::panel, $main::generate, 
	"      Generate       ", [135, 90] );
    my( $b3 ) = Wx::Button->new( $main::panel, $main::execute, 
	"       Execute       ", [255, 90] );

    use Wx qw(wxTheApp wxNullIcon wxNullBitmap);

    if( $Wx::_platform != $Wx::_motif ) {
      my $bmp = Wx::Bitmap->new( dist_file('g-language', 'bmp/glang_f01.bmp'), wxBITMAP_TYPE_BMP );
      if( $bmp->Ok() ) {
        $bmp->SetMask( Wx::Mask->new( $bmp, wxBLUE ) );
        $this->{bmp} = Wx::BitmapButton->new( $main::panel, -1, $bmp, [380, 10] );
      }
    }

    $this->SetIcon( Wx::GetWxPerlIcon() );

    my( $file_menu ) = Wx::Menu->new( '', wxMENU_TEAROFF );

    $file_menu->Append( $main::load_script, "&Load Script...\tCtrl-O" );
    $file_menu->Append( $main::converter_script, "&Convert Perl Script...\t" );

    $file_menu->AppendSeparator();
    $file_menu->Append( 4, "E&xit\tCtrl-Q", 'Quit G-language Manager' );

    my( $menu_bar ) = Wx::MenuBar->new();
    $menu_bar->Append( $file_menu, '&File' );

    my( $help_menu ) = Wx::Menu->new();
    $help_menu->Append( 7, "&www.g-language.org",
                         'access G-language Project web site', 1 );
    $help_menu->AppendSeparator();
    $help_menu->Append( 3, "&About" );

    $menu_bar->Append( $help_menu, '&Help' );

    $this->SetMenuBar( $menu_bar );


    use Wx::Event qw(EVT_TIMER);

    $this->{TIMER} = Wx::Timer->new( $this, 1 );
    $main::timer = 0;
    $this->{TIMER}->Start( 30 );

    EVT_TIMER( $this, 1, \&OnTimer );

    use Wx::Event qw(EVT_CLOSE EVT_MENU);

    EVT_BUTTON($this, $main::execute, \&OnExecute);
    EVT_BUTTON($this, $main::configure, \&OnConfigure);
    EVT_BUTTON($this, $main::generate, \&OnGenerate);

    EVT_MENU( $this, 4, \&OnQuit );
    EVT_MENU( $this, 3, \&OnAbout );
    EVT_MENU( $this, 7, \&OnWeb);
    EVT_CLOSE( $this, \&OnClose );

    $this;
}


sub OnTimer {
  my ($this) = shift;

  $main::timer ++;
  if ($main::timer <= 13){
     if( $Wx::_platform != $Wx::_motif ) {
      my $bmp = Wx::Bitmap->new( dist_file('g-language', 'bmp/glang_f' . 
			sprintf("%02d", $main::timer) . '.bmp'), wxBITMAP_TYPE_BMP );
      	if( $bmp->Ok() ) {
        	$this->{bmp}->SetBitmapLabel($bmp);
	        $this->{bmp}->Refresh();
        }
     }
  }elsif($main::timer >= 500){
     $main::timer = 0;
  }

}

sub LoadFile {
  my $this = shift;

  my( $str ) = Wx::FileSelector( 'Load Script', undef, undef, undef, 'GCF file (*.gcf)|*.gcf' );


  &OnUpdateLabel($this, $str) if(length $str);

  &G::Messenger::msg_error("GCF File Loaded.");

  $main::configurator->Show(0);
  $main::configurator->Destroy();
  $main::configurator = Configurator->new(undef, -1, "Configurator",
					   [-1,-1], [480,480] );

  $main::configurator->Show( 1 );
}


sub ConvertFile{
  my $this = shift;
  my ( $str ) = Wx::FileSelector( 'Convert Perl Script', undef, undef, undef, 'perl script(*.pl)|*.pl|perl modules(*.pm)|*.pm|all files(*)|*' );

  $str = &ConvertToGCF($str) if(length $str);
  &OnUpdateLabel($this, $str) if(length $str);
  
  &G::Messenger::msg_error("Perl Script Loaded.");

  $main::configurator->Show(0);
  $main::configurator->Destroy();
  $main::configurator = Configurator->new(undef, -1, "Configurator", [-1, -1], [480, 480]);
    
  $main::configurator->Show(1);

}

sub OnUpdateLabel {
    my( $this, $str ) = @_;

    $script = $str;

    open(FILE,"$script");
    while(<FILE>){
        $main::engine=$1 if(/>Engine:\s(.+)/);
        $main::configure=$1 if(/>Configure:\s(.+)/);
    }
    close(FILE);

    my $last;

    if ('MSWin32' eq $^O){
	my @path = split(/\\/, $str);
	$last = pop @path;
    }else{
	my @path = split(/\//, $str);
        $last = pop @path;
    }
	
    $this->{LABEL}->SetLabel("Script: $last");
}

sub ConvertToGCF{
    my( $str ) = @_;
    my $line;
    my $file = $str;
    my $filename;
    my $flag=0;
    my @array="";
    my $default;
    my $default_flag=0;
    
    if($file=~ /(.*)\..*/){
	$filename = $1.".gcf";
	print $filename, "\n";
    }
    
    open(FILE, $file);
    open(OUT, '>'.$filename);
    
    while(<FILE>){
	$line = $_;
	push(@array, $line);
	if(/^use/){
	    print OUT $line;
	}
    }
    close FILE;
    
    print OUT '
>Engine: CHI
>Configurator: CHI

<< CONFIGURE >>

$gb < /home/uran/ecoli.gbk

';
    $default_flag=0; 
    foreach $line(@array){
	if ($line =~ /sub (.*)\{/){
	    my $name = $1;
	    $default =~ s/\&opt_default\(//g;
	    $default =~ s/\)\;//g;
	    $default =~ s/^\s+//g;
	    $default =~ s/\"//g;
	    $default =~ s/\'//g;	
	    split(/\s*\,\s*/, $default);
	    foreach(@_){	    
		if(/(.*)\=\>(.*)/){
		    print OUT "-$1\t$2\n";
		}
	    }
	    $default = "";
	    print OUT "\n>$name";
	    print OUT '
!comment
!switch
!order
instnace_G     $gb
';
	    
	}elsif($line =~ /opt_default\((.*)\)/){		
	    if($1 =~ /if/){
		next;
	    }	
	    split(/\s*\,\s*/, $1);
	    foreach(@_){	    
		if(/(.*)\=\>(.*)/){
		    my $value = $2;
		    $value =~ s/\"//g;
		    $value =~ s/\'//g;	
		    print OUT "-$1\t$value\n";
		}
	    }
	}elsif($line =~ /opt_default\(.*/){
	    $default_flag=1;
	}elsif($default_flag==1 && $line =~ /.*\=\>.*\)\;$/){
	    $default_flag=1;
	}else{
	    $default_flag=0;
	}
	
	
	if($default_flag==1){
	    $default .= $line;
	}	
    }
    
    print OUT 'CONFIGURE';
    print OUT "\n\n";
    
    $flag=0;
    foreach $line(@array){
	if ($line =~ /^sub\s.+\{/){
	    $flag=1;
	}elsif($line =~ /^\}/){
	    $flag=0;
	    print OUT "}\n\n";
	}
	
	if($flag==1){
	    print OUT $line;
	}
    }
    close (OUT);
    
    return $filename;
}


sub OnQuit {
  my $this = shift;

  $this->Close( 1 );
}

sub OnExecute {
  my $this = shift;

  $main::text->Show(1);


  G::Messenger::msg_progress($this->{GAUGE});
  G::Messenger::msg_percent(0);
  G::Messenger::msg_error("Start Analysis:\n");

  my $msg = '';

  {
	no strict 'refs';
        $msg = &{"G::System::" . $main::engine . '::' . $main::engine . '_engine'}("$script", -src=>"");
  }

  sleep(3);
  chdir('../') unless ($msg eq 'HOGE');

  G::Messenger::msg_error("Done.\n");
}


sub OnGenerate {
  my $this = shift;
  my( $str ) = Wx::FileSelector( 'Generate', undef, 'out.pl', undef, 
		'Perl file (*.pl)|*.pl',wxSAVE );

  &OnGenerateExec($this, $str) if (length $str);
}

sub OnGenerateExec {
   my ($this, $str) = @_;

   {
	no strict 'refs';
        &{"G::System::" . $main::engine . '::' . $main::engine . '_engine'}("$script",-src=>"$str");
  }
    &G::Messenger::msg_error("Script generated.\n");
}

sub OnConfigure {
   my $this = shift;

   $main::configurator->Show(1);
}

sub OnWeb {
   my $this = shift;

   &G::Messenger::msg_error('Enjoy!:-)', "\n");
   system("$browser http://www.g-language.org/");
}

sub OnAbout {
  my $this = shift;

  use Wx qw(wxOK wxCENTRE);

  Wx::MessageBox( "G-language Genome Analysis Environment\n\nKazuharu Arakawa (gaou\@g-language.org)\nKoya Mori (mory\@g-language.org)\nand others in the G-language Project.\n\nCopyright(C) 2001 G-language Project\nInstitute for Advanced Biosciences\nKeio University\n\nhttp://www.g-language.org/", "About G-language Genome Analysis Environment", wxOK|wxCENTRE, $this );
}

sub OnClose {
  my( $this ) = shift;

  $this->Destroy;
  $main::configurator->Destroy;
  $main::console->Destroy;
  $main::text->Destroy;

  $_[0]->Skip();
}

sub DESTROY {
    my $self = shift;


    $self->{TIMER}->Destroy;
}


package Configurator;
use strict;
use vars qw(@ISA);
use Wx qw(wxTheApp);


use Wx qw(:everything);
use Wx::Event qw(EVT_SIZE EVT_CLOSE EVT_TEXT EVT_TEXT_ENTER EVT_BUTTON EVT_CHECKBOX);

@ISA = qw(Wx::Panel);
@ISA = qw(Wx::Frame);

sub new {
    my $class = shift;
    my( $this ) = $class->SUPER::new( @_ );

    if ($script ne 'none'){
	no strict 'refs';

	my $tmp = $main::engine;
	my $evalstr = 'G::System::' . $tmp . '::' . $tmp;
	$evalstr .= "\_parser";

	$hsGCF = &{$evalstr}($script);
    }

    my $panel = Wx::Panel->new( $this, -1, [0,0], [480,480]);

    $this->SetIcon( Wx::GetWxPerlIcon() );

    my $id = 256;
    my $height = 45;
    my $gbpanel = Wx::ScrolledWindow->new($panel, -1, [0,0], [470,$height + 5]);
    my $y = 0;
    foreach my $key (sort keys %{$hsGCF}){
	next unless ($key =~ /^G\d/);
	Wx::StaticBox->new( $gbpanel, -1, $hsGCF->{$key}->{instance}, [3, $y], [445, $height] );
	$this->{$id}->{key} = $key;
	my $button = $this->{$id}->{instance} = 
			Wx::TextCtrl->new($gbpanel, $id, $hsGCF->{$key}->{data}, 
			[20, $y + 15], [405, 20]);
        EVT_TEXT($this, -1, sub {
				$hsGCF->{$key}->{data} = $button->GetValue();
			    });
        $id ++;
	$y += $height + 5;
    }
    $gbpanel->SetScrollbars(0,$height,0,int($y/$height) + 1);

    $main::midpanel = Wx::Panel->new($panel, -1, [0,0], [480,370]);
    $main::odysseypanel = Wx::ScrolledWindow->new($main::midpanel, -1, [0,0], [240,370]);
    $height = 68;
    my $h = 0;
    my $top = '';
    {
	no strict 'refs';
        foreach my $key (sort keys %{$hsGCF}){
		next if ($key =~ /^G\d/ || $key eq 'GCF' || $key eq 'Order' || $key eq 'subroutines');
		$top = $key if ($top eq '');
                $this->{$id}->{edit} = Wx::Button->new($main::odysseypanel, 
						       $id . '1', " Edit ",
							[20,$h + 20]);
		my $chk = $this->{$id}->{switch} = 
					Wx::CheckBox->new($main::odysseypanel, $id . '2', 
					" On/Off ", [107, $h + 19]);
		$this->{$id}->{switch}->SetValue(1) if ($hsGCF->{$key}->{switch} eq 'Y');

        	EVT_CHECKBOX($this->{$id}->{switch}, -1, sub {
					if ($chk->GetValue() == 1){
						$hsGCF->{$key}->{switch} = 'Y';
					}else{
						$hsGCF->{$key}->{switch} = 'N';
					}
			    		});

		my $ord = $this->{$id}->{order}  = 
					Wx::TextCtrl->new($main::odysseypanel,
							  $id . '3',  
							  $hsGCF->{$key}->{order}, 
							  [175, $h + 22], [30, 20]);

        	EVT_TEXT($this->{$id}->{order}, -1, sub {
					$hsGCF->{$key}->{order} = $ord->GetValue();
			    		});

	        $this->{$id}->{key} = $key;
		$this->{$key} = $id;
    		$this->{$id}->{txt} = Wx::StaticText->new( $main::odysseypanel,
                                        	    -1, $hsGCF->{$key}->{comment}, 
                                        	    [16, $h + 45],
						    [100,40]);
		$this->{$id}->{txt}->SetFont(Wx::Font->new(6, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "", wxFONTENCODING_ISO8859_1));
		$this->{$id}->{stat} = Wx::StaticBox->new( $main::odysseypanel, -1, 
							   $key, [8, $h], 
							   [207, $height] );
		
		$this->{$id}->{txt}->SetFont(Wx::Font->new(8, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "", wxFONTENCODING_ISO8859_1));

    		EVT_BUTTON($this->{$id}->{edit}, $id . '1', sub {DrawEditPanel($this, $key)});

        	$id ++;
		$h += $height + 5;
	}
    }
    $main::odysseypanel->SetScrollbars(0,$height,0,int($h/$height) + 1);
    $main::odysseypanel->EnableScrolling(0,1);

    &DrawEditPanel($this, $top);

    my $topsizer = Wx::BoxSizer->new(wxVERTICAL);
    my $bottunsizer = Wx::BoxSizer->new(wxHORIZONTAL);

    $bottunsizer->Add(
	new Wx::Button($panel, 2048, "         Save         "),
	1,
	wxALL,
	5);
    $bottunsizer->Add(
	new Wx::Button($panel, 2049, "      Save As...      "),
	1,
	wxALL,
	5);
    $bottunsizer->Add(
	new Wx::Button($panel, 2050, "         Close        "),
	1,
	wxALL,
	5);

    $topsizer->Add($gbpanel, 0, wxCENTER);
    $topsizer->Add($main::midpanel, 0, wxCENTER);
    $topsizer->Add($bottunsizer, 0, wxCENTER);

    $panel->SetSizer($topsizer);
    $panel->SetAutoLayout(1);

    $topsizer->Fit($panel);
    $topsizer->SetSizeHints($panel);

    EVT_CLOSE( $this, \&OnClose );

    EVT_BUTTON($this, 2048, \&OnSave);
    EVT_BUTTON($this, 2049, \&OnSaveAs);
    EVT_BUTTON($this, 2050, \&OnClose);

    $this;
}
  
sub OnSave {
  my( $this ) = shift;

  if ( Wx::MessageBox( "This action will overwrite the gcf file.\n" .
                         "Really proceed?\n" , "Alert". $main::script,
                         wxICON_QUESTION | wxYES_NO, $this ) != wxYES ) {
      				return;
  }

  &OnSaveFinal($this, $script);
}

sub OnSaveAs {
  my $this = shift;
  my( $str ) = Wx::FileSelector( 'Save As...', undef, $main::script, undef, 'GCF file (*.gcf)|*.gcf', wxSAVE);

  if (length $str){
	&OnSaveFinal($this, $str);
  }
}

sub OnSaveFinal {
  my $this = shift;
  my $str = shift;
  my $out = '';

  {
	no strict 'refs';
        $out = &{"G::System::" . $main::engine . '::' . $main::engine . 
		'_scripter'}($hsGCF);
  }
  open(OUT, '>' . $str) || G::Messenger::msg_error("Cannot open the file to save. ");
  print OUT $out;
  close(OUT);

  &G::Messenger::msg_error("Saved gcf.\n");
}

sub DrawEditPanel {
    my ($this, $key) = @_;
    my $id = $this->{$key};

    $main::editpanel->Destroy() if (length $main::editpanel);
    $main::editpanel = Wx::ScrolledWindow->new($main::midpanel, -1, [240, 0], [235, 370]); 
    my ($h, $i, $len, $j) = (20, 1, 0, 0);
    my @paramarray = ();
    while(length $hsGCF->{$key}->{"param$i"}){ push (@paramarray, "param$i"); $i ++;}

    my $innerid = 0;
    my $height = 45;
    my $top = '';
    my $maxheight = ($height) * $i;
    $maxheight = 360 if ($maxheight < 360);

    my $statbox = Wx::StaticBox->new( $main::editpanel, -1, 
				      $key, [8, 5], [205, $maxheight - 3] );

    $statbox->SetFont(Wx::Font->new(9, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "", wxFONTENCODING_ISO8859_1));

    foreach my $keys (@paramarray){
	
	$this->{$id . sprintf("%2d", $innerid)}->{txt} = 
	  Wx::StaticText->new( $main::editpanel,
			       -1, $hsGCF->{$key}->{$keys}->{key} . ": ", [10, $h + 20]);

	$this->{$id . sprintf("%2d", $innerid)}->{txt}->SetFont(Wx::Font->new(9, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "", wxFONTENCODING_ISO8859_1));

	$innerid ++;

    	my $parambox = $this->{$id . sprintf("%2d", $innerid)}->{order}  = 
		Wx::TextCtrl->new($main::editpanel, $id . '3',  
		$hsGCF->{$key}->{$keys}->{value}, [100, $h + 16], [100, 20]);
	my $ref_cf = \$hsGCF->{$key}->{$keys}->{value};

        EVT_TEXT($parambox, -1, 
			    sub {
				$hsGCF->{$key}->{$keys}->{value} = $parambox->GetValue();
		    	    });

	$innerid ++;

        $this->{$id . sprintf("%2d", $innerid)}->{txt} = 
                      Wx::StaticText->new( $main::editpanel,
                                           -1, $hsGCF->{$key}->{$keys}->{comment}, 
                                           [50, $h + 37]);

	$this->{$id . sprintf("%2d", $innerid)}->{txt}->SetFont(Wx::Font->new(8, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "", wxFONTENCODING_ISO8859_1));

	$innerid ++;
	$h += $height;
    }

    $main::editpanel->SetScrollbars(0,$height,0,int($h/$height) + 1);
    $main::editpanel->EnableScrolling(0,1);

}

sub OnClose {
  my( $this ) = shift;

  $main::configurator->Show(0);
}

sub DESTROY {
    my $self = shift;
}


package Console;
use strict;
use vars qw(@ISA);
use Wx qw(wxTheApp);

use Wx qw(:everything);
use Wx::Event qw(EVT_SIZE EVT_CLOSE EVT_TEXT EVT_TEXT_ENTER);

@ISA = qw(Wx::Panel);
@ISA = qw(Wx::Frame);

sub new {
    my $class = shift;
    my( $this ) = $class->SUPER::new( @_ );

    $main::console = Wx::TextCtrl->new($this, -1, undef, [-1,-1], [-1,-1], wxTE_MULTILINE);

    $this->SetIcon( Wx::GetWxPerlIcon() );

    G::Messenger::msg_system_console($main::console);

    $this;
}
  
sub OnClose {
  my( $this ) = shift;

  $main::console->Show(0);
}

sub DESTROY {
    my $self = shift;
}


package TextOutput;
use strict;
use vars qw(@ISA);
use Wx qw(wxTheApp);

use Wx qw(wxALL wxCENTER wxNOT_FOUND wxDefaultSize wxSAVE wxVERTICAL wxHORIZONTAL wxLEFT 
	  wxSMALL_FONT wxNORMAL wxDEFAULT wxICON_QUESTION wxYES_NO wxYES wxTE_MULTILINE);
use Wx::Event qw(EVT_SIZE EVT_CLOSE EVT_TEXT EVT_TEXT_ENTER);

@ISA = qw(Wx::Panel);
@ISA = qw(Wx::Frame);

sub new {
    my $class = shift;
    my( $this ) = $class->SUPER::new( @_ );

    $main::text = Wx::TextCtrl->new($this, -1, undef, [-1,-1], [-1,-1], wxTE_MULTILINE);

    $this->SetIcon( Wx::GetWxPerlIcon() );

    G::Messenger::msg_term_console($main::text);

    $this;
}
  
sub OnClose {
  my( $this ) = shift;

  $main::text->Show(0);
}

sub DESTROY {
    my $self = shift;
}


package main;

my( $app ) = MyApp->new();
$app->MainLoop();




