phpgtk__legacy/wiki1/wiki.d/CodeSnippets.GtkImage

21 lines
7.1 KiB
Text

version=pmwiki-1.0.5
newline=²
text=!!! complete code example²²[[include:Main/CodeTable]]²<?php²²error_reporting(E_ALL);²²//standard stuff for window creation²$wnd = new GtkWindow();²$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));²$wnd->set_position(Gtk::WIN_POS_CENTER);²# $wnd->set_size_request(200, 200);²²$btn = new GtkButton('select');²$btn->connect_simple('clicked', 'activate_select');²# $wnd->add($btn);²²$file = 'php-gtk.gif';²²# quick usage²# $img = GtkImage::new_from_file($file);²²# more complexe usage with pixbuf²$pixbuf = GdkPixbuf::new_from_file($file);²$img = new GtkImage();²$img->set_from_pixbuf($pixbuf);²²$wnd->add($img);²²$wnd->show_all();²Gtk::main();²²?>²[[include:Main/CodeTableEnd]]²²²!!! reading from URL ²²-> you can read image directly from web site like that ; but you need to have bundled GD library compliled in (the one included with php sources). ²²[[include:Main/CodeTable]]²<?php²²$file = 'http://gtk.php.net/gifs/php-gtk.gif';²$gif = imagecreatefromgif($file);²$pixbuf = GdkPixbuf::new_from_gd($gif);²²$img = new GtkImage();²$img->set_from_pixbuf($pixbuf);²²²?>²[[include:Main/CodeTableEnd]]²²
time=1158830923
diff:1158824712:1158824712:=1,36c1²< ²< !!! complete code example²< ²< [[include:Main/CodeTable]]²< <?php²< ²< error_reporting(E_ALL);²< ²< //standard stuff for window creation²< $wnd = new GtkWindow();²< $wnd->connect_simple('destroy', array('Gtk', 'main_quit'));²< $wnd->set_position(Gtk::WIN_POS_CENTER);²< # $wnd->set_size_request(200, 200);²< ²< $btn = new GtkButton('select');²< $btn->connect_simple('clicked', 'activate_select');²< # $wnd->add($btn);²< ²< $file = 'php-gtk.gif';²< ²< # quick usage²< # $img = GtkImage::new_from_file($file);²< ²< # more complexe usage with pixbuf²< $pixbuf = GdkPixbuf::new_from_file($file);²< $img = new GtkImage();²< $img->set_from_pixbuf($pixbuf);²< ²< $wnd->add($img);²< ²< $wnd->show_all();²< Gtk::main();²< ²< ?>²< [[include:Main/CodeTableEnd]]²< ²---²> Describe GtkImage here.²\ No newline at end of file²
author=Marc Quinton
author:1158824712=Marc Quinton
host:1158824712=82.234.62.122
name=CodeSnippets.GtkImage
host=143.196.162.107
agent=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041217
rev=4
diff:1158825475:1158824712:=0a1²> ²32,50d32²< ²< ?>²< [[include:Main/CodeTableEnd]]²< ²< ²< !!! reading from URL ²< ²< -> you can read image directly from web site like that ; but you need to have bundled GD library compliled in (the one included with php sources). ²< ²< [[include:Main/CodeTable]]²< <?php²< ²< $file = 'http://gtk.php.net/gifs/php-gtk.gif';²< $gif = imagecreatefromgif($file);²< $pixbuf = GdkPixbuf::new_from_gd($gif);²< ²< $img = new GtkImage();²< $img->set_from_pixbuf($pixbuf);²< ²
author:1158825475=Marc Quinton
host:1158825475=82.234.62.122
diff:1158830850:1158825475:=1,4c1²< !!! show Gtk widget tree²< ²< * just add this function and you will see complete widget tree.²< * you need to call this function width any main window (GtkWindow)²---²> !!! complete code example²9,10c6²< function show_widget_tree($widget, $level=0){²< $childs = $widget->get_children();²---²> error_reporting(E_ALL);²12,13c8,12²< $spacing = str_repeat(' ', $level);²< foreach($childs as $child){²---²> //standard stuff for window creation²> $wnd = new GtkWindow();²> $wnd->connect_simple('destroy', array('Gtk', 'main_quit'));²> $wnd->set_position(Gtk::WIN_POS_CENTER);²> # $wnd->set_size_request(200, 200);²15,18c14,16²< if(is_a($child, 'GtkWidget'))²< $name = $child->get_name();²< else²< $name = '';²---²> $btn = new GtkButton('select');²> $btn->connect_simple('clicked', 'activate_select');²> # $wnd->add($btn);²20,23c18²< if(is_a($child, 'GtkLabel'))²< $label = " : " . $child->get_label();²< else²< $label = '';²---²> $file = 'php-gtk.gif';²25c20,21²< echo "$spacing - " . get_class($child) . " - $name $label\n";²---²> # quick usage²> # $img = GtkImage::new_from_file($file);²27,30c23,26²< # recurse GtkWidget tree (containers)²< if(is_a($child, 'GtkContainer'))²< show_widget_tree($child, $level+1);²< }²---²> # more complexe usage with pixbuf²> $pixbuf = GdkPixbuf::new_from_file($file);²> $img = new GtkImage();²> $img->set_from_pixbuf($pixbuf);²32c28²< }²---²> $wnd->add($img);²34c30,31²< function on_test_activate($window){²---²> $wnd->show_all();²> Gtk::main();²36,37c33,34²< show_widget_tree($window);²< }²---²> ?>²> [[include:Main/CodeTableEnd]]²39d35²< ...²41,42c37²< $btn = new GtkButton('tree');²< $btn->connect_simple('clicked', 'on_test_activate', $wnd);²---²> !!! reading from URL ²44c39²< ...²---²> -> you can read image directly from web site like that ; but you need to have bundled GD library compliled in (the one included with php sources). ²46c41,42²< ?>²---²> [[include:Main/CodeTable]]²> <?php²47a44,52²> $file = 'http://gtk.php.net/gifs/php-gtk.gif';²> $gif = imagecreatefromgif($file);²> $pixbuf = GdkPixbuf::new_from_gd($gif);²> ²> $img = new GtkImage();²> $img->set_from_pixbuf($pixbuf);²> ²> ²> ?>²
author:1158830850=Marc Quinton
host:1158830850=143.196.162.107
diff:1158830923:1158830850:=1c1,4²< !!! complete code example²---²> !!! show Gtk widget tree²> ²> * just add this function and you will see complete widget tree.²> * you need to call this function width any main window (GtkWindow)²6,12c9,10²< error_reporting(E_ALL);²< ²< //standard stuff for window creation²< $wnd = new GtkWindow();²< $wnd->connect_simple('destroy', array('Gtk', 'main_quit'));²< $wnd->set_position(Gtk::WIN_POS_CENTER);²< # $wnd->set_size_request(200, 200);²---²> function show_widget_tree($widget, $level=0){²> $childs = $widget->get_children();²14,16c12,13²< $btn = new GtkButton('select');²< $btn->connect_simple('clicked', 'activate_select');²< # $wnd->add($btn);²---²> $spacing = str_repeat(' ', $level);²> foreach($childs as $child){²18c15,18²< $file = 'php-gtk.gif';²---²> if(is_a($child, 'GtkWidget'))²> $name = $child->get_name();²> else²> $name = '';²20,21c20,23²< # quick usage²< # $img = GtkImage::new_from_file($file);²---²> if(is_a($child, 'GtkLabel'))²> $label = " : " . $child->get_label();²> else²> $label = '';²23,26c25²< # more complexe usage with pixbuf²< $pixbuf = GdkPixbuf::new_from_file($file);²< $img = new GtkImage();²< $img->set_from_pixbuf($pixbuf);²---²> echo "$spacing - " . get_class($child) . " - $name $label\n";²28c27,30²< $wnd->add($img);²---²> # recurse GtkWidget tree (containers)²> if(is_a($child, 'GtkContainer'))²> show_widget_tree($child, $level+1);²> }²30,31c32²< $wnd->show_all();²< Gtk::main();²---²> }²33,34c34²< ?>²< [[include:Main/CodeTableEnd]]²---²> function on_test_activate($window){²35a36,37²> show_widget_tree($window);²> }²37c39²< !!! reading from URL ²---²> ...²39,49c41,42²< -> you can read image directly from web site like that ; but you need to have bundled GD library compliled in (the one included with php sources). ²< ²< [[include:Main/CodeTable]]²< <?php²< ²< $file = 'http://gtk.php.net/gifs/php-gtk.gif';²< $gif = imagecreatefromgif($file);²< $pixbuf = GdkPixbuf::new_from_gd($gif);²< ²< $img = new GtkImage();²< $img->set_from_pixbuf($pixbuf);²---²> $btn = new GtkButton('tree');²> $btn->connect_simple('clicked', 'on_test_activate', $wnd);²50a44²> ...²52a47²> ²
author:1158830923=Marc Quinton
host:1158830923=143.196.162.107