1
# PiTiVi , Non-linear video editor
3
# pitivi/ui/signalgroup.py
5
# Copyright (c) 2006, Richard Boulton <richard@tartarus.org>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU Lesser General Public
9
# License as published by the Free Software Foundation; either
10
# version 2.1 of the License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public
18
# License along with this program; if not, write to the
19
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20
# Boston, MA 02110-1301, USA.
23
A group of signals, which can be disconnected easily.
25
Used to make it easy to keep signals attached to the current project.
31
self.signal_handler_ids = {}
33
def connect(self, object, signal, sid, callback, *args):
36
_ `object` is the object which defines the signal.
37
_ `signal` is the name of the signal to connect to.
38
_ `id` is a unique (within this SignalGroup) identifer for the signal to
39
connect to. If this is None, the value of `signal` will be used
41
_ `callback` is the callable to call on the signal.
42
_ `args` are any extra arguments to pass to the callback.
44
If there is already a connected signal in the group with the specified
45
unique identifier, this signal will first be disconnected.
51
if sid in self.signal_handler_ids:
52
old_object, handler_id = self.signal_handler_ids[sid]
53
old_object.disconnect(handler_id)
54
del self.signal_handler_ids[sid]
56
handler_id = object.connect(signal, callback, *args)
57
self.signal_handler_ids[id] = (object, handler_id)
59
def disconnect(self, sid):
60
"""Disconnect the signal with the specified unique identifier.
62
If there is no such signal, this returns without having any effect.
65
if id in self.signal_handler_ids:
66
old_object, handler_id = self.signal_handler_ids.pop(sid)
67
old_object.disconnect(handler_id)
69
def disconnectAll(self):
70
"""Disconnect all signals in the group.
73
for old_object, handler_id in self.signal_handler_ids.itervalues():
74
old_object.disconnect(handler_id)
75
self.signal_handler_ids = {}
77
def disconnectForObject(self, obj):
79
Disconnects all signal in the group connect on the given object
82
objids = [sid for sid in self.signal_handler_ids.keys() if self.signal_handler_ids[sid][0] == obj]
84
old_object, handler_id = self.signal_handler_ids.pop(id)
85
old_object.disconnect(handler_id)