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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: