~ubuntu-branches/ubuntu/utopic/pitivi/utopic

« back to all changes in this revision

Viewing changes to pitivi/signalgroup.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-04-05 15:28:16 UTC
  • mfrom: (6.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140405152816-6lijoax4cngiz5j5
Tags: 0.93-3
* debian/control:
  + Depend on python-gi (>= 3.10), older versions do not work
    with pitivi (Closes: #732813).
  + Add missing dependency on gir1.2-clutter-gst-2.0 (Closes: #743692).
  + Add suggests on gir1.2-notify-0.7 and gir1.2-gnomedesktop-3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# PiTiVi , Non-linear video editor
2
 
#
3
 
#       pitivi/ui/signalgroup.py
4
 
#
5
 
# Copyright (c) 2006, Richard Boulton <richard@tartarus.org>
6
 
#
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.
11
 
#
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.
16
 
#
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.
21
 
 
22
 
"""
23
 
A group of signals, which can be disconnected easily.
24
 
 
25
 
Used to make it easy to keep signals attached to the current project.
26
 
"""
27
 
 
28
 
 
29
 
class SignalGroup:
30
 
    def __init__(self):
31
 
        self.signal_handler_ids = {}
32
 
 
33
 
    def connect(self, object, signal, sid, callback, *args):
34
 
        """Connect a signal.
35
 
 
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
40
 
           instead.
41
 
         _ `callback` is the callable to call on the signal.
42
 
         _ `args` are any extra arguments to pass to the callback.
43
 
 
44
 
        If there is already a connected signal in the group with the specified
45
 
        unique identifier, this signal will first be disconnected.
46
 
 
47
 
        """
48
 
        if sid is None:
49
 
            sid = signal
50
 
 
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]
55
 
 
56
 
        handler_id = object.connect(signal, callback, *args)
57
 
        self.signal_handler_ids[id] = (object, handler_id)
58
 
 
59
 
    def disconnect(self, sid):
60
 
        """Disconnect the signal with the specified unique identifier.
61
 
 
62
 
        If there is no such signal, this returns without having any effect.
63
 
 
64
 
        """
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)
68
 
 
69
 
    def disconnectAll(self):
70
 
        """Disconnect all signals in the group.
71
 
 
72
 
        """
73
 
        for old_object, handler_id in self.signal_handler_ids.itervalues():
74
 
            old_object.disconnect(handler_id)
75
 
        self.signal_handler_ids = {}
76
 
 
77
 
    def disconnectForObject(self, obj):
78
 
        """
79
 
        Disconnects all signal in the group connect on the given object
80
 
        """
81
 
        assert obj != None
82
 
        objids = [sid for sid in self.signal_handler_ids.keys() if self.signal_handler_ids[sid][0] == obj]
83
 
        for sid in objids:
84
 
            old_object, handler_id = self.signal_handler_ids.pop(id)
85
 
            old_object.disconnect(handler_id)