GtkTreeView does not show data after clear()



I'm writing a program in gtk3-perl and am experiencing a problem with a TreeView that does not display a second load of data after a clear().  FWIW, I'm doing a customer search, and this sub is run if there are multiple results from a search on a name.

 I am including the code below where this happens..  I'm using xml generated by glade and loading it with GtkBuilder.  Notice that I'm using clear() before the first display, on an empty ListStore, and the first pass displays correctly.  If I do a subsequent search, the dialog shows with the header for the TreeView, but nothing is shown.  If I eliminate the clear(), then the data from the previous search is shown (as expected), with the result of the second search appended, but when clear() is executed, the data is blank.

I've used the same procedure with Gtk2 in another program, and it worked, and, in fact, I edited this file to use Gtk2, and edited the .glade file until it didn't produce errors on load and this worked.  I even rewrote the program in C, and it works as expected.  Admittedly, when I experimented with Gtk2, I simply deleted properties and things in the glade file and the output was not correct, bu6 I don't believe I eliminated anything that would have corrected the problem.

Of course AFAIK, there is no documentation as of yet for Gtk3-Perl, and I could be using some incorrect code, but I truly feel that there's a bug in the Gtk3 code that is doing this.

I've been a bit longwinded, but, to summarize, when $dlg is run the first time, the tree view displays the data, but on a second pass, after dlear() ing, nothing (except for the column headers) is shown.

The database engine I'm using is DBI with DBD::Pg (postgresql)

sub select_cust_from_ids {
    my $ids = shift;    # A list of ID's to search for in the database

#   'dlg_customer_view_multi' is a dialog defined in the glade file.  it is a dialog
#    containing a treeview with its ListStore Model and its columns defined also in
#    the glade file.
    my $dlg = $builder->get_object ('dlg_customer_view_multi');
    my $view = $builder->get_object ('treeview_customer_data');

    # First build a list of placeholders for the query
    my @placeholders;

    foreach (@$ids) {
        push @placeholders, 'cust_id = ?';
    }

    my $qry = qq/SELECT lastname,firstname,coalesce(mi,''),streetaddr,/ .
    qq/city,state,zip,cust_id FROM poolsalesfullview WHERE / .
    join (' OR ', @placeholders);

    my $custs = $dbh->selectall_arrayref ($qry, undef, @$ids);
   unless ($custs) {
        my $msg = 'No data was retrieved...';

        if ($dbh->err) {
            $msg .= "\n" . $dbh->errstr;
        }

        my $d = Gtk3::MessageDialog->new ($w_main, 'destroy-with-parent',
            'notice', 'gtk-ok', $msg);
        $d->run;
        $d->destroy;
        return;
    }

    my $m = $view->get_model;
    $m->clear;

    foreach my $row (@$custs) {
        my $iter = $view->get_model->append();

        unless ($view->get_model->iter_is_valid($iter)) {
            my $d = MessageDialog->new ($dlg, 'destroy-with-parent',
:                'warning', 'gtk-close',
                'Invalid iter for TreeView');
            return;
        }

        my (@cols, @vals);
        my @parms = ($iter);

        for (my $x = 0; $x < scalar (@$row); $x++) {
            #push(@cols, $x); push (@vals, $row->[$x]);
            push (@parms, $x => $row->[$x]);
        }

        #$view->get_model->set ($iter, \@cols, \@vals);
        $view->get_model->set(@parms);
    }

#     ------ Testing ------
#    this displays the correct data in the second pass
#    so it appears that the Liststore itself is being populated correctly
#    it seems that somehow, the treeview is losing its relation to the Model
#    when the ListStore is clear()-ed when data is in it.

#    my $it = $view->get_model->get_iter_first;
#
#    while ($it) {
#        my ($l,$f);
#        $l = $view->get_model->get_value($it, 0);
#        $f = $view->get_model->get_value($it, 1);
#        print "$f $l\n";
#
#        unless ($view->get_model->iter_next($it)) {
#            $it = undef;
#        }
#    } print "\n";
#     ------ Testing ------

    $dlg->run;
    $dlg->hide;
}





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