Introduction | Developer's Guide | General Remarks |
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:
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...
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.
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.
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 tiger.ps and golfer.ps (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 |