[pitivi] Highlight separator while drag'n'drop
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] Highlight separator while drag'n'drop
- Date: Sat, 21 Jul 2012 20:01:33 +0000 (UTC)
commit 6bf5e6496a29396f2bd3fcff954cc3d8493f1220
Author: Paul Lange <palango gmx de>
Date: Sun Jul 15 19:54:25 2012 +0200
Highlight separator while drag'n'drop
pitivi/timeline/layer.py | 33 ++++++++++++++++++++++++++-------
pitivi/timeline/timeline.py | 30 ++++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 9 deletions(-)
---
diff --git a/pitivi/timeline/layer.py b/pitivi/timeline/layer.py
index e1b0fd1..37791c4 100644
--- a/pitivi/timeline/layer.py
+++ b/pitivi/timeline/layer.py
@@ -47,9 +47,9 @@ class BaseLayerControl(gtk.VBox, Loggable):
self.layer = layer
self._selected = False
- # get the default colour for the current theme
+ # get the default color for the current theme
self.UNSELECTED_COLOR = self.rc_get_style().bg[gtk.STATE_NORMAL]
- # use base instead of bg colours so that we get the lighter colour
+ # use base instead of bg colors so that we get the lighter color
# that is used for list items in TreeView.
self.SELECTED_COLOR = self.rc_get_style().base[gtk.STATE_SELECTED]
@@ -256,7 +256,7 @@ class BaseLayerControl(gtk.VBox, Loggable):
-2 = first and last item -> all disabled
"""
for menu_item in (self.layer_up, self.layer_first,
- self.layer_down, self.layer_last):
+ self.layer_down, self.layer_last):
menu_item.set_sensitive(True)
if position == -2 or position == 0:
@@ -267,6 +267,17 @@ class BaseLayerControl(gtk.VBox, Loggable):
self.layer_down.set_sensitive(False)
self.layer_last.set_sensitive(False)
+ def setSeparatorHighlight(self, highlighted):
+ """
+ Sets if the Separator should be highlighted
+
+ Used for visual drag'n'drop feedback
+ """
+ if highlighted:
+ self.sep.modify_bg(gtk.STATE_NORMAL, self.SELECTED_COLOR)
+ else:
+ self.sep.modify_bg(gtk.STATE_NORMAL, self.UNSELECTED_COLOR)
+
class VideoLayerControl(BaseLayerControl):
"""
@@ -353,10 +364,18 @@ class TwoStateButton(gtk.Button):
self.emit("changed-state", self._state)
-class SpacedSeparator(gtk.VBox):
+class SpacedSeparator(gtk.EventBox):
+ """
+ A Separator with vertical spacing
+
+ Inherits from EventBox since we want to change background color
+ """
def __init__(self):
- gtk.VBox.__init__(self)
+ gtk.EventBox.__init__(self)
+
+ self.box = gtk.VBox()
+ self.box.add(gtk.HSeparator())
+ self.box.props.border_width = 6
- self.add(gtk.HSeparator())
- self.props.border_width = 6
+ self.add(self.box)
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 87cd9f2..842883c 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -513,6 +513,7 @@ class TimelineControls(gtk.VBox, Loggable):
# drag'n' drop
self.connect("drag_data_received", self._dragDataReceivedCb)
+ self.connect("drag_motion", self._dragMotionCb)
self.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
gtk.DEST_DEFAULT_DROP,
[LAYER_CONTROL_TUPLE], gtk.gdk.ACTION_MOVE)
@@ -750,6 +751,30 @@ class TimelineControls(gtk.VBox, Loggable):
widget = self.getControlFromId(int(selection.data))
widget_type = type(widget)
+ for child in self.get_children():
+ child.setSeparatorHighlight(False)
+
+ self.moveControlWidget(widget, self._getIndexForPosition(y))
+
+ def _dragMotionCb(self, widget, context, x, y, timestamp):
+ """
+ Highlight separator where control would go when dropping
+ """
+ index = self._getIndexForPosition(y)
+
+ for child in self.get_children():
+ child.setSeparatorHighlight(False)
+
+ # control would go in first position
+ if index == 0:
+ pass
+ else:
+ self.get_children()[index - 1].setSeparatorHighlight(True)
+
+ def _getIndexForPosition(self, y):
+ """
+ Calculates the new index for a dragged layer
+ """
counter = 0
index = 0
@@ -757,12 +782,13 @@ class TimelineControls(gtk.VBox, Loggable):
for child in self.get_children():
next = counter + child.getHeight()
if y >= counter and y < next:
- self.moveControlWidget(widget, index)
- return
+ return index
counter = next
index += 1
+ return index
+
def moveControlWidget(self, control, index):
"""
Moves control to the given index and cares for moving the linked layer
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]