views:

931

answers:

8

I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.

Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite database to do all the middle man work? It should spare me the work of manually writing event handlers, input evaluators and view updates.

The technologies in question are just examples, but I want to stick with Python as far as possible.

+4  A: 

PyQt and its models can automate some of these tasks for you (to some amount off course, e.g. filling widgets with data from a database and handling most of the widgets behaviour, buffering etc.).

If you want a more object-oriented approach to handling SQL you could look into an ORM-oriented solution (for example SQLAlchemy).

ChristopheD
Well I hope if library X is doing what I described, I won't even have to use SQLAlchemy much. I'll have a look at PyQt, would still prefer Gtk+ though, for Ubuntu nativeness factor.
paniq
For Gnome nativeness, you mean... you could always switch to KDE if you wanted Qt apps to look more native ;-) (kidding, sort of)
David Zaslavsky
+1  A: 

wxGlade may help, although I haven't used it myself so I don't speak from experience.

Boa Constructor apparently has a wxPython GUI builder in it, and there is also PythonCard, though development on these two projects seems to have stalled.

John Fouhy
+4  A: 

Dabo is built on top of wxPython, so you may not prefer it, but it's designed to make it easy to tie a GUI to a database, so I'd recommend you check it out if you haven't already. In particular, it's got good facilities for tying widgets to data, and handling a lot of the common cases of GUI development.

Ryan Ginstrom
I was looking for something like this, thanks for the link!
Subtwo
+5  A: 

Besides the ones already mentioned I can add:

I've never used any of them so have no recommendations but, for what it's worth, I have used at least 2 complex programs built directly on pygtk that worked in both Windows and Linux.

I think Kiwi is the only one of these with baked in support for db (through interface with SQLAlchemy, SQLObject, or Storm) but I would be surprised if you couldn't use one of those ORM's inside any of the other frameworks.

Van Gale
kiwi offers pretty much the functionality i was describing, thank you very much.
paniq
+1  A: 

Traits might be a good option for you. http://code.enthought.com/projects/traits/docs/html/TUIUG/index.html

AS simple as it is to map a UI to an object, it doesn't seem too far fetched to incorporate SQLAlchemy for persistence.

Tom Willis
interesting. do you have any personal experience with this library? at first sight it appears like it actually does nothing but busy aristocratic housekeeping. but i keep reading.
paniq
okay i had a look at it. the concept is certainly interesting, but it looks like the UI part does not go very deep, at least judging from the manual.
paniq
My experience with it is pretty light. I mentioned it here because I had the same questions you had when I stumbled on it a couple of months back. This ppt seems to dive deeper into Traits UI capability http://tinyurl.com/d4rwhp
Tom Willis
A: 

I had lots of success with wxPython, but that was some years ago now and there may be better new solutions...

Jeff Kotula
+1  A: 

There is a good book on wxPython, "wxPython in Action", which can't be said for some of the other solutions. No knock on the others. I've had success developing with wxPython in the past and it comes with a great set of demo applications with source code from which you can borrow liberally.

The best UI designer I found for wxPython applications is a commercial one, Anthemion DialogBlocks. It's by one of the wxPython programmers and is worth the money. Other solutions for UI design include wxGlade (I found it usable but not featureful) and Boa Constructor (haven't used it). Wing IDE might also have one. Stani's Python Editor bundles wxGlade, I believe. There are a lot of other projects that don't really work or are fairly old.

As far as SQL automation goes, as another answerer says, I'd look at SQL alchemy, but the learning curve for a small application might be too much and you'd be better off just going straight to odbc. The best odbc api is the one used by Django, pyodbc.

It's been a while since I developed with these tools, so there may be something newer for each, but at the time these were definitely the best of breed in my opinion.

Binary Phile
A: 

Ok this is an unconventional solution but write yourself a code generator. I have done this several times using Mako. So in my case I auto inspect a table which columns it contains and types and generate classes from that. It's more work upfront but does exactly what you want and is reusable in subsequent projects.

AngelBlaZe