Treemodel


#1

Is it possible to create a custom treemodel in ruby?
I’ve seen that other people want to do this but have not heard if
anyone has been successful.

If it is possible, does anyone have an example to share?

I have data in an sql database that I rather not copy into a treestore
in order to display in a treeview.

Thanks,
Alex Norman


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


#2

Hi,

From: Alex removed_email_address@domain.invalid
Date: Tue, 3 Jul 2007 17:28:50 -0700

Is it possible to create a custom treemodel in ruby?

Unfortunately it isn’t.
This functionality is not implemented yet, because it has some
technical difficulties.

– Masahiro S.


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


#3

Hmm, what are the technical difficulties? This would be really useful
for me and a lot of other people I assume.
either way i think the documentation should indicate that it isn’t
possible to create custom treemodels yet.

-Alex

On 7/6/07, Masahiro S. removed_email_address@domain.invalid wrote:

https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


#4

Hi,

On Sat, 7 Jul 2007 12:24:41 -0700
Alex removed_email_address@domain.invalid wrote:

Hmm, what are the technical difficulties? This would be really useful
for me and a lot of other people I assume.

Could you implement them?
I hope someone contribute it ;).


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


#5

Hmm, what are the technical difficulties? This would be really useful
for me and a lot of other people I assume.

Could you implement them?
I hope someone contribute it ;).

I’d like to help (also very keen to create a couple of custom cell
renderers and tree models) but not sure what the first steps should be.
How should we go about implementing this?

All the best,
Andrew


#6

On Sun, 2007-07-08 at 10:31 +0900, Masao M. wrote:

On Sat, 7 Jul 2007 12:24:41 -0700
Alex removed_email_address@domain.invalid wrote:

Hmm, what are the technical difficulties? This would be really useful
for me and a lot of other people I assume.

Could you implement them?
I hope someone contribute it ;).

I had a look at doing this about a year ago, but after looking through
all the docuentation I could find, and looking through quite a bit of
source code, I ended up thoroughly lost on where to start. I couldn’t
get my head around how the macros were used to create a GTK object and
expose it as a subclassable Ruby object.

I would also really like to write custom TreeModels in Ruby, and I’d be
happy to help with the implementation.

My initial thought was to create something like an SubclassableTreeModel
whose C implementation was simply calls through to a ruby subclass.
Would that be a viable approach?

bye
John


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


#7

My initial thought was to create something like an SubclassableTreeModel
whose C implementation was simply calls through to a ruby subclass.
Would that be a viable approach?

That sounds good to me! But how would the C methods in the
SubclassableTreeModel delegate to the ruby methods?

All the best,
Andrew


#8

i also use treemodels to view mysql data,
i copy the data into the treemodel (sync the data back to the sql server
on treeview events like destroy and stuff), and let the treemodel do the
sorting and filtering (on user events)
and i tested it on different scenarios, and my conclusion was that this
method is a lot faster than doing the filtering and sorting with the
mysql server, that’s over 3000 rows.
i think your implementation might bring a bit of confort to the ruby
coders in the same situation, but for larger amount of data they’ll have
to go the old way.

and of course i’m also very interested in your solution.


#9

Looks like we can base this around the following C code:

rb_funcall(self, rb_intern(“ruby_method_name”), number_of_args, args…)

within each ‘subclassable’ method, to call ruby code. No idea how to get
the “self” reference, though (ie. the Ruby object that we should
delegate to), from within the C subclass - any ideas? There must be a
way…

It would be great, in the long run, to produce a few handy classes like
subclassableWidget, SubclassableCellRenderer, SubclassableTreeModel etc.

Best,
Andrew


#10

Hi,

From: Alex removed_email_address@domain.invalid
Date: Sat, 7 Jul 2007 12:24:41 -0700

Hmm, what are the technical difficulties?

As always, one big problem is memory management.
If we represent nodes of treemodel as ruby objects, we need to manage
them with ruby’s garbage collection. But they are refered by
GtkTreeIter and we cannot keep track of the usages of GtkTreeIter.
After all, I don’t know the precise condition when we should protect a
node from garbage collection and when we shouldn’t.

Another reason is that we don’t have satisfactory basis for
implementing gobject types in ruby yet. I think we need it first
before supporting custom treemodel.

– Masahiro S.


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


#11

On Sat, 2007-07-14 at 02:57 +0900, Masahiro S. wrote:

Hmm, what are the technical difficulties?

As always, one big problem is memory management.
If we represent nodes of treemodel as ruby objects, we need to manage
them with ruby’s garbage collection. But they are refered by
GtkTreeIter and we cannot keep track of the usages of GtkTreeIter.
After all, I don’t know the precise condition when we should protect a
node from garbage collection and when we shouldn’t.

I’m thinking of the Java Swing TreeModel interface. A TreeModel subclass
would have it’s own (Ruby) storage mechanism for objects in the tree.
Say the storage mechanism used Array instances. Any nodes in the tree
would end up as items in arrays, which I think would take care of one
part of the garbage collection issue.

The other part could possibly be to have Ruby iterator objects that act
as wrappers for GtkTreeIter objects. That way, if a ruby node has been
removed from the TreeModel’s storage mechanism but an iterator still
refers to it, the iterator will be bound to a Ruby object and so it
won’t be garbage collected until the iterator object is ready to be
garbage collected.

Another reason is that we don’t have satisfactory basis for
implementing gobject types in ruby yet. I think we need it first
before supporting custom treemodel.

I won’t make a suggestion here, because I don’t know enough about how
gobject works :wink:

bye
John


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


#12

On Fri, 2007-07-13 at 12:20 +0200, Andrew Whyte wrote:

My initial thought was to create something like an SubclassableTreeModel
whose C implementation was simply calls through to a ruby subclass.
Would that be a viable approach?

That sounds good to me! But how would the C methods in the
SubclassableTreeModel delegate to the ruby methods?

There would need to be a GTK object which has (in the loose sense) a
ruby object. Any calls to the GTK object GtkTreeModel methods would
forward to specific methods in the ruby object, using the normal Ruby
method call mechanism.

Maybe a more idiomatic way to do it would be that the GTK object is
wrapped in a Module, and a class that wants to be a TreeModel includes
the relevant module and then implements the methods expected by the GTK
object.

Does that make sense?

bye
John


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/