O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Views and Validators

The notifications before the event are intended to validate data, and the notifications after the event can maintain custom views. Accordingly, we define two types of delegate:

  • A Validator is an object a BookSet notifies before changing data, asking for permission to proceed.

  • A View is an object the BookSet notifies after changes have been made.[1] It also has a method to return a 2D array of data on demand, which contains whatever users wish.

It was traditional until recently to have just one delegate for an object. Some Java development environments allow a list of delegates that can be added and removed at runtime, and we’ve borrowed this pattern. We could also have built a more complex delegate that combined the functions of Validator and View, but this seemed a better fit to our goals for the users.

For each delegate, youshould provide a base class users can subclass. You should also define a subclass of BookSet that can use them. All this code can be found in the module doubletalk.userhooks , which also includes examples of Validators and Views. Here’s the definition of a View:

class View: """This delegate is informed of all changes after they occur, and returns a 2d array of data when asked.""" def setBookSet(self, aBookSet): self.BookSet = aBookSet self.recalc() def getDescription(self): return 'abstract base class for Views' # hooks for notification after the event def didAdd(self, aTransaction): pass def didEdit(self, index, newTransaction): pass def ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required