Re: GtkTreeview and interactive search for PHP-GTK v2.0

From: Date: Mon, 02 Jun 2008 09:31:10 +0000
Subject: Re: GtkTreeview and interactive search for PHP-GTK v2.0
References: 1 2  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-8268@lists.php.net to get a copy of this message
Thanks for your help kksou, I modify your script : - merge the two classes - add a timeout - add aparameter column - As I had problem with class destructor, I used hide/show - move all signal connexion into the class $search_app = new Interactive_Search($treeview); class Interactive_Search extends GtkWindow { protected $treeview; // the tree view protected $search_entry; protected $timeout_handler_delay = 3000; // autoclose the search window function __construct($treeview, $col = 0 ) { parent::__construct(); $this->treeview = $treeview; $this->add($vbox = new GtkVBox()); $this->set_modal(0); $this->set_decorated(0); // I don't know if this is necessary
//     $this->set_parent_window($this->treeview->get_toplevel()->window);
$this->set_transient_for($this->treeview->get_toplevel()); $this->search_entry = new GtkEntry(); $vbox->pack_start($frame = new GtkFrame(), 0); $frame->add($this->search_entry); $this->treeview->set_enable_search(false); $this->treeview->connect_simple('start-interactive-search', array($this, 'start_interactive_search')); $this->treeview->connect('key-press-event', array($this, 'start_interactive_search')); $this->search_entry->connect('key-press-event', array($this, 'on_entry_keypress')); $this->search_entry->connect('focus-out-event', array($this, 'stop_interactive_search')); $this->treeview->set_search_entry($this->search_entry); $this->treeview->set_search_column($col); } public function start_interactive_search($treeview = null, $event = null){ $this->show_all(); // if start from treeview key_pressed if($event->string!=""){
     $this->search_entry->set_text($event->string);
     $this->search_entry->set_position(-1);
} // Position of the search window $win_pos = $this->treeview->get_toplevel()->get_position(); $x = $win_pos[0] + $this->treeview->allocation->width -
     $this->search_entry->allocation->width + $this->x_shift;
$y = $win_pos[1] + $this->treeview->allocation->height +
     $this->treeview->allocation->y +
     $this->search_entry->allocation->height + $this->y_shift ;
$this->move($x, $y); // Timeout signal connexion if($this->timeout_handler_id){
     Gtk::timeout_remove($this->timeout_handler_id);
} $this->timeout_handler_id = Gtk::timeout_add($this->timeout_handler_delay, array($this, 'stop_interactive_search')); } public function stop_interactive_search(){ Gtk::timeout_remove($this->timeout_handler_id); $this->hide(); return false; } public function on_entry_keypress($entry, $event) { if ($event->keyval==Gdk::KEY_Return || $event->keyval==Gdk::KEY_Escape) {
     $this->stop_interactive_search();
} else {
     // Refresh timeout
     Gtk::timeout_remove($this->timeout_handler_id);
     $this->timeout_handler_id = Gtk::timeout_add($this->timeout_handler_delay, array($this, 'stop_interactive_search'));
} return false; } } kksou a écrit :
Benjamin FOURTICQ wrote:
Seems that interactive search doesn't work since I upgrade to new version. Can anybody give me an example ?
    
Hi Benjamin, I think the bug lies in the gtk+v2.12 and not PHP-GTK. While we wait for the bug to be fixed, Carl recently posted a very interesting work-around here: http://www.kksou.com/php-gtk2/PHP-GTK2-Help/248-ReGtkTreeView-search-on-windows/Page-2/Page-2.php#248 I built on his idea to come out with a complete sample code for interactive search on GtkTreeView: http://www.kksou.com/php-gtk2/PHP-GTK2-Help/260-ReGtkTreeView-search-on-windows.php#260 Hope it helps. Regards, /kksou


« previous php.gtk.general (#8268) next »