[PYTHON MATRIX-SIG] ezmodule this week! (long message)
Tom Schwaller
tschwal@artinet.de
Thu, 20 Jun 1996 19:55:34 +0200 (MET DST)
Hi all,
I am just finishing a new Python module
ezmodule
which is a new GUI-Library with
an incorporated 3D-Api (very similar to OpenGL).
It only works on X-windows, but a nice thing about it is,
that you have all what you need in one very
compact module. The Tk C-API should be available this
year, which will finally blow out the Tcl Stuff
in the Tk-Module, the Netscape plugin for Tk is
also out soon, so why another toolkit?
Well, look at it. It's fast, easy to use
and very easy to install (compared to a
Tkinter, OpenGL (Mesa), Tk/OpenGL widget installation)
-rwxrwxr-x 1 et users 640870 Jun 20 16:33 ezmodule.so
For a toolkit which allows you to programm in 3D (eg.
with numerical Python, drawing surfaces with Gouraud shading)
building GUI's (including notebooks, drawing of ppm's),
that's really not bad. Setting callbacks and configuring
widgets is dead easy. Here's a simple example:
#!/usr/local/bin/python
from EZ import *
import sys
def shellCB(widget, bitmap, color):
global p2
widget.Configure(BITMAP_FILE=bitmap)
p2.Configure(FOREGROUND=color)
def main():
global p2
Initialize(1)
SetApplicationName('Test1')
f = Frame(label='NoteBook');
n = f.NoteBook()
p1 = n.NoteBookPage(label='RadioButtons')
p1.Configure(FOREGROUND="Blue", BACKGROUND="White")
p1.im = p1.Label()
p1.im.Configure(IMAGE='logo.ppm')
p1.f = p1.Frame('Classification')
p1.f.Configure(STACKING = VERTICAL, SIDE=LEFT, FOREGROUND="Red")
p1.f.l1 = p1.f.RadioButton(label='VeryCcool', value=0)
p1.f.l2 = p1.f.RadioButton(label='Cool', value=1)
p1.f.l3 = p1.f.RadioButton(label='Ok', value=2)
p1.f.l3 = p1.f.RadioButton(label='Bad', value=3)
p1.f.l4 = p1.f.RadioButton(label='Very Bad', value=4)
p2 = n.NoteBookPage(label='Pixmaps')
p2.Configure(FOREGROUND="Red", BACKGROUND="#007f6f")
p2.f = p2.Frame('Shells')
p2.f.Configure(BITMAP_FILE='xterm.xpm')
p2.f.Configure(STACKING = VERTICAL, SIDE=LEFT)
i=0;
colors=['Red', 'Green', 'Blue', 'Yellow', 'Cyan', 'Magenta']
for s in ['axp', 'blank', 'dec', 'sgi', 'sol', 'sun']:
b = p2.f.RadioButton(label='xterm-'+s, gid=1, value=i)
b.SetCallBack(shellCB, p2.f, 'xterm-'+s+'.xpm', colors[i])
i = i+1
p3 = n.NoteBookPage(label='Text')
p3.t = p3.TextWidget()
p3.t.LoadAnnotatedFile('text.txt')
p4 = n.NoteBookPage(label='Misc')
p4.f = p4.Frame()
p4.f.Configure(BITMAP_FILE='xterm-sun.xpm')
p4.b1 = p4.MenuButton(label='Menu')
p4.b2 = p4.Button(label='Quit')
p4.b2.SetCallBack(sys.exit)
#p4.s = p4.Slider()
f.Display()
f.MainLoop()
main()
Check
http://www.artinet.de/python/notebook.jpeg
to see how it looks like.
At http://www.artinet.de/python/EZWGL.tgz
you can get EZGL from
Maorong Zou
Department of Mathematics
The University of Texas at Austin
Austin, TX 78712
mzou@ma.utexas.edu
to have a first impression. I lost the annoucment.
Somewehere in comp.os.linux.apps last week
I used SWIG plus some handcoding for the callback and
widget configuration mechanism. Fortunately I
did not have to change the source code for it.
I had to llok quite a bit to find a solution,
but it wirks now. :-)
Last but not least, here's the REDME.
If you are interested, please tell me,
so I'm even more motivated to work on it...
____________________________________________________________
Python ez-Module: Version 0.1 (20 June 1996)
by Tom Schwaller (German Linux Magazine, tschwal@artinet.de)
Tested and developped on Linux 1.2.13 (ELF) with gcc 2.7.0
Available at http://www.artinet.de/python/ez.html
-----------------------------------------------------------------
This is my first version of the ez-Module, which interfaces the
C-library EZWGL, done by
Maorong Zou
Department of Mathematics
The University of Texas at Austin
Austin, TX 78712
mzou@ma.utexas.edu
This high-level library incorporates a GUI widget set for
the X-Window System (No cross platform tool, sorry!) and
Graphics commands, which resemble OpenGL a lot (except the
names and (in the actual version) missing texture mapping).
When I read the announcment I thought first, well another
GUI library but when I saw the first GUI/3D applications
with it on my screen, I immediately decided to write
a Python module (had some time :-), being quite busy for
the German Linux Magazine).
It wrapps nearly 280 C-Functions, so it seemed ideal for
testing SWIG (Simplified Wrapper and Interface Generator),
done by
David M. Beazley
Department of Computer Science
University of Utah
Salt Lake City, Utah 84112
beazley@cs.utah.edu
even though SWIG does not generate that kind of code I use
to write myself wrapping libraries. But you can get results
very fast, which is cool!
Not everything is quite polished at the moment, but it seems to
works. A challenge in writing the module things was
the Python translation of the Widget Configuration
p1 = n.NoteBookPage(label='RadioButtons')
p1.Configure(FOREGROUND="Blue", BACKGROUND="White")
which uses variable argument lists in the C-API. Also
the callback mechnism was not straightforward, but look
at the result to understand how it works:
def callback0():
print 'No Argument!'
def callback1(widget):
print 'One Argument:', widget
def callback2(widget, color):
print 'Two Arguments:', widget, color
a.SetCallBack(callback0)
b.SetCallBack(callback1, w)
c.SetCallBack(callback2, w, color)
Just use the same number of arguments as in the function
definition when registering the callback with SetCallBack.
I found that solution very appealing, when coding it.
Another problem was, that the header file ez.h is not ANSI
at the moment, so I had to write the declarations myself
for use with SWIG. As in the OpenGL module (Version 0.4 by
James Hugunin, David Ascher and myself to follow soon I hope)
I would have liked to use the matrix module, but I decided not
to at the moment, so everybody interested in this module can
give it a try. One will have to rewrite some of the 3d Graphics
functions in the ez-module for easier use. At the moment just
look at the OpenGL examples in the SWIG Distribtion to see how
they work.
Installation:
This should be fairly easy. First compile the EZ library libEZ.a
(You can do a shared library if you want) and make shure
your compiler finds it while linking. Then add the following
line to your Python Setup file (eg. after *noconfig*)
ez ezmodule.c -DALLOW_NULL -DEZ_MAIN -lEZ -lX11 -lXext
Install EZ.py somewhere in your PYTHONPATH. That's all.
Now you are ready for GUI and 3D Programming.
Testing:
Change to the examples subdirectory and try test.py
to see if it works (It really should!). You can also
take a look at notebook.jpeg in the same directory to
compare.
More examples (GUI/3D) to follow....
I have not tested everything at the moment (there are also
some small bugs in EZWGL itself, remeber it's a Beta Version),
so I hope to get some feedback. In my eyes ezmodule is very
well suited for medium sized Scientific applications (e.g take
a look at the isosurf example in the EZGL examples subdirectory,
which is taken from the Mesa distribution and rewritten
in EZGL and you will see what I mean). Displaying shaded
surfaces a la Matlab, Mathematica or Maple should be straightforward.
Any volunteers? In conjunction with Numerical Python this module
gives you a small and easy to use library for writing visualisation
tools (Installing Python with Tkinter, OpenGL and some
Tk/OpenGL widget is not that easy as it should be).
Have fun. Enhacments, comments and contributions welcome.
Please send them to tschwal@artinet.de to incorporate them
in the next release.
Thanks to all in the Python Community.
Special thanks to Maorong Zou, for contributung EZWGL.
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================