test1.pl
changeset 1 90185416e8ff
parent 0 43c199fb1993
child 2 46f2fcdca04f
equal deleted inserted replaced
0:43c199fb1993 1:90185416e8ff
     7 
     7 
     8 use Gtk2 '-init';
     8 use Gtk2 '-init';
     9 use Gtk2::GladeXML;
     9 use Gtk2::GladeXML;
    10 use Gtk2::Gdk::Keysyms; # keyboard code constants
    10 use Gtk2::Gdk::Keysyms; # keyboard code constants
    11 
    11 
       
    12 use Data::Dumper;
       
    13 
    12 my $glade;
    14 my $glade;
    13 my $label;
    15 my $label;
    14 my $field;
    16 my $field;
    15 my $window_about;
    17 my $window_about;
    16 
    18 
    17 # load UI
    19 # load UI
    18 $glade = Gtk2::GladeXML->new("test1.glade");
    20 $glade = Gtk2::GladeXML->new("test1.glade");
       
    21 #$glade = Gtk2::GladeXML->new("/tmp/glade/hello-world.glade");
    19 
    22 
    20 # connect signals
    23 # connect signals
    21 $glade->signal_autoconnect_from_package('main');
    24 $glade->signal_autoconnect_from_package('main');
    22 
    25 
    23 $label = $glade->get_widget('label1');
    26 $label = $glade->get_widget('main_text1');
    24 $field = $glade->get_widget('yourname_field');
    27 $field = $glade->get_widget('entry');
    25 $window_about = $glade->get_widget('aboutdialog1');
    28 $window_about = $glade->get_widget('aboutdialog1');
    26 
    29 
       
    30 print "firing up\n";
    27 Gtk2->main;
    31 Gtk2->main;
    28 
    32 
    29 exit 0;
    33 exit 0;
    30 
    34 
    31 
    35 
       
    36 sub on_colour_button_color_set {
       
    37     my $button = shift;
       
    38     my $color = $button->get_color();
       
    39     my $alpha = $button->get_alpha();
       
    40     print "Color is: ", $color->to_string(), "\n";
       
    41     print "Alpha is: ", $alpha, "\n";
       
    42     
       
    43     # Gtk2::StateType?!
       
    44     #  FATAL: invalid enum GtkStateType value what, expecting: normal / GTK_STATE_NORMAL, 
       
    45     # active / GTK_STATE_ACTIVE, prelight / GTK_STATE_PRELIGHT, selected / GTK_STATE_SELECTED, 
       
    46     # insensitive / GTK_STATE_INSENSITIVE 
       
    47     $label->modify_bg( 'prelight', $color);
       
    48     $label->modify_fg( 'active', $color);
       
    49     $label->modify_text( 'normal', $color);
       
    50 }
       
    51 
       
    52 
       
    53 sub on_main_about_button_clicked {
       
    54     $window_about->show();
       
    55     return 1;
       
    56 }
       
    57 
       
    58 sub on_aboutdialog1_close {
       
    59     $window_about->hide();
       
    60     return 1;
       
    61 }
       
    62 
       
    63 sub on_entry_key_release_event {
       
    64     my $widget = shift;
       
    65     my $event = shift;
       
    66     
       
    67     if( $event->keyval == $Gtk2::Gdk::Keysyms{KP_Enter} || 
       
    68               $event->keyval == $Gtk2::Gdk::Keysyms{Return} ) {
       
    69         on_main_ok_button_clicked();
       
    70         return 1;
       
    71     }
       
    72     return 0;
       
    73 }
       
    74 
       
    75 
       
    76 sub on_main_ok_button_clicked {
       
    77     my $txt = $field->get_text();
       
    78     $label->set_markup( "hello <b>$txt</b>!" );
       
    79 }
    32 
    80 
    33 # Handles window-manager-quit: shuts down gtk2 lib
    81 # Handles window-manager-quit: shuts down gtk2 lib
    34 sub on_main_delete_event {Gtk2->main_quit;}
    82 sub on_main_delete_event {Gtk2->main_quit;}
    35 
    83 
    36 # Handles close-button quit
    84 # Handles close-button quit
    37 sub on_close_button_clicked {on_main_delete_event;}    
    85 sub on_main_nay_button_clicked {on_main_delete_event;}