Building a GUI agnostic database application

Brian Kelley bkelley at wi.mit.edu
Wed Dec 3 06:48:32 EST 2003


Uwe Grauer wrote:
> Take at look at PAF http://www.dctools.org
> 
> Uwe
> 
> Rasjid Wilcox wrote:
> 
>> I am wanting to write a database application using Python.
>>
>> I want it to be GUI agnostic.  The GUI will probably be 
>> Python/wxPython, but
>> I would also like the option of a Webbased (PHP?) gui, and possibly GUI's
>> in Java or C++, Visual Basic etc.
>>
>> The Python 'backend' may run on the same machine as the client (thick
>> client), or on the same machine as the database (thin client).
>>
>> My main requirements are:
>> 1.  Reasonably light-weight
>> 2.  Secure authentication between the GUI and the backend.
>> 3.  Ideally runs wherever Python runs, and at least on Linux, Mac and
>> Windows.

Why not just make a database model that doesn't know anything about the 
GUI?  The model can a python compliant database driver (say odbc or 
whatnot) and you can supply the proper  business logic in a concise model.

For example

class model:
     def connect(self,...)
     def adduser(self,...)
     def addPurchase(self,user,item,cosperunit,units):

Now using this database model you can control it with a webbased gui or 
a wxPython gui.  I don't think that there is a need to use a wire 
protocol in this case to attach to your database code which itself uses 
a wire protocol to attach to the database.  Just consolidate your code 
into a model.

This is a typical model->view->controller approach.  In my experience 
the best way to program this is to write the model first without using a 
gui, just a lot of test cases.  Once the model does what you want, hook 
it up to a gui.  This helps to ensure that the model works in at least 
two independent environments, the python interactive environment and 
also your gui code.

Brian





More information about the Python-list mailing list