|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
GtkTreeview and interactive searchSeems that interactive search doesn't work since I upgrade to new
version. Can anybody give me an example ? my example that doesn't work : <?php $window = new GtkWindow(); $window->set_size_request(400, 200); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox()); $sc = new GtkScrolledWindow(); $vbox->add($sc); $model = new GtkListStore(GObject::TYPE_LONG); for($i=10; $i < 20; $i++){ $model->append(array($i)); } $view = new GtkTreeView($model); $view->append_column(new GtkTreeViewColumn( "", new GtkCellRendererText(), 'text', 0)); $sc->add($view); //$view->set_enable_search(1); $view->set_search_column(0); $window->show_all(); Gtk::main(); ?> Thanks in advance, Benjamin. -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: GtkTreeview and interactive search for PHP-GTK v2.0Hi 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 |
|
|
Re: GtkTreeview and interactive search for PHP-GTK v2.0Thanks 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 > > > |
|
|
Re: GtkTreeview and interactive search for PHP-GTK v2.0Hi Benjamin,
Just a little suggestion. In your code, you have used: protected $timeout_handler_delay = 3000; $this->timeout_handler_id = Gtk::timeout_add($this->timeout_handler_delay, array($this, 'stop_interactive_search')); Imagine a user typing slowly. At the end of 3 seconds, the search box will automatically hide, even though he is still typing halfway. So you might want to change the code slightly so that each mouse or button activity in the search field will reset the start time of inactivity. Here's a sample code for your reference: http://www.kksou.com/php-gtk2/articles/setup-interactive-search-in-GtkTreeView-for-PHP-GTK-v2.0---Part-4---automatically-hide-after-3-seconds.php Regards, /kksou |
| Free embeddable forum powered by Nabble | Forum Help |