Python code hidden in leo.py 3.1

Edward K. Ream edream@tds.net
Thu, 25 Jul 2002 20:07:45 GMT


leo.py 3.1 contains Python code that may be of interest to some Python
programmers.  This is the first and last time I shall be mentioning this
code on comp.lang.python.announce.

----- c2py.py

This script does much of the grunt work of converting from C/C++ syntax to
Python syntax.  It was surprisingly effective in converting Leo from C++ to
Python.  These scripts don't need to be perfect to save a _lot_ of work.
And of course you can always add your own improvements...

As written, the script converts an entire Leo tree.  It would be easy to
write an entry that would convert plain text files, but it's probably best
to import the files to be converted into Leo first.  That way the slow
algorithms in c2py.py will work on smaller pieces of text.

----- disStats.py

This code gathers and prints static statistics about Python bytecode.

----- Tkinter utilities in leoUtils.py

w,h,x,y = get_window_info(top) returns the width, height, x and y positions
of the Tkinter window top.

center_dialog(top) centers the Tkinter window top on the screen.

w,f = create_labeled_frame(parent...) creates a labeled Tkinter window as a
child of parent.  The caller packs widgets into f to create the frame.
create_labeled_frame uses a grid to create the labeled frame, so care is
sometimes needed not to mix the grid and packing managers improperly.

leoUtils.py contains many other routines that may be of interest, or not,
including an Python version of the Sherlock tracing package.  About the only
advantage of trace(x) over print x is that trace x also prints the name of
the function in which the trace statement appears.

----- Font dialog

leoFontPanel.py puts up a Font dialog.  This dialog dispenses with the
typical "sample" pane and instead changes text immediately directly on the
screen.  Comes with Ok, Cancel and Revert buttons.  IMO, this dialog is much
better than the sample Tk/Tkinter font dialogs available on the web.

----- Syntax coloring code

leoColor.py contains code to syntax color Tk.Text widgets for a variety of
languages.  Supporting a new language here is mostly a matter of adding
another table of keywords.

----- Tree code

Leo supports powerful outlining features, including clones.  Clones are
challenging to implement, to say the least.  The vnode and tnode classes,
defined in leoNodes.py, represent the underlying data.  vnodes represent
nodes on the screen.  vnodes may share text, the tnode class is the "unit of
sharing" of such text.  The leoTree class draws the tree and handles events,
including dragging nodes around the screen.  The Commands class calls the
vnode, tnode and leoTree classes to handle menu commands.  In Smalltalk's
model/view/controller terminology, the vnode and tnode classes are model
class, the leoTree class is a view class, and the Commands class is a
controller class.

How to get this code
--------------------

All of this code is contained in the distribution of leo.py 3.1.  All Python
files are derived from LeoPy.leo.

leo.py itself requires Python 2.2 and tcl/tk 8.3 or above.  The scripts
above will probably work on earlier versions of Python.

What is Leo?
------------
 - A programmer's editor, an outlining editor and a flexible browser.
 - A literate programming tool, compatible with noweb and CWEB.
 - A data organizer and project manager. Leo provides multiple views
   of projects within a single outline.
 - Fully scriptable using Python. Leo saves its files in XML format.
 - Portable. leo.py is 100% pure Python.
 - Open Software, distributed under the Python License.

Links:
------
Leo:      http://personalpages.tds.net/~edream/front.html
Home:     http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:      http://sourceforge.net/cvs/?group_id=3458

--------------------------------------------------------------------
Edward K. Ream   email:  edream@tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------