Gtk + database tutorial

Hi all!

I’d like to create a gtk2 application, which stores data in a database.
I guess it is not so trivial to combine treeview with databases.

Is there a tutorial for such a combination?

ps: if possible, I’d like to have a cross-platform (both linux and
windows) solution

thanks
Gergo


±[ Gergely K. [email protected] ]------------------+
| |
| Mobile:(+36 20)356 9656 |
| |
± “Olyan lángész vagyok, hogy poroltóval kellene járnom!” -+

Le Wednesday 17 October 2007 18:04:24 KONTRA, Gergely, vous avez écrit :

Hi all!

I’d like to create a gtk2 application, which stores data in a database.
I guess it is not so trivial to combine treeview with databases.

Is there a tutorial for such a combination?

See activerecord gem. It’s quite usefull for manipulating databases.
It’s a
part of rails, but can be used standalone.

ps: if possible, I’d like to have a cross-platform (both linux and
windows) solution


Loiseleur Michel / SLL
Groupe Linagora
27, rue de Berri / 75008 PARIS
Tel/Fax : 01 58 18 68 28 / 01 58 18 68 29
http://www.linagora.com/societe/nous_rejoindre/
“Ce n’est pas le logiciel qui est libre, c’est vous”

As of yet there is no way to make your own treemodel that uses an
activerecord or mysql based database back-end [in ruby-gtk2]

so what I’ve been doing is use active record, and have an column in my
treestore be a object from active record… i don’t actually display
this but when i update other columns in the treestore i also update
the data in the active record object.
it is lame to have to have redundant data, but it is nice to have the
ease of treeview as well as storage via mysql and the ease of use of
active record…

-Alex

First thanks for the answers.

But it is painful.

So there is no easy way (and documentation) to have a databased
application with treeviews?


±[ Gergely K. [email protected] ]------------------+
| |
| Mobile:(+36 20)356 9656 |
| |
± “Olyan lángész vagyok, hogy poroltóval kellene járnom!” -+

i think Alex’s solution is pretty cool. i’d have implemeted that, if it
had been enough for my project.
i have something similar now, but i realized i have to take a turn, and
implement network-distributed caching and event oriented data modifying
technology layers in between my mysql and gtk layers.
but for a smaller project i’ll probably go with the activerecord
solution.
go for that.

Re: one ruby object per row…

In one of my OSS projects I use what I call an “ObjectListStore” which
is essentially a Gtk liststore with one column that is a ruby object,
and procs for setting the other columns (from the object).

You can see it here:

http://codebrowse.launchpad.net/~ian-mcintosh/luz/trunk/annotate/ian%
40openanswers.org-20071017181738-geywltg6xc309r80?file_id=utilsobject_liststor-20070824200135-jcia9d4dmmq30mca-229

It’s based on SmartListStore which, together with SmartTreeView, make it
easy to define columns in a liststore/treeview and link the two.

Adding a column ends up looking like this:

class MyListStore < ObjectListStore
column :title, :type => :text, :from_object => Proc.new { |object|
object.title }
end

It’s not really library-quality yet but it might be useful to someone.
I’ll make it LGPL if anyone needs that.

Best,
-Ian

Where exist ObjectListStore I want use it

it would be cool if the render could actually render data from the
active record info instead of requiring a numerical column for
rendering, maybe a solution would be a custom renderer that could do
something like that? Then your model [liststore] could just have one
column…

-Alex

ObjectListStore and related files are part of Luz and available here:

http://codebrowse.launchpad.net/~ian-mcintosh/luz/trunk/files/ian%
40openanswers.org-20071017181738-geywltg6xc309r80