does python support mvc architecture

K

ketulp_baroda

Hi
Does python support MVC architecture? Java has register & notify
obsever methods in javax.util . Does python has these functions. If
not then how to register the views with the models & how to notify the
views that the model has been updated??
 
J

John Roth

Hi
Does python support MVC architecture? Java has register & notify
obsever methods in javax.util . Does python has these functions. If
not then how to register the views with the models & how to notify the
views that the model has been updated??

I don't know of a notifier class in the standard library,
but it's not all that difficult to write one. This is the
one I am currently using:

-----------------------------------------------------
# module Notify

class Notify(object):
def __init__(self):
self.listenerList = []

def sendMessage(self, event):
for callback in self.listenerList:
callback(event)
return

def addListener(self, callback):
self.listenerList.append(callback)

def removeListener(self, callback):
self.listenerList.remove(callback)
-----------------------------------------------------

callback has to be a callable of some kind,
a bound method is perfectly acceptable and
that's what I use. Works great.

John Roth
 
T

Thomas Heller

John Roth said:
Hi
Does python support MVC architecture? Java has register & notify
obsever methods in javax.util . Does python has these functions. If
not then how to register the views with the models & how to notify the
views that the model has been updated??

I don't know of a notifier class in the standard library,
but it's not all that difficult to write one. This is the
one I am currently using:

-----------------------------------------------------
# module Notify

class Notify(object):
def __init__(self):
self.listenerList = []

def sendMessage(self, event):
for callback in self.listenerList:
callback(event)
return

def addListener(self, callback):
self.listenerList.append(callback)

def removeListener(self, callback):
self.listenerList.remove(callback)
-----------------------------------------------------

callback has to be a callable of some kind,
a bound method is perfectly acceptable and
that's what I use. Works great.

I can heartily recommend the dispatcher module from Patrick O'Brian.
I'm still using a hacked up version from ActiveState's Python cookbook,
but there's also a newer version on sourceforge.

Thomas
 
D

DH

Does python support MVC architecture? Java has register & notify
obsever methods in javax.util . Does python has these functions. If
not then how to register the views with the models & how to notify the
views that the model has been updated??

The one that is closest to Java's implementation is here:
http://jamesthornton.com/eckel/TIPython/code/util/
but see also:
http://sra.itc.it/people/cavada/mvc/index.html
http://sourceforge.net/projects/pydispatcher/

And various python frameworks have Observable support built-in, such as
Twisted, anygui, WCK, etc.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top