com gtk/php-gtk: Image browser has preview images in the list and the ability to deactivate them: demos/imgbrowser.php
[email protected] (David Soria Parra) Thu, 06 Apr 2006 10:50:54 +0000
| Newsgroups | php.gtk.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit: 3527207aeeb0976f35e3c64dd40e375cf1f64a2d Author: Christian Weiske <[email protected]> Thu, 6 Apr 2006 10:50:54 +0000 Parents: 83ab4e773d51412248438615423f1e2f4a94ff3d Branches: master Link: http://git.php.net/?p=gtk/php-gtk.git;a=commitdiff;h=3527207aeeb0976f35e3c64dd40e375cf1f64a2d Log: Image browser has preview images in the list and the ability to deactivate them Changed paths: M demos/imgbrowser.php Diff: 3527207aeeb0976f35e3c64dd40e375cf1f64a2d diff --git a/demos/imgbrowser.php b/demos/imgbrowser.php index f3db42f..87b1799 100644 --- a/demos/imgbrowser.php +++ b/demos/imgbrowser.php @@ -4,7 +4,7 @@ class ImgBrowser extends GtkWindow { var $img = null; - + var $bLoadPreview = true; function __construct($parent = null) @@ -39,26 +39,49 @@ class ImgBrowser extends GtkWindow $paned = new GtkHPaned(); $paned->set_position(200); - //filename, fullpath, is_dir - $mFile = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_BOOLEAN); + //filename, markup-filename, fullpath, is_dir, preview image + $mFile = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_BOOLEAN, GdkPixbuf::gtype); + $mFile->set_sort_column_id(0, Gtk::SORT_ASCENDING); + $vFile = new GtkTreeView($mFile); - $vFile->append_column( - new GtkTreeViewColumn( - 'Files', - new GtkCellRendererText(), - 'markup', - 0 - ) - ); + $col = new GtkTreeViewColumn( + 'Image', + new GtkCellRendererPixbuf(), + 'pixbuf', + 4 + ); + $text = new GtkCellRendererText(); + $col->pack_start($text); + $col->add_attribute($text, 'markup', 1); + $vFile->append_column($col); + $vFile->set_headers_visible(false); + $vFile->connect('key-press-event', array($this, 'onPressFile')); $vFile->connect('button-press-event', array($this, 'onPressFile')); +/* + GtkIconView has some problems with text that are too long + and missing icons + $vFile = new GtkIconView(); + $vFile->set_model($mFile); + $vFile->set_columns(1); + $vFile->set_pixbuf_column(3); + $vFile->set_text_column(0); + $vFile->set_item_width(100); +*/ $this->loadFiles($mFile, getcwd()); $scrwndFiles = new GtkScrolledWindow(); $scrwndFiles->add($vFile); $scrwndFiles->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - $paned->add1($scrwndFiles); + $vboxFile = new GtkVBox(); + $vboxFile->pack_start($scrwndFiles); + + $chkImg = new GtkCheckbutton('Load preview images'); + $chkImg->set_active(true); + $chkImg->connect('toggled', array($this, 'onCheckPreview')); + $vboxFile->pack_start($chkImg, false); + $paned->add1($vboxFile); $this->img = new GtkImage(); @@ -78,12 +101,16 @@ class ImgBrowser extends GtkWindow { $hdl = dir($strDir); $mFile->clear(); + $pb = null; while (false !== ($file = $hdl->read())) { $path = $hdl->path . DIRECTORY_SEPARATOR . $file; if (is_dir($path) && $file !== '.') { - $mFile->append(array('<span color="#00F">' . $file . '</span>', $path, true)); + $mFile->append(array($file, '<span color="#00F">' . $file . '</span>', $path, true, null)); } else if (substr($path, -4) == '.png' || substr($path, -4) == '.jpg') { - $mFile->append(array($file, $path, false)); + if ($this->bLoadPreview) { + $pb = GdkPixbuf::new_from_file($path)->scale_simple(32, 32, Gdk::INTERP_BILINEAR); + } + $mFile->append(array($file, $file, $path, false, $pb)); } } } @@ -98,8 +125,8 @@ class ImgBrowser extends GtkWindow ) { list($model, $iter) = $vFile->get_selection()->get_selected(); if ($iter !== null) { - $path = $model->get_value($iter, 1); - if ($model->get_value($iter, 2)) { + $path = $model->get_value($iter, 2); + if ($model->get_value($iter, 3)) { $this->loadFiles($model, $path); } else { $this->showImage($path); @@ -110,6 +137,13 @@ class ImgBrowser extends GtkWindow + public function onCheckPreview($chkImg) + { + $this->bLoadPreview = $chkImg->get_active(); + } + + + function showImage($path) { $this->img->set_from_file($path);