test1.pl
author Peter Gervai <grin@grin.hu>
Thu, 16 Oct 2008 12:38:29 +0200
changeset 3 689bf4b363c3
parent 2 46f2fcdca04f
child 5 89516833532f
permissions -rwxr-xr-x
test1: and coloring works too * using an eventbox. * coloring frame works too
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;
3
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    17
my $eventbox;
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    18
my $window_about;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    19
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    20
# load UI
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    21
$glade = Gtk2::GladeXML->new("test1.glade");
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    22
#$glade = Gtk2::GladeXML->new("/tmp/glade/hello-world.glade");
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    23
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    24
# connect signals
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    25
$glade->signal_autoconnect_from_package('main');
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    26
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    27
$label = $glade->get_widget('main_text1');
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    28
$field = $glade->get_widget('entry');
3
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    29
$eventbox = $glade->get_widget('eventbox1');
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    30
$window_about = $glade->get_widget('aboutdialog1');
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    31
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    32
print "firing up\n";
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    33
Gtk2->main;
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
exit 0;
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    36
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    37
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    38
sub on_colour_button_color_set {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    39
    my $button = shift;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    40
    my $color = $button->get_color();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    41
    my $alpha = $button->get_alpha();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    42
    print "Color is: ", $color->to_string(), "\n";
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    43
    print "Alpha is: ", $alpha, "\n";
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    44
    
3
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    45
    # Gtk2::StateType?! (man gtk2::widget)
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    46
    #  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
    47
    # 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
    48
    # insensitive / GTK_STATE_INSENSITIVE 
3
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    49
    #$label->modify_bg( 'prelight', $color);
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    50
    #$label->modify_fg( 'active', $color);
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    51
    #$label->modify_text( 'normal', $color);
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    52
    
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    53
    $eventbox->modify_bg( 'normal', $color);
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    54
    #$glade->get_widget('frame1')->modify_bg( 'normal', $color);
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    55
    
689bf4b363c3 test1: and coloring works too
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    56
    $window_about->modify_bg( 'prelight', $color);
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    57
}
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    58
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    59
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    60
sub on_main_about_button_clicked {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    61
    $window_about->show();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    62
    return 1;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    63
}
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    64
2
46f2fcdca04f test1: about close works
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    65
sub on_aboutdialog1_response {
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    66
    $window_about->hide();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    67
    return 1;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    68
}
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    69
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    70
sub on_entry_key_release_event {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    71
    my $widget = shift;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    72
    my $event = shift;
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
    if( $event->keyval == $Gtk2::Gdk::Keysyms{KP_Enter} || 
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    75
              $event->keyval == $Gtk2::Gdk::Keysyms{Return} ) {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    76
        on_main_ok_button_clicked();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    77
        return 1;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    78
    }
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    79
    return 0;
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    80
}
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    81
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    82
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    83
sub on_main_ok_button_clicked {
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    84
    my $txt = $field->get_text();
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    85
    $label->set_markup( "hello <b>$txt</b>!" );
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    86
}
0
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    87
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    88
# Handles window-manager-quit: shuts down gtk2 lib
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    89
sub on_main_delete_event {Gtk2->main_quit;}
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    90
43c199fb1993 glade perl test, first import
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    91
# Handles close-button quit
1
90185416e8ff test1 kind of working version
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    92
sub on_main_nay_button_clicked {on_main_delete_event;}