[pitivi: 2/7] menus for timeline



commit d78e58151ff22c1ec1a03fda919720c33a979aca
Author: Brandon Lewis <brandon_lewis berkeley edu>
Date:   Wed Apr 1 23:25:08 2009 -0700

    menus for timeline
---
 pitivi/timeline/timeline.py |    5 +++
 pitivi/ui/timeline.py       |   66 +++++++++++++++++++++++++++++-------------
 2 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 4342cce..2de98e1 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -443,6 +443,7 @@ class Timeline(object ,Signallable):
         'duration-changed': ['duration'],
         'track-added': ['track'],
         'track-removed': ['track'],
+        'selection-changed': [],
     }
 
     def __init__(self):
@@ -590,6 +591,8 @@ class Timeline(object ,Signallable):
         for obj in old_selection - self.timeline_selection:
             obj.selected = False
 
+        self.emit("selection-changed")
+
     def linkSelection(self):
         if len(self.timeline_selection) < 2:
             return
@@ -612,6 +615,7 @@ class Timeline(object ,Signallable):
             self.links.remove(old_link)
 
         self.links.append(link)
+        self.emit("selection-changed")
 
     def unlinkSelection(self):
         empty_links = set()
@@ -626,6 +630,7 @@ class Timeline(object ,Signallable):
 
         for link in empty_links:
             self.links.remove(link)
+        self.emit("selection-changed")
 
     def groupSelection(self):
         if len(self.timeline_selection) < 2:
diff --git a/pitivi/ui/timeline.py b/pitivi/ui/timeline.py
index 50f7c62..3b02e13 100644
--- a/pitivi/ui/timeline.py
+++ b/pitivi/ui/timeline.py
@@ -61,10 +61,10 @@ ui = '''
         <menu action="Timeline">
             <placeholder name="Timeline">
                 <menuitem action="Razor" />
-                <menuitem action="DeleteObj" />
                 <separator />
-                <menuitem action="UnlinkObj" />
+                <menuitem action="DeleteObj" />
                 <menuitem action="LinkObj" />
+                <menuitem action="UnlinkObj" />
             </placeholder>
         </menu>
     </menubar>
@@ -171,15 +171,18 @@ class Timeline(gtk.Table, Loggable, Zoomable):
                 self._zoomInCb),
             ("ZoomOut", gtk.STOCK_ZOOM_OUT, None, None, ZOOM_OUT,
                 self._zoomOutCb),
+        )
+
+        selection_actions = (
             ("DeleteObj", gtk.STOCK_DELETE, None, "Delete", DELETE,
                 self.deleteSelected),
-            ("UnlinkObj", "pitivi-unlink", None, None, UNLINK,
+            ("UnlinkObj", "pitivi-unlink", None, "<Shift><Control>L", UNLINK,
                 self.unlinkSelected),
-            ("LinkObj", "pitivi-link", None, None, LINK,
+            ("LinkObj", "pitivi-link", None, "<Control>L", LINK,
                 self.linkSelected),
-            ("UngroupObj", "pitivi-ungroup", None, None, UNGROUP,
+            ("UngroupObj", "pitivi-ungroup", "<Shift><Control>G", None, UNGROUP,
                 self.ungroupSelected),
-            ("GroupObj", "pitivi-group", None, None, GROUP,
+            ("GroupObj", "pitivi-group", None, "<Control>G", GROUP,
                 self.groupSelected),
         )
 
@@ -187,11 +190,20 @@ class Timeline(gtk.Table, Loggable, Zoomable):
             ("Razor", "pitivi-split", _("Razor"), "<Ctrl>R", RAZOR,
                 self.toggleRazor),
         )
-        self.actiongroup = gtk.ActionGroup("complextimeline")
-        self.actiongroup.add_actions(actions)
-        self.actiongroup.add_toggle_actions(toggle_actions)
-        #self.actiongroup.set_visible(False)
-        self.ui_manager.insert_action_group(self.actiongroup, 0)
+
+        actiongroup = gtk.ActionGroup("timelinepermanent")
+        actiongroup.add_actions(actions)
+        actiongroup.add_toggle_actions(toggle_actions)
+        self.ui_manager.insert_action_group(actiongroup, 0)
+
+        actiongroup = gtk.ActionGroup("timelineselection")
+        actiongroup.add_actions(selection_actions)
+        self.link_action = actiongroup.get_action("LinkObj")
+        self.unlink_action = actiongroup.get_action("UnlinkObj")
+        self.delete_action = actiongroup.get_action("DeleteObj")
+
+        self.ui_manager.insert_action_group(actiongroup)
+
         self.ui_manager.add_ui_from_string(ui)
 
         # drag and drop
@@ -312,7 +324,11 @@ class Timeline(gtk.Table, Loggable, Zoomable):
 
 ## Timeline callbacks
 
-    timeline = receiver()
+    def _set_timeline(self):
+        if self.timeline:
+            self._timelineSelectionChanged(self.timeline)
+
+    timeline = receiver(_set_timeline)
 
     @handler(timeline, "duration-changed")
     def _timelineStartDurationChanged(self, unused_timeline, duration):
@@ -320,16 +336,24 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         self._canvas.setMaxDuration(duration)
         self.ruler.setShadedDuration(duration)
 
-## ToolBar callbacks
-
-    ## override show()/hide() methods to take care of actions
-    def show(self):
-        gtk.VBox.show(self)
-        self.actiongroup.set_visible(True)
+    @handler(timeline, "selection-changed")
+    def _timelineSelectionChanged(self, timeline):
+        delete = False
+        link = False
+        unlink = False
+        if timeline.timeline_selection:
+            delete = True
+            if len(timeline.timeline_selection) > 1:
+                link = True
+            for obj in self.timeline.timeline_selection:
+                if obj.link:
+                    unlink = True
+                    break
+        self.delete_action.set_sensitive(delete)
+        self.link_action.set_sensitive(link)
+        self.unlink_action.set_sensitive(unlink)
 
-    def show_all(self):
-        gtk.VBox.show_all(self)
-        self.actiongroup.set_visible(True)
+## ToolBar callbacks
 
     def hide(self):
         self.actiongroup.set_visible(False)



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