Developer's Guide: The Design of Skencil

Introduction | Developer's Guide | General Remarks

# The Design of Skencil

Skencil 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 Skencil uses this fact to implement some time critical functions and Python objects in C.

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

User Interface

  Skencil currently uses the Tk Toolkit via the Tkinter module from the standard Python library. Skencil 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).

  Skencil 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

  Skencil 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

  Skencil has classes and functions for reading drawings in several formats (well, just three as of this writing). Skencil of course defines its own special format and can read and write this. In addition, there is currently partial support for reading and writing SVG and Adobe Illustrator (AI) files, just to name a few.

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

Miscellaneous

  There are a variety of support modules that provide objects representing 2D points/vectors, rectangles, affine transformations, fonts and font-metrics, or code to handle postscript files and a generic method passing mechanism.

Skencil 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