[pitivi] Re-enables drag and drop from the medialibrary to the timeline
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] Re-enables drag and drop from the medialibrary to the timeline
- Date: Sun, 2 Sep 2012 04:03:00 +0000 (UTC)
commit 49138f66314073ab14d381628e865280bae7389f
Author: Mathieu Duponchelle <mathieu duponchelle epitech eu>
Date: Sat Aug 11 23:45:21 2012 +0200
Re-enables drag and drop from the medialibrary to the timeline
pitivi/medialibrary.py | 134 +++++++++----------------------------------
pitivi/timeline/timeline.py | 61 ++++++--------------
2 files changed, 46 insertions(+), 149 deletions(-)
---
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 4503adb..a674906 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -32,6 +32,8 @@ import pango
import os
import time
+from gi.repository import Gdk
+
from urllib import unquote
from gettext import gettext as _
from hashlib import md5
@@ -49,6 +51,7 @@ from pitivi.utils.loggable import Loggable
import pitivi.utils.ui as dnd
from pitivi.utils.ui import beautify_info, info_name, SPACING, PADDING
+from pitivi.utils.ui import TYPE_PITIVI_FILESOURCE
SHOW_TREEVIEW = 1
SHOW_ICONVIEW = 2
@@ -272,6 +275,7 @@ class MediaLibraryWidget(gtk.VBox, Loggable):
self._errors = []
self._project = None
self.dummy_selected = []
+ self._draggedItems = None
# Store
# icon, infotext, objectfactory, uri, length
@@ -438,20 +442,20 @@ class MediaLibraryWidget(gtk.VBox, Loggable):
self.connect("drag_data_received", self._dndDataReceivedCb)
self.treeview.drag_source_set(0, [], gtk.gdk.ACTION_COPY)
- self.treeview.connect("motion-notify-event",
- self._treeViewMotionNotifyEventCb)
- self.treeview.connect("button-release-event",
- self._treeViewButtonReleaseCb)
+ self.treeview.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, [("pitivi/file-source", 0, TYPE_PITIVI_FILESOURCE)], Gdk.DragAction.COPY)
+ self.treeview.drag_source_set_target_list(None)
+ self.treeview.drag_source_add_uri_targets()
+ self.treeview.drag_source_add_text_targets()
+
self.treeview.connect("drag_begin", self._dndDragBeginCb)
- self.treeview.connect("drag_data_get", self._dndDataGetCb)
self.iconview.drag_source_set(0, [], gtk.gdk.ACTION_COPY)
- self.iconview.connect("motion-notify-event",
- self._iconViewMotionNotifyEventCb)
- self.iconview.connect("button-release-event",
- self._iconViewButtonReleaseCb)
+ self.iconview.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, [gtk.TargetEntry.new("pitivi/file-source", 0, TYPE_PITIVI_FILESOURCE)], Gdk.DragAction.COPY)
+ self.iconview.drag_source_set_target_list(None)
+ self.iconview.drag_source_add_uri_targets()
+ self.iconview.drag_source_add_text_targets()
+
self.iconview.connect("drag_begin", self._dndDragBeginCb)
- self.iconview.connect("drag_data_get", self._dndDataGetCb)
# Hack so that the views have the same method as self
self.treeview.getSelectedItems = self.getSelectedItems
@@ -1108,55 +1112,19 @@ class MediaLibraryWidget(gtk.VBox, Loggable):
self._viewShowPopup(treeview, event)
chain_up = False
- else:
-
- if not event.state & (gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK):
- chain_up = not self._rowUnderMouseSelected(treeview, event)
+ elif not event.state & (gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK):
+ chain_up = not self._rowUnderMouseSelected(treeview, event)
- self._dragStarted = False
- self._dragSelection = False
- self._dragButton = event.button
- self._dragX = int(event.x)
- self._dragY = int(event.y)
-
- if chain_up:
- gtk.TreeView.do_button_press_event(treeview, event)
+ if not chain_up:
+ self._draggedItems = self.getSelectedItems()
else:
- treeview.grab_focus()
+ self._draggedItems = None
+ gtk.TreeView.do_button_press_event(treeview, event)
self._ignoreRelease = chain_up
return True
- def _treeViewMotionNotifyEventCb(self, treeview, event):
- if not self._dragButton:
- return True
-
- if self._nothingUnderMouse(treeview, event):
- return True
-
- if treeview.drag_check_threshold(self._dragX, self._dragY,
- int(event.x), int(event.y)):
- context = treeview.drag_begin(
- gtk.TargetList.new([dnd.URI_TARGET_ENTRY,
- dnd.FILESOURCE_TARGET_ENTRY]),
- gtk.gdk.ACTION_COPY,
- self._dragButton,
- event)
- self._dragStarted = True
- return False
-
- def _treeViewButtonReleaseCb(self, treeview, event):
- if event.button == self._dragButton:
- self._dragButton = None
- if (not self._ignoreRelease) and (not self._dragStarted):
- treeview.get_selection().unselect_all()
- result = treeview.get_path_at_pos(int(event.x), int(event.y))
- if result:
- path = result[0]
- treeview.get_selection().select_path(path)
- return False
-
def _viewSelectionChangedCb(self, unused):
if self._viewHasSelection():
self.selection_actions.set_sensitive(True)
@@ -1171,27 +1139,6 @@ class MediaLibraryWidget(gtk.VBox, Loggable):
path = self.modelFilter[path][COL_URI]
self.emit('play', path)
- def _iconViewMotionNotifyEventCb(self, iconview, event):
- if not self._dragButton:
- return True
-
- if self._dragSelection:
- return False
-
- if self._nothingUnderMouse(iconview, event):
- return True
-
- if iconview.drag_check_threshold(self._dragX, self._dragY,
- int(event.x), int(event.y)):
- context = iconview.drag_begin(
- gtk.TargetList([dnd.URI_TARGET_ENTRY,
- dnd.FILESOURCE_TARGET_ENTRY]),
- gtk.gdk.ACTION_COPY,
- self._dragButton,
- event)
- self._dragStarted = True
- return False
-
def _iconViewButtonPressEventCb(self, iconview, event):
chain_up = True
@@ -1203,36 +1150,18 @@ class MediaLibraryWidget(gtk.VBox, Loggable):
elif event.button == 3:
self._viewShowPopup(iconview, event)
chain_up = False
- else:
- if not event.state & (gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK):
- chain_up = not self._rowUnderMouseSelected(iconview, event)
-
- self._dragStarted = False
- self._dragSelection = self._nothingUnderMouse(iconview, event)
- self._dragButton = event.button
- self._dragX = int(event.x)
- self._dragY = int(event.y)
+ elif not event.state & (gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK):
+ chain_up = not self._rowUnderMouseSelected(iconview, event)
- if chain_up:
- gtk.IconView.do_button_press_event(iconview, event)
+ if not chain_up:
+ self._draggedItems = self.getSelectedItems()
else:
- iconview.grab_focus()
-
+ self._draggedItems = None
+ gtk.IconView.do_button_press_event(iconview, event)
self._ignoreRelease = chain_up
return True
- def _iconViewButtonReleaseCb(self, iconview, event):
- if event.button == self._dragButton:
- self._dragButton = None
- self._dragSelection = False
- if (not self._ignoreRelease) and (not self._dragStarted):
- iconview.unselect_all()
- path = iconview.get_path_at_pos(int(event.x), int(event.y))
- if path:
- iconview.select_path(path)
- return False
-
def _newProjectCreatedCb(self, app, project):
if not self._project is project:
self._project = project
@@ -1324,16 +1253,9 @@ class MediaLibraryWidget(gtk.VBox, Loggable):
def getSelectedItems(self):
""" Returns a list of selected items URIs """
+ if self._draggedItems:
+ return self._draggedItems
return [self.modelFilter[path][COL_URI]
for path in self.getSelectedPaths()]
- def _dndDataGetCb(self, unused_widget, context, selection,
- targettype, unused_eventtime):
- self.info("data get, type:%d", targettype)
- uris = self.getSelectedItems()
- if len(uris) < 1:
- return
- selection.set(selection.target, 8, '\n'.join(uris))
- gtk.drag_set_icon_pixbuf(context, INVISIBLE, 0, 0)
-
gobject.type_register(MediaLibraryWidget)
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 2552de0..191e976 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -35,6 +35,9 @@ import ruler
import gobject
import goocanvas
+from gi.repository import Gtk
+from gi.repository import Gdk
+
from gettext import gettext as _
from os.path import join
@@ -513,8 +516,7 @@ class TimelineControls(gtk.VBox, Loggable):
self.connect("drag_drop", self._dragDropCb)
self.connect("drag_motion", self._dragMotionCb)
self.connect("drag_leave", self._dragLeaveCb)
- self.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
- gtk.DEST_DEFAULT_DROP,
+ self.drag_dest_set(gtk.DEST_DEFAULT_ALL,
[LAYER_CONTROL_TARGET_ENTRY], gtk.gdk.ACTION_MOVE)
def _sizeAllocatedCb(self, widget, alloc):
@@ -1121,11 +1123,13 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self.ui_manager.add_ui_from_string(ui)
# drag and drop
- self._canvas.drag_dest_set(gtk.DEST_DEFAULT_MOTION,
- [FILESOURCE_TARGET_ENTRY, EFFECT_TARGET_ENTRY],
- gtk.gdk.ACTION_COPY)
- self._canvas.connect("drag-data-received", self._dragDataReceivedCb)
+ self._canvas.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT,
+ [FILESOURCE_TARGET_ENTRY, EFFECT_TARGET_ENTRY],
+ gtk.gdk.ACTION_COPY)
+
+ self._canvas.drag_dest_add_text_targets()
+
self._canvas.connect("drag-leave", self._dragLeaveCb)
self._canvas.connect("drag-drop", self._dragDropCb)
self._canvas.connect("drag-motion", self._dragMotionCb)
@@ -1165,17 +1169,10 @@ class Timeline(gtk.Table, Loggable, Zoomable):
def _dragMotionCb(self, unused, context, x, y, timestamp):
# Set up the initial data when we first initiate the drag operation
+
if not self._drag_started:
- self.debug("Drag start")
- if context.targets in DND_EFFECT_LIST:
- atom = gtk.gdk.atom_intern(EFFECT_TARGET_ENTRY.target)
- else:
- atom = gtk.gdk.atom_intern(FILESOURCE_TARGET_ENTRY.target)
self._drag_started = True
- self._canvas.drag_get_data(context, atom, timestamp)
- self._canvas.drag_highlight()
- # We want to show the clips being dragged to the timeline (not effects)
- elif context.targets not in DND_EFFECT_LIST:
+ elif context.list_targets() not in DND_EFFECT_LIST:
if not self._temp_objects and not self._creating_tckobjs_sigid:
self._create_temp_source(x, y)
@@ -1216,9 +1213,8 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self.debug("Drag cleanup")
self._drag_started = False
self._factories = []
- if context.targets not in DND_EFFECT_LIST:
+ if context.list_targets() not in DND_EFFECT_LIST:
self.timeline.enable_update(True)
- self._canvas.drag_unhighlight()
self.debug("Need to cleanup %d objects" % len(self._temp_objects))
for obj in self._temp_objects:
layer = obj.get_layer()
@@ -1234,7 +1230,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
# Resetting _drag_started will tell _dragCleanUp to not do anything
self._drag_started = False
self.debug("Drag drop")
- if context.targets not in DND_EFFECT_LIST:
+ if context.list_targets() not in DND_EFFECT_LIST:
self._canvas.drag_unhighlight()
self.app.action_log.begin("add clip")
if self._move_context is not None:
@@ -1246,7 +1242,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
# Clear the temporary references to objects, as they are real now.
self._temp_objects = []
self._factories = []
- context.drop_finish(True, timestamp)
+ #context.drop_finish(True, timestamp)
else:
if self.app.current.timeline.props.duration == 0:
return False
@@ -1278,32 +1274,11 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self.app.action_log.commit()
self._factories = None
self._seeker.flush()
- context.drop_finish(True, timestamp)
self.timeline.selection.setSelection(timeline_objs, SELECT)
break
return True
- def _dragDataReceivedCb(self, unused_layout, context, x, y,
- selection, targetType, timestamp):
- self.log("targetType:%d, selection.data:%s" % (targetType, selection.data))
- self.selection_data = selection.data
-
- if targetType not in [TYPE_PITIVI_FILESOURCE, TYPE_PITIVI_EFFECT]:
- context.finish(False, False, timestamp)
- return
-
- if targetType == TYPE_PITIVI_FILESOURCE:
- uris = selection.data.split("\n")
- self._factories = [self._project.medialibrary.getInfoFromUri(uri) for uri in uris]
- else:
- if not self.app.current.timeline.props.duration > 0:
- return False
- self._factories = [self.app.effects.getFactoryFromName(selection.data)]
-
- context.drag_status(gtk.gdk.ACTION_COPY, timestamp)
- return True
-
def _getTimelineObjectUnderMouse(self, x, y):
timeline_objs = []
items_in_area = self._canvas.getItemsInArea(x, y, x + 1, y + 1)
@@ -1385,12 +1360,12 @@ class Timeline(gtk.Table, Loggable, Zoomable):
Create temporary clips to be displayed on the timeline during a
drag-and-drop operation.
"""
- infos = self._factories
layer = self._ensureLayer()[0]
duration = 0
- for info in infos:
- src = ges.TimelineFileSource(uri=info.get_uri())
+ for uri in self.app.gui.medialibrary.getSelectedItems():
+ info = self._project.medialibrary.getInfoFromUri(uri)
+ src = ges.TimelineFileSource(uri=uri)
src.props.start = duration
# Set image duration
# FIXME: after GES Materials are merged, check if image instead
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]