Some suggestion for a GUI kit evolved on Perl

Makhno mak at imakhno.freeserve.co.uk
Wed Apr 5 16:08:23 EDT 2000


I have written a GUI kit called Orchard. It is essentially a code library
with c-like functions which when called correctly will create windows,
buttons and other controls. I have had great success writing an interface
for this with Perl, and now I'm about to attempt a Python module.
One of the main points of Orchard is to keep the GUI-creation code as quick
and as neat as possible. Because Perl ignores whitespace, I have designed
the module in such a way so that the user can take advantage of this and use
whitespace indicate GUI structure. For example, the following code creates a
window with a button and a label in it:

Orchard::NewOrcWindow
(
    title=>"Test"
)->Add
(
    OrcVGroup
    (
        OrcButton,
        $label=OrcLabel
    )
)->Show;

As you can see, the window consists of a button and a label arranged
horizontally. A ref is kept to the label so it can be changed in later code,
and the window's Add() method returns a ref to the window so that Show() can
be called on it.

The problem I'm having is that Python has reserved whitespace (to indicate
program scope). Having looked at the Tk modules, I see it doing the
equivalent of:

window=Orchard.NewOrcWindow(title="Test")
button=OrcButton
label=Label
vgroup=OrcVGroup
window.add(vgroup)
vgroup.add(button)
vgroup.add(label)
window.Show

The problem is that this code stores references to everything (There's often
no need to keep references to buttons, it's looked after internally), it's
not as easy to read, and is easily complicated by GUI additions.

An alternative would be to use the style I've used with Perl; creating GUI
elements in the contructors of other GUI elements.

Orchard.NewOrcWindow(title=Text).Add(OrcVGroup(...

But without whitespace to help separate the elements I end up with a long
line that looks even worse than before. Separating the long line to several
smaller lines doesn't help readablity either (it just ends up all wrapped
round rather than structured). And the line has to be split up when I want
to keep a reference to the element anyway.

This complication is precisely the sort of thing I wished to avoid when
creating Orchard!
Does anybody have any advice as to how I could 'structure' Python code to
make neat, extendable GUI code? Essentially it comes down to what I can use
to indicate GUI structure. I can't use whitespace, so what can I use?

Thankyou.

(The Library and Perl interface are located here:
http://www.bebits.com/app/829 )












More information about the Python-list mailing list