Advertisement
hackloper775

PerlBrowser Gtk3 4.1

Jan 1st, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 7.76 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.1
  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.         my $ventana = Gtk3::Window->new('toplevel');
  20.     my $icono = 'logo.png';
  21.     if ( -e $icono ) {
  22.             my $pixbuf = Gtk3::Gdk::Pixbuf->new_from_file($icono);
  23.             $ventana->set_icon_from_file($icono);
  24.     }
  25.  
  26.     # Parametros de la ventana
  27.  
  28.     my $titulo = "Simple Perl Browser 3";
  29.         $ventana->set_default_size(800, 600);
  30.     $ventana->set_title($titulo);  
  31.     $ventana->unfullscreen();
  32.     $ventana->set_border_width(5);
  33.     $ventana->signal_connect (delete_event => sub { Gtk3->main_quit });
  34.    
  35.     # Notebook
  36.  
  37.     my $multipes = Gtk3::Notebook->new();
  38.     $multipes->set_show_tabs(TRUE);
  39.     $multipes->set_show_border(FALSE);
  40.  
  41.     # Opciones
  42.  
  43.     my $table = Gtk3::Grid->new;
  44.  
  45.     my @entries = (
  46.     [ "Opciones", undef, "_Opciones" ],
  47.     ["Acerca de", undef, "_Acerca de", undef, "Acerca de", \&activate_action ],
  48.     ["Salir", undef, "_Salir", undef, "Salir", \&activate_action ]
  49.     );
  50.  
  51.     my @toggle_entries = (                      
  52.     ["Completa",undef, "_Pantalla Completa", undef,    
  53.     "Pantalla completa", \&activate_action, FALSE ],
  54.     ["HideTitlebar", undef, "_Hide Titlebar", undef,
  55.     "Hide Titlebar",  \&activate_action,FALSE]
  56.     );
  57.  
  58.     my $action_group = Gtk3::ActionGroup->new('AppWindowActions');
  59.     $action_group->add_actions( \@entries, undef );
  60.         $action_group->add_toggle_actions( \@toggle_entries, undef );
  61.  
  62.     my $ui = Gtk3::UIManager->new();
  63.         $ui->insert_action_group( $action_group, 0 );
  64.     my $ui_info = get_ui();
  65.         $ui->add_ui_from_string( $ui_info, length($ui_info) );
  66.         $table->attach( $ui->get_widget('/MenuBar'), 0, 0, 1, 1 );
  67.  
  68.         # Opciones
  69.  
  70.     # Webkit
  71.  
  72.         my $uri = shift @ARGV || 'http://www.duckduckgo.com';
  73.     my $ver = Gtk3::WebKit::WebView->new();
  74.     my $ver2 = Gtk3::WebKit::WebView->new();
  75.  
  76.     # Cargamos url 
  77.    
  78.     &web();
  79.        
  80.     # Añadimos url a scrolls
  81.  
  82.         my $scrolls = Gtk3::ScrolledWindow->new();
  83.         $scrolls->set_policy ('automatic', 'automatic');    
  84.     $scrolls->add($ver);
  85.  
  86. ###
  87.  
  88.     my $scrolls2 = Gtk3::ScrolledWindow->new();
  89.         $scrolls2->set_policy ('automatic', 'automatic');  
  90.     $scrolls2->add($ver2);
  91.    
  92.     # Entrada
  93.  
  94.     my $entry = Gtk3::Entry->new;  
  95.     $entry->signal_connect( "activate" => \&entrada, undef );
  96.  
  97.     # Progresssbar
  98.  
  99.     my $progressbar = Gtk3::ProgressBar->new;  
  100.     $progressbar->set_text(undef); 
  101.     $progressbar->set_show_text(FALSE);
  102.  
  103.     # Botones
  104.  
  105.     my $brg = Gtk3::ToolButton->new_from_stock('gtk-quit');
  106.     my $go = Gtk3::ToolButton->new_from_stock('gtk-find');
  107.     my $fresh = Gtk3::ToolButton->new_from_stock('gtk-refresh');
  108.     my $frenar = Gtk3::ToolButton->new_from_stock('gtk-stop'); 
  109.     my $batras = Gtk3::ToolButton->new_from_stock('gtk-go-back');
  110.         my $belante = Gtk3::ToolButton->new_from_stock('gtk-go-forward');
  111.     my $vermenos = Gtk3::ToolButton->new_from_stock('gtk-zoom-in');
  112.         my $vermas = Gtk3::ToolButton->new_from_stock('gtk-zoom-out');
  113.     my $label = Gtk3::Label->new("");
  114.     my $label3 = Gtk3::Label->new("Hola Mundo");
  115.  
  116.     $go->signal_connect ( "clicked" => \&entrada, undef );
  117.     $fresh->signal_connect ( "clicked" => \&recargar, undef ); 
  118.     $frenar->signal_connect ( "clicked" => \&parar );  
  119.     $batras->signal_connect( "clicked" => \&atras );
  120.     $belante->signal_connect ( "clicked" => \&adelante );
  121.     $vermenos->signal_connect ( "clicked" => \&zomin );
  122.     $vermas->signal_connect ( "clicked" => \&zomout);  
  123.  
  124.     # Frenar y recargar unificados
  125.  
  126.     my $botones = Gtk3::Notebook->new();
  127.     $botones->set_show_tabs(FALSE);
  128.     $botones->set_show_border(FALSE);
  129.     $botones->append_page($fresh);
  130.     $botones->append_page($frenar);
  131.  
  132.     # Unimos todo
  133.    
  134.     # hbox
  135.  
  136.     my $hbox = Gtk3::Box->new("horizontal", 0);
  137.     $hbox->pack_start($entry, TRUE,TRUE , 0);
  138.     $hbox->pack_start($go, FALSE,FALSE , 0);
  139.     $hbox->pack_start($label, FALSE,FALSE , 0);
  140.     $hbox->pack_start($botones, FALSE,FALSE , 0);
  141.     $hbox->pack_start($vermas, FALSE,FALSE , 0);
  142.     $hbox->pack_start($vermenos, FALSE,FALSE , 0); 
  143.     $hbox->pack_start($batras, FALSE, FALSE, 0);
  144.     $hbox->pack_start($belante, FALSE, FALSE, 0);
  145.     $hbox->pack_start($table,FALSE, FALSE, 0);
  146.    
  147.     # Pestañas
  148.  
  149.     $multipes->append_page($scrolls);
  150.     $multipes->append_page($scrolls2);
  151.  
  152.     my $hbox2 = Gtk3::Box->new("horizontal", 0);
  153.     $hbox2->pack_start($multipes, TRUE,TRUE , 0);
  154.  
  155.     # vbox
  156.  
  157.     my $vbox = Gtk3::Box->new("vertical", 0);
  158.     $vbox->pack_start($hbox, FALSE, FALSE, 0);
  159.     $vbox->pack_start($hbox2, TRUE, TRUE,    0);
  160.  
  161.     $ventana->add($vbox);
  162.    
  163.     # Lo mostramos
  164.  
  165.     $ventana->show_all();
  166.      
  167.        
  168. Gtk3->main();  
  169.  
  170. ### Funciones :) ###
  171.  
  172. sub salir { Gtk3->main_quit;
  173. return FALSE;
  174. }
  175.  
  176. sub adelante{
  177.  
  178. $ver->go_forward;
  179.  
  180. &cargar();
  181.  
  182. }
  183.  
  184. sub atras{
  185.  
  186. $ver->go_back;
  187.  
  188. &cargar();
  189.  
  190. }
  191.  
  192. sub entrada{
  193.  
  194. &cargar();
  195.  
  196. my $uri = $entry->get_text;
  197.  
  198. my $sbr = substr($uri,0,7);
  199.  
  200.     if ($sbr eq "http://") {    
  201.  
  202.         $uri = $uri;
  203.     }
  204.  
  205.     elsif($uri =~ /[.]/) {
  206.        
  207.          $uri = "http://$uri";
  208.     }
  209.     else {  
  210.  
  211.         $uri = "http://www.google.com/search?q=$uri";
  212.     }
  213.    
  214.    
  215.     $ver->load_uri($uri);
  216.    
  217.     my $url_sitio = $ver->get_uri();
  218.  
  219.     $botones->set_current_page(1);
  220. }
  221.  
  222. sub zomin { $ver->zoom_in }
  223.  
  224. sub zomout { $ver->zoom_out }
  225.  
  226. sub progreso{
  227. &cargar();
  228. my $ctitulo;
  229. my $carga = $ver->get('progress');
  230. my $url_sitio = $ver->get_uri();
  231. $entry->set_text("$url_sitio");
  232. for ( $ctitulo < 100 ) {
  233.    my $ctitul = sprintf ("%2d%%", 100 * $carga);
  234.    $ctitulo = chop($ctitul);
  235.    $label->set_markup("$ctitul%");  
  236.    if ($ctitul == 100) {
  237.    $botones->set_current_page(0);
  238.         }
  239.     }
  240. }
  241.  
  242. sub titulo {
  243. my $titul2 = $ver->get_title();
  244. if ($titul2){
  245. $ventana->set_title( $titul2 );    
  246. my $titulp = substr($titul2,0,7);
  247. $multipes->set_tab_label_text($scrolls, "$titulp...", 1); };
  248. }
  249.  
  250. sub recargar {
  251.  
  252. &cargar();
  253.  
  254. $ver->reload;
  255.  
  256. }
  257.  
  258. sub parar {
  259.  
  260. $ver->stop_loading;
  261.  
  262. $botones->set_current_page(0);
  263.  
  264. }
  265.  
  266. sub cargar { $botones->set_current_page(1); }
  267.  
  268. sub acerca_de {
  269.  
  270. my $texto =<<ACERCA;
  271.  
  272. SimplePerlBrowser
  273.  
  274. Navegador Web escrito en Perl
  275.  
  276. Por: Tiempo de Tux
  277.  
  278. Version: 4.5
  279.  
  280. ACERCA
  281.  
  282. my $dialog = Gtk3::MessageDialog->new(
  283. $ventana,'destroy-with-parent', 'info', 'close', $texto);
  284. $dialog->signal_connect( response => sub { $dialog->destroy } );
  285. $dialog->show();
  286. }
  287.  
  288. sub completa {
  289. $ventana->fullscreen();
  290. return TRUE;
  291. }
  292.  
  293. sub hide {
  294. $ventana->set_hide_titlebar_when_maximized (TRUE);
  295. }
  296. sub web {
  297. $ver->load_uri( $uri );
  298. $ver->signal_connect( 'notify::progress' => \&progreso, undef );
  299. $ver->signal_connect( 'notify::title' => \&titulo, undef );
  300. $ver2->load_uri( $uri );
  301. $ver2->signal_connect( 'notify::progress' => \&progreso, undef );
  302. $ver2->signal_connect( 'notify::title' => \&titulo, undef );
  303. my $hola=$multipes->get_n_pages();
  304. }
  305.  
  306. sub activate_action {
  307.     my $action = shift;
  308.     my $name = $action->get_name;
  309.     if ( $name eq 'Completa' ) {
  310.     $ventana->fullscreen();
  311.     return FALSE;
  312. }elsif ( $name eq 'HideTitlebar'){
  313.  
  314. my $value = $ventana->get_hide_titlebar_when_maximized();
  315.  
  316. if ( $value == 0 ) { $ventana->set_hide_titlebar_when_maximized (TRUE);}
  317. else{ $ventana->set_hide_titlebar_when_maximized (FALSE); }
  318. }
  319. elsif ( $name eq 'Acerca de'){ &acerca_de(); }
  320. elsif ( $name eq 'Salir'){ &salir(); }
  321. }
  322.  
  323. sub get_ui {
  324.     return "<ui>
  325.     <menubar name='MenuBar'>
  326.    <menu action='Opciones'>
  327.       <menuitem action='Completa'/>
  328.       <menuitem action='HideTitlebar'/>
  329.       <menuitem action='Acerca de'/>
  330.       <menuitem action='Salir'/>
  331.    </menu>
  332.  </menubar>
  333. </ui>";
  334. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement