Greetings All.

I Am trying to generate (in PERL) a subroutine that prompts a user to select from a list of people. The list has both names and photos.

I've got most of this working using GTK3 Liststore/Treeview code. However, I cannot seem to figure out how to get the window to automatically follow the cursor. If the user moves the cursor past the bottom (or top) of the displayed window using up/down keys, they must manually adjust the scrollbar to see it.

Can some kind soul suggest the magic needed to do this? Suggestions on a better way to accomplish this task are also appreciated.

Thanx.

Richard Rosa

sub get_person_dialog { ###################################################### # Create a Liststore so that pictures can be used. # # Column 0 of the liststore is the person's full name# # Column 1 of the liststore is the person's dbid # # Column 2 of the liststore is the person's picture # ###################################################### my $col_name = 0; my $col_id = 1; my $col_picture = 2; my $liststore = Gtk3::ListStore->new ('Glib::String', 'Glib::String','Gtk3::Gdk::Pixbuf'); #### List of all DBindexes for every person in the database my @people_keys = sort_by_name(); ### Custom sorting routine foreach my $key (@people_keys) { my $iter = $liststore->append; $liststore->set ($iter, $col_last,FALSE); ### toggle $liststore->set ($iter, $col_name, "$dbase{$key}{'name'}"); $liststore->set ($iter, $col_id, "$key"); ### Is there a picture for this person? my $picture = $dbase{$key}{'picture'}; if ($picture) { my $pixbuf = Gtk3::Gdk::Pixbuf->new_from_file_at_size( "$picture",100,100); $liststore->set($iter,$col_picture,$pixbuf); } } my $treeview = Gtk3::TreeView->new ($liststore); $treeview->set_enable_search(TRUE); ### allow for search $treeview->set_headers_visible(FALSE); $treeview->set_search_column($col_name); $treeview->set_hover_selection(FALSE); ### Column and Cell renderer for the person's Full Name my $renderer = Gtk3::CellRendererText->new; $renderer ->set(editable => FALSE); my $treecol = Gtk3::TreeViewColumn->new_with_attributes('name', $renderer,'text' => $col_name); $treeview->append_column($treecol); ### Column and Cell renderer for the person's ID $renderer = Gtk3::CellRendererText->new; $renderer ->set(editable => FALSE); $treecol = Gtk3::TreeViewColumn->new_with_attributes( 'id',$renderer,'text' => $col_id); $treeview->append_column($treecol); ### Column and Cell renderer for the persons Photo $renderer = Gtk3::CellRendererPixbuf->new; $treecol = Gtk3::TreeViewColumn->new_with_attributes( 'picture',$renderer,'pixbuf' => $col_picture); $treeview->append_column($treecol); ### put this in a scrolled window my $tvsb = Gtk3::ScrolledWindow->new; $tvsb->add_with_viewport($treeview); $tvsb->set_min_content_height(400); $tvsb->set_min_content_width(900); $tvsb->set_policy('GTK_POLICY_ALWAYS', 'GTK_POLICY_ALWAYS'); ### Build a dialog to show this selection my $dl = Gtk3::MessageDialog->new( $main_window, ### parent [qw/modal destroy-with-parent/], ### flags 'GTK_MESSAGE_QUESTION', 'GTK_BUTTONS_NONE', "Please select the person to edit"); $dl->get_content_area()->add($tvsb); ### add an ICON for the Dialog my $stock = Gtk3::Image->new_from_icon_name( $stock_icons[3],'GTK_ICON_SIZE_DIALOG'); $dl->set_image($stock); ### Add some buttons $dl->add_button('gtk-ok','ok'); $dl->add_button('gtk-cancel','cancel'); $dl->show_all; my $response = $dl->run; ### Get selected item my $value = 0; my $selection = $treeview->get_selection(); if ($selection) { my ($md,$iter) = $selection->get_selected(); if ($iter) { $value = $liststore->get($iter,$col_id); if (!$value) {$value = 0;} } } $dl->destroy; if ($response eq 'cancel') {return 0;} return $value; ## Person's ID will be returned

In reply to GTK3 Treeview question by richardrosa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.