[pitivi/ges: 163/287] signal: Add a utils/signal.py file
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges: 163/287] signal: Add a utils/signal.py file
- Date: Thu, 15 Mar 2012 16:39:32 +0000 (UTC)
commit 0e988537a53c9d6fad46199005bef664e754fb43
Author: Thibault Saunier <thibault saunier collabora com>
Date: Mon Jan 9 14:25:42 2012 -0300
signal: Add a utils/signal.py file
This is were all the helpers classes/functions concerning signal
should land
pitivi/Makefile.am | 2 -
pitivi/application.py | 2 +-
pitivi/project.py | 2 +-
pitivi/projectmanager.py | 2 +-
pitivi/settings.py | 2 +-
pitivi/signalgroup.py | 85 -----------------------
pitivi/sourcelist.py | 2 +-
pitivi/system.py | 2 +-
pitivi/threads.py | 2 +-
pitivi/ui/alignmentprogress.py | 2 +-
pitivi/ui/encodingdialog.py | 2 +-
pitivi/ui/encodingprogress.py | 2 +-
pitivi/ui/filelisterrordialog.py | 2 +-
pitivi/ui/previewer.py | 2 +-
pitivi/ui/sourcelist.py | 3 +-
pitivi/ui/trackobject.py | 2 +-
pitivi/undo/timeline.py | 2 +-
pitivi/undo/undo.py | 2 +-
pitivi/utils/Makefile.am | 1 +
pitivi/utils/misc.py | 2 +-
pitivi/utils/playback.py | 2 +-
pitivi/{signalinterface.py => utils/signal.py} | 87 ++++++++++++++++++++---
pitivi/utils/timeline.py | 2 +-
tests/test_integration.py | 2 +-
tests/test_signallable.py | 2 +-
25 files changed, 98 insertions(+), 120 deletions(-)
---
diff --git a/pitivi/Makefile.am b/pitivi/Makefile.am
index 6c7c560..e727e9b 100644
--- a/pitivi/Makefile.am
+++ b/pitivi/Makefile.am
@@ -17,8 +17,6 @@ pitivi_PYTHON = \
projectmanager.py \
receiver.py \
settings.py \
- signalgroup.py \
- signalinterface.py \
sourcelist.py \
system.py \
threads.py \
diff --git a/pitivi/application.py b/pitivi/application.py
index 270c47c..196743b 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -41,7 +41,7 @@ from pitivi.effects import EffectsHandler
from pitivi.configure import APPNAME
from pitivi.settings import GlobalSettings
from pitivi.threads import ThreadMaster
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.system import getSystem
from pitivi.utils.loggable import Loggable
import pitivi.utils.loggable as log
diff --git a/pitivi/project.py b/pitivi/project.py
index 25bf5d2..28ee297 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -30,7 +30,7 @@ from pitivi.utils.playback import Seeker
from pitivi.utils.loggable import Loggable
from pitivi.sourcelist import SourceList
from pitivi.settings import MultimediaSettings
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.utils.timeline import Selection
diff --git a/pitivi/projectmanager.py b/pitivi/projectmanager.py
index 21a50f2..9d48a0c 100644
--- a/pitivi/projectmanager.py
+++ b/pitivi/projectmanager.py
@@ -29,7 +29,7 @@ from urlparse import urlparse
from pwd import getpwuid
from pitivi.project import Project
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.utils.loggable import Loggable
from pitivi.undo.undo import UndoableAction
diff --git a/pitivi/settings.py b/pitivi/settings.py
index f0bdf7b..7d9d757 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -30,7 +30,7 @@ import xdg.BaseDirectory as xdg_dirs # Freedesktop directories spec
from gettext import gettext as _
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.encode import available_combinations, \
get_compatible_sink_caps
from pitivi.utils.loggable import Loggable
diff --git a/pitivi/sourcelist.py b/pitivi/sourcelist.py
index 5108a63..7fe8859 100644
--- a/pitivi/sourcelist.py
+++ b/pitivi/sourcelist.py
@@ -27,7 +27,7 @@ Handles the list of source for a project
import urllib
import gst
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.utils.loggable import Loggable
diff --git a/pitivi/system.py b/pitivi/system.py
index 881182a..7c21979 100644
--- a/pitivi/system.py
+++ b/pitivi/system.py
@@ -24,7 +24,7 @@ import os
from pitivi.configure import APPNAME
from pitivi.utils.loggable import Loggable
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
class System(Signallable, Loggable):
diff --git a/pitivi/threads.py b/pitivi/threads.py
index e4724a0..287b94d 100644
--- a/pitivi/threads.py
+++ b/pitivi/threads.py
@@ -23,7 +23,7 @@ Threading support
"""
import threading
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.utils.loggable import Loggable
#
diff --git a/pitivi/ui/alignmentprogress.py b/pitivi/ui/alignmentprogress.py
index f746b88..9069e06 100644
--- a/pitivi/ui/alignmentprogress.py
+++ b/pitivi/ui/alignmentprogress.py
@@ -32,7 +32,7 @@ import gtk
import gst
import pitivi.configure as configure
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
class AlignmentProgressDialog:
diff --git a/pitivi/ui/encodingdialog.py b/pitivi/ui/encodingdialog.py
index a4edcb5..8be577a 100644
--- a/pitivi/ui/encodingdialog.py
+++ b/pitivi/ui/encodingdialog.py
@@ -35,7 +35,7 @@ from gettext import gettext as _
from pitivi import configure
from pitivi.utils.misc import togglePlayback, Seeker, beautify_ETA
from pitivi.settings import MultimediaSettings
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.utils.loggable import Loggable
from pitivi.ui.gstwidget import GstElementSettingsDialog
diff --git a/pitivi/ui/encodingprogress.py b/pitivi/ui/encodingprogress.py
index 8ad8462..877284c 100644
--- a/pitivi/ui/encodingprogress.py
+++ b/pitivi/ui/encodingprogress.py
@@ -29,7 +29,7 @@ import gst
import pitivi.configure as configure
from gettext import gettext as _
import gobject
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
class EncodingProgressDialog(Signallable):
diff --git a/pitivi/ui/filelisterrordialog.py b/pitivi/ui/filelisterrordialog.py
index ff7e8ce..5cf0c1a 100644
--- a/pitivi/ui/filelisterrordialog.py
+++ b/pitivi/ui/filelisterrordialog.py
@@ -31,7 +31,7 @@ from gettext import gettext as _
from urllib import unquote
from pitivi.configure import get_ui_dir
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.utils.loggable import Loggable
diff --git a/pitivi/ui/previewer.py b/pitivi/ui/previewer.py
index 40cf9ad..e2d6716 100644
--- a/pitivi/ui/previewer.py
+++ b/pitivi/ui/previewer.py
@@ -30,7 +30,7 @@ import os
from gettext import gettext as _
import pitivi.utils as utils
from pitivi.configure import get_pixmap_dir
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.settings import GlobalSettings
from pitivi.ui.zoominterface import Zoomable
from pitivi.utils.loggable import Loggable
diff --git a/pitivi/ui/sourcelist.py b/pitivi/ui/sourcelist.py
index 74cb2eb..cccf6cd 100644
--- a/pitivi/ui/sourcelist.py
+++ b/pitivi/ui/sourcelist.py
@@ -34,9 +34,10 @@ from hashlib import md5
import pitivi.ui.dnd as dnd
from pitivi.configure import get_pixmap_dir
-from pitivi.signalgroup import SignalGroup
from pitivi.settings import GlobalSettings
+
from pitivi.utils.misc import beautify_length
+from pitivi.utils.signal import SignalGroup
from pitivi.ui.pathwalker import PathWalker, quote_uri
from pitivi.ui.filelisterrordialog import FileListErrorDialog
diff --git a/pitivi/ui/trackobject.py b/pitivi/ui/trackobject.py
index 449e30c..7f28099 100644
--- a/pitivi/ui/trackobject.py
+++ b/pitivi/ui/trackobject.py
@@ -18,7 +18,7 @@ from pitivi.utils.loggable import Loggable
from pitivi.settings import GlobalSettings
from pitivi.receiver import receiver, handler
from pitivi.ui.prefs import PreferencesDialog
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.utils.timeline import SELECT, SELECT_ADD, UNSELECT, \
SELECT_BETWEEN, MoveContext, TrimStartContext, TrimEndContext
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index 0f7d29d..076f998 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -21,7 +21,7 @@
import gobject
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.undo.undo import PropertyChangeTracker
from pitivi.undo.undo import UndoableAction
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index 436e85f..7cac947 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -23,7 +23,7 @@
Base classes for the undo/redo feature implementation
"""
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.utils.loggable import Loggable
diff --git a/pitivi/utils/Makefile.am b/pitivi/utils/Makefile.am
index 6ef20df..fae096b 100644
--- a/pitivi/utils/Makefile.am
+++ b/pitivi/utils/Makefile.am
@@ -8,6 +8,7 @@ utils_PYTHON = \
timeline.py \
loggable.py \
playback.py \
+ signal.py \
misc.py
clean-local:
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index 7a3eb7b..9177416 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -32,7 +32,7 @@ import struct
import time
from pitivi.configure import APPMANUALURL_OFFLINE, APPMANUALURL_ONLINE
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
import pitivi.utils.loggable as log
from gettext import ngettext
try:
diff --git a/pitivi/utils/playback.py b/pitivi/utils/playback.py
index fc6a479..7b9afa6 100644
--- a/pitivi/utils/playback.py
+++ b/pitivi/utils/playback.py
@@ -29,7 +29,7 @@ import gobject
import pitivi.utils.loggable as log
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
class Seeker(Signallable):
diff --git a/pitivi/signalinterface.py b/pitivi/utils/signal.py
similarity index 68%
rename from pitivi/signalinterface.py
rename to pitivi/utils/signal.py
index 9273277..5c921af 100644
--- a/pitivi/signalinterface.py
+++ b/pitivi/utils/signal.py
@@ -1,8 +1,9 @@
-# PiTiVi , Non-linear video editor
+#!/usr/bin/env python
#
-# signalinterface.py
+# signal.py
#
-# Copyright (c) 2008, Edward Hervey <bilboed bilboed com>
+# Copyright (c) 2006, Richard Boulton <richard tartarus org>
+# Copyright (C) 2012 Thibault Saunier <thibaul saunier collabora com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -16,22 +17,84 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
-# Boston, MA 02110-1301, USA.
-
-# FIXME/IDEA : Add a decorator to easily add signals (ex: @signal(name="mysignal"))
-# FIXME/IDEA : Add a function to quickly define signals (a-la pygobject gsignals)
-# FIXME/IDEA : Use Weak dictionnaries for tracking connected callbacks/objects
-# FIXME/IDEA : Make specific exceptions !
-# FIXME : How to handle classes which are already using gobject (i.e. gst.Pipeline)
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
"""
-Interfaces for event-based programming
+ Helpers classes to handle signals
"""
from random import randint
+class SignalGroup:
+ """
+ A group of signals, which can be disconnected easily.
+
+ Used to make it easy to keep signals attached to the current project.
+ """
+ def __init__(self):
+ self.signal_handler_ids = {}
+
+ def connect(self, object, signal, sid, callback, *args):
+ """Connect a signal.
+
+ _ `object` is the object which defines the signal.
+ _ `signal` is the name of the signal to connect to.
+ _ `id` is a unique (within this SignalGroup) identifer for the signal to
+ connect to. If this is None, the value of `signal` will be used
+ instead.
+ _ `callback` is the callable to call on the signal.
+ _ `args` are any extra arguments to pass to the callback.
+
+ If there is already a connected signal in the group with the specified
+ unique identifier, this signal will first be disconnected.
+
+ """
+ if sid is None:
+ sid = signal
+
+ if sid in self.signal_handler_ids:
+ old_object, handler_id = self.signal_handler_ids[sid]
+ old_object.disconnect(handler_id)
+ del self.signal_handler_ids[sid]
+
+ handler_id = object.connect(signal, callback, *args)
+ self.signal_handler_ids[id] = (object, handler_id)
+
+ def disconnect(self, sid):
+ """Disconnect the signal with the specified unique identifier.
+
+ If there is no such signal, this returns without having any effect.
+
+ """
+ if id in self.signal_handler_ids:
+ old_object, handler_id = self.signal_handler_ids.pop(sid)
+ old_object.disconnect(handler_id)
+
+ def disconnectAll(self):
+ """Disconnect all signals in the group.
+
+ """
+ for old_object, handler_id in self.signal_handler_ids.itervalues():
+ old_object.disconnect(handler_id)
+ self.signal_handler_ids = {}
+
+ def disconnectForObject(self, obj):
+ """
+ Disconnects all signal in the group connect on the given object
+ """
+ assert obj != None
+ objids = [sid for sid in self.signal_handler_ids.keys() if self.signal_handler_ids[sid][0] == obj]
+ for sid in objids:
+ old_object, handler_id = self.signal_handler_ids.pop(id)
+ old_object.disconnect(handler_id)
+
+
class Signallable(object):
"""
Signallable interface
diff --git a/pitivi/utils/timeline.py b/pitivi/utils/timeline.py
index b98f425..07eed83 100644
--- a/pitivi/utils/timeline.py
+++ b/pitivi/utils/timeline.py
@@ -26,7 +26,7 @@ from gst import SECOND
from pitivi.utils.misc import infinity
from pitivi.utils.loggable import Loggable
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
#from pitivi.utils.align import AutoAligner
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 9f505f2..cb939a0 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -27,7 +27,7 @@ TestCase = unittest.TestCase
from pitivi.application import InteractivePitivi
from pitivi.utils.timeline import MoveContext, TrimStartContext,\
TrimEndContext
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
from pitivi.stream import AudioStream, VideoStream
import pitivi.instance
import gobject
diff --git a/tests/test_signallable.py b/tests/test_signallable.py
index 6b8285a..1c1c505 100644
--- a/tests/test_signallable.py
+++ b/tests/test_signallable.py
@@ -1,5 +1,5 @@
import unittest
-from pitivi.signalinterface import Signallable
+from pitivi.utils.signal import Signallable
class myobject(Signallable):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]