Motorcycle Adventures and Free Software
Henri Bergius
Biker, free software consultant, neogeographer

See also my JavaScript blog, The Universal Runtime

This entry was posted on 2011-12-16 16:04:16 UTC in 47° 48.570 N 13° 3.300 E Salzburg, AT to

Using CoffeeScript for GNOME development

In Suski's blog I saw a question on whether developing GNOME apps would be possible in CoffeeScript. The answer is yes. I wrote a quick example back in Desktop Summit:

# GObject Introspection APIs are available from imports.gi.Modulename
Gtk = imports.gi.Gtk

# For GNOME 3.2+ this should be Gtk.init null, 0
Gtk.init 0, null

win = new Gtk.Window
type: Gtk.WindowType.TOPLEVEL
win.set_border_width 10
win.connect "destroy", (widget) ->
Gtk.main_quit()

button = new Gtk.Button
label: "Hello, world"
button.connect "clicked", ->
button.set_label "Bar"
win.add button

button.show()
win.show()

Gtk.main()

Gjs doesn't run CoffeeScript directly, so you need to convert this before running:

$ coffee -c window.coffee 
$ gjs window.js

You should see something similar to:

gjs-coffee-example.png

Sponsored links

save money using, phone card

Comments:

There have been no comments so far.

Post a comment:

You need to be logged in to publish comments.

Back