It’s possible to write Linux desktop apps using ruby! All you need is a distribution running KDE 4.2. I have Kubuntu running on my Macbook.
First off, get the Ruby bindings installed:
apt-get install ruby-kde4Next up, create a project directory for your Plasmoid. You can follow along with ‘Rakete’, which is my attempt at a Twitter client. The only thing Rakete does so far is to load and display an SVG.

you can call your root directory anything you like. In my case, it’s ‘application’ instread of ‘rakete’.
The `contents`directory holds the main files in a number of subdirectories. The most important of these is `code`, which, you guessed it, holds your ruby entry point, `main.rb`. `images` holds the SVG we want to render. You can create SVGs with a number of tools such as Adobe Illustrator or Inkscape (open source).
require 'plasma_applet'module Rakete
class Main < PlasmaScripting::Applet
enddef initialize(parent, args = nil)
super
end
enddef init
@svg = Plasma::Svg.new(self)
@svg.imagePath = 'widgets/rakete'
enddef paintInterface(painter, option, contentsRect)
@svg.resize(size())
@svg.paint(painter, 0, 0)
end`main.rb`should contain a class called `Main`, inside of a module named after your application. There are a number of callbacks you have to implement.
First off, you have ìnit`, which is called when the applet is first loaded. In here, we construct Plasma::Svg, which loads up rakete.svg.
SVGs are read from the svg.imagePath. This is relative to the $KDE_ROOT/apps/desktoptheme/default. KDE_ROOT varies from system to system. In the case of Kubuntu, it is /usr/share/kde4. So specifying an svg image path of
@svg.imagePath = 'widgets/rakete'will mean that the svg is searched for under
/usr/share/kde4/apps/desktoptheme/default/widgets/rakete.svgThis lies outside of your Plasmoid directory structure, so the SVGs you package have to be staged into the widgets directory. Currently I don’t see any way of automating this staging process, so you’ll have to copy the svg from images/ over to the widgets directory. I’ll post more info as soon as I get it.
UPDATE 25.12.08: you can reference images inside of your plasmoid directory structure in your code. it turns out that doing so is very easy. applets have a `package` method, which returns an object representing your plasmoid package. the package object can resolve the canonical filename of your svg like this:
@svg.imagePath = package.file_path("images", "rakete.svg")now you don’t need to worry about staging anything.
Next, create the metadata.desktop file:
[Desktop Entry]
Name=Rakete
Comment=an attempt at a better twitter plasmoid using ruby.
Icon=
Type=Service
ServiceTypes=Plasma/Applet
X-Plasma-API=ruby-scriptX-KDE-PluginInfo-Author=Rany Keddo
X-KDE-PluginInfo-Email=purzelrakete@gmail.com
X-KDE-PluginInfo-Name=rakete
X-KDE-PluginInfo-Version=pre0.1
X-KDE-PluginInfo-Website=http://playtype.net
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=MIT
X-KDE-PluginInfo-EnabledByDefault=trueReplace the pertinent field values.
Finally, you’ll want to run this thing. Run the following above the plasma root directory:
plasmapkg --upgrade applicationThis will install the Plasmoid on your system, or update it is already installed. Note that if you plasmoid root directory has a different name to “application”, you’ll need to cahnge the packaging command accordingly.
Finally, open the cashew in the top righthand corner of your desktop and select “Add Widget”. You’ll find your widget in the list.
As it stands, Plasma will sometimes crash when running this Applet. I’ll pass this information on to Richard Dale, the maintainer of the Ruby bindings. Hopefully he will be able to locate problems in the runtime, which is still in Beta1.
Richard was also super helpful in getting this example to run. Thank you Richard :-)
I’ll write more posts as I make progress with the Twitter client. You can find Rakete on Github.



