[pygtk] Clean UI and data seperation
Christian Robottom Reis
kiko at async.com.br
Mon Mar 15 22:11:51 WST 2004
On Sat, Mar 13, 2004 at 11:00:21PM +0100, Kai Weber wrote:
> The UI is build with Glade. I want to separate the GUI from the data
> logic. But I have no idea how to merge them together. My idea:
> class File():
> Loads and writes the *.readme meta information for a file.
> *** finished and ready ***
> class UI():
> Loads the Glade-XML and holds references to the widgets.
> I can run a gtk.main() and display the window and have references to
> the widgets (self.url = self.xml.get_widget("url_entry")
> class Application():
> ""Handles loading and updating the UI and calling the File functions"""
> But how!? I am too stupid, it seems. Could anybody fill in some abstract
> functions which help me get started?
I think I would only have a separate Application class if I had multiple
windows to manage. At any rate, I wouldn't use Application as an MVC
"controller" -- I would have the UI class call the File methods as
necessary. Something like:
Application instantiates UI
UI instantiates File and loads it into itself
I would have the UI class handle the events; I know this isn't kosher
MVC, but in my experience classic MVC is not a good design pattern for
modelling whole applications -- the View and Controller class end up
being too coupled for the split to be useful. Java Swing has the concept
of a Delegate, which is a class that handles both View and Controller
responsabilities, and I think it's a smarter model to work with for the
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 261 2331
More information about the pygtk