#!/usr/bin/perl -w use Gtk; use strict; my $dialog; my $label; my @errors; sub error{ if ($dialog){ $label->set_text( "ERROR " . $errors[rand @errors] ) }else{ $dialog = new Gtk::Window() ; my $bbox = new Gtk::Widget "Gtk::VBox", visible => 1, parent => $dialog; my $button = new Gtk::Widget "Gtk::Button", label => "Close", parent => $bbox, visible => 1; $label = new Gtk::Widget "Gtk::Label", label => $errors[rand @errors], parent => $bbox, visible => 1 ; $button->signal_connect( "clicked", sub{ $dialog->hide }); } $dialog -> show; } sub my_quit { exit(0); } sub remote_quit{ $dialog -> hide } # or $dialog -> destroy; # if you will not be opening it again init Gtk; my $window = new Gtk::Widget "Gtk::Window", type => -toplevel, title => "Error box", allow_grow => 0, allow_shrink => 0, border_width => 10, visible => 1; $window->signal_connect("destroy" => \&Gtk::main_quit); $window->signal_connect("delete_event" => \&Gtk::false); my $box1 = new Gtk::Widget "Gtk::VBox", homogeneous => 0, spacing => 5, parent => $window, visible => 1; my $bbox= new Gtk::Widget "Gtk::HButtonBox", spacing => 5, parent => $box1, visible => 1; my $fixed = new Gtk::Widget "Gtk::Fixed", visible => 1; $fixed->set_usize(200,50); $label = new Gtk::Widget "Gtk::Label", label => "Waiting on user input", parent => $box1, visible => 1 ; new Gtk::Widget "Gtk::HSeparator", parent => $box1, visible => 1; my $err_btn = new Gtk::Widget "Gtk::Button", label => "Click me", clicked => "error", visible => 1, parent => $bbox; my $quit = new Gtk::Widget "Gtk::Button", label => "Quit", clicked => "my_quit", visible => 1, parent => $bbox; my $rquit = new Gtk::Widget "Gtk::Button", label => "Close the other window", clicked => "remote_quit", visible => 1, parent => $bbox; main Gtk; BEGIN{ @errors=( "Remote message: I don't like you. Go 'way.", "oh no, there is a 0 in the matrix!", "Error in matrix: Agent Smith Activated", "D'oh you've deleted the data set", "Matrix Error: You might want to take a pill", "so...lemme guess, you just clicked yes?", "no ks7 data left after removeal of zero channels", "Almost converged, you can probably stop now", "write(0,*) 'Game Over'", "I just Cannea do it Cap'n I just dinnea hea the power.", "Warning: Can't get handle for AAAGH NO SWITCH IT OFF!!! SWITCH IT OFFF!!!", "print *,'2.7182818'", "STOP PRESSING THE BUTTON GODDAMIT", ); }