MCPcopy Index your code
hub / github.com/PyQt5/PyQt / addSignal

Function addSignal

QWebChannel/Data/qwebchannel.js:240–293  ·  view source on GitHub ↗
(signalData, isPropertyNotifySignal)

Source from the content-addressed store, hash-verified

238 }
239
240 function addSignal(signalData, isPropertyNotifySignal)
241 {
242 var signalName = signalData[0];
243 var signalIndex = signalData[1];
244 object[signalName] = {
245 connect: function(callback) {
246 if (typeof(callback) !== "function") {
247 console.error("Bad callback given to connect to signal " + signalName);
248 return;
249 }
250
251 object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];
252 object.__objectSignals__[signalIndex].push(callback);
253
254 // only required for "pure" signals, handled separately for properties in propertyUpdate
255 if (isPropertyNotifySignal)
256 return;
257
258 // also note that we always get notified about the destroyed signal
259 if (signalName === "destroyed" || signalName === "destroyed()" || signalName === "destroyed(QObject*)")
260 return;
261
262 // and otherwise we only need to be connected only once
263 if (object.__objectSignals__[signalIndex].length == 1) {
264 webChannel.exec({
265 type: QWebChannelMessageTypes.connectToSignal,
266 object: object.__id__,
267 signal: signalIndex
268 });
269 }
270 },
271 disconnect: function(callback) {
272 if (typeof(callback) !== "function") {
273 console.error("Bad callback given to disconnect from signal " + signalName);
274 return;
275 }
276 object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];
277 var idx = object.__objectSignals__[signalIndex].indexOf(callback);
278 if (idx === -1) {
279 console.error("Cannot find connection of signal " + signalName + " to " + callback.name);
280 return;
281 }
282 object.__objectSignals__[signalIndex].splice(idx, 1);
283 if (!isPropertyNotifySignal && object.__objectSignals__[signalIndex].length === 0) {
284 // only required for "pure" signals, handled separately for properties in propertyUpdate
285 webChannel.exec({
286 type: QWebChannelMessageTypes.disconnectFromSignal,
287 object: object.__id__,
288 signal: signalIndex
289 });
290 }
291 }
292 };
293 }
294
295 /**
296 * Invokes all callbacks for the given signalname. Also works for property notify callbacks.

Callers 2

bindGetterSetterFunction · 0.70
QObjectFunction · 0.70

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected