Re: Handling children




On Dec 16, 2005, at 3:17 AM, Mario Ospelt wrote:

I'm writing a program to search a database and display the search results in pages of a notebook. Each search creates a new page in the notebook. Pages can also be removed. Each page contains a ListStore desplaying the results. A double-click on a row in the liststore should now open a certain pdf file, that is created out of the selected row. Therefore I have to know the TreeModel and the TreeView (to use GtkTreeSelection) of the actual page of the notebook. So should I store each model and treeview on teir creation in a public array, on that I could refer later, or is it possible to get the TreeModel and the TreeView otherwise because of the actual page of the notebook? Or in other words: Can I obtain the TreeModel and the TreeView as children of the actual page of the notebook at any time?

You shouldn't need to do any of that stuff. Double-clicking on a row is "activating" a row (just like hitting Enter in the view while the row is selected), which fires the TreeView's row-activated signal. The row-activated signal gets the view, the path to the activated row, and the TreeViewColumn of the clicked column. You can get to both the model and the selection from the view, but you shouldn't need the selection because you got the path.

       ...
       $view->signal_connect (row_activated => \&row_activated);
       ...

   # note that this uses only its arguments, no globals, so it will do
   # the right thing no matter which notebook page contains the view.
   sub row_activated {
       my ($view, $path, $column) = @_;
       my $model = $view->get_model;
       my $iter = $model->get_iter ($path);
       my $filename = $model->get ($iter, FILENAME_COLUMN);
       my $parent_window = $view->get_toplevel);
       launch_viewer_window ($parent_window, $filename);
   }



--
Jolt is my co-pilot.
  -- Slogan on a giant paper airplane hung in Lobby 7 at MIT.
     http://hacks.mit.edu/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]