| 1 | package WordNet::Similarity::Visual::GUI_Window; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | WordNet::Similarity::Visual::GUI_Window | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | =head2 Basic Usage Example | ||
| 10 | |||
| 11 | use WordNet::Similarity::Visual::GUI_Window; | ||
| 12 | |||
| 13 | my $gui = WordNet::Similarity::Visual::GUI_Window->new; | ||
| 14 | |||
| 15 | $gui->initialize; | ||
| 16 | |||
| 17 | $gui->show_all; | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | This package implements the basic gui window to be used by | ||
| 22 | WordNet::Similarity::Visual module. | ||
| 23 | |||
| 24 | =head2 Methods | ||
| 25 | |||
| 26 | The following methods are defined in this package: | ||
| 27 | |||
| 28 | =head3 Public methods | ||
| 29 | |||
| 30 | =over | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | use 5.008004; | ||
| 35 | use strict; | ||
| 36 | use warnings; | ||
| 37 | our $VERSION = '0.07'; | ||
| 38 | use Gtk2 '-init'; | ||
| 39 | use constant TRUE => 1; | ||
| 40 | use constant FALSE => 0; | ||
| 41 | my $window; | ||
| 42 | my $vbox; | ||
| 43 | |||
| 44 | =item $obj->new | ||
| 45 | |||
| 46 | The constructor for WordNet::Similarity::Visual::GUI_Window objects. | ||
| 47 | |||
| 48 | Return value: the new blessed object | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | sub new | ||
| 53 | { | ||
| 54 | my ($class) = @_; | ||
| 55 | my $self = {}; | ||
| 56 | bless $self, $class; | ||
| 57 | } | ||
| 58 | |||
| 59 | =item $obj->initialize | ||
| 60 | |||
| 61 | To initialize the GUI. Creates all objets of various GTK2 widgets and adds them | ||
| 62 | to the window, to create the GUI. | ||
| 63 | |||
| 64 | Return Value: None | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | sub initialize | ||
| 69 | { | ||
| 70 | my ($self, $title, $b_width, $width, $height) = @_; | ||
| 71 | |||
| 72 | $self->{ window } = Gtk2::Window->new("toplevel"); | ||
| 73 | $self->{ window }->set_title($title); | ||
| 74 | #Create an instance of window | ||
| 75 | $self->{ window }->set_border_width($b_width); | ||
| 76 | # set the window border width | ||
| 77 | $self->{ window }->set_default_size($width,$height); | ||
| 78 | $self->{ window }->signal_connect(destroy => sub { Gtk2->main_quit; }); | ||
| 79 | # connect the quit signal with the window | ||
| 80 | # quit from the GTK blocking call when the exit signal is recieved | ||
| 81 | $self->{ vbox } = Gtk2::VBox->new(FALSE,0); | ||
| 82 | $self->{ window }->add($self->{ vbox }); | ||
| 83 | } | ||
| 84 | |||
| 85 | sub update_ui | ||
| 86 | { | ||
| 87 | Gtk2->main_iteration while (Gtk2->events_pending); | ||
| 88 | } | ||
| 89 | |||
| 90 | sub add | ||
| 91 | { | ||
| 92 | my ($self, $toadd) = @_; | ||
| 93 | $self->{ vbox }->add($toadd); | ||
| 94 | } | ||
| 95 | |||
| 96 | sub pack_start | ||
| 97 | { | ||
| 98 | my ($self, @args) = @_; | ||
| 99 | $self->{ vbox }->pack_start(@args); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub pack_end | ||
| 103 | { | ||
| 104 | my ($self, @args) = @_; | ||
| 105 | $self->{ vbox }->pack_start(@args); | ||
| 106 | } | ||
| 107 | |||
| 108 | sub message | ||
| 109 | { | ||
| 110 | my ($self, $flag, $msgtype, $buttons, $msg) = @_; | ||
| 111 | my $message = Gtk2::MessageDialog->new( $self->{ window }, $flag, $msgtype, $buttons, $msg); | ||
| 112 | my $response = $message->run(); | ||
| 113 | if ($response =~ "ok" ) | ||
| 114 | { | ||
| 115 | $message->destroy(); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | =item $obj->show_all | ||
| 120 | |||
| 121 | To Display all the widgets on the screen. | ||
| 122 | |||
| 123 | Return Value: None | ||
| 124 | |||
| 125 | =cut | ||
| 126 | |||
| 127 | sub show_all | ||
| 128 | { | ||
| 129 | my ($self)=@_; | ||
| 130 | $self->{ window }->show_all; | ||
| 131 | } | ||
| 132 | |||
| 133 | =item $obj->display | ||
| 134 | |||
| 135 | Display all the measures and pass the control to GTK. | ||
| 136 | |||
| 137 | Return Value: None | ||
| 138 | |||
| 139 | =cut | ||
| 140 | |||
| 141 | sub display | ||
| 142 | { | ||
| 143 | my ($self) = @_; | ||
| 144 | $self->{ window }->show_all; | ||
| 145 | Gtk2->main; | ||
| 146 | } | ||
| 147 | 1; | ||
| 148 | __END__ |