Re: SimpleList questions from a beginner

Ross McFarland wrote:

Bjarne Steinsbø said:

Question one: I noticed that I couldn't "push" an array to the
SimpleList.  Instead, I had to push row by row.  Is this a bug, or is it
meant to work this way?  Looking at the implementation, I would guess
the same applies to "unshift"...

the fill button/branch shows how to completely replace the data in the list
with an array of array references (read array of rows.) i'd have to know more
exactly what you're trying to do to tell what is/isn't the case with
push/unshift, it can get kinda tricky.

What I did was to add another button (called it "Many"), since I wanted to test the performance of this widget when handling large amounts of data. Adding the button was just a question of adding it to the list of buttons to make. In "btn_clicked" I then added a case to the switch for my new button "Many". I first tried the code
elsif( $op eq 'Many' )
   my @more;
   for (my $i = 0; $i < 10000; $i++)
      push @more, [
         'many', $i, $i + $i/100, 1, 'many', undef, 'many', []
   push @{$slist->{data}}, @more;
This is probably closest to the way I want to add data to the model, i.e. the data already prepared in an array for adding, and then added to the model in one go. At the time I hadn't looked at the implementation of the SimpleList, so I also thought that this would have a better performance than adding the data one row at a time. I know see that it doesn't really matter that much. However, it didn't work as expected. Only one row (the first one) was added to the model. I had expected the call signature of the "push" function to be honored, but it's not. From the "". the problem seems to be in the PUSH (and SHIFT) function in ...::TiedList. It's not expecting more than one parameter in addtion to the object itself. This making any sense to you? It is of course no big deal to change the code to add the data one row at the time.

Question three: Am I on the right track?  Does anybody have any example
code for customized renderers I could look at?  Would I have to write
the renderer in C, or is the class inheritance between GObjects and perl
classes transparant enough for me to write my own class that inherits
from Gtk::CellRenderer and take it from there?

you're doing some pretty fancy things and you may be better of working
directly with the mvc stuff, or perhaps making your own 'ComlexList' widget,
modled on SimpleList that is better suited for your needs. SimpleList was
intended to be a way for someone that doesn't under stand all of the mvc stuff
to put a list widget in their app with only a few mins work, but obviously
it's capible of more. but at some point you'll run into it being more trouble
than it's worth. those type of 'extensions' are where Gtk2-Perl will have room
tro grow/improve after the initial wrapper libs are done. and i suspect they
will, whether the gtk2-perl teams does it or others.

as for customized renderers i would suspect you'd have better luck doing those
in C and then writting wrappers for them, but in theory it would be possible.
there's plenty of doc on writting your own widgets, that's the starting point,
either way it's going to be some work. a possible, although perhaps not ideal,
workaround is to have the editing take place in a dialog that is created on
the double click signal, it would be simplier to do, but not quite as smooth.
I'm not doing it yet... :-) I might decide that it's not really *that* important , when I see how much work it's going to be. It will definitely be pushed down on the stack of things to do if it turns out that I have to do it in C. And, as you say, there is more than one way to do it. If I decide to make my own TreeView, having SimpleList to look at will definitely be a great help.



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