# Gtk + database tutorial

**URL:** <https://www.ruby-forum.com/t/gtk-database-tutorial/117523>\
**Category:** Ruby-Gnome 2\
**Created:** [October 17, 2007, 6:04pm UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523 "2007-10-17T18:04:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [October 17, 2007, 6:04pm UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/1 "2007-10-17T18:04:57Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) ]------------------+  
| |  
| Mobile:(+36 20)356 9656 |  
| |  
± “Olyan lángész vagyok, hogy poroltóval kellene járnom!” -+

---

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [October 17, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/2 "2007-10-17T18:40:07Z")

</div>

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/](http://www.linagora.com/societe/nous_rejoindre/)  
“Ce n’est pas le logiciel qui est libre, c’est vous”

---

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [October 18, 2007, 3:56am UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/3 "2007-10-18T03:56:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [October 18, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/4 "2007-10-18T17:41:45Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) ]------------------+  
| |  
| Mobile:(+36 20)356 9656 |  
| |  
± “Olyan lángész vagyok, hogy poroltóval kellene járnom!” -+

---

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [October 18, 2007, 7:05pm UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/5 "2007-10-18T19:05:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [October 18, 2007, 9:27pm UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/6 "2007-10-18T21:27:54Z")

</div>

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%](http://codebrowse.launchpad.net/~ian-mcintosh/luz/trunk/annotate/ian%25)  
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

---

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [January 25, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/7 "2008-01-25T23:34:12Z")

</div>

Where exist ObjectListStore I want use it

---

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [October 18, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/8 "2007-10-18T19:38:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KONTRAS\_Gergely](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9e8a1a/32.png) [@KONTRAS\_Gergely](https://www.ruby-forum.com/u/KONTRAS_Gergely)\
**Post date:** [January 26, 2008, 12:44am UTC](https://www.ruby-forum.com/t/gtk-database-tutorial/117523/9 "2008-01-26T00:44:37Z")

</div>

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

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