[Home] [Credit Search] [Category Browser] [Staff Roll Call] | The LINUX.COM Article Archive |
Originally Published: Monday, 2 October 2000 | Author: Samuli Kärkkäinen |
Published to: develop_articles/Development Articles | Page: 1/1 - [Printable] |
Unix Web Application Architectures - Part 5: An Alternate Approach
In this last chapter of the document I'll mention a completely different approach to web application development. I call this style "Abstracted HTML."
|
Page 1 of 1 | |
Unix Web Application Architectures
15 An Alternate Approach: Abstracted HTMLIn this last chapter of the document I'll mention a completely different approach to web application development. I call this style "Abstracted HTML." In this approach, web programming is made to feel to the programmer as much like traditional GUI programming as possible. HTML elements and constructs are wrapped in persistent objects that know how to render themselves using the browser, and HTTP requests are handled as GUI callbacks. The objects are kept in memory or stored on disk between requests. When a callback for an object arrives, the appropriate method of the object is invoked. Below is the commented source of that application. Notice that the code is short and easy to understand even for someone who has never done web programming. The question is, does this approach scale to larger programs, or is the web technology too different from traditional GUI programming to make this viable?
#!/usr/bin/python
Import the Web Application Toolkit module.
Create a new class which subclasses wat.Application. All WAT apps must derive this class and override the construct method.
def construct(self):
dialog = wat.Dialog(self, "Text Viewer", align = "center")
Create a text box widget (a form input control).
Create a button on the right of the text box, and bind also
its "clicked" event to self.display_file.
Insert a Text widget containing <hr> at position 1,0 to
create a horizontal line below the two widgets above.
Store the dialog so that we can access it in other methods, and
return it to the caller.
The display_file method is called when the user clicks the Display
File button or hits enter in the input control. This is a
user-defined method and was bound to those events in the construct()
method. The o parameter is the object which this method was
connected to. If the user clicks the button, o will be the Button
widget. If the user hits enter in the input control, o will be the
Input widget. We don't actually use it below, but Python requires it
to be in the parameter list.
contents = wat.Text(self)
for line in open(self.file_input.value).readlines():
contents.text = "Unable to open file:" + self.file_input.value Finally insert the contents widget at position 0,2 in the dialog (below the horizontal line). self.dialog.form.set_cell(0, 2, contents, colspan = 2)
app = TextViewer()
Copyright (c) 2000 by Samuli Kärkkäinen <skarkkai@woods.iki.fi>. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). Up-to-date versions of the entire Unix Web Application Architectures document is available at webapparch.sourceforge.net.
| |
Page 1 of 1 |