pydrawing

Anonymous Eduardo Tarasiuk
Attachments
code-example7.gif (119020 bytes)
example1.gif (179833 bytes)
example2.gif (132541 bytes)
example2.jpg (89207 bytes)
example3.jpg (118888 bytes)
example4.jpg (107872 bytes)
example5.gif (43273 bytes)

What is pydrawing ?

pyDrawing is a generic 2D Graphic Library for Python, to be used to draw block diagrams in a Tkinter Canvas.

You can draw a block diagram using the following graphic primitives:

  • Rectangles and Constant Aspect Ratio Rectangles
  • Squares
  • Circles
  • Ellipses and Constant Aspect Ratio Ellipses
  • Equilateral, General and Constant Aspect Ratio Triangles
  • Lines
  • Regular Polygons (5-12 sides)
  • Connectors (used to connect the graphic primitives)
  • Splitter (split a full connected connector)

Each Primitive type is a different Python class and includes all the methods necessary to allow interactive modifications as moving, resizing and connecting it to others primitives.

For example, the command line:

prim2=Square(screen,x0,y0,l)

Will create a Square which lower left corner is (x0,y0) and size is "l".
This Square can be re sized and moved in the Tkinter canvas without writing any other extra command, just play with it.

Some Highlights :

  • The Primitives can be displayed on a canvas with a background grid or without it.
  • The Primitives can be displayed with or without their connector handlers (print view)
  • Primitives can be freezed, i.e disable interactive modifications.
  • Primitives are drawn in World Real Number Coordinates (origin is in bottom left corner)

The library source is highly commented and I hope that was written clearly for whom is wishing to add more functionality.
My humble request is to receive such pieces of code, so I will be able to publish them under your name in this site, for all.

The library is highly configurable and I think highly expandable.

Two demo programs are included to show the pydrawing major abilities:

  • pydrEdit : can create and edit a pyDrawing diagram and save it in a file.
  • pydrView - can visualize a saved pydr previously saved file.

For now, the only supported formats for save are: postscript and pydr
pydr is a file that simply includes pyDrawing commands that will be replayed inside pydrEdit and pydrView, and can be used to learn how the library should be used.

Python Version

The Library and demos were developed in Windows XP and it was tested on Windows 7 and Windows 2008R2 using Python 2.7.1, but it should be trivial to make the required changes to make it run on Linux
I used the following line on the source modules:

from __future__ import print_function,division,nested_scopes

To make it compatible for 3.x