# Sample desktop app

**URL:** <https://www.ruby-forum.com/t/sample-desktop-app/149365>\
**Category:** wxRuby\
**Created:** [September 24, 2008, 4:55am UTC](https://www.ruby-forum.com/t/sample-desktop-app/149365 "2008-09-24T04:55:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nmotter](https://www.ruby-forum.com/u/nmotter)\
**Post date:** [September 24, 2008, 4:55am UTC](https://www.ruby-forum.com/t/sample-desktop-app/149365/1 "2008-09-24T04:55:29Z")

</div>

Hi all,  
I’m trying to develop a desktop application, and since I’ve done a fair  
bit of work with RoR before, I figured ruby is a good way to go about  
it. My application will be largely database driven.  
I’m looking for a sample desktop application which I can learn a few  
things from. Obviously the less restrictive the license the better, and  
it’d also be good if I can find one which is database driven. Google  
seems to provide very little… or at least, the results are cluttered by  
RoR things. I was wondering if anyone in the group knows of any.  
Nathan

---

<div class="post-metadata">

**Author:** ![nmotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nmotter](https://www.ruby-forum.com/u/nmotter)\
**Post date:** [September 24, 2008, 9:00am UTC](https://www.ruby-forum.com/t/sample-desktop-app/149365/2 "2008-09-24T09:00:22Z")

</div>

Hi Nathan

Nathan Macinnes wrote:

> I’m trying to develop a desktop application, and since I’ve done a fair  
> bit of work with RoR before, I figured ruby is a good way to go about  
> it. My application will be largely database driven.  
> I’m looking for a sample desktop application which I can learn a few  
> things from. Obviously the less restrictive the license the better, and  
> it’d also be good if I can find one which is database driven. Google  
> seems to provide very little.. or at least, the results are cluttered by  
> RoR things. I was wondering if anyone in the group knows of any.  
> There’s a list of some wxRuby applications on the wiki:  
> [http://wxruby.rubyforge.org/wiki/wiki.pl?OnlineCodeExamples](http://wxruby.rubyforge.org/wiki/wiki.pl?OnlineCodeExamples)

Of those, Weft QDA is a database (SQLite) backed application, and has a  
public domain licence.  
[http://rubyforge.org/projects/weft-qda/](http://rubyforge.org/projects/weft-qda/)

It uses its own ActiveRecord-like persistence layer, with an Observer  
pattern to update the relevant GUI elements as changes to the database  
are saved. I’d recommend you look at the code in Subversion as its a  
better model for designing database apps.

A disadvantage for study purposes is that its a relatively complex app -

> 15k lines of ruby code, with a schema running to several hundred  
> lines using triggers and views:  
> [http://weft-qda.rubyforge.org/svn/trunk/weft-qda/share/schema.sql](http://weft-qda.rubyforge.org/svn/trunk/weft-qda/share/schema.sql)

A simpler example to look at might be Ruby SQLite GUI, which is a  
desktop browser for SQLite databases:  
[http://rsqlitegui.rubyforge.org/](http://rsqlitegui.rubyforge.org/)

It uses Ruby-GTK2, rather than wxRuby. GTK2 is another good GUI library,  
long established and with a wide range of widgets. However IMHO it works  
considerably less well on Windows and OS X than it does on Linux,  
whereas wxRuby is equally good on all three.

hth  
alex

---

<div class="post-metadata">

**Author:** ![nmotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nmotter](https://www.ruby-forum.com/u/nmotter)\
**Post date:** [September 24, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/sample-desktop-app/149365/3 "2008-09-24T15:46:23Z")

</div>

Just be sure to organize your code from the beginning. It’s too easy to  
write spaghetti code in a scripting language. Stick with your MVC  
roots.  
It’s useful with any kind of application development, not just the web.

But also, don’t try to mimic rails, there’s a lot of ways to implement  
MVC,  
not just the way rails does.

-jk

---

<div class="post-metadata">

**Author:** ![nmotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nmotter](https://www.ruby-forum.com/u/nmotter)\
**Post date:** [September 25, 2008, 12:59am UTC](https://www.ruby-forum.com/t/sample-desktop-app/149365/4 "2008-09-25T00:59:20Z")

</div>

Nathan Macinnes wrote:

> John, thanks for the heads-up. I do plan on sticking to MVC as much as  
> possible… I’m not quite sure what that looks like yet though.

I think John’s advice was sound. I’ve never sat down and read a book  
about MVC and I’m not a professionaly programmer, though in a previous  
life I did a lot of web programming in Perl. But I can say what enabled  
Weft QDA to go from a specialised and limited program to something to  
which its now quite extensible - I mean, that I can add quite radical  
new features to without breaking lots of stuff. It probably roughly fits  
an MVC model…

M: your non-GUI classes stand alone and can be unit-tested. So you know  
that the objects you’re going to display (in Weft, Documents,  
Categories, Text Fragments, etc) can be created, changed, saved and  
restored without problems. This means you don’t waste time clicking  
round in a GUI to fix issues with databases or how they translate to  
ruby classes.

V: Your GUI code is strictly separate - in Weft, it’s all in a wxgui  
directory. All the GUI code deals with layout (whether that’s through  
XRC, some kind of sugary syntax, or bog-standard wxRuby code - Weft uses  
all three) and event handling. The sort of logic that deals with saving  
non-GUI objects, and updating related objects should be outside the GUI  
code. So you say:

def on\_click\_ok  
document.title = gui\_text\_box.value  
document.save  
rescue BadDocumentTitleError  
display\_gui\_error\_message “The title was invalid”  
end

The validation, and the mechanics of how the object is saved are hidden  
from the GUI code. It just has to know how to deal with errors.

The biggest jump for Weft was separating the GUI code that made changes  
to objects, from the GUI code that updates the state of objects.  
Otherwise every place that changes a database object has to know about  
every place that that object might be displayed. This quickly becomes  
impossible, and you get endless problems with stale/inconsistent object  
data being presented to the user.

One way of tackling this is to use Observer: when an object is saved,  
all interested GUI representations are informed and deal with the new  
state of the object (eg a new title) accordingly. Another is using  
wxRuby’s UpdateUIEvent - this is handy when, for example, you want menu  
items to be enabled or disabled based on a criterion, but don’t want to  
have to keep track of that every time it changes, just when the relevant  
menu item is displayed.

So, if you want a “Save” menu item that is only active when there are  
unsaved changes in a model object called document, you can do something  
like

evt\_update\_ui(Wx::ID\_SAVE) { | e | e.enable(true) if  
document.has\_unsaved\_changes }

hth  
alex

---

<div class="post-metadata">

**Author:** ![nmotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nmotter](https://www.ruby-forum.com/u/nmotter)\
**Post date:** [September 24, 2008, 4:54pm UTC](https://www.ruby-forum.com/t/sample-desktop-app/149365/5 "2008-09-24T16:54:31Z")

</div>

Thanks for the help guys. Weft looks like a good option for me to use…  
and because it’s public domain, I can even use the code without any  
worries.

The Ruby SQLite GUI is a bit easier for me to get my head around, but at  
the same time, the code isn’t as well organised… I suppose for a  
smaller project it doesn’t matter so much. And you’re right about the  
Ruby-GTK2 point… I’d already decided I want to use wxWidgets because I  
use Linux but most of my target audience use Windows… and it wouldn’t  
hurt to make it work for Macs too.

John, thanks for the heads-up. I do plan on sticking to MVC as much as  
possible… I’m not quite sure what that looks like yet though.
