up with PyGUI!

Carlos Ribeiro carribeiro at gmail.com
Wed Sep 29 14:16:26 CEST 2004

On Wed, 29 Sep 2004 17:52:35 +1200, Greg Ewing
<greg at cosc.canterbury.ac.nz> wrote:
>    class MyWindow(Window):
>      def __init__(self):
>        instance b1(Button):
>          size = (40, 40)
>          text = "b1"


I don't know how far have you advanced with your own system. I'm
writing my own, but I decided to focus on HTML generation -- it's a
templating system, but designed to work entirely in Python. But the
basic design can be used for other types of application - for example,
generation of Qt or wxPython code.

I've posted some code last week, but I have improved greatly since,
and solved some problems. There are a few issues where I still haven't
found a satisfactory solution. Here's a sample of code I'm working

class Page(HtmlPage):
    class html_head(HtmlHeader):
        copyright = trimdocstring("""
                    Web Application Framework
                    ABCD/TS - Abusing Class Declarations Templating System
                    (c) 2004 Carlos Ribeiro
                    carribeiro at gmail.com
        title = 'Web Application Framework'
        style = CSSStyleSheet
    class html_body(HtmlBlock, Tag('body')):
        class main_document(TwoColumnLayout):
            class head(PageHeader):
                title = ''
            class nav(NavigationPane):
                class menu(HtmlMenu)
                    id = 'navmenu'
                    options = [("Usuários", "/usuarios"),
                        ("Tarefas", "/tarefas"),
                        ("Notas fiscais", "/notasfiscais"),
                        ("Estoque", "/estoque"),
                        ("Sobre o sistema", "/sobre"),
            class content(DocumentPane):
                text = ''

class AboutPage(Page):
    class html_head(Page.html_head):
        title = 'About this system'
    class html_body(Page.html_body):
        title = 'About this system'
        class main_document(Page.html_body.main_document):
            class content(Page.html_body.main_document.content):
                text = trimdocstring("""
                    <h2>Templating system</h2>
                    This is a templating system based on Python
declarations. The main
                    advantage is the possibility to express complex
data structures using
                    code-driven intelligence. The system is fully
object-oriented, supports
                    inheritance, and allows for easy modularization
and code reuse.

All interesting classes shown above are descendants from a single
HtmlElement class, which declares a method 'text'. The following
sequence renders the AboutPage:


One thing that still bothers me is that I need to redeclare the full
path to the nested classes when I want to override some behavior, as

...         class content(Page.html_body.main_document.content):

That was the best solution that I could find. I tried to use
descriptors to write this code in a slightly simpler way, but couldn't
manage to make them work as wanted, and I'm not even sure if it's

The resulting html code is being designed for *readability* first, and
is properly indented, which makes easier to debug the system at this
stage. I'm keeping good distance of premature optimization at this
point. It's my intention, in the future, to provide a way to generate
native applications from the same templates, within a 'browser-like'
environment but using native controls for data editing whenever

Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com

More information about the Python-list mailing list