#!/usr/bin/perl -w
use strict;
use Glib qw(TRUE FALSE);
use Gtk2 -init;
use Gnome2::Vte;
use Data::Dumper;
use IO::Handle;
use IPC::Open2;
  
  # create things
  
  
 
  my $line;
  my $window = Gtk2::Window->new;
  my $scrollbar = Gtk2::VScrollbar->new;
  my $hbox = Gtk2::HBox->new;
  my $terminal = Gnome2::Vte::Terminal->new;
  my $frame=Gtk2::Frame->new('Frame');
  my $expander = Gtk2::Expander->new_with_mnemonic('Show pdlshell');
  my $wbox=Gtk2::VBox->new;
  my $int;
  my $entry=Gtk2::Entry->new;
  # set up scrolling
  $scrollbar->set_adjustment ($terminal->get_adjustment);
  my $data="more\na=[1 2 3 3]*2\n";
  # lay 'em out
  $window->add ($wbox);
  $frame->add($hbox);
  $hbox->pack_start ($terminal, FALSE, FALSE, 0);
  $hbox->pack_start ($scrollbar, FALSE, FALSE, 0);
  $wbox->pack_start($entry,FALSE,FALSE,0);
  $wbox->pack_end($expander,FALSE,FALSE,0);
  $window->show_all;
$entry->signal_connect('changed'=>sub{my $text=$entry->get_text;print "$text\n";$terminal->feed_child($data);});

 my $pid; 
 $pid=$terminal->fork_command ('octave', undef, undef,
                           '/home/domine/Work-dir/Meativis-gtk', FALSE, FALSE, FALSE);
			   print "PID IS: $pid\n";
			   print "SS is $$\n"; 
  
  $terminal->signal_connect('key-press-event' => \&catch_print);
  $terminal->signal_connect ('child_exited' => sub { $expander->set_expanded(FALSE);kill($int);print "Terminal over\n";});
  $window->signal_connect ('delete_event' =>
                           sub { Gtk2->main_quit; FALSE });
  $expander->signal_connect_after('activate' => sub {
	if($expander->get_expanded){
		$expander->set_label('Hide pdlshell');
		$expander->add($frame);	
		$frame->show_all;
	}else{ 
		$expander->set_label('Show pdlshell');
		$expander->remove($frame);
		
	}
	return FALSE;
  });

  
  Gtk2->main;

sub catch_print{
my ($widget,$event)= @_;
my $press_key=$event->keyval();
	if($press_key==65293){
	print "ENTER PRESSED\n";
	}
	return FALSE;
}
