| |
|
1:
#!/usr/bin/perl
|
|
2:
|
|
3:
#
|
|
4:
# Include il supporto per Gtk
|
|
5:
#
|
|
6:
use Gtk;
|
|
7:
|
|
8:
#
|
|
9:
# Inizializza Gtk
|
|
10:
#
|
|
11:
init Gtk;
|
|
12:
|
|
13:
#
|
|
14:
# Crea la finestra e la dimensiona
|
|
15:
#
|
|
16:
my $win = new Gtk::Window('toplevel');
|
|
17:
$win->height(300);
|
|
18:
$win->width(300);
|
|
19:
|
|
20:
#
|
|
21:
# Il box che sviluppa in verticale
|
|
22:
#
|
|
23:
my $vbox = new Gtk::VBox();
|
|
24:
$win->add($vbox);
|
|
25:
|
|
26:
#
|
|
27:
# La finestra scrollante che contiene
|
|
28:
# il riquadro del testo
|
|
29:
#
|
|
30:
my $sw = new Gtk::ScrolledWindow();
|
|
31:
$vbox->pack_start( $sw, 1,1,0 );
|
|
32:
|
|
33:
#
|
|
34:
# Il counter dei caratteri
|
|
35:
#
|
|
36:
my $cchar = 0;
|
|
37:
|
|
38:
#
|
|
39:
# Crea il riquadro per il testo
|
|
40:
#
|
|
41:
my $text = new Gtk::Text();
|
|
42:
$sw->add( $text );
|
|
43:
$text->insert(undef,undef,undef,"Questo e' un riquadro per l'inserimento del testo");
|
|
44:
$text->set_editable(1); # Accetta input nel riquadro del testo
|
|
45:
|
|
46:
#
|
|
47:
# Il box orizzontale che contiene i bottoni
|
|
48:
# a piede di pagina
|
|
49:
#
|
|
50:
my $hbox = new Gtk::HBox();
|
|
51:
$vbox->pack_start( $hbox, 0,0,0 );
|
|
52:
|
|
53:
#
|
|
54:
# Una lable esplicativa
|
|
55:
#
|
|
56:
my $label = new Gtk::Label('Hai inserito');
|
|
57:
$hbox->pack_start($label, 0,0,0 );
|
|
58:
|
|
59:
#
|
|
60:
# La entry del testo che conta i caratteri inseriti
|
|
61:
#
|
|
62:
my $charcount = new Gtk::Entry();
|
|
63:
$hbox->pack_start( $charcount, 1,1,0 );
|
|
64:
|
|
65:
#
|
|
66:
# I due bottoni...
|
|
67:
#
|
|
68:
my $quit = new Gtk::Button('Quit');
|
|
69:
$quit->signal_connect('clicked', sub { $win->destroy(); exit; });
|
|
70:
|
|
71:
my $clear = new Gtk::Button('Cancella 10 caratteri');
|
|
72:
$clear->signal_connect('clicked', sub { $text->set_point( 0 ); $text->forward_delete(10); });
|
|
73:
|
|
74:
#
|
|
75:
# Include i due bottoni
|
|
76:
#
|
|
77:
$hbox->pack_end( $quit, 0,0,0 );
|
|
78:
$hbox->pack_end( $clear, 0,0,0 );
|
|
79:
|
|
80:
#
|
|
81:
# Chiede alla finestra principale di mostrare
|
|
82:
# tutti i widget in essa contenuti
|
|
83:
#
|
|
84:
$win->show_all();
|
|
85:
|
|
86:
#
|
|
87:
# Collega un handler all'inserimento del testo
|
|
88:
#
|
|
89:
$text->signal_connect('changed', sub { $cchar++; $charcount->set_text($cchar); } );
|
|
90:
|
|
91:
#
|
|
92:
# Attiva il gestore degli eventi
|
|
93:
#
|
|
94:
main Gtk;
|
| |