gnope php gtk gui gnope.org  

Crash application on set_text() for GtkEntry

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
danilo



Joined: 01 Oct 2006
Posts: 2

PostPosted: Sun Oct 01, 2006 8:55 pm    Post subject: Crash application on set_text() for GtkEntry Reply with quote

Good evening.
I've just started to study how work PHP-GTK2. I try to fill a GtkEntry with some text after click a button. The Gtk interface is very simple: a button in the bottom of the form and a GtkEntry on the top. On the click of the button, in the text-field will appear some text (the classic 'Hello World'). The problem is that when I click on the button, the form close itself without an error or warning.
I load the GUI from a .glade file (Glade version 2.12.1 for windows).
In detail, my code is:
*******************************
<?php
// Create a new glade instance, load the
// widgets from the file passed as parameter
$glade = new GladeXML('testglade.glade');

//Again, get the widget object and connect the clicked signal
$button = $glade->get_widget('button1');
$nome = $glade->get_widget('entry1');

// Connection signal->function
$button->connect_simple('clicked', 'onClickButton');

//This method is called when the button is clicked
function onClickButton() {
$nome->set_text('Hello world!');
$nome->grab_focus();
}


//Start the main loop
Gtk::main();
?>

*******************************
and the .glade (testglade.glade) file is:

******************************************

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="title" translatable="yes">window1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>

<child>
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>

<child>
<widget class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>

<child>
<widget class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">button1</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>

</glade-interface>
********************************************

What is wrong ?
Thank you in advance for your help.
Danilo
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Sun Oct 01, 2006 9:19 pm    Post subject: Reply with quote

$nome is not available in the method.
Back to top
danilo



Joined: 01 Oct 2006
Posts: 2

PostPosted: Mon Oct 02, 2006 8:07 am    Post subject: Reply with quote

Thank you very much !

If it can be useful to other people, follow the correct code:
**************************************
<?php

// Create a new glade instance, load the
// widgets from the file passed as parameter
$glade = new GladeXML('testglade.glade');

//Again, get the widget object and connect the clicked signal
$button = $glade->get_widget('button1');
$nome = $glade->get_widget('entry1');

// Connection signal->function
$button->connect_simple('clicked', 'onClickButton', $nome);

//This method is called when the button is clicked
function onClickButton($nome) {
$nome->set_text('Hello world!');
$nome->grab_focus();
}

//Start the main loop
Gtk::main();
?>

**************************************
Other possibility was to declare $nome as global in the function (not really nice...)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.