class SignalEmitter(object): (source)
Known subclasses: zim.config.dicts.ControlledDict
, zim.config.manager.ConfigFile
, zim.fs.FSObjectMonitor
, zim.fs.FSSingletonClass
, zim.gui.customtools.CustomToolManager
, zim.history.History
, zim.newfs.helpers.FileTreeWatcher
, zim.newfs.helpers.FSObjectMonitor
, zim.notebook.index.base.IndexerBase
, zim.notebook.index.files.FilesIndexer
, zim.notebook.index.Index
, zim.notebook.index.IndexUpdateIter
, zim.notebook.notebook.Notebook
, zim.notebook.operations.NotebookOperation
, zim.notebook.page.Page
, zim.plugins.base.imagegenerator.ImageGeneratorModel
, zim.plugins.ExtensionBase
, zim.plugins.InsertedObjectTypeMap
, zim.plugins.PluginManagerClass
, zim.plugins.tableeditor.TableModel
, zim.plugins.trayicon.AppIndicatorTrayIcon
, zim.templates.Template
Replacement for GObject to make objects emit signals. API should be (mostly) compatible with API offered by GObject.
Supported signals need to be defined in the dict __signals__. For each signal a 3-tuple is provided where the first argument is either SIGNAL_RUN_FIRST or SIGNAL_RUN_LAST, the second is the return argument (or None for most signals) and the third is the argument spec for the signal.
When a signal is emitted all handlers are called one by one and exceptions in a handler are intercepted. If the class defines a method do_signalname() (where "signalname" is the name of the signal with "-" replaced by "_") this is considered a default handler that is automatically connected. The SIGNAL_RUN_FIRST and SIGNAL_RUN_LAST flags in the signal spec control where in the emission sequence this default handler is called: it either runs as the first or as the last handler. Typically the default handler is used to implement the change signalled by the signal. So if your signal name suggests something happened already (e.g. "changed"), probably you want to use SIGNAL_RUN_FIRST. However if the action is phrased as still happening (e.g. "change") and the handlers can influence this, you probably want SIGNAL_RUN_LAST.
Signals connected with connect_after()
always run after all the normal handlers (which are connected with connect()
) and after the default handler (even if the default handler is setup with SIGNAL_RUN_LAST).
If a signal defines a return type, emission should use either emit_return_first()
or emit_return_iter()
to handle return values.
(Also see the Glib documentation to understand the full system of which we implement a sub-set here.)
Method | __new__ |
Undocumented |
Method | block_signals |
Returns a context manager for blocking one or more signals |
Method | connect |
Register a handler for a specific object. |
Method | connect_after |
Like connect() but handler will be called after default handler |
Method | disconnect |
Undocumented |
Method | emit |
Undocumented |
Method | emit_return_first |
Emits a signal and stops emission on the first handler that returns a not-None value. |
Method | emit_return_iter |
Returns an generator that calls one handler on each iteration and yields the return values. This allows aggregating return values. |
Class Variable | __signals__ |
Undocumented |
Method | _connect |
Undocumented |
Method | _setup_signal |
Undocumented |
Method | _teardown_signal |
Undocumented |
Register a handler for a specific object.
Note that connecting makes a hard reference to the connected object. So connecting an bound method will prevent the object the method belongs to to be destroyed until the signal is disconnected.
Parameters | |
signal | the signal name |
handler | callback to be called upon the signal, first object to the callback will be the emitting object, other params are signal specific. |
Returns | |
an id for the registered handler |
zim.config.dicts.ControlledDict
, zim.config.manager.ConfigFile
, zim.fs.FSObjectMonitor
, zim.fs.FSSingletonClass
, zim.gui.customtools.CustomToolManager
, zim.history.History
, zim.newfs.helpers.FileTreeWatcher
, zim.newfs.helpers.FSObjectMonitor
, zim.notebook.index.base.IndexerBase
, zim.notebook.index.files.FilesIndexer
, zim.notebook.index.Index
, zim.notebook.index.IndexUpdateIter
, zim.notebook.notebook.Notebook
, zim.notebook.operations.NotebookOperation
, zim.notebook.page.Page
, zim.plugins.base.imagegenerator.ImageGeneratorModel
, zim.plugins.ExtensionBase
, zim.plugins.InsertedObjectTypeMap
, zim.plugins.PluginManagerClass
, zim.plugins.tableeditor.TableModel
, zim.plugins.trayicon.AppIndicatorTrayIcon
, zim.templates.Template
Undocumented