custom TreeModel

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

custom TreeModel

Jens Luedicke
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hiya...

I whipped up a custom TreeModel and I get the following error:

type Filer::ListStore does not support property 'Glib::Object' at
/home/jens/devel/filer/Filer/FilePane.pm line 100.

My custom TreeModel has 7 columns:

$treemodel{ident $self} = new Filer::ListStore(qw(Glib::Object
Glib::String Glib::String Glib::String Glib::String Glib::String
Glib::Scalar));

any idea how to fix this?

TIA,
Jens


- --
Jens Luedicke
web: http://perldude.de

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCGkmiCvkc4H0gTERAo/6AKDzTxFKtDTfNjfgbA0E5IgAm5M7EACcDCNQ
D44MhrmIMoiiSJvkT+kXQIk=
=u0fb
-----END PGP SIGNATURE-----
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

Jan Hudec
On Sun, Aug 21, 2005 at 13:44:38 +0200, Jens Luedicke wrote:
> I whipped up a custom TreeModel and I get the following error:
>
> type Filer::ListStore does not support property 'Glib::Object' at
> /home/jens/devel/filer/Filer/FilePane.pm line 100.

Is your tree model actually a subclass of Gtk2::TreeModel? Using the
Glib::Object::Subclass pragma? It has to use that.

-------------------------------------------------------------------------------
                                                 Jan 'Bulb' Hudec <[hidden email]>

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

Jens Luedicke
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jan Hudec wrote:

> On Sun, Aug 21, 2005 at 13:44:38 +0200, Jens Luedicke wrote:
>
>>I whipped up a custom TreeModel and I get the following error:
>>
>>type Filer::ListStore does not support property 'Glib::Object' at
>>/home/jens/devel/filer/Filer/FilePane.pm line 100.
>
>
> Is your tree model actually a subclass of Gtk2::TreeModel? Using the
> Glib::Object::Subclass pragma? It has to use that.
>
code attached. based on the gmusicbrowser_list.pm




- --
Jens Luedicke
web: http://perldude.de

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCHgHiCvkc4H0gTERAkyrAJ9ehcsBhfTPg8QQ22jMAP6Sj2YqfgCg1pnV
mJH1YNQ8E4mLKqiRIKGyseM=
=rGsZ
-----END PGP SIGNATURE-----

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

ListStore.pm (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

muppet-6
In reply to this post by Jens Luedicke

On Aug 21, 2005, at 7:44 AM, Jens Luedicke wrote:

> I whipped up a custom TreeModel and I get the following error:
>
> type Filer::ListStore does not support property 'Glib::Object' at
> /home/jens/devel/filer/Filer/FilePane.pm line 100.
>
> My custom TreeModel has 7 columns:
>
> $treemodel{ident $self} = new Filer::ListStore(qw(Glib::Object
> Glib::String Glib::String Glib::String Glib::String Glib::String
> Glib::Scalar));
>
> any idea how to fix this?

Short answer:

Either

   # set the column types in instance initializer.  handy for
   # future derivation, but not so handy if you wanted the
   # column types to be set by a subclass.
   sub INIT_INSTANCE {
       my $self = shift;
       # where set_column_types is a method of your own that
       # tells your instance what the column types are.  it doesn't
       # have to be like this, it could just be an array assignment.
       $self->set_column_types (qw(Glib::Object Glib::String...));
   }

or

   # parameterized constructor.
   sub new {
       my ($class, @column_types) = @_;
       my $self = Glib::Object::new ($type);
       # see note above about set_column_types
       $self->set_column_types (@_);
       return $self;
   }


Long answer:

You're inheriting Glib::Object::new(), which treats the argument list  
as property-name/value pairs.  However, you're trying to call it like  
Gtk2::ListStore::new, which takes a list of column types that are  
then passed to gtk_list_store_set_column_types().

The TreeModel GInterface provides an API for querying and using a  
TreeModel; each implementation is responsible for coming up with its  
own way to configure and populate the store.

Glib::Object::Subclass checks to see if your class has a new(); if it  
doesn't, it will alias YourClass::new() to Glib::Object::new(), which  
is a factory constructor.  This is important, because the factory  
constructor is the only way to create a GObject instance; the various  
widget and object constructors in each class of gtk+'s API are  
actually convenience functions which merely marshal their parameters  
into g_object_new().  To ensure useful derivation, pretty much  
everything that you can configure about a GObject should be made an  
object property, and no setup code should occur in a new()  
implementation.

For your Filer::ListStore, the first question is, "is this supposed  
to be a special-case store object, or a parameterized store?"  That  
is, will you want to create a Filer::ListStore with different column  
types in different parts of your code?  If the answer is "no", then  
set up your column types in INIT_INSTANCE so that no matter how the  
object gets created, the column types will be right.  If the answer  
is "yes", you'll need to provide some way to set the column types  
after the object has been instantiated.  Gtk2::ListStore provides  
set_column_types() for exactly this purpose.

You can, of course, mix and match these approaches.  For example,  
Filer::ListStore may be a parameterized list, but Filer::FooList may  
set the column types in its INIT_INSTANCE so that creating one is as  
simple as "$foolist = Filer::FooList->new($where_to_find_the_foos);".


--
muppet <scott at asofyet dot org>

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

Jens Luedicke
In reply to this post by Jens Luedicke
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quentin wrote:

> On Sun, 2005-08-21 at 14:48 +0200, Jens Luedicke wrote:
>
>>code attached. based on the gmusicbrowser_list.pm
>
>
> You might also want to look at customlist.pl in the examples/ directory
> of the gtk-perl package (installed in /usr/share/doc/perl-Gtk2*/ on
> mandrake)
>
> my custom list in gmusicbrowser_list.pm is based on this file.
>

Thanks for the hint!

I ripped out the CustomList package and modified it to suit my needs
(adjusted the record stuff).

if I call Filer::ListStore->new:

Can't locate object method "new" via package "Filer::ListStore" at
/home/jens/devel/filer/Filer/FilePane.pm line 96.

I wonder why it doesn't work - my implementation is basically the same
thing as CustomList.



- --
Jens Luedicke
web: http://perldude.de

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCNhSiCvkc4H0gTERAjZfAKCODwWrDzs+SgSRRIQ72VwBVtGZ/wCeNv63
fAc5jMYx4gTAra4nVnApz1I=
=zTaV
-----END PGP SIGNATURE-----
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

muppet-6

On Aug 21, 2005, at 3:38 PM, Jens Luedicke wrote:

> if I call Filer::ListStore->new:
>
> Can't locate object method "new" via package "Filer::ListStore" at
> /home/jens/devel/filer/Filer/FilePane.pm line 96.
>
> I wonder why it doesn't work - my implementation is basically the same
> thing as CustomList.

Code?



--
I like drawing and painting.  If you make something really weird,  
that means "abstract".
   -- Some kid on a PBS kid's show.



_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

Jens Luedicke
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

re-send to the list as well.

muppet wrote:

>
> On Aug 21, 2005, at 3:38 PM, Jens Luedicke wrote:
>
>> if I call Filer::ListStore->new:
>>
>> Can't locate object method "new" via package "Filer::ListStore" at
>> /home/jens/devel/filer/Filer/FilePane.pm line 96.
>>
>> I wonder why it doesn't work - my implementation is basically the same
>> thing as CustomList.
>
>
> Code?
>
This is how it looks like now (code attached).

the following error comes up after clearing and appending new items:

Gtk-CRITICAL **: file gtktreeview.c: line 4827 (validate_visible_area):
assertion `has_next' failed.
There is a disparity between the internal view of the GtkTreeView,
and the GtkTreeModel.  This generally means that the model has changed
without letting the view know.  Any display from now on is likely to
be incorrect.

I guess my clear() method isn't perfect.

Jens

- --
Jens Luedicke
web: http://perldude.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCaCgiCvkc4H0gTERAkqdAKDn98P7qexpG3x+CPDswIcv1A5BnwCgwCTO
ajkThfZjfQc/YXdVKbfGtaI=
=UEEn
-----END PGP SIGNATURE-----

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

ListStore.pm (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

muppet-6

On Aug 22, 2005, at 5:53 AM, Jens Luedicke wrote:

> muppet wrote:
>
>> On Aug 21, 2005, at 3:38 PM, Jens Luedicke wrote:
>>
>>> if I call Filer::ListStore->new:
>>>
>>> Can't locate object method "new" via package "Filer::ListStore" at
>>> /home/jens/devel/filer/Filer/FilePane.pm line 96.
>>>
>>> I wonder why it doesn't work - my implementation is basically the  
>>> same
>>> thing as CustomList.
>>
>> Code?
>
> This is how it looks like now (code attached).
>
> the following error comes up after clearing and appending new items:
>
> Gtk-CRITICAL **: file gtktreeview.c: line 4827  
> (validate_visible_area):
> assertion `has_next' failed.
> There is a disparity between the internal view of the GtkTreeView,
> and the GtkTreeModel.  This generally means that the model has changed
> without letting the view know.  Any display from now on is likely to
> be incorrect.
>
> I guess my clear() method isn't perfect.

I can't recreate this with a little test program, so obviously i'm  
not exercising the broken code.  Can you post some driver code that  
exhibits the problem?


--
Examples really shouldn't include unexploded ordnance.
   -- Joe Smith, referring to an example program i wrote.

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

Jens Luedicke
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

muppet wrote:

>> Gtk-CRITICAL **: file gtktreeview.c: line 4827  (validate_visible_area):
>> assertion `has_next' failed.
>> There is a disparity between the internal view of the GtkTreeView,
>> and the GtkTreeModel.  This generally means that the model has changed
>> without letting the view know.  Any display from now on is likely to
>> be incorrect.
>>
>> I guess my clear() method isn't perfect.
>
>
> I can't recreate this with a little test program, so obviously i'm  not
> exercising the broken code.  Can you post some driver code that
> exhibits the problem?

the attached example shows the problem.

it is based on customlist.pl and I added a 'refresh' button
and a clear() method. clear should clear the treeview and clean the
$self->{rows} array.




- --
Jens Luedicke
web: http://perldude.de

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCfp5iCvkc4H0gTERAiJAAJ9L+RNT0El0PtrHSGoccn3kTZkL8ACeOObF
S1JxIPqSE4DOT0sRTq9UPKc=
=WS4d
-----END PGP SIGNATURE-----
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

Jens Luedicke
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

forgot the attachment. here it comes.

- --
Jens Luedicke
web: http://perldude.de

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCf+eiCvkc4H0gTERAkiuAKDwW51m3bh8zKrg+Ec8WmE1zzZ0XgCfQPCl
nAyKuar21eOsVh22jAM9SP4=
=CgOs
-----END PGP SIGNATURE-----

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

treemodel.tar.gz (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

squentin

your for loop is wrong in your clear method: the row number changes as
you remove rows, you must either, always remove the row 0, or remove
rows from last to first.


_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: custom TreeModel

Jens Luedicke
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quentin wrote:
> your for loop is wrong in your clear method: the row number changes as
> you remove rows, you must either, always remove the row 0, or remove
> rows from last to first.

thanks! works fine now :)


- --
Jens Luedicke
web: http://perldude.de

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCiViiCvkc4H0gTERAhidAKDkYWID1kyyVQVu5qYpO7Fy1mn5rgCgs5Lb
tHddiZuGa5P6PiLwoTLs+38=
=rYRR
-----END PGP SIGNATURE-----
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list