Advertisement
hackloper775

PerlBrowser Gtk3 4

Dec 5th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.42 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. #
  4. # Instalar Gtk3 y Gtk3::WebKit por CPAN,para funcionar correctamente
  5. # Programa de prueba para Tiempo de Tux <http://www.itimetux.com>
  6. # Por Demianx864
  7. # Eres libre de estudiar modificar y añadir nuevas cosas a el programa,que te diviertas :D
  8. # Simple PerlBrowser 4.0
  9. # Gracias al modulo WebKit <http://webkitgtk.org/>
  10. #
  11.  
  12. use strict;
  13. use feature ':5.14';
  14. use Glib qw/TRUE FALSE/;
  15. use Gtk3 -init;
  16.  
  17.         use Gtk3::WebKit;  
  18.  
  19.     # Parametros de la ventana
  20.  
  21.     my $titulo = "Simple Perl Browser 3";
  22.         my $ventana = Gtk3::Window->new('toplevel');
  23.         $ventana->set_default_size(800, 600);
  24.     $ventana->set_title($titulo);  
  25.     $ventana->set_border_width(5);
  26.     $ventana->signal_connect (delete_event => \&salir );
  27.  
  28.     # Webkit
  29.  
  30.         my $uri = shift @ARGV || 'http://www.duckduckgo.com';
  31.     my $ver = Gtk3::WebKit::WebView->new();
  32.  
  33.     # Cargamos url 
  34.    
  35.         $ver->load_uri( $uri );
  36.     $ver->signal_connect( 'notify::progress' => \&progreso, undef );
  37.     $ver->signal_connect( 'notify::title' => \&titulo, undef );
  38.  
  39.     # Añadimos url a scrolls
  40.  
  41.         my $scrolls = Gtk3::ScrolledWindow->new();
  42.         $scrolls->set_policy ('automatic', 'automatic');    
  43.     $scrolls->add($ver);
  44.    
  45.     # Entrada
  46.  
  47.     my $entry = Gtk3::Entry->new;  
  48.     $entry->signal_connect( "activate" => \&entrada, undef );
  49.    
  50.     # Botones
  51.  
  52.     my $brg = Gtk3::ToolButton->new_from_stock('gtk-quit');
  53.     my $go = Gtk3::ToolButton->new_from_stock('gtk-find');
  54.     my $fresh = Gtk3::ToolButton->new_from_stock('gtk-refresh');
  55.     my $frenar = Gtk3::ToolButton->new_from_stock('gtk-stop'); 
  56.     my $batras = Gtk3::ToolButton->new_from_stock('gtk-go-back');
  57.         my $belante = Gtk3::ToolButton->new_from_stock('gtk-go-forward');
  58.     my $vermenos = Gtk3::ToolButton->new_from_stock('gtk-zoom-in');
  59.         my $vermas = Gtk3::ToolButton->new_from_stock('gtk-zoom-out');
  60.     my $label = Gtk3::Label->new("");
  61.  
  62.     $go->signal_connect ( "clicked" => \&entrada, undef );
  63.     $fresh->signal_connect ( "clicked" => \&recargar, undef ); 
  64.     $frenar->signal_connect ( "clicked" => \&parar );  
  65.     $batras->signal_connect( "clicked" => \&atras );
  66.     $belante->signal_connect ( "clicked" => \&adelante );
  67.     $vermenos->signal_connect ( "clicked" => \&zomin );
  68.     $vermas->signal_connect ( "clicked" => \&zomout);  
  69.  
  70.     # Frenar y recargar unificados
  71.  
  72.     my $botones = Gtk3::Notebook->new();
  73.     $botones->set_show_tabs(FALSE);
  74.     $botones->set_show_border(FALSE);
  75.     $botones->append_page($fresh);
  76.     $botones->append_page($frenar);
  77.  
  78.     # Unimos todo
  79.    
  80.     # hbox
  81.  
  82.     my $hbox = Gtk3::Box->new("horizontal", 0);
  83.     $hbox->pack_start($entry, TRUE,TRUE , 0);
  84.     $hbox->pack_start($go, FALSE,FALSE , 0);
  85.     $hbox->pack_start($label, FALSE,FALSE , 0);
  86.     $hbox->pack_start($botones, FALSE,FALSE , 0);
  87.     $hbox->pack_start($vermas, FALSE,FALSE , 0);
  88.     $hbox->pack_start($vermenos, FALSE,FALSE , 0); 
  89.     $hbox->pack_start($batras, FALSE, FALSE, 0);
  90.     $hbox->pack_start($belante, FALSE, FALSE, 0);
  91.  
  92.     # vbox
  93.  
  94.     my $vbox = Gtk3::Box->new("vertical", 0);
  95.     $vbox->pack_start($hbox, FALSE, FALSE, 0);
  96.     $vbox->pack_start($scrolls,TRUE, TRUE, 0);
  97.  
  98.     $ventana->add($vbox);
  99.    
  100.     # Lo mostramos
  101.  
  102.     $ventana->show_all();
  103.      
  104. Gtk3->main();  
  105.  
  106. ### Funciones :) ###
  107.  
  108. sub salir {
  109. say "Hasta luego";
  110. Gtk3->main_quit;
  111. return FALSE;
  112. }
  113.  
  114. sub adelante{
  115.  
  116. $ver->go_forward;
  117.  
  118. &cargar();
  119.  
  120. }
  121.  
  122. sub atras{
  123.  
  124. $ver->go_back;
  125.  
  126. &cargar();
  127.  
  128. }
  129.  
  130. sub entrada{
  131.  
  132. &cargar();
  133.  
  134. my $uri = $entry->get_text;
  135.  
  136. my $sbr = substr($uri,0,7);
  137.  
  138.     if ($sbr eq "http://") {    
  139.  
  140.         $uri = $uri;
  141.     }
  142.  
  143.     elsif($uri =~ /[.]/) {
  144.        
  145.          $uri = "http://$uri";
  146.     }
  147.     else {  
  148.  
  149.         $uri = "http://www.google.com/search?q=$uri";
  150.     }
  151.    
  152.    
  153.     $ver->load_uri($uri);
  154.    
  155.     my $url_sitio = $ver->get_uri();
  156.  
  157.     $botones->set_current_page(1);
  158. }
  159.  
  160. sub zomin { $ver->zoom_in }
  161.  
  162. sub zomout { $ver->zoom_out }
  163.  
  164. sub progreso{
  165. &cargar();
  166. my $ctitulo;
  167. my $carga = $ver->get('progress');
  168. my $url_sitio = $ver->get_uri();
  169. $entry->set_text("$url_sitio");
  170. for ( $ctitulo < 100 ) {
  171.    my $ctitul = sprintf ("%2d%%", 100 * $carga);
  172.    $ctitulo = chop($ctitul);
  173.    $label->set_markup("$ctitul%");  
  174.    if ($ctitul == 100) {
  175.    $botones->set_current_page(0);
  176.         }
  177.     }
  178. }
  179.  
  180. sub titulo {
  181. my $titul2 = $ver->get_title();
  182.   if ($titul2){ $ventana->set_title( $titul2 ) };
  183. }
  184.  
  185. sub recargar {
  186.  
  187. &cargar();
  188.  
  189. $ver->reload;
  190.  
  191. }
  192.  
  193. sub parar {
  194.  
  195. $ver->stop_loading;
  196.  
  197. $botones->set_current_page(0);
  198.  
  199. }
  200.  
  201. sub cargar { $botones->set_current_page(1); }
  202.  
  203. #........
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement