Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- #===============================================================================
- #
- # FILE: programa.pl
- #
- # USAGE: perl programa.pl
- #
- # DESCRIPTION: Programa de demostración de algoritmo de energía real básico
- #
- # REQUIREMENTS: Gtk3
- # BUGS: ---
- # NOTES: ---
- # AUTHOR: ,
- # ORGANIZATION:
- # VERSION: 1.0
- # CREATED: 03/12/12 12:05:33
- #===============================================================================
- use strict;
- use warnings;
- use utf8;
- use Glib qw/TRUE FALSE/;
- use Gtk3 -init;
- # Parametros de la ventana
- my $titulo = "Parametros de luz";
- my $ventana = Gtk3::Window->new('toplevel');
- $ventana->set_default_size(400, 300);
- $ventana->set_title($titulo);
- $ventana->set_border_width(5);
- $ventana->signal_connect (delete_event => sub { Gtk3->main_quit });
- # Parametros de la fotografia del foco
- my $foto = "apagado.jpg";
- my $imagen = Gtk3::Image->new_from_file ("$foto",undef);
- # Parametros swich
- my $nombre_switch = Gtk3::Label->new("Swich");
- my $switch = Gtk3::Switch->new;
- $switch->set_active( FALSE );
- # Parametros apagador
- my $nombre_apagador = Gtk3::Label->new("Apagador");
- my $apagador = Gtk3::Switch->new;
- $apagador->set_active( FALSE );
- # Señales
- $switch->signal_connect( 'notify::active' => \&switch );
- $apagador->signal_connect( 'notify::active' => \&apagador );
- # Forma de la ventana
- my $vertical_apagador = Gtk3::Box->new("vertical", 0);
- $vertical_apagador->pack_start($nombre_apagador, FALSE, FALSE, 0);
- $vertical_apagador->pack_start($apagador, FALSE, FALSE, 0);
- my $vertical_swich = Gtk3::Box->new("vertical", 0);
- $vertical_swich->pack_start($nombre_switch, FALSE, FALSE, 0);
- $vertical_swich->pack_start($switch, FALSE, FALSE, 0);
- my $luz = Gtk3::Box->new("horizontal", 0);
- $luz->pack_start($vertical_swich, FALSE, FALSE, 70);
- $luz->pack_start($vertical_apagador, FALSE, FALSE, 0);
- my $vbox = Gtk3::Box->new("vertical", 0);
- $vbox->pack_start($imagen, FALSE, FALSE, 0);
- $vbox->pack_start($luz, FALSE, FALSE, 0);
- # Mostramos todo
- $ventana->add($vbox);
- $ventana->show_all;
- Gtk3->main;
- ## FUNCIONES ^_^ ##
- sub switch {
- my ($widget, $data) = @_;
- if ( $widget->get_active == TRUE ) {
- &apagador();
- }
- else{ &apagado(); }
- return FALSE;
- }
- sub apagador {
- if ( $switch->get_active == TRUE ) {
- if ( $apagador->get_active == TRUE ) {
- &encendido();
- }
- else{ &apagado(); }
- return FALSE;
- }
- else { &apagado(); }
- }
- sub apagado {
- $foto = "apagado.jpg";
- $imagen->set_from_file("$foto");
- }
- sub encendido {
- $foto = "encendido.png";
- $imagen->set_from_file("$foto");
- }
- # Fin del programa :( #
- # Quisa no :) #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement