[pitivi] Set the timeline toolbar sensitivity when the selection changes



commit 5942413e3bbb35b5a4a0b057bfdf2d070688db33
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Sat Jun 2 20:07:14 2012 -0400

    Set the timeline toolbar sensitivity when the selection changes

 pitivi/timeline/timeline.py |   41 +++++++++++++++++++++++++++++------------
 pitivi/timeline/track.py    |    6 +++++-
 2 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 4deac36..21d0659 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -608,8 +608,8 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         self._project = None
         self._projectmanager = None
 
-        #Ids of the layer-added and layer-removed signals
-        self._layer_sig_ids = []
+        # The IDs of the various gobject signals we connect to
+        self._signal_ids = []
 
         self._settings = self.app.settings
         self._settings.connect("edgeSnapDeadbandChanged",
@@ -1272,16 +1272,20 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         self._timeline = timeline
 
         if timeline:
-            # Connecting to timeline signals
-            self._layer_sig_ids.append(self._timeline.connect("layer-added",
+            # Connecting to timeline gobject signals
+            self._signal_ids.append(timeline.connect("layer-added",
                     self._layerAddedCb))
-            self._layer_sig_ids.append(self._timeline.connect("layer-removed",
+            self._signal_ids.append(timeline.connect("layer-removed",
                     self._layerRemovedCb))
-            self._layer_sig_ids.append(timeline.connect("notify::update",
+            self._signal_ids.append(timeline.connect("notify::update",
                     self._timelineUpdateChangedCb))
-            self._layer_sig_ids.append(timeline.connect("notify::duration",
+            self._signal_ids.append(timeline.connect("notify::duration",
                     self._timelineDurationChangedCb))
 
+            # The Selection object of _timeline inherits signallable
+            # We will be able to disconnect it with disconnect_by_func
+            self._timeline.selection.connect("selection-changed", self._selectionChangedCb)
+
             # Make sure to set the current layer in use
             self._layerAddedCb(None, None)
             self._timeline.props.snapping_distance = \
@@ -1294,12 +1298,12 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         return self._timeline
 
     def delTimeline(self):
-        # Disconnect signal
-        for sigid in self._layer_sig_ids:
+        # Disconnect signals
+        for sigid in self._signal_ids:
             self._timeline.disconnect(sigid)
-
-        # clear list
-        self._layer_sig_ids = []
+        self._signal_ids = []
+        if hasattr(self._timeline, "selection"):
+            self._timeline.selection.disconnect_by_func(self._selectionChangedCb)
 
         #Remove references to the ges timeline
         self._timeline = None
@@ -1356,6 +1360,19 @@ class Timeline(gtk.Table, Loggable, Zoomable):
             self.log("Setting 'zoomed_fitted' to True")
             self.zoomed_fitted = True
 
+    def _selectionChangedCb(self, selection):
+        """
+        The selected clips on the timeline canvas have changed with the
+        "selection-changed" signal.
+
+        This is where you apply global UI changes, unlike individual
+        track elements' "selected-changed" signal from the Selected class.
+        """
+        if selection:
+            self.selection_actions.set_sensitive(True)
+        else:
+            self.selection_actions.set_sensitive(False)
+
 ## ToolBar callbacks
     def _zoomFitCb(self, unused, unsued2=None):
         self._setBestZoomRatio()
diff --git a/pitivi/timeline/track.py b/pitivi/timeline/track.py
index 37a0e49..51e87aa 100644
--- a/pitivi/timeline/track.py
+++ b/pitivi/timeline/track.py
@@ -118,11 +118,14 @@ def text_size(text):
 
 #--------------------------------------------------------------#
 #                            Main Classes                      #
-class Selected (Signallable):
+class Selected(Signallable):
     """
     A simple class that let us emit a selected-changed signal
     when needed, and that can be check directly to know if the
     object is selected or not.
+
+    This is meant only for individual elements, do not confuse this with
+    utils.timeline's "Selection" class.
     """
 
     __signals__ = {
@@ -552,6 +555,7 @@ class TrackObject(View, goocanvas.Group, Zoomable, Loggable):
         self._update()
 
     def selectedChangedCb(self, element, unused_selection):
+        # Do not confuse this method with _selectionChangedCb in Timeline
         # unused_selection is True only when no clip was selected before
         # Note that element is a track.Selected object,
         # whereas self.element is a GES object (ex: TrackVideoTransition)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]