test1 kind of working version
authorPeter Gervai <grin@grin.hu>
Thu, 16 Oct 2008 12:21:33 +0200
changeset 1 90185416e8ff
parent 0 43c199fb1993
child 2 46f2fcdca04f
test1 kind of working version * cannot close about * cannot change color
test1.glade
test1.pl
--- a/test1.glade	Thu Oct 16 11:09:43 2008 +0200
+++ b/test1.glade	Thu Oct 16 12:21:33 2008 +0200
@@ -1,11 +1,13 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Thu Oct 16 11:06:53 2008 -->
+<!--Generated with glade3 3.4.5 on Thu Oct 16 12:18:29 2008 -->
 <glade-interface>
-  <widget class="GtkDialog" id="dialog1">
+  <widget class="GtkDialog" id="nemmain">
+    <property name="visible">True</property>
     <property name="border_width">5</property>
+    <property name="title" translatable="yes">Main window * test#1</property>
     <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
-    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
       <widget class="GtkVBox" id="dialog-vbox1">
@@ -135,6 +137,7 @@
     <property name="license" translatable="yes">Licensed under RSSL (Really Scary Shit License)</property>
     <property name="authors">grin, others not</property>
     <property name="artists">grin</property>
+    <signal name="close" handler="on_aboutdialog1_close"/>
     <child internal-child="vbox">
       <widget class="GtkVBox" id="dialog-vbox2">
         <property name="visible">True</property>
@@ -146,6 +149,7 @@
           <widget class="GtkHButtonBox" id="dialog-action_area2">
             <property name="visible">True</property>
             <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <signal name="remove" handler="on_dialog-action_area2_remove"/>
           </widget>
           <packing>
             <property name="expand">False</property>
@@ -155,4 +159,135 @@
       </widget>
     </child>
   </widget>
+  <widget class="GtkWindow" id="main">
+    <property name="visible">True</property>
+    <property name="can_focus">True</property>
+    <property name="has_focus">True</property>
+    <property name="border_width">20</property>
+    <property name="title" translatable="yes">Test #1</property>
+    <property name="window_position">GTK_WIN_POS_CENTER</property>
+    <child>
+      <widget class="GtkVBox" id="vbox2">
+        <property name="visible">True</property>
+        <child>
+          <widget class="GtkVBox" id="vbox3">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkImage" id="image2">
+                    <property name="visible">True</property>
+                    <property name="stock">gtk-dialog-info</property>
+                    <property name="icon_size">6</property>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="main_text1">
+                    <property name="visible">True</property>
+                    <property name="has_tooltip">True</property>
+                    <property name="tooltip_markup">Az üdvozlő szöveg</property>
+                    <property name="label" translatable="yes">Enter your name and
+bear the consequences.</property>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="hbox3">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Thy name:</property>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkEntry" id="entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="has_tooltip">True</property>
+                    <property name="tooltip_markup">Yourname here</property>
+                    <signal name="key_release_event" handler="on_entry_key_release_event"/>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+        </child>
+        <child>
+          <widget class="GtkHButtonBox" id="hbuttonbox1">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkButton" id="main_ok_button">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-ok</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+                <signal name="clicked" handler="on_main_ok_button_clicked"/>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkButton" id="main_nay_button">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">_Nay</property>
+                <property name="use_underline">True</property>
+                <property name="response_id">0</property>
+                <signal name="clicked" handler="on_main_nay_button_clicked"/>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="main_about_button">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="label" translatable="yes">gtk-about</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">0</property>
+                <signal name="clicked" handler="on_main_about_button_clicked"/>
+                <signal name="activate" handler="on_main_about_button_activate"/>
+              </widget>
+              <packing>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkColorButton" id="colour_button">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="response_id">0</property>
+                <property name="use_alpha">True</property>
+                <property name="color">#0000a079c40a</property>
+                <property name="alpha">32768</property>
+                <signal name="color_set" handler="on_colour_button_color_set"/>
+              </widget>
+              <packing>
+                <property name="position">3</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
 </glade-interface>
--- a/test1.pl	Thu Oct 16 11:09:43 2008 +0200
+++ b/test1.pl	Thu Oct 16 12:21:33 2008 +0200
@@ -9,6 +9,8 @@
 use Gtk2::GladeXML;
 use Gtk2::Gdk::Keysyms; # keyboard code constants
 
+use Data::Dumper;
+
 my $glade;
 my $label;
 my $field;
@@ -16,22 +18,68 @@
 
 # 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('label1');
-$field = $glade->get_widget('yourname_field');
+$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_close_button_clicked {on_main_delete_event;}    
+sub on_main_nay_button_clicked {on_main_delete_event;}