Saturday, January 9, 2010

DBus and Etoys DBus interface

This post is a bit of a digression from Etoys and Sugar Activities interface. It describes a fun use of the Etoys and Squeak interface to DBus. DBus is a crucial link that allows Squeak and the underlying operating system interact at the low level. DBus bindings for Squeak are available on http://squeaksource.com/dbus.html, and can be used to interface with, for example, KDE or Gnome desktop components. Below you will find some screenshots of how DBus console in Etoys can manipulate DBus enabled components in an operating system.

If you want to experiment with Etoys DBus console, you can do it either on Sugar or Linux (technically any OS with DBus!). I figure most people reading this run Linux, so it may be more useful to show screenshots on Linux.

1. First, some terms, links, and installation notes:

1.1 DBus

DBus is a message bus system for inter-process communication. It is part of the Freedesktop specs. "It is supported on most POSIX operating systems, and a port for Windows exists" [1]. Some DBus links:

1.2 DBus interface for Squeak / Etoys

DBus bindings for Squeak was written by Jan Fietz of Impara and Bert Freudenberg and was sponsored by Viewpoints research for the OLPC project (see http://vpri.org/pdf/tr2009001_etoys4olpc.pdf and DBus for Squeak download site [4] http://squeaksource.com/dbus.html).

1.3 If you want to follow steps below hands-on, you need to have:
  • A DBus installed in Squeak image, or the latest Etoys image. You can install DBus into Squeak from the squeaksource link above. The simpliest way to obtain a DBus enabled image is to download Etoys-To-Go from http://squeakland.org/download/. One note: if you are on 64-bit Linux as I am, and want to use Etoys-To-Go, you have to modify Etoys-To-Go file etoys.sh and change the line defining CPU to be CPU=i686.
  • DBus server running in your OS. Without too much detail, if you are on Linux, you will have DBus. The screenshots below are from KDE.

2. Playing with Squeak/Etoys DBus Explorer (screenshots below from Etoys-To-Go and Linux KDE)


2.1 Start DBusConsole from Squeak/Etoys .

Open your Squeak/Etoys image (Squeak with DBus installed or Etoys-To-Go for simplicity, see above). Open a Workspace. In Etoys, enter Alt-Shift-W with cursor on Squeak desktop. The "World Menu" comes up. In the World Menu, click Open. The "Open Menu" will come up. In this menu, click "Workspace".In Workspace, type:

DBusExplorer new inAWindow openInWorld.




2.2 Highlight what you typed above and click do-it (CTRL-D in Etoys).

The DBusConsole will open, with two channels, a System bus and a Session bus:




2.3 Start konsole (terminal) from your KDE desktop:

(Other DBus-enabled desktops and applications can be manipulated)




2.4 org.kde.konsole and it's DBus interface shows in Etoys DBusConsole




2.5 Expand org.kde.konsole and navigate through konsole/mainWindow_1/actions/file_quit to see it's actions available via DBus.

Click on com.trolltech.QAction.trigger.



You have just called, from Etoys, "quit action" on DBus enabled operating system component, and the konsole disappeared (screenshot shown before action triggered).

2.6 Now start konsole again, and navigate to the konsole/mainWindow_1/setCaption

Click on set Caption, a popup window will show, asking to enter parameters. Write some text (I typed "Changed From Squeak") , and the konsole descritopn on top changes:





3. Obviously, the above is just a very simple application of what can be done from Squeak / Etoys via it's DBus interface. 

In principle, the DBus interface allows Squeak to write components and interface with components, on any DBus enables operating system! (similar to what can be done with, for example, Python)

Followers