Ya he resuelto todos los problemas, así queda finalmente:
Using perl Syntax Highlighting
- #!/usr/bin/perl
- use warnings;
- use strict;
- use LWP::Simple;
- use Gtk2 '-init';
- use constant TRUE => 1;
- use constant FALSE => 0;
- binmode STDOUT, ":encoding(UTF-8)";
- sub raeSearch()
- {
- my $rae = get("http://buscon.rae.es/draeI/SrvltGUIBusUsual?LEMA=$_[0]");
- my $resultado;
- while ($rae =~ m/name="[\d_]+"> (.*?) <\/p/smgix)
- {
- my $desc = $1;
- # Quitar las marcas HTML
- $desc =~ s/<.*?>//gsm;
- # Quitar los espacios a los lados
- $desc =~ s/^\s+//sm;
- $desc =~ s/\s+$//sm;
- # Quitar espacios excesivos
- $desc =~ s/\s+/ /gsm;
- $resultado .= "$desc\n";
- }
- return $resultado;
- }
- # Propiedades de ventana:
- my $window = Gtk2::Window->new();
- $window->set_title("Rae Search");
- $window->set_border_width(3);
- $window->signal_connect(destroy => sub{Gtk2->main_quit});
- $window->set_auto_startup_notification(TRUE);
- $window->set_decorated(TRUE);
- $window->set_default_icon_from_file("camel.ico");
- $window->move(0, 0);
- $window->resize(700, 100);
- $window->set_resizable(TRUE);
- # Frame:
- my $frame = Gtk2::Frame->new("Entrada");
- # VBox:
- my $vbox = Gtk2::VBox->new(FALSE, 10);
- $vbox->pack_start($frame, TRUE, TRUE, 0);
- # HBox:
- my $hbox = Gtk2::HBox->new(FALSE, 6);
- # Entry:
- my $dir_entry = Gtk2::Entry->new_with_max_length(30);
- $dir_entry->set_text("encono");
- $dir_entry->set_activates_default(FALSE);
- $dir_entry->set_position(100);
- # Button:
- my $button = Gtk2::Button->new("_Buscar");
- $button->set_focus_on_click(TRUE);
- my $rae;
- # TextView :
- my $textview = Gtk2::TextView->new();
- $textview->set_border_window_size('top', 1);
- my $buffer = $textview->get_buffer;
- $button->signal_connect(clicked => sub
- {
- $buffer->set_text(&raeSearch($dir_entry->get_text));
- }
- );
- # Scroll Window :
- my $scroll = Gtk2::ScrolledWindow->new();
- $scroll->set_policy('automatic', 'automatic');
- $scroll->set_shadow_type('out');
- $scroll->add($textview);
- $vbox->pack_end($scroll, TRUE, TRUE, 0);
- $frame->add($hbox);
- $hbox->pack_start($dir_entry, FALSE, FALSE, 0);
- $hbox->pack_start($button, FALSE, FALSE, 0);
- $window->add($vbox);
- $window->show_all;
- Gtk2->main;
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4