I want LISP but I don’t want LISP

LISP basically has everything I as a developer want. But somehow I just can’t bring myself to touch it with a ten-foot-pole. Maybe it’s the parenthesis ridden syntax, maybe it’s the functional paradigm, maybe it’s its mostly academic nature. Maybe it’s my preference for curly-brace languages, or my preference for object orientation. Maybe it’s those weird cons data structures and the equally weird car, cdr functions. Like LISP, Haskell and Erlang scare me. They have awesome concepts, programs can be mathematically proven to be correct, support parallel computing and more. Yet it’s that very mathematical nature that makes me uneasy. Math never held much fun or interest for me. It has always been a chore, a means to an end.
Read more of this post


ImageSlicer Progress…

The past two weeks I have been working on a small tool to slice images using Python, PIL and pygtk. I decided to use Glade for the user interface, and it’s great. It really simplifies coding GTK applications and lets me concentrate on handling events, writing callbacks. It is still necessary to know how GTK works to correctly create the interface and define signals and callbacks. But after that I just load the Glade XML file, fetch those widgets I’m really interested in (windows, buttons and menuitems mostly), connect handlers to the signals, show the main window and enter GTK’s main loop. As long as the widget names and signal names stay the same, I can now start trying out changing the user interface.

I want the ImageSlicer let the user create, move and resize rectangles over an image. I also wanted the display of the image and the rectangles to be zoomable. Since there isn’t any GTK widget that remotely does something like that, I had to come up with something. At first I thought, I’d just use some canvas component. I started by playing around with GnomeCanvas, but it didn’t have many features I needed and did have many features I didn’t need. Then I tried out GooCanvas, which at first seemed to be just what I needed. But then I noticed, it really isn’t suited to displaying images and working with them on a pixel level. While GooCanvas supports zooming, it will interpolate (blur, smooth) images and draw rectangles between pixels (which also blurs them). This is, because it really is meant to be used for displaying and modifing vector graphics. So I went back to creating my own solution.

I use a GtkDrawingArea for displaying the image and slice rectangles. I store the image as a GdkPixbuf, and draw only the visible area. I get the the visible area from two GtkAdjustments (one for the x axis, one for the y axis) which I also use for scrolling in a GtkScrolledWindow. For the zoom scale I also used a GtkAdjustment. I recalculate the visible width and height whenever the window size or the zoom changes and store that in the page_size property of the corresponding GtkAdjustment. I use GdkRectangles for the slice rectangles but I’ll probably change that to something else, since I also need to store more data with the slices like name, image type and options for the image type.

So far I have image loading, scrolling, zooming and creating slice rectangles done, but I’m having trouble with getting the pixel offset of the pointer correct once zoomed in. This results in some strange, wobbly behaviour when dragging or resizing slice rectangles. Once I have that fixed, I can continue with creating a user interface for setting properties of slices.

I really want to add support for gimp files (xcf), so the user can load a gimp file and enable/disable layers. I also want some way of monitoring images for changes, so they can be reloaded if they’re edited. I already thought up a basic undo/redo system but I’ll need to get a bit further along with the other issues before I know if it will work well.

Lua Userdata with user data

Sometimes I play around with Lua, and recently I decided it’s time to learn how to write modules in C/C++. I implemented a simple userdata with a few methods and property getter/setters. And while writing the Lua script to test the module, I noticed you could not set arbitrary properties on the userdata (of course not, it’s a userdata not a table). Then I started investigating, how this might be achived, yet every time I thought I had a solution it turned out it wouldn’t work, for some reason or other…

I was just about to give up, when I noticed a simple little paragraph in the Lua docs:

Pops a table from the stack and sets it as the new environment for the value at the given index. If the value at the given index is neither a function nor a thread nor a userdata, lua_setfenv returns 0. Otherwise it returns 1.


I knew about this function and its getter equivalent (lua_getfenv) but always assumed the “f” in the name stood for “function”. I have no idea what it might stand for, but once the implication of the emphasized part hit me, it became clear! Every userdata can have its own environment table! And with two simple metatable functions for “__index” and “__newindex”, this environment table can be exposed to the Lua side and user properties/methods could be set!

And just after I had it implemented, I found a page in the lua-users wiki where it shows how to do just that (although it is not the main focus on the page)… I hate when that happens. :-(

PHP project and library structure tips

I thought I’d share some tips on working on larger projects, and how to name and structure stuff.  Most importantly, whatever conventions you come up with, they should be as simple as possible, but no simpler.  If these conventions and structures are too complicated, no one (not even yourself) will adhere to them and everything will revert/degrade into one big mess in a heart beat.  However, they shouldn’t be too simplistic (constrictive) to keep you from extending them (ie. rules like: only one depth of namespaces, only 20 characters for class names.)

Read more of this post

What’s going on?

I have got two unfinished entries – one about JavaScript and another about font usage on the web – but I just moved into a new apartment. So, once I have settled in the new apartment, I’ll finish those up.

It’ll probably be a while before I sit down and work on the image slicer tool… there is just so much to do after a move *sigh*

Linux and Image Slicing

A while ago I created a new page on this blog for Xfwm theming tools. Basically I wanted to have one place for all the scripts and tools that make creating Xfwm themes easier.

Ever since then I have been mulling over quite a few ideas I had. And I always seem to come back to the same basic problem. Whenever you want to create a theme based on individual images (pixbuf theme in GTK slang), you just don’t have the right tools, at least on Linux.

The most common way to create a pixbuf theme is by first creating a single large mock-up that captures the basic concept. Then that mock-up is sliced up into individual images. And at this point the tool chain on Linux is broken, as there is no easy to use, yet flexible program to slice up images.

Read more of this post

Returning Arrays from __get

Sometimes you have a class that has magic properties, ie. it implements property access overload methods. And you might have had the problem that one of these magic properties holds an array. And you just can’t seem to update that array what-so-ever.

Read more of this post