GtkText
| From: | Rhys Campbell | Date: | Fri, 14 May 2004 12:05:42 +0000 |
| Subject: | GtkText | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-4483@lists.php.net to get a copy of this message | ||
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?
[code]
<?php
require('commonfunctions.inc'); // include file for common functions
/////////////////////////////////////////////////////////
// //
// Functions //
// //
/////////////////////////////////////////////////////////
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
}
/////////////////////////////////////////
// //
// 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'); // connect button click
// action to function
/* Tells the window to show all elements */
$window->show_all();
/* Required to run */
Gtk::main();
?>
[/code]
Regards,
Rhys Campbell
DA Systems
e: rhys.campbell@da-systems.co.uk
t: +44(0)1494 512626
f: +44(0)1494 512727
w: www.da-systems.co.uk