gavo.base.events module

General event handling.

Basically, everything roughly classified as user interaction should go through this module. gavo.base, on import, creates an instance of EventDispatcher and installs it as base.ui. The rest of the library can then call methods of base.ui.

Clients can then register observers (probably derived from base.observer.Observer) that subscribe to events and can display or log them in some form appropriate to the client.

class gavo.base.events.DispatcherType(name, bases, dict)[source]

Bases: type

is a metaclass for dispatching of messages.

Basically, you define methods called notify<whatever> in your class. For each of them, a subscribe<whatever> method is added.

Then, when notify<whatever> is called, your defined method is called, and its result is then passed to all callbacks passed in through subscribe<whatever>.

class gavo.base.events.EventDispatcher[source]

Bases: object

is the central event dispatcher.

Events are posted by using notify* methods. Various handlers can then attach to them.

eventTypes = ['ExceptionMutation', 'NewSource', 'SourceError', 'SourceFinished', 'Shipout', 'IncomingRow', 'IndexCreation', 'ScriptRunning', 'Error', 'Failure', 'Warning', 'Info', 'Debug', 'WebServerUp', 'DBTableModified', 'ProcessStarts', 'ProcessEnded', 'Progress']
logOldExc(newExc)[source]

notifies of and ExceptionMutation and returns newExc.

This is just a convenience when mutating exceptions.

notifyDBTableModified(*args, **kwargs)[source]
notifyDebug(*args, **kwargs)[source]
notifyError(*args, **kwargs)[source]
notifyExceptionMutation(*args, **kwargs)[source]
notifyFailure(*args, **kwargs)[source]
notifyIncomingRow(*args, **kwargs)[source]
notifyIndexCreation(*args, **kwargs)[source]
notifyInfo(*args, **kwargs)[source]
notifyNewSource(*args, **kwargs)[source]
notifyProcessEnded(*args, **kwargs)[source]
notifyProcessStarts(*args, **kwargs)[source]
notifyProgress(*args, **kwargs)[source]
notifyScriptRunning(*args, **kwargs)[source]
notifyShipout(*args, **kwargs)[source]
notifySourceError(*args, **kwargs)[source]
notifySourceFinished(*args, **kwargs)[source]
notifyWarning(*args, **kwargs)[source]
notifyWebServerUp(*args, **kwargs)[source]
subscribe(evName, callback)[source]
subscribeDBTableModified(callback)
subscribeDebug(callback)
subscribeError(callback)
subscribeExceptionMutation(callback)
subscribeFailure(callback)
subscribeIncomingRow(callback)
subscribeIndexCreation(callback)
subscribeInfo(callback)
subscribeNewSource(callback)
subscribeProcessEnded(callback)
subscribeProcessStarts(callback)
subscribeProgress(callback)
subscribeScriptRunning(callback)
subscribeShipout(callback)
subscribeSourceError(callback)
subscribeSourceFinished(callback)
subscribeWarning(callback)
subscribeWebServerUp(callback)
suspended(evName)[source]

a context manager suspending notification for a specific event.

This is mainly for use by test code that wants to avoid spilling too much junk into the log.

One weak point here is that any subscriptions entered while notification is suspended are lost. So: Don’t suspend notifications for normal code.

unsubscribe(evName, callback)[source]

removes a callback from evName’s callback list.

It is not an error to unsubscribe a callback that’s not subscribed.

unsubscribeDBTableModified(callback)
unsubscribeDebug(callback)
unsubscribeError(callback)
unsubscribeExceptionMutation(callback)
unsubscribeFailure(callback)
unsubscribeIncomingRow(callback)
unsubscribeIndexCreation(callback)
unsubscribeInfo(callback)
unsubscribeNewSource(callback)
unsubscribeProcessEnded(callback)
unsubscribeProcessStarts(callback)
unsubscribeProgress(callback)
unsubscribeScriptRunning(callback)
unsubscribeShipout(callback)
unsubscribeSourceError(callback)
unsubscribeSourceFinished(callback)
unsubscribeWarning(callback)
unsubscribeWebServerUp(callback)