Short gtkhtml2 tutorial

GtkHTML2 is a sorely undocumented widget. I still occasionally get trouble with it, and I know I'm not the only one. While its future may be in question — gtkhtml1 replacing it is still a possibility, because the Ximian hackers are committed to maintaining it — it's the HTML widget of choice for Gtk2/GNOME 2 hacking today. Few notes on it follow, examples in Python:

Initializing the widget.

# I assume there's a scrolledwindow widget called html_scrolled_window

# in a glade widget tree available

scrolled_window = glade_widget_tree.get_widget('html_scrolled_window')

htmlview = gtkhtml2.View()

document = gtkhtml2.Document()







IIRC doing things in the wrong sequence could cause segfaults.

There are a few signals that are useful to connect to:

# The document object's link-clicked signal is emitted when the user

# clicks a link.

document.connect("link-clicked", link_clicked)

# The document emits request-url when it needs data from an url.

# This is used for at least image fetching.

document.connect("request-url", request_url)

# Htmlview emits on_url (yes, this is spelled with an underscore

# unlike the two others) when the mouse is on an url. This is useful for

# displaying the URL somewhere.

htmlview.connect("on_url", on_url)

link_clicked receives the document object and link href as arguments. request_url receives the document, URL and a stream to write the data to. You should just fetch the data from the URL and write it to the stream. on_url receives the htmlview object and the url.

To display data in the widget, you need to write to the document object's stream. Something like this:


document.open_stream("text/html") # this is the only mime type recognized

document.write_stream("<html><head><title>title</title>" +



Note that this — I think — assumes ISO 8859-1 encoding. If you want something different, you have to specify that... wait for it, try to guess... with a meta header. There is apparently no API to do that; it must be specified in the document stream itself. So, for UTF-8, you want to add this to the head part:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

That's it. Now you can display HTML documents in your GNOME 2 applications. I'll probably write some more once I have something to tell about using CSS with gtkhtml2.

Article page

Tilde on the web

Mark Pilgrim expounds on the history of the tilde.

One of the unanswered questions was "When did it migrate into the world of web servers to provide a cheap and simple way of giving individual users their own web sites?"

You could just email Rob McCool or someone and ask them when this was introduced, but it's much more fun to play archaeologist, isn't it?

The CERN/W3C web server added support for ~username in 1994. Change notes (sorry, no direct link to the relevant version, they don't have anchors on that page) for version 2.15beta, released 11 February 1994, say this: "User-supported directories enabling URLs starting with /~username".

NCSA's web server is more difficult. The version history page first mention of the feature, I think, at version 1.0a4, but that was already a bug fix. It doesn't mention release dates, either. Grabbing the old versions from their ftp server, the feature wasn't in 0.5 but it was in 1.1 (obviously), which was apparently released somewhere around March 25th, 1994. At least that's the date of the newest files. Sadly none of the versions between those two are available for download.

Quick Googling didn't find version history for Plexus.

Switching to Google Groups,

Article page

Things we do for money

C#. .NET. And logistics automation.

I expect this will be a learning experience.

I suppose I should start investigating Mono now :-)

Article page


parser paragraphs

Some of Dale Chihuly's work is on display at Tampere. We were there last weekend, and went to see the exhibition.

It was incredible. It was beautiful.

Finland is a country of world-famous glass blowers (think Timo Sarpaneva), but Chihuly's work something the kind of which I've never seen before. The colours, the shapes, scale of the works were totally different from what I'm used to. No nordic minimalism in sight. A rowboat full of red glass objects shaped like tentacles, stars and things totally alien, reaching out in every direction, is such an full-on assault on your visual cortex that it leaves you breathless.

Article page