Re: [PHP-GTK] create a php-gtk browser using GtkHTML
[email protected] (malk0)
| Newsgroups | php.gtk.general |
|---|---|
| Message-ID | <[email protected]> |
Hi, I'm still looking for a way to display image with no success :( regards, nathan On 9/1/07, kksou <[email protected]> wrote: > > Hi, > > I'm trying to come out with a sample code to illustrate the use of GtkHTML > by creating a simple php-gtk browser. The code is attached below. > > The bullk of the code runs ok, except for the image loading part. Through > the signal 'url-requested', I managed to get the url of each image in the > signal handler. > > In C, we would then do something like this: > gtk_html_stream_write($stream, $img, strlen($img)); > > However, using the inspector, there's no GtkHTMLStream or similar method in > GtkHTML. > So, how do we load the image in GtkHTML? > > I've seen quite a number of postings in PHP-GTK-DEV between Alan and Andrei > titled "gtkhtml: yes - working!" But that was back in 2001, and I believe it > was for php-gtk1. > > Was wondering if anyone has managed to get the image loading part to work > for GtkHTML, using the beta release of PHP-GTK2? > > Regards, > /kksou > > Note: the sample code below requires the beta release of PHP-GTK2 > > More details in: > http://www.kksou.com/php-gtk2/articles/create-a-php-gtk-browser-using-gtkhtml---Part-1.php > > <?php > $window = new GtkWindow(); > $window->set_title($argv[0]); > $window->set_size_request(800, 640); > $window->connect_simple('destroy', array('Gtk','main_quit')); > $window->add($vbox = new GtkVBox()); > > $hbox = new GtkHBox(); > $vbox->pack_start($hbox, 0); > > $hbox->pack_start(new GtkLabel('URL: '), 0); > $hbox->pack_start($url_entry = new GtkEntry('http://www.google.com')); > $hbox->pack_start($go_button = new GtkButton('Go'), 0); > $go_button->set_size_request(32, -1); > > $scrolled_win = new GtkScrolledWindow(); > $scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC); > $vbox->pack_start($scrolled_win); > $gtkhtml = new GtkHTML(); // note 1 > $scrolled_win->add($gtkhtml); > > $gtkhtml->connect('url-requested', 'on_url_requested'); // note 2 > > $url_entry->connect('activate', 'on_url_entry_activate', $go_button); // > note 3 > $go_button->connect('clicked', 'on_go_button', $url_entry, $gtkhtml); // > note 4 > $go_button->clicked(); > > $window->show_all(); > Gtk::main(); > > function on_url_entry_activate($entry, $go_button) { > $go_button->clicked(); // note 5 > } > > function on_go_button($button, $url_entry, $gtkhtml) { > $url = $url_entry->get_text(); // note 6 > $html_text = file_get_contents($url); // note 7 > $gtkhtml->set_base($url); > $gtkhtml->load_from_string($html_text); // note 8 > } > > function on_url_requested($gtkhtml, $url, $stream) { > echo "image url = $url\n"; // note 9 > > // load the image > $handle = fopen($url, "rb"); > $img = ''; > while (!feof($handle)) { > $img .= fread($handle, 8192); > } > fclose($handle); > > // in C, we would then do this > // gtk_html_stream_write($stream, $img, strlen($img)); > // gtk_html_stream_close($stream, (strlen($img)<0) ? > // Gtk::HTML_STREAM_ERROR:Gtk::HTML_STREAM_OK); > // However, there's no GtkHTMLStream or similar method in GtkHTML. > // So, how do we load the image in GtkHTML? > } > > ?> > > > > -- > View this message in context: http://www.nabble.com/create-a-php-gtk-browser-using-GtkHTML-tf4365215.html#a12442327 > Sent from the Php - GTK - General mailing list archive at Nabble.com. > > -- > PHP-GTK General Mailing List (http://gtk.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- -- le savoir ne vaut que s'il est partagé par tous --