test1.pl
author Peter Gervai <grin@grin.hu>
Thu, 16 Oct 2008 12:21:33 +0200
changeset 1 90185416e8ff
parent 0 43c199fb1993
child 2 46f2fcdca04f
permissions -rwxr-xr-x
test1 kind of working version * cannot close about * cannot change color

#!/usr/bin/perl -w
#$Id$
#

use strict;
use warnings;

use Gtk2 '-init';
use Gtk2::GladeXML;
use Gtk2::Gdk::Keysyms; # keyboard code constants

use Data::Dumper;

my $glade;
my $label;
my $field;
my $window_about;

# load UI
$glade = Gtk2::GladeXML->new("test1.glade");
#$glade = Gtk2::GladeXML->new("/tmp/glade/hello-world.glade");

# connect signals
$glade->signal_autoconnect_from_package('main');

$label = $glade->get_widget('main_text1');
$field = $glade->get_widget('entry');
$window_about = $glade->get_widget('aboutdialog1');

print "firing up\n";
Gtk2->main;

exit 0;


sub on_colour_button_color_set {
    my $button = shift;
    my $color = $button->get_color();
    my $alpha = $button->get_alpha();
    print "Color is: ", $color->to_string(), "\n";
    print "Alpha is: ", $alpha, "\n";
    
    # Gtk2::StateType?!
    #  FATAL: invalid enum GtkStateType value what, expecting: normal / GTK_STATE_NORMAL, 
    # active / GTK_STATE_ACTIVE, prelight / GTK_STATE_PRELIGHT, selected / GTK_STATE_SELECTED, 
    # insensitive / GTK_STATE_INSENSITIVE 
    $label->modify_bg( 'prelight', $color);
    $label->modify_fg( 'active', $color);
    $label->modify_text( 'normal', $color);
}


sub on_main_about_button_clicked {
    $window_about->show();
    return 1;
}

sub on_aboutdialog1_close {
    $window_about->hide();
    return 1;
}

sub on_entry_key_release_event {
    my $widget = shift;
    my $event = shift;
    
    if( $event->keyval == $Gtk2::Gdk::Keysyms{KP_Enter} || 
              $event->keyval == $Gtk2::Gdk::Keysyms{Return} ) {
        on_main_ok_button_clicked();
        return 1;
    }
    return 0;
}


sub on_main_ok_button_clicked {
    my $txt = $field->get_text();
    $label->set_markup( "hello <b>$txt</b>!" );
}

# Handles window-manager-quit: shuts down gtk2 lib
sub on_main_delete_event {Gtk2->main_quit;}

# Handles close-button quit
sub on_main_nay_button_clicked {on_main_delete_event;}