Re: GtkTreeView does not show data after clear()



Sorry for breaking the thread but I wasn't subscribed when I posted and got the replies.

On Fri, 25 Nov 2016 20:58:40 Torsten Schoenfeld said:

On 22.11.2016 02:35, David Lowrence wrote:
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.
Well, as always, the C docs are relevant.  Plus, there is "perli11ndoc"
and there are some tutorials; see the newly updated (thanks, Brian!)
<http://gtk2-perl.sourceforge.net/doc/> for pointers.

Yes, I've looked at all these.  I just wondered if there might have been some quirk in the Gtk3 binding that had changed.

If this doesn't turn up anything obvious, I'd need a minimal standalone example program that exhibits the problem to investigate further.

I don't know whether the list accepts attachments so I'm including it inline.

I didn't try valgrind (yet) but I did write a simple program to display the problem.  It's pretty rudimentary, (I didn't even display the main window), but I think it's all pretty identical to what I was doing.

When the program runs, the data is displayed on the first pass, but on the second, it's not. I edited the program changing "Gtk3" to "Gtk2" and changed the version requirement in the Glade file, and the data displays on both passes.

I realize that perhaps I am doing something wrong and may have some setting, perhaps in the Glade code, which Gtk2 accepted but not Gtk3, but I cannot find it.

Here is the program:

#! /usr/bin/perl -w

use strict;
use Gtk3 -init;

my $data = "">
    ["Sam", "Spade"],
    ["Rock", "Hudson"],
    ["Tom", "Mix"]
];

my $builder = Gtk3::Builder->new;
$builder->add_from_file("ls.glade");

for (0 ... 1) {
    select_cust_from_ids($data);
}

# Originally, the following sub was passed a list of id's
# for which to search the database, but for test purposes, I'm passing
# the above $data AoA, which is the same format as the $dbh->selectall_arrayref
# function returns.

sub select_cust_from_ids {
    my $custs = shift;

    my $dlg = $builder->get_object ('dlg_customer_view_multi');
    unless ($dlg) {print "Failed to retrieve dialog\n"; return;}
    my $view = $builder->get_object ('treeview_customer_data');
    unless ($view) {print "Failed to retrieve Treeview\n";return}

    # First build a list of placeholders for the query
    # Eliminated the database functions for brevity

    # Note that this is called before loading the first dataset.
    # The data is displayed on the first pass.
    $view->get_model->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 (@parms, $x => $row->[$x]);
        }

        $view->get_model->set(@parms);
    }

#     ------ Testing ------
#    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 ------
#     Looped through the model.  On each pass, it contains data

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

and the Glade file.  Some of the lines wrapped but maybe won't hurt for xml...
Note that this was generated on Debian Jessie, which using somewhat older versions of the programs.  I've also tried the (original) program on Linux Mint and Ubuntu (I think) - these having later version of Gtk3 etc, and wherever I tried it, I got the same result with no data showing on any pass past the first.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
  <requires lib="gtk+" version="3.12"/>
  <object class="GtkListStore" id="liststore1">
    <columns>
      <!-- column-name firstname -->
      <column type="gchararray"/>
      <!-- column-name lastname -->
      <column type="gchararray"/>
    </columns>
  </object>
  <object class="GtkWindow" id="wmain">
    <property name="can_focus">False</property>
    <signal name="delete-event" handler="sub (delete-event}" swapped="no"/>
    <child>
      <placeholder/>
    </child>
  </object>
  <object class="GtkDialog" id="dlg_customer_view_multi">
    <property name="can_focus">False</property>
    <property name="type_hint">dialog</property>
    <property name="transient_for">wmain</property>
    <child internal-child="vbox">
      <object class="GtkBox" id="vbox1">
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <property name="spacing">2</property>
        <child internal-child="action_area">
          <object class="GtkButtonBox" id="dialog-action_area1">
            <property name="can_focus">False</property>
            <property name="layout_style">end</property>
            <child>
              <placeholder/>
            </child>
            <child>
              <object class="GtkButton" id="button_ok">
                <property name="label" translatable="yes">button</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkTreeView" id="treeview_customer_data">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="model">liststore1</property>
            <property name="enable_search">False</property>
            <property name="search_column">0</property>
            <child internal-child="selection">
              <object class="GtkTreeSelection" id="treeview-selection"/>
            </child>
            <child>
              <object class="GtkTreeViewColumn" id="ln_col">
                <property name="title" translatable="yes">Last</property>
                <child>
                  <object class="GtkCellRendererText" id="cellrenderer-ln">
                  </object>
                  <attributes>
                    <attribute name="text">1</attribute>
                  </attributes>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkTreeViewColumn" id="fn_col">
                <property name="title" translatable="yes">First</property>
                <child>
                  <object class="GtkCellRendererText" id="cellrenderertext-fn">
                  </object>
                  <attributes>
                    <attribute name="text">0</attribute>
                  </attributes>
                </child>
              </object>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
      </object>
    </child>
    <action-widgets>
      <action-widget response="-5">button_ok</action-widget>
    </action-widgets>
  </object>
</interface>



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