[pitivi] Drag and drop is functionnal once again from the effectslist



commit 95c7335c11207b3fbee0afb2cf5294a575cb6fe2
Author: Mathieu Duponchelle <mathieu duponchelle epitech eu>
Date:   Thu Apr 18 02:47:22 2013 +0200

    Drag and drop is functionnal once again from the effectslist

 pitivi/clipproperties.py    |   27 +++++++++++++++------------
 pitivi/effects.py           |   10 ++++++++--
 pitivi/medialibrary.py      |    2 +-
 pitivi/timeline/elements.py |    3 +++
 pitivi/timeline/timeline.py |   39 +++++++++++++++++++++++++++++----------
 5 files changed, 56 insertions(+), 25 deletions(-)
---
diff --git a/pitivi/clipproperties.py b/pitivi/clipproperties.py
index 5cf645e..1cf400c 100644
--- a/pitivi/clipproperties.py
+++ b/pitivi/clipproperties.py
@@ -320,19 +320,13 @@ class EffectProperties(Gtk.Expander, Loggable):
     def _cleanCache(self, effect):
         config_ui = self.effect_props_handling.cleanCache(effect)
 
-    def addEffectToCurrentSelection(self, bin_desc):
-        if self.clips:
-            media_type = self.app.effects.getFactoryFromName(bin_desc).media_type
-
-            # Trying to apply effect only on the first object of the selection
-            clip = self.clips[0]
+    def addEffectToClip(self, clip, bin_desc):
+        media_type = self.app.effects.getFactoryFromName(bin_desc).media_type
 
-            # Checking that this effect can be applied on this track object
-            # Which means, it has the corresponding media_type
-            for track_element in clip.get_children():
-                track_type = track_element.get_track_type()
-                if track_type == GES.TrackType.AUDIO and media_type == AUDIO_EFFECT or \
-                        track_type == GES.TrackType.VIDEO and media_type == VIDEO_EFFECT:
+        for track_element in clip.get_children():
+            track_type = track_element.get_track_type()
+            if track_type == GES.TrackType.AUDIO and media_type == AUDIO_EFFECT or \
+                    track_type == GES.TrackType.VIDEO and media_type == VIDEO_EFFECT:
                     #Actually add the effect
                     self.app.action_log.begin("add effect")
                     effect = GES.Effect.new(bin_description=bin_desc)
@@ -343,6 +337,15 @@ class EffectProperties(Gtk.Expander, Loggable):
 
                     break
 
+    def addEffectToCurrentSelection(self, bin_desc):
+        if self.clips:
+            # Trying to apply effect only on the first object of the selection
+            clip = self.clips[0]
+
+            # Checking that this effect can be applied on this track object
+            # Which means, it has the corresponding media_type
+            self.addEffectToClip(clip, bin_desc)
+
     def _dragDropCb(self, *unused_arguments):
         self.info("An item has been dropped onto the clip properties' effects list")
         self.addEffectToCurrentSelection(self.app.gui.effectlist.getSelectedItems())
diff --git a/pitivi/effects.py b/pitivi/effects.py
index 405a321..9590220 100644
--- a/pitivi/effects.py
+++ b/pitivi/effects.py
@@ -423,13 +423,16 @@ class EffectListWidget(Gtk.VBox, Loggable):
 
         self.view.drag_source_set(0, [], Gdk.DragAction.COPY)
         self.view.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, [("pitivi/effect", 0, 
TYPE_PITIVI_EFFECT)], Gdk.DragAction.COPY)
+        #self.view.drag_source_set_target_list([("pitivi/effect", 0, TYPE_PITIVI_EFFECT)])
         self.view.drag_source_set_target_list([])
+        self.view.drag_source_add_uri_targets()
         self.view.drag_source_add_text_targets()
 
         self.view.connect("button-press-event", self._buttonPressEventCb)
         self.view.connect("select-cursor-row", self._enterPressEventCb)
-        self.view.connect("drag_begin", self._dndDragBeginCb)
-        self.view.connect("drag_end", self._dndDragEndCb)
+        self.view.connect("drag-begin", self._dndDragBeginCb)
+        self.view.connect("drag-end", self._dndDragEndCb)
+        self.view.connect("drag-data-get", self._dndDragDataGetCb)
 
         scrollwin = Gtk.ScrolledWindow()
         scrollwin.props.hscrollbar_policy = Gtk.PolicyType.NEVER
@@ -505,6 +508,9 @@ class EffectListWidget(Gtk.VBox, Loggable):
     def _dndDragEndCb(self, unused_view, context):
         self.info("Drag operation ended")
 
+    def _dndDragDataGetCb(self, unused_view, context, data, info, timestamp):
+        data.set_uris([self.getSelectedItems()])
+
     def _rowUnderMouseSelected(self, view, event):
         result = view.get_path_at_pos(int(event.x), int(event.y))
         if result:
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 9d9a311..3e1cc98 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -323,7 +323,7 @@ class MediaLibraryWidget(Gtk.VBox, Loggable):
         view.drag_source_add_uri_targets()
         view.drag_source_add_text_targets()
         view.connect("drag-data-get", self._dndDragDataGetCb)
-        view.connect("drag_begin", self._dndDragBeginCb)
+        view.connect("drag-begin", self._dndDragBeginCb)
         view.connect("drag-end", self._dndDragEndCb)
 
     def _importSourcesCb(self, unused_action):
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index 3b70a7b..16e1394 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -364,6 +364,7 @@ class TimelineElement(Clutter.Actor, Zoomable):
 
     def _createBorder(self):
         self.border = RoundedRectangle(0, 0, 5, 5)
+        self.border.bElement = self.bElement
         color = Cogl.Color()
 
         color.init_from_4ub(100, 100, 100, 255)
@@ -387,6 +388,7 @@ class TimelineElement(Clutter.Actor, Zoomable):
     def _createMarquee(self):
         # TODO: difference between Actor.new() and Actor()?
         self.marquee = Clutter.Actor()
+        self.marquee.bElement = self.bElement
 
         self.marquee.set_background_color(Clutter.Color.new(60, 60, 60, 100))
         self.marquee.props.visible = False
@@ -459,6 +461,7 @@ class ClipElement(TimelineElement):
 
     def _createBackground(self, track):
         self.background = RoundedRectangle(0, 0, 5, 5)
+        self.background.bElement = self.bElement
 
         if track.type == GES.TrackType.AUDIO:
             color = Cogl.Color()
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 268b7f6..5ad680c 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -8,7 +8,7 @@ from datetime import datetime
 from pitivi.utils.timeline import Zoomable, Selection, UNSELECT
 from pitivi.settings import GlobalSettings
 from pitivi.dialogs.prefs import PreferencesDialog
-from pitivi.utils.ui import EXPANDED_SIZE, SPACING, PLAYHEAD_WIDTH, CONTROL_WIDTH
+from pitivi.utils.ui import EXPANDED_SIZE, SPACING, PLAYHEAD_WIDTH, CONTROL_WIDTH, TYPE_PITIVI_EFFECT
 from pitivi.utils.widgets import ZoomBox
 
 from ruler import ScaleRuler
@@ -1066,47 +1066,66 @@ class Timeline(Gtk.VBox, Zoomable):
             if data.get_length() > 0:
                 if not self.dropOccured:
                     self.timeline.resetGhostClips()
-                self.dropData = data.get_data()
+                self.dropData = data.get_uris()
                 self.dropDataReady = True
 
         if self.dropOccured:
             self.dropOccured = False
             Gtk.drag_finish(context, True, False, time)
             self._dragLeaveCb(widget, context, time)
+        else:
+            self.isDraggedClip = True
 
     def _dragDropCb(self, widget, context, x, y, time):
         target = widget.drag_dest_find_target(context, None)
+        y -= self.ruler.get_allocation().height
         if target.name() == "text/uri-list":
             self.dropOccured = True
             widget.drag_get_data(context, target, time)
-            self.timeline.convertGhostClips()
+            if self.isDraggedClip:
+                self.timeline.convertGhostClips()
+                self.timeline.resetGhostClips()
+            else:
+                actor = self.stage.get_actor_at_pos(Clutter.PickMode.ALL, x, y)
+                try:
+                    bElement = actor.bElement
+                    self.app.gui.clipconfig.effect_expander.addEffectToClip(bElement.get_parent(), 
self.dropData[0])
+                except AttributeError:
+                    return False
             return True
         else:
             return False
 
     def _dragMotionCb(self, widget, context, x, y, time):
         target = widget.drag_dest_find_target(context, None)
-        if target.name() != "text/uri-list":
+        if target.name() not in ["text/uri-list", "pitivi/effect"]:
             return False
         if not self.dropDataReady:
             widget.drag_get_data(context, target, time)
             Gdk.drag_status(context, 0, time)
         else:
             x, y = self._transposeXY(x, y)
-            if not self.timeline.ghostClips:
-                asset = self.app.gui.medialibrary.getAssetForUri(self.dropData)
-                self.timeline.addGhostClip(asset, x, y)
-            self.timeline.updateGhostClips(x, y)
+
+            # dragged from the media library
+            if not self.timeline.ghostClips and self.isDraggedClip:
+                for uri in self.dropData:
+                    asset = self.app.gui.medialibrary.getAssetForUri(uri)
+                    if asset is None:
+                        self.isDraggedClip = False
+                        break
+                    self.timeline.addGhostClip(asset, x, y)
+
+            if self.isDraggedClip:
+                self.timeline.updateGhostClips(x, y)
+
             Gdk.drag_status(context, Gdk.DragAction.COPY, time)
             if not self.dropHighlight:
                 widget.drag_highlight()
                 self.dropHighlight = True
-#        Gtk.drag_set_icon_pixbuf(context, self.pixbuf, 0, 0)
         return True
 
     def _dragLeaveCb(self, widget, context, time):
         if self.dropDataReady:
-            self.dropData = None
             self.dropDataReady = False
         if self.dropHighlight:
             widget.drag_unhighlight()


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