#!/usr/bin/perl use warnings; use strict; use Gtk2; ## todo: change mnemonic into an accelerator (^D) ## todo: do another one for quitting (^Q) ## bug (fixed by forking): halts on infinite loops :^P my ($window, $vbox, $ptext, $but, $label); my $font = 'Monospace 10'; my $perl = '/usr/bin/perl'; sub do_run { my $pid; my $buf = $ptext->get_buffer; local $SIG{'CHLD'} = 'IGNORE'; warn "fork: $!" and return unless defined ($pid = fork); if ($pid) { ## parent $ptext->grab_focus; return; } ## child $pid = open my $fd, '|-', $perl, '-t' or die "fork: $!"; print "\n$perl PID: $pid\n"; ## for easy killing print $fd $buf->get_text ($buf->get_bounds, 1); close $fd; exit; } Gtk2->init; $window = Gtk2::Window->new ('toplevel'); $vbox = Gtk2::VBox->new (0, 0); $ptext = Gtk2::TextView->new; $but = Gtk2::Button->new; $label = Gtk2::Label->new_with_mnemonic ('_Run!'); $but->signal_connect (clicked => \&do_run); $but->add ($label); $but->set_size_request (50, 30); $ptext->set_size_request (50, 20); $ptext->set_border_width (4); $ptext->modify_font (Gtk2::Pango::FontDescription->from_string ($font)); $ptext->get_buffer->set_text (<<_DEF_TEXT_); use warnings; use strict; use Data::Dumper; \$ENV{'PATH'} = \$ENV{'CDPATH'} = '/usr/bin:/bin'; _DEF_TEXT_ $vbox->add ($ptext); $vbox->pack_end ($but, 0, 0, 0); $window->signal_connect (destroy => sub { Gtk2->main_quit; }); $window->set_default_size (700, 400); $window->add ($vbox); $window->show_all; Gtk2->main;