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: str, bases: Tuple[type, ...], dict: Dict)[source]

Bases: type

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: Exception) Exception[source]

notifies of and ExceptionMutation and returns newExc.

This is just a convenience when mutating exceptions.

notifyDBTableModified(*args: Any, **kwargs: Any) Any[source]
notifyDebug(*args: Any, **kwargs: Any) Any[source]
notifyError(*args: Any, **kwargs: Any) Any[source]
notifyExceptionMutation(*args: Any, **kwargs: Any) Any[source]
notifyFailure(*args: Any, **kwargs: Any) Any[source]
notifyIncomingRow(*args: Any, **kwargs: Any) Any[source]
notifyIndexCreation(*args: Any, **kwargs: Any) Any[source]
notifyInfo(*args: Any, **kwargs: Any) Any[source]
notifyNewSource(*args: Any, **kwargs: Any) Any[source]
notifyProcessEnded(*args: Any, **kwargs: Any) Any[source]
notifyProcessStarts(*args: Any, **kwargs: Any) Any[source]
notifyProgress(*args: Any, **kwargs: Any) Any[source]
notifyScriptRunning(*args: Any, **kwargs: Any) Any[source]
notifyShipout(*args: Any, **kwargs: Any) Any[source]
notifySourceError(*args: Any, **kwargs: Any) Any[source]
notifySourceFinished(*args: Any, **kwargs: Any) Any[source]
notifyWarning(*args: Any, **kwargs: Any) Any[source]
notifyWebServerUp(*args: Any, **kwargs: Any) Any[source]
subscribe(evName: str, callback: Callable[[...], None]) None[source]
subscribeDBTableModified(callback: Callable[[...], None]) None
subscribeDebug(callback: Callable[[...], None]) None
subscribeError(callback: Callable[[...], None]) None
subscribeExceptionMutation(callback: Callable[[...], None]) None
subscribeFailure(callback: Callable[[...], None]) None
subscribeIncomingRow(callback: Callable[[...], None]) None
subscribeIndexCreation(callback: Callable[[...], None]) None
subscribeInfo(callback: Callable[[...], None]) None
subscribeNewSource(callback: Callable[[...], None]) None
subscribeProcessEnded(callback: Callable[[...], None]) None
subscribeProcessStarts(callback: Callable[[...], None]) None
subscribeProgress(callback: Callable[[...], None]) None
subscribeScriptRunning(callback: Callable[[...], None]) None
subscribeShipout(callback: Callable[[...], None]) None
subscribeSourceError(callback: Callable[[...], None]) None
subscribeSourceFinished(callback: Callable[[...], None]) None
subscribeWarning(callback: Callable[[...], None]) None
subscribeWebServerUp(callback: Callable[[...], None]) None
suspended(evName: str) Iterator[None][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: str, callback: Callable[[...], None]) None[source]

removes a callback from evName’s callback list.

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

unsubscribeDBTableModified(callback: Callable[[...], None]) None
unsubscribeDebug(callback: Callable[[...], None]) None
unsubscribeError(callback: Callable[[...], None]) None
unsubscribeExceptionMutation(callback: Callable[[...], None]) None
unsubscribeFailure(callback: Callable[[...], None]) None
unsubscribeIncomingRow(callback: Callable[[...], None]) None
unsubscribeIndexCreation(callback: Callable[[...], None]) None
unsubscribeInfo(callback: Callable[[...], None]) None
unsubscribeNewSource(callback: Callable[[...], None]) None
unsubscribeProcessEnded(callback: Callable[[...], None]) None
unsubscribeProcessStarts(callback: Callable[[...], None]) None
unsubscribeProgress(callback: Callable[[...], None]) None
unsubscribeScriptRunning(callback: Callable[[...], None]) None
unsubscribeShipout(callback: Callable[[...], None]) None
unsubscribeSourceError(callback: Callable[[...], None]) None
unsubscribeSourceFinished(callback: Callable[[...], None]) None
unsubscribeWarning(callback: Callable[[...], None]) None
unsubscribeWebServerUp(callback: Callable[[...], None]) None