test1.pl
author Peter Gervai <grin@grin.hu>
Thu, 16 Oct 2008 12:27:55 +0200
changeset 2 46f2fcdca04f
parent 1 90185416e8ff
child 3 689bf4b363c3
permissions -rwxr-xr-x
test1: about close works
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     1
#!/usr/bin/perl -w
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     2
#$Id$
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     3
#
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     4
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     5
use strict;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     6
use warnings;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     7
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     8
use Gtk2 '-init';
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     9
use Gtk2::GladeXML;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    10
use Gtk2::Gdk::Keysyms; # keyboard code constants
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    11
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    12
use Data::Dumper;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    13
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    14
my $glade;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    15
my $label;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    16
my $field;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    17
my $window_about;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    18
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    19
# load UI
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    20
$glade = Gtk2::GladeXML->new("test1.glade");
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    21
#$glade = Gtk2::GladeXML->new("/tmp/glade/hello-world.glade");
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    22
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    23
# connect signals
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    24
$glade->signal_autoconnect_from_package('main');
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    25
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    26
$label = $glade->get_widget('main_text1');
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    27
$field = $glade->get_widget('entry');
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    28
$window_about = $glade->get_widget('aboutdialog1');
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    29
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    30
print "firing up\n";
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    31
Gtk2->main;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    32
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    33
exit 0;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    34
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    35
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    36
sub on_colour_button_color_set {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    37
    my $button = shift;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    38
    my $color = $button->get_color();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    39
    my $alpha = $button->get_alpha();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    40
    print "Color is: ", $color->to_string(), "\n";
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    41
    print "Alpha is: ", $alpha, "\n";
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    42
    
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    43
    # Gtk2::StateType?!
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    44
    #  FATAL: invalid enum GtkStateType value what, expecting: normal / GTK_STATE_NORMAL, 
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    45
    # active / GTK_STATE_ACTIVE, prelight / GTK_STATE_PRELIGHT, selected / GTK_STATE_SELECTED, 
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    46
    # insensitive / GTK_STATE_INSENSITIVE 
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    47
    $label->modify_bg( 'prelight', $color);
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    48
    $label->modify_fg( 'active', $color);
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    49
    $label->modify_text( 'normal', $color);
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    50
}
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    51
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    52
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    53
sub on_main_about_button_clicked {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    54
    $window_about->show();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    55
    return 1;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    56
}
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    57
2
46f2fcdca04f test1: about close works
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    58
sub on_aboutdialog1_response {
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    59
    $window_about->hide();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    60
    return 1;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    61
}
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    62
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    63
sub on_entry_key_release_event {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    64
    my $widget = shift;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    65
    my $event = shift;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    66
    
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    67
    if( $event->keyval == $Gtk2::Gdk::Keysyms{KP_Enter} || 
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    68
              $event->keyval == $Gtk2::Gdk::Keysyms{Return} ) {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    69
        on_main_ok_button_clicked();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    70
        return 1;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    71
    }
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    72
    return 0;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    73
}
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    74
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    75
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    76
sub on_main_ok_button_clicked {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    77
    my $txt = $field->get_text();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    78
    $label->set_markup( "hello <b>$txt</b>!" );
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    79
}
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    80
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    81
# Handles window-manager-quit: shuts down gtk2 lib
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    82
sub on_main_delete_event {Gtk2->main_quit;}
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    83
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    84
# Handles close-button quit
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    85
sub on_main_nay_button_clicked {on_main_delete_event;}