Dynamic HTML controls

A

Alan Harris-Reid

Hi,

Does anyone know where I can find any decent dynamically-constructed
HTML control classes (dropdown list, table, input field, checkbox, etc.)
written in Python. For example, for a HTML table I would like something
like...

MyTable = html_table() # instantiate class
MyTable.data = data_list # data-list (eg. cursor from SQL SELECT
statement)
MyTable.border = 1
MyTable.width = 987
MyTable.column_headers = col_headers # list or tuple of column-headers
table_code = MyTable.table.create() # returns string
containing appropriate HTML code

I don't mind writing my own classes (it will be good practice for me),
but I don't want to re-invent the wheel if it can be avoided.


TIA,
Alan Harris-Reid
 
A

alex23

Does anyone know where I can find any decent dynamically-constructed
HTML control classes (dropdown list, table, input field, checkbox, etc.)
written in Python.

There's pyWeb[1], which seems pretty close to what you're asking for:

mytable = table(align='center', cellspacing=0, cellpadding=3,
border=0)
mytable.add(tr(td("first row"), td("second row")))

While it might be a little heavier than what you're after, you should
also be able to do this with ToscaWidgets[2]. You'd probably have to
make basic widgets for the general HTML controls, but that would give
you a good head-start on writing your own, more complex widgets.
Widgets can be a compilation of Python, HTML, CSS & JS. (I used this
fairly extensively when it used to be called TurboWidgets)

If you want to roll your own from scratch, I'm a big fan of the html
[3] library:
... with h.tr:
... for header in ['column 1', 'column 2']:
... h.th(header)
... <table width="987" border="1">
<tr><th>column 1</th><th>column 2</th></tr>
</table>

1: http://www.freenet.org.nz/python/pyweb
2: http://toscawidgets.org
3: http://pypi.python.org/pypi/html/1.7
 
P

Pierre Quentel

Hi,

Does anyone know where I can find any decent dynamically-constructed
HTML control classes (dropdown list, table, input field, checkbox, etc.)
written in Python.  For example, for a HTML table I would like something
like...

MyTable = html_table()       # instantiate class
MyTable.data = data_list    # data-list (eg. cursor from SQL SELECT
statement)
MyTable.border = 1          
MyTable.width = 987  
MyTable.column_headers = col_headers    # list or tuple of column-headers
table_code = MyTable.table.create()           # returns string
containing appropriate HTML code

I don't mind writing my own classes (it will be good practice for me),
but I don't want to re-invent the wheel if it can be avoided.

TIA,
Alan Harris-Reid

Hi,

There are a few modules to generate HTML from Python : there is a list
at http://wiki.python.org/moin/Templating, section HTML Generation
packages

With HTMLTags, your example would be coded like this :

from HTMLTags import *
table = TABLE(border=1,width=987)
table <= TR(Sum([TD(header) for header in col_headers]))
for result in data_list:
table <= TR(Sum([TD(value) for value in result]))
print table

The operator <= means "add child" in the DOM tree structure, it avoids
having to nest tags with brackets

- Pierre
 
D

Diez B. Roggisch

Alan said:
Hi,

Does anyone know where I can find any decent dynamically-constructed
HTML control classes (dropdown list, table, input field, checkbox, etc.)
written in Python. For example, for a HTML table I would like something
like...

MyTable = html_table() # instantiate class
MyTable.data = data_list # data-list (eg. cursor from SQL SELECT
statement)
MyTable.border = 1 MyTable.width = 987 MyTable.column_headers
= col_headers # list or tuple of column-headers table_code =
MyTable.table.create() # returns string containing appropriate
HTML code

I don't mind writing my own classes (it will be good practice for me),
but I don't want to re-invent the wheel if it can be avoided.


Maybe toscawidgets is for you, it has a lot of additional features such
as static dependency declaration & injection.

For a form within a table, it would look like this:


table_form = TableForm("table_form",
fields=[SingleSelectField("foo", options=["A",
"B", "C"]), action="/some/action", method="GET")


table_form.render(dict(foo="B"))


Diez
 
M

Michel Claveau - MVP

Hi!

I had write PLUIE, for use DHTML as GUI:
http://www.ponx.org/ponx/guie.htm
But it is not a good answer to your problem. Sorry.

Nevertheless, there are several functions & methods
for generate DHTML objects (and Python keep the
control on each object.

@+
 
A

Aahz

Does anyone know where I can find any decent dynamically-constructed
HTML control classes (dropdown list, table, input field, checkbox, etc.)
written in Python. For example, for a HTML table I would like something
like...

You might look at Quixote:
http://quixote.ca/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,177
Messages
2,570,954
Members
47,507
Latest member
codeguru31

Latest Threads

Top