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.5.1
- # Gracias al modulo WebKit <http://webkitgtk.org/>
- #
- use strict;
- use feature ':5.14';
- use feature qw{ switch };
- use Glib qw/TRUE FALSE/;
- use Gtk3 -init;
- use Gtk3::WebKit;
- binmode STDOUT, ":utf8";
- use utf8;
- use JSON;
- my $json; &json; my $unscreen = "unfullscreen";
- my $confP = decode_json($json);
- my $iniP = $confP->{'pantalla'}->{'inicio'}->[0];
- my $ventana = Gtk3::Window->new('toplevel');
- my $icono = 'icon.xpm';
- if ( -e $icono ) {
- $ventana->set_icon_from_file($icono);
- }
- my $inicio; my $titulo = "Simple Perl Browser";
- $ventana->set_default_size(800, 600);
- $ventana->maximize(TRUE);
- $ventana->set_title($titulo);
- $ventana->set_border_width(2);
- $ventana->$unscreen;
- $ventana->signal_connect(delete_event => \&salir);
- my $table = Gtk3::Grid->new;
- my @entries = (
- [ "Opciones", undef, "_Opciones" ],
- ["Acerca de", 'gtk-about', "_Acerca de", '<control>B', "Acerca de", \&activate_action ],
- ["Configuracion", 'gtk-properties', "_Configuracion",'<control>S',
- "Configuracion", \&activate_action ],
- ["Salir", 'gtk-quit', "_Salir", '<control>Q', "Salir", \&activate_action ],
- [ "Quit", 'gtk-quit', "_Quit", "<control>Q", "Quitar", \&activate_action ],
- [ "About", undef, "_About", "<control>A", "About", \&activate_action ],
- [ "Logo", "demo-gtk-logo", undef, undef, "GTK+", \&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 );
- $ventana->add_accel_group( $ui->get_accel_group );
- 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 );
- my $uri = shift @ARGV || $iniP ;
- my $ver = Gtk3::WebKit::WebView->new(); &web();
- my $scrolls = Gtk3::ScrolledWindow->new(); $scrolls->add($ver);
- my $entry = Gtk3::Entry->new;
- $entry->signal_connect( "activate" => \&entrada, undef );
- my $entrycio = Gtk3::Entry->new;
- $entry->set_icon_from_stock( 'secondary', 'gtk-apply' );
- $entry->signal_connect( 'icon-press' => \&entrada, undef );
- $entrycio->signal_connect( "activate" => \&confinicio, undef );
- my $brg = Gtk3::ToolButton->new_from_stock('gtk-quit');
- 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 $home = Gtk3::ToolButton->new_from_stock('gtk-home');
- my $label = Gtk3::Label->new("");
- my $spinner = Gtk3::Spinner->new();
- $fresh->signal_connect ( "clicked" => \&recargar );
- $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);
- $home->signal_connect ( "clicked" => \&home);
- my $botones = Gtk3::Notebook->new();
- $botones->set_show_tabs(FALSE);
- $botones->set_show_border(FALSE);
- $botones->append_page($fresh);
- $botones->append_page($frenar);
- my $hbox = Gtk3::Box->new("horizontal", 0);
- $hbox->pack_start($entry, TRUE,TRUE , 0);
- $hbox->pack_start($home, FALSE,FALSE , 0);
- $hbox->pack_start($botones, FALSE,FALSE , 0);
- $hbox->pack_start($label, FALSE,FALSE , 5);
- $hbox->pack_start($spinner, FALSE,FALSE , 5);
- $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);
- my $vbox = Gtk3::Box->new("vertical", 0);
- $vbox->pack_start($hbox, FALSE, FALSE, 0);
- $vbox->pack_start($scrolls, TRUE, TRUE, 0);
- $ventana->add($vbox);
- $ventana->show_all();
- Gtk3->main();
- sub salir {
- Gtk3->main_quit;
- }
- sub adelante{
- $ver->go_forward;
- &cargar();
- }
- sub atras{
- $ver->go_back;
- &cargar();
- }
- sub entrada{
- &cargar();
- &json;
- my $motorb = $confP->{'pantalla'}->{'inicio'}->[1];
- my $uri = $entry->get_text;
- given ($uri) {
- when (substr($uri,0,7) eq "http://") {
- $uri = $uri;
- }
- when (substr($uri,0,5) eq "https") {
- $uri = $uri;
- }
- when($uri =~ /\s/) {
- $uri = "$motorb" . "$uri";
- }
- when($uri =~ /[.]/) {
- $uri = "http://" . $uri;
- }
- default {
- $uri = "$motorb" . "$uri";
- }
- }
- $ver->load_uri($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');
- $spinner->start();
- for ( $ctitulo < 100 ) {
- my $ctitul = sprintf ("%2d%%", 100 * $carga);
- $label->set_markup("$ctitul");
- if ($ctitul == 100) {
- $botones->set_current_page(0);
- $spinner->stop();
- }
- }
- }
- sub titulo {
- my $titul2 = $ver->get_title();
- my $url_sitio = $ver->get_uri();
- if ($titul2){
- $ventana->set_title( $titul2 );}
- my $titulp = substr($titul2,0,7);
- $entry->set_text("$url_sitio");
- }
- 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 =<<EOF;
- SimplePerlBrowser
- Navegador Web escrito en Perl
- Por: Tiempo de Tux
- Version: 4.5.1
- EOF
- my $dialog = Gtk3::MessageDialog->new(
- $ventana,'destroy-with-parent', 'info', 'close', $texto);
- $dialog->signal_connect( response => sub { $dialog->destroy } );
- $dialog->show();
- }
- sub web {
- $ver->load_uri( $uri );
- $ver->signal_connect( 'notify::progress' => \&progreso, undef );
- $ver->signal_connect( 'notify::title' => \&titulo, undef );
- }
- sub activate_action {
- my $action = shift;
- my $name = $action->get_name;
- given ($name) {
- when( $name eq 'Completa' ) { &pantallacompleta($unscreen);}
- when( $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); }
- }
- when ( $name eq 'Acerca de'){ &acerca_de(); }
- when ( $name eq 'Configuracion'){ &buscador_actual(); }
- when ( $name eq 'Salir'){ &salir(); }
- }
- }
- sub buscador_actual {
- &json;
- my $data;
- my $buscador_actual = $confP->{'pantalla'}->{'inicio'}->[1];
- if ( $buscador_actual =~ m/google/ ) {
- $data = "Google";
- } elsif ( $buscador_actual =~ m/bing/) {
- $data = "Bing";
- } elsif ( $buscador_actual =~ m/duck/) {
- $data = "Duckduckgo";
- } else {
- $data = "No tienes configurado JSON";
- }
- &inicioconf($data);
- }
- sub inicioconf {
- my $motor_actual = shift;
- $inicio = Gtk3::Window->new('toplevel');
- $inicio->set_default_size(280, 100);
- $inicio->set_title("Pagina de inicio");
- $inicio->set_resizable(FALSE);
- $inicio->set_border_width(5);
- $inicio->set_position("center");
- $inicio->set_decorated(FALSE);
- $inicio->signal_connect (delete_event => sub {$inicio->destroy });
- $entrycio->set_icon_from_stock( 'secondary', 'gtk-apply' );
- my $config = Gtk3::RadioButton->new_with_label_from_widget(undef, "Actual: $motor_actual");
- my $config0 = Gtk3::RadioButton->new_with_label_from_widget($config, "Google");
- my $config1 = Gtk3::RadioButton->new_with_label_from_widget($config, "Duckduckgo");
- my $config2 = Gtk3::RadioButton->new_with_label_from_widget($config, "Bing");
- my $separador0 = Gtk3::Separator->new('horizontal');
- my $separador1 = Gtk3::Separator->new('horizontal');
- my $separador2 = Gtk3::Separator->new('horizontal');
- my $labl0 = Gtk3::Label->new("Opciones");
- my $labl1 = Gtk3::Label->new("http://");
- my $labl2 = Gtk3::Label->new("Pagina de inicio");
- my $labl3 = Gtk3::Label->new("Buscador");
- my $ok = Gtk3::Button->new_from_stock('gtk-ok');
- my $cerrar = Gtk3::Button->new_from_stock('gtk-quit');
- $entrycio->signal_connect( 'icon-press' => \&confinicio );
- $config0->signal_connect (toggled => \&confnav, "Google");
- $config1->signal_connect (toggled => \&confnav, "Duck");
- $config2->signal_connect (toggled => \&confnav, "Bing");
- $cerrar->signal_connect ( "clicked" => sub {$inicio->destroy });
- $ok->signal_connect ( "clicked" => \&confinicio, 'ok' );
- &seticio;
- my $hcio = Gtk3::Box->new("horizontal", 0);
- $hcio->pack_start($labl1, FALSE, FALSE, 0);
- $hcio->pack_start($entrycio, FALSE, FALSE, 0);
- my $ayc = Gtk3::Box->new("horizontal", 0);
- $ayc->pack_start($ok, FALSE, FALSE, 30);
- $ayc->pack_start($cerrar, FALSE, FALSE, 30);
- my $vcio = Gtk3::Box->new("vertical", 2);
- $vcio->pack_start($labl0, FALSE, FALSE, 0);
- $vcio->pack_start($separador0, FALSE, FALSE, 0);
- $vcio->pack_start($labl2, FALSE, FALSE, 0);
- $vcio->pack_start($hcio, FALSE, FALSE, 2);
- $vcio->pack_start($separador1, FALSE, FALSE, 5);
- $vcio->pack_start($labl3, FALSE, FALSE, 5);
- $vcio->pack_start($config, FALSE, FALSE, 5);
- $vcio->pack_start($config0, FALSE, FALSE, 5);
- $vcio->pack_start($config1, FALSE, FALSE, 5);
- $vcio->pack_start($config2, FALSE, FALSE, 5);
- $vcio->pack_start($separador2, FALSE, FALSE, 5);
- $vcio->pack_start($ayc, FALSE, FALSE, 5);
- $vcio->set_homogeneous(TRUE);
- $inicio->add($vcio);
- $inicio->show_all();
- }
- sub get_ui {
- return "<ui>
- <menubar name='MenuBar'>
- <menu action='Opciones'>
- <menuitem action='Completa'/>
- <menuitem action='HideTitlebar'/>
- <menuitem action='Configuracion'/>
- <menuitem action='Acerca de'/>
- <menuitem action='Salir'/>
- </menu>
- </menubar>
- </ui>";
- }
- sub confinicio {
- my ($widget,$text) = @_;
- my $paginicio = $entrycio->get_text;
- if (substr($paginicio,0,7) eq 'http://') {
- &opensettings(0,$paginicio);
- }
- elsif ($paginicio ne "") {
- &opensettings(0,"http://" . $paginicio);
- }
- else {
- my $texto =<<EOF;
- No tienes bien configurado conf.json
- EOF
- my $dialog = Gtk3::MessageDialog->new(
- $ventana,'destroy-with-parent', 'info', 'close', $texto);
- $dialog->signal_connect( response => sub { $dialog->destroy } );
- $dialog->show();
- }
- if ($text eq 'ok') {
- &opensettings(0,"http://" . $paginicio);
- $inicio->destroy;
- } }
- sub pantallacompleta {
- my $setting = shift;
- given($setting) {
- when($setting eq 'unfullscreen') { $unscreen = 'fullscreen'}
- when($setting eq 'fullscreen') { $unscreen = 'unfullscreen'}
- }
- $ventana->$unscreen();
- }
- sub json {
- {
- local $/;
- open my $cf, "<", "conf.json";
- $json = <$cf>;
- close $cf;
- }
- }
- sub seticio {
- $iniP = $confP->{'pantalla'}->{'inicio'}->[0];
- my @text = split(m/^http[:]\/\//,$iniP);
- $entrycio->set_text($text[1]);
- }
- sub confnav {
- my ($widget,$buscador) = @_;
- my @motores = (
- "http://www.bing.com/search?q=",
- "https://duckduckgo.com/?q=",
- "http://www.google.com/search?q="
- );
- if ($buscador eq 'Bing') {
- &opensettings(1,$motores[0]);
- }
- elsif($buscador eq 'Duck' ) {
- &opensettings(1,$motores[1]);
- }
- elsif ($buscador eq 'Google' ){
- &opensettings(1,$motores[2]);
- }
- }
- sub opensettings {
- my ($number,$setting) = @_;
- $unscreen = $confP->{'pantalla'}->{'inicio'}->[$number] = "$setting";
- open my $cfn, ">", "conf.json";
- print $cfn encode_json($confP);
- close $cfn;
- }
- sub home {
- $uri = $iniP;
- &web;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement