Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- #
- # Instalar Gtk3 y Gtk3::WebKit por CPAN,para funcionar correctamente
- # Programa de prueba para Tiempo de Tux <http://www.itimetux.com>
- # Por Demianx864
- # Eres libre de estudiar modificar y añadir nuevas cosas a el programa,que te diviertas :D
- # Simple PerlBrowser 4.1
- # Gracias al modulo WebKit <http://webkitgtk.org/>
- #
- use strict;
- use feature ':5.14';
- use Glib qw/TRUE FALSE/;
- use Gtk3 -init;
- use Gtk3::WebKit;
- my $ventana = Gtk3::Window->new('toplevel');
- my $icono = 'logo.png';
- if ( -e $icono ) {
- my $pixbuf = Gtk3::Gdk::Pixbuf->new_from_file($icono);
- $ventana->set_icon_from_file($icono);
- }
- # Parametros de la ventana
- my $titulo = "Simple Perl Browser 3";
- $ventana->set_default_size(800, 600);
- $ventana->set_title($titulo);
- $ventana->unfullscreen();
- $ventana->set_border_width(5);
- $ventana->signal_connect (delete_event => sub { Gtk3->main_quit });
- # Notebook
- my $multipes = Gtk3::Notebook->new();
- $multipes->set_show_tabs(TRUE);
- $multipes->set_show_border(FALSE);
- # Opciones
- my $table = Gtk3::Grid->new;
- my @entries = (
- [ "Opciones", undef, "_Opciones" ],
- ["Acerca de", undef, "_Acerca de", undef, "Acerca de", \&activate_action ],
- ["Salir", undef, "_Salir", undef, "Salir", \&activate_action ]
- );
- my @toggle_entries = (
- ["Completa",undef, "_Pantalla Completa", undef,
- "Pantalla completa", \&activate_action, FALSE ],
- ["HideTitlebar", undef, "_Hide Titlebar", undef,
- "Hide Titlebar", \&activate_action,FALSE]
- );
- my $action_group = Gtk3::ActionGroup->new('AppWindowActions');
- $action_group->add_actions( \@entries, undef );
- $action_group->add_toggle_actions( \@toggle_entries, undef );
- my $ui = Gtk3::UIManager->new();
- $ui->insert_action_group( $action_group, 0 );
- my $ui_info = get_ui();
- $ui->add_ui_from_string( $ui_info, length($ui_info) );
- $table->attach( $ui->get_widget('/MenuBar'), 0, 0, 1, 1 );
- # Opciones
- # Webkit
- my $uri = shift @ARGV || 'http://www.duckduckgo.com';
- my $ver = Gtk3::WebKit::WebView->new();
- my $ver2 = Gtk3::WebKit::WebView->new();
- # Cargamos url
- &web();
- # Añadimos url a scrolls
- my $scrolls = Gtk3::ScrolledWindow->new();
- $scrolls->set_policy ('automatic', 'automatic');
- $scrolls->add($ver);
- ###
- my $scrolls2 = Gtk3::ScrolledWindow->new();
- $scrolls2->set_policy ('automatic', 'automatic');
- $scrolls2->add($ver2);
- # Entrada
- my $entry = Gtk3::Entry->new;
- $entry->signal_connect( "activate" => \&entrada, undef );
- # Progresssbar
- my $progressbar = Gtk3::ProgressBar->new;
- $progressbar->set_text(undef);
- $progressbar->set_show_text(FALSE);
- # Botones
- my $brg = Gtk3::ToolButton->new_from_stock('gtk-quit');
- my $go = Gtk3::ToolButton->new_from_stock('gtk-find');
- my $fresh = Gtk3::ToolButton->new_from_stock('gtk-refresh');
- my $frenar = Gtk3::ToolButton->new_from_stock('gtk-stop');
- my $batras = Gtk3::ToolButton->new_from_stock('gtk-go-back');
- my $belante = Gtk3::ToolButton->new_from_stock('gtk-go-forward');
- my $vermenos = Gtk3::ToolButton->new_from_stock('gtk-zoom-in');
- my $vermas = Gtk3::ToolButton->new_from_stock('gtk-zoom-out');
- my $label = Gtk3::Label->new("");
- my $label3 = Gtk3::Label->new("Hola Mundo");
- $go->signal_connect ( "clicked" => \&entrada, undef );
- $fresh->signal_connect ( "clicked" => \&recargar, undef );
- $frenar->signal_connect ( "clicked" => \¶r );
- $batras->signal_connect( "clicked" => \&atras );
- $belante->signal_connect ( "clicked" => \&adelante );
- $vermenos->signal_connect ( "clicked" => \&zomin );
- $vermas->signal_connect ( "clicked" => \&zomout);
- # Frenar y recargar unificados
- my $botones = Gtk3::Notebook->new();
- $botones->set_show_tabs(FALSE);
- $botones->set_show_border(FALSE);
- $botones->append_page($fresh);
- $botones->append_page($frenar);
- # Unimos todo
- # hbox
- my $hbox = Gtk3::Box->new("horizontal", 0);
- $hbox->pack_start($entry, TRUE,TRUE , 0);
- $hbox->pack_start($go, FALSE,FALSE , 0);
- $hbox->pack_start($label, FALSE,FALSE , 0);
- $hbox->pack_start($botones, FALSE,FALSE , 0);
- $hbox->pack_start($vermas, FALSE,FALSE , 0);
- $hbox->pack_start($vermenos, FALSE,FALSE , 0);
- $hbox->pack_start($batras, FALSE, FALSE, 0);
- $hbox->pack_start($belante, FALSE, FALSE, 0);
- $hbox->pack_start($table,FALSE, FALSE, 0);
- # Pestañas
- $multipes->append_page($scrolls);
- $multipes->append_page($scrolls2);
- my $hbox2 = Gtk3::Box->new("horizontal", 0);
- $hbox2->pack_start($multipes, TRUE,TRUE , 0);
- # vbox
- my $vbox = Gtk3::Box->new("vertical", 0);
- $vbox->pack_start($hbox, FALSE, FALSE, 0);
- $vbox->pack_start($hbox2, TRUE, TRUE, 0);
- $ventana->add($vbox);
- # Lo mostramos
- $ventana->show_all();
- Gtk3->main();
- ### Funciones :) ###
- sub salir { Gtk3->main_quit;
- return FALSE;
- }
- sub adelante{
- $ver->go_forward;
- &cargar();
- }
- sub atras{
- $ver->go_back;
- &cargar();
- }
- sub entrada{
- &cargar();
- my $uri = $entry->get_text;
- my $sbr = substr($uri,0,7);
- if ($sbr eq "http://") {
- $uri = $uri;
- }
- elsif($uri =~ /[.]/) {
- $uri = "http://$uri";
- }
- else {
- $uri = "http://www.google.com/search?q=$uri";
- }
- $ver->load_uri($uri);
- my $url_sitio = $ver->get_uri();
- $botones->set_current_page(1);
- }
- sub zomin { $ver->zoom_in }
- sub zomout { $ver->zoom_out }
- sub progreso{
- &cargar();
- my $ctitulo;
- my $carga = $ver->get('progress');
- my $url_sitio = $ver->get_uri();
- $entry->set_text("$url_sitio");
- for ( $ctitulo < 100 ) {
- my $ctitul = sprintf ("%2d%%", 100 * $carga);
- $ctitulo = chop($ctitul);
- $label->set_markup("$ctitul%");
- if ($ctitul == 100) {
- $botones->set_current_page(0);
- }
- }
- }
- sub titulo {
- my $titul2 = $ver->get_title();
- if ($titul2){
- $ventana->set_title( $titul2 );
- my $titulp = substr($titul2,0,7);
- $multipes->set_tab_label_text($scrolls, "$titulp...", 1); };
- }
- sub recargar {
- &cargar();
- $ver->reload;
- }
- sub parar {
- $ver->stop_loading;
- $botones->set_current_page(0);
- }
- sub cargar { $botones->set_current_page(1); }
- sub acerca_de {
- my $texto =<<ACERCA;
- SimplePerlBrowser
- Navegador Web escrito en Perl
- Por: Tiempo de Tux
- Version: 4.5
- ACERCA
- my $dialog = Gtk3::MessageDialog->new(
- $ventana,'destroy-with-parent', 'info', 'close', $texto);
- $dialog->signal_connect( response => sub { $dialog->destroy } );
- $dialog->show();
- }
- sub completa {
- $ventana->fullscreen();
- return TRUE;
- }
- sub hide {
- $ventana->set_hide_titlebar_when_maximized (TRUE);
- }
- sub web {
- $ver->load_uri( $uri );
- $ver->signal_connect( 'notify::progress' => \&progreso, undef );
- $ver->signal_connect( 'notify::title' => \&titulo, undef );
- $ver2->load_uri( $uri );
- $ver2->signal_connect( 'notify::progress' => \&progreso, undef );
- $ver2->signal_connect( 'notify::title' => \&titulo, undef );
- my $hola=$multipes->get_n_pages();
- }
- sub activate_action {
- my $action = shift;
- my $name = $action->get_name;
- if ( $name eq 'Completa' ) {
- $ventana->fullscreen();
- return FALSE;
- }elsif ( $name eq 'HideTitlebar'){
- my $value = $ventana->get_hide_titlebar_when_maximized();
- if ( $value == 0 ) { $ventana->set_hide_titlebar_when_maximized (TRUE);}
- else{ $ventana->set_hide_titlebar_when_maximized (FALSE); }
- }
- elsif ( $name eq 'Acerca de'){ &acerca_de(); }
- elsif ( $name eq 'Salir'){ &salir(); }
- }
- sub get_ui {
- return "<ui>
- <menubar name='MenuBar'>
- <menu action='Opciones'>
- <menuitem action='Completa'/>
- <menuitem action='HideTitlebar'/>
- <menuitem action='Acerca de'/>
- <menuitem action='Salir'/>
- </menu>
- </menubar>
- </ui>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement