Prev Up Next
Introduction Developer's Guide General Remarks

The Design of Sketch

Sketch is written almost completely in Python, an object oriented interpreted programming language. Python can easily be extended by modules written in C to increase performance and Sketch uses this fact to implement some time critical functions and Python objects in C.

The source code of Sketch can be divided roughly into these parts:

User Interface

Sketch currently uses the Tk Toolkit via the Tkinter module from the standard Python library. Sketch only uses some generic widgets like buttons, menus and scrollbars and none of the more sophisticated widgets like Tk's Text or Canvas widgets. The main widget where the drawing is displayed is a Tk widget that is almost entirely implemented in Python using a C-module that provides GCs, Pixmaps, Fonts etc as Python objects (This module is heavily based on the Xt module).

Sketch also has some classes that provide a more abstract interface to generic GUI elements like buttons and menus that hopefully make it relatively simple to switch to another toolkit. In fact I already switched toolkits once, from Xt/Athena to Tk, which was simpler than I had expected...

Graphics Devices

Sketch defines several classes for drawing into a window or into a PostScript file that share a common, generic interface. This allows us to use the same code for drawing on the screen and for printing.

Document- and Graphics Objects

These objects represent entire documents and the parts thereof in an abstract way. This representation is independent of any particular output device or operating system.

File IO

Sketch has classes and functions for reading drawings in several formats (well, just three as of this writing). Sketch of course defines its own special format and can read and write this. In addition, there is currently partial support for reading XFig files and Adobe Illustrator (AI) files. Many common drawing programs for MS Windows can export drawings in Illustrator format. Two examples of this file format can also be found in ghostscript's examples directory as and (Sketch can read these).

For reading bitmap graphics Sketch uses the Python Imaging Library so that it should be able to read everything that this library can read.


There are some modules that provide objects representing 2D points/vectors, rectangles, affine transformations, fonts and font-metrics, etc.

Sketch uses a variation of the model/view/controller concept. The document and graphics object classes form the model which represents the drawing in a device independent way and which can be manipulated through a specific set of methods. The class SketchCanvas serves both as the main view and controller. It manages a window graphics device that is used to display that drawing and it accepts user input in the form of mouse and keyboard events and translates them into method invocations on the document object.

Introduction Developer's Guide General Remarks
Prev Up Next