Griffon: the Quickly connection

Posted by: Andres Almiray on 01/28/2010
The following is but a preview of the capabilities exposed by the Griffon Gtk plugin. Ubuntu's Quickly is a desktop application framework inspired by Rails. It lets you build Gtk+Python applications in a snap (is there any doubt that a new breed of desktop application frameworks was needed?), in a similar fashion as Griffon lets you do it.

Quickly applications rely on XML formatted files to describe their UI elements. These files can be parsed using Glade. It turns out that the java-gnome supports parsing glade files too; and the griffon-gtk plugin relies on java-gnome to do its thing. I think you can guess where this conversation is headed ;-)

If you have an Ubuntu distro on your machine you can install Quickly by issuing the following command

$ sudo apt-get install quickly

Once you have Quickly installed you create a basic project with the following commands:

$ quickly create ubuntu-project foo
$ cd foo

If you inspect the contents of foo/data/ui you'll find all the UI definitions that can be parsed at bootstrap in order to construct the application's user interface. We're ready to build a Griffon application that will have the same user interface. The first step would be to create a Griffon application project.

$ griffon create-app quick

Now we copy all media files to the application's resource directory

$ copy $FOO_HOME/data/media/* quick/griffon-app/resources

Where $FOO_HOME points to the directory that contains the foo application created by the quickly command. Then we copy the target glade file, in this case we'll only copy the main window

$ copy $FOO_HOME/data/ui/FooWindow.ui quick/griffon-app/resources/foo-window.glade

Once the griffon-gtk plugin is installed (must be built from source at the moment, you won't find it at the central plugin repository) the View script is certainly very simple

The glade node instructs the builder to search for a glade file in the classpath, parse its contents and insert a widget whose id matches 'vbox1'. If you inspect the contents of foo-window.glade you'll find that vbox1 is the only child of the topmost window. However if you attempt to run the application right now you'll encounter a few errors. I have not located the source of the problem yet, it may be java-gnome's parsing capabilities or Quickly's version of glade xml, truth is you need to make some adjustments before getting some results. These are the required adjustments that need to be made on foo-window.glade
  1. change <interface> to <glade-interface>
  2. comment out <requires lib="gtk+" version="2.16"/>
  3. change all <object> elements to <widget>
  4. remove type="submenu" from every menu widget
  5. comment out the image1 element, we'll insert it on the Groovy side.
That last change is needed because java-gnome attempts to load background.png from a temporal directory instead of the application's resource directory. The last step would be to update the View script with the following code

Note how an image node is nested inside the glade node (which resolves to vbox1) so the actual image is embedded into vbox1; the only change left is to reorder the nodes on vbox1.

These steps take care of reusing Quickly UI definitions on a Griffon application. What about the application's logic? If only there was a way to run python code on the JVM (hint, hint ;-))

Keep on Groovying!

About Andres Almiray

Andres Almiray

Andres is a Java/Groovy developer and Java Champion, with more than 11 years of experience in software design and development. He has been involved in web and desktop application developments since the early days of Java. He has also been teacher of computer science courses in the most prestigious education institute in Mexico. His current interests include Groovy and Swing. He is a true believer of open source and has participated in popular projects like Groovy, Griffon, JMatter and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member and current project lead of the Griffon framework. He blogs periodically at http://jroller.com/aalmiray. You can find him on twitter too as @aalmiray. He likes to spend time with his beloved wife, Ixchel, when not hacking around.

More About Andres »

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 7
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 3
  • Automation Tools: Git, Hudson, Sonar
  • HTML5, Ajax, jQuery, Usability
  • Mobile Applications - iPhone and Android
  • More...
Learn More »

NFJS, the Magazine

December Issue Now Available
  • BDD and REST

    by Brian Sletten
  • Mocks and Stubs in Groovy Tests

    by Kenneth Kousen
  • Algorithms for Better Text Search Results

    by John Griffin
  • Knowns and Unknowns of Scrum and Agile

    by Brian Tarbox
Learn More »