[pitivi] Properly update popup menu sensitivity
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] Properly update popup menu sensitivity
- Date: Sat, 21 Jul 2012 20:01:28 +0000 (UTC)
commit 6c9ce0530478308dd6977cb6eef248f37237c252
Author: Paul Lange <palango gmx de>
Date: Sun Jul 15 18:54:51 2012 +0200
Properly update popup menu sensitivity
pitivi/timeline/layer.py | 54 +++++++++++++++++++++++++++++-------------
pitivi/timeline/timeline.py | 51 +++++++++++++++++++++++++++++++++++-----
2 files changed, 81 insertions(+), 24 deletions(-)
---
diff --git a/pitivi/timeline/layer.py b/pitivi/timeline/layer.py
index d5daed2..e1b0fd1 100644
--- a/pitivi/timeline/layer.py
+++ b/pitivi/timeline/layer.py
@@ -123,23 +123,23 @@ class BaseLayerControl(gtk.VBox, Loggable):
layer_delete = gtk.ImageMenuItem(_("_Delete layer"))
layer_delete.connect("activate", self._deleteLayerCb)
layer_delete.set_image(gtk.image_new_from_icon_name("edit-delete", gtk.ICON_SIZE_MENU))
- layer_up = gtk.ImageMenuItem(_("Move layer up"))
- layer_up.connect("activate", self._moveLayerCb, -1)
- layer_up.set_image(gtk.image_new_from_icon_name("go-up", gtk.ICON_SIZE_MENU))
- layer_down = gtk.ImageMenuItem(_("Move layer down"))
- layer_down.connect("activate", self._moveLayerCb, 1)
- layer_down.set_image(gtk.image_new_from_icon_name("go-down", gtk.ICON_SIZE_MENU))
- layer_first = gtk.ImageMenuItem(_("Move layer to top"))
- layer_first.connect("activate", self._moveLayerCb, -2)
- layer_first.set_image(gtk.image_new_from_icon_name("go-top", gtk.ICON_SIZE_MENU))
- layer_last = gtk.ImageMenuItem(_("Move layer to bottom"))
- layer_last.connect("activate", self._moveLayerCb, 2)
- layer_last.set_image(gtk.image_new_from_icon_name("go-bottom", gtk.ICON_SIZE_MENU))
-
- self.popup.append(layer_first)
- self.popup.append(layer_up)
- self.popup.append(layer_down)
- self.popup.append(layer_last)
+ self.layer_up = gtk.ImageMenuItem(_("Move layer up"))
+ self.layer_up.connect("activate", self._moveLayerCb, -1)
+ self.layer_up.set_image(gtk.image_new_from_icon_name("go-up", gtk.ICON_SIZE_MENU))
+ self.layer_down = gtk.ImageMenuItem(_("Move layer down"))
+ self.layer_down.connect("activate", self._moveLayerCb, 1)
+ self.layer_down.set_image(gtk.image_new_from_icon_name("go-down", gtk.ICON_SIZE_MENU))
+ self.layer_first = gtk.ImageMenuItem(_("Move layer to top"))
+ self.layer_first.connect("activate", self._moveLayerCb, -2)
+ self.layer_first.set_image(gtk.image_new_from_icon_name("go-top", gtk.ICON_SIZE_MENU))
+ self.layer_last = gtk.ImageMenuItem(_("Move layer to bottom"))
+ self.layer_last.connect("activate", self._moveLayerCb, 2)
+ self.layer_last.set_image(gtk.image_new_from_icon_name("go-bottom", gtk.ICON_SIZE_MENU))
+
+ self.popup.append(self.layer_first)
+ self.popup.append(self.layer_up)
+ self.popup.append(self.layer_down)
+ self.popup.append(self.layer_last)
self.popup.append(gtk.SeparatorMenuItem())
self.popup.append(layer_delete)
self.popup.show_all()
@@ -247,6 +247,26 @@ class BaseLayerControl(gtk.VBox, Loggable):
else:
self.sep.hide()
+ def updateMenuSensitivity(self, position):
+ """
+ Update Menu item sensitivity
+
+ 0 = first item -> disable "up" and "first"
+ -1 = last item -> disable "down" and "last"
+ -2 = first and last item -> all disabled
+ """
+ for menu_item in (self.layer_up, self.layer_first,
+ self.layer_down, self.layer_last):
+ menu_item.set_sensitive(True)
+
+ if position == -2 or position == 0:
+ self.layer_first.set_sensitive(False)
+ self.layer_up.set_sensitive(False)
+
+ if position == -2 or position == -1:
+ self.layer_down.set_sensitive(False)
+ self.layer_last.set_sensitive(False)
+
class VideoLayerControl(BaseLayerControl):
"""
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 621db57..87cd9f2 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -566,8 +566,21 @@ class TimelineControls(gtk.VBox, Loggable):
self._orderControls()
self._hideLastSeparator()
+ self._updatePopupMenus()
+
+ def _layerRemovedCb(self, timeline, layer):
+ audio_control = self._layer_controls[layer][ges.TRACK_TYPE_AUDIO]
+ video_control = self._layer_controls[layer][ges.TRACK_TYPE_VIDEO]
+
+ self.remove(audio_control)
+ self.remove(video_control)
+
+ del self._layer_controls[layer]
+ self._hideLastSeparator()
+ self._updatePopupMenus()
def _orderControls(self):
+ # this works since every layer has audio and video
middle = len(self.get_children()) / 2
for child in self.get_children():
if isinstance(child, VideoLayerControl):
@@ -582,15 +595,38 @@ class TimelineControls(gtk.VBox, Loggable):
self.children()[-1].setSeparatorVisibility(False)
- def _layerRemovedCb(self, timeline, layer):
- audio_control = self._layer_controls[layer][ges.TRACK_TYPE_AUDIO]
- video_control = self._layer_controls[layer][ges.TRACK_TYPE_VIDEO]
+ def _updatePopupMenus(self):
+ """
+ Update sensitivity of menus
- self.remove(audio_control)
- self.remove(video_control)
+ Should be called after _orderControls as it expects the controls
+ in ordered state
+ """
+ children = self.get_children()
- del self._layer_controls[layer]
- self._hideLastSeparator()
+ # handle no layer case
+ if not children:
+ return
+
+ # handle one layer case
+ if len(children) == 2:
+ for child in children:
+ child.updateMenuSensitivity(-2)
+ return
+
+ # all other cases
+ last = None
+ index = 0
+ for child in children:
+ if type(child) == AudioLayerControl:
+ index = 0
+ last.updateMenuSensitivity(-1)
+
+ child.updateMenuSensitivity(index)
+ index += 1
+ last = child
+
+ last.updateMenuSensitivity(-1)
def getHeightOfLayer(self, track_type, layer):
if track_type == ges.TRACK_TYPE_VIDEO:
@@ -746,6 +782,7 @@ class TimelineControls(gtk.VBox, Loggable):
# order controls and update separators
self._orderControls()
self._hideLastSeparator()
+ self._updatePopupMenus()
def getControlIndex(self, control):
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]