RE: [PHP-GTK] GtkText
| From: | Rhys Campbell | Date: | Fri, 14 May 2004 12:32:49 +0000 |
| Subject: | RE: [PHP-GTK] GtkText | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-4486@lists.php.net to get a copy of this message | ||
Thanks, I think that's partially there now. I made the changes you suggested but
'Object' gets written to the file instead of the actual value.
[code]
<?php
require('commonfunctions.inc'); // include file for common functions
/////////////////////////////////////////////////////////
// //
// Functions //
// //
/////////////////////////////////////////////////////////
function write_message($device_name)
{
$filename = 'C:\messages\test.txt';
$handle = fopen($filename, 'w'); // open \ create in write mode
fwrite($handle, $device_name); // write to file
fclose($handle); // close file when done
}
/////////////////////////////////////////
// //
// Creates the main window //
// //
/////////////////////////////////////////
$window = &new GtkWindow();
$window->set_name('main window');
$window->set_title('NX Interface App');
$window->connect('destroy', 'destroy');
$window->connect('delete-event', 'delete_event');
$window->set_border_width(10);
$window->set_position(GTK_WIN_POS_CENTER);
//////////////////////////////////////////
// //
// Creates widgets //
// //
//////////////////////////////////////////
/* Create a new vertical layout box. */
$box = &new GtkVBox(false, 10);
// creation of text boxes
$message = &new GtkText(); // create message text box
$message->set_editable(1); // make the text box editable
$message->set_word_wrap(1); // make the text box word wrap
$device = &new GtkText(); // create device text box
$device->set_editable(1); // make the text box editable
$device->set_word_wrap(1); // make the text box word wrap
$device->set_usize(10, 30);
// creation of buttons
$button = &new GtkButton("Send"); // create button
//////////////////////////////////////////////////////////
// //
// Start adding the widgets to the window. //
// //
//////////////////////////////////////////////////////////
$box->pack_start($device); // add device field to box
$box->pack_start($message); // add the message text field to the box
$box->pack_start($button); // add the button to the box
$window->add($box); // add the box to the window
//////////////////////////////////////////////////////////
// //
// Connect events to widgets //
// //
//////////////////////////////////////////////////////////
$device_name = $device->get_chars(0,-1);
$button->connect('clicked', 'write_message', '$device_name');
// connect button click
// action to function
/* Tells the window to show all elements */
$window->show_all();
/* Required to run */
Gtk::main();
?>
[/code]
-----Original Message-----
From: Scott Mattocks [mailto:crisscott@netzero.com]
Sent: 14 May 2004 13:16
To: PHP-GTK Mailing List (E-mail)
Subject: Re: [PHP-GTK] GtkText
Rhys Campbell wrote:
> Trying to use GtkText boxes and write it value to a file but having some problems extracting
> it. Would anyone mind having a quick look?
>
> function write_message()
> {
> $filename = 'C:\messages\test.txt';
> $handle = fopen($filename, 'w'); // open \ create in write mode
> fwrite($handle, $device_name); // write to file
> fclose($handle); // close file when done
> }
>
> $button->connect('clicked', 'write_message'); // connect button
> click
> // action to function
I am kind of new to php-gtk but it looks to me like you aren't passing
the device name to the method when you connect it. I think you need to
have $device_name be a parameter to your write_message function. You
alos need to add it to your connect call.
function write_message($device_name) {
...
}
...
$button->connect('clicked', 'write_message', $device_name);
Scott Mattocks
P.S. Is there a reason the reply to address on these messages is not the
list?
--
PHP-GTK General Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php