[pitivi] viewer: Add a button to undock the viewer directly instead of using menu actions



commit 17fee0c0802e5f4e7746b3afbed8ffc3fe0b9989
Author: Jean-François Fortin Tam <nekohayo gmail com>
Date:   Fri Dec 27 14:45:48 2013 -0500

    viewer: Add a button to undock the viewer directly instead of using menu actions

 data/ui/mainwindow.xml |    2 --
 pitivi/mainwindow.py   |    5 +----
 pitivi/viewer.py       |   38 ++++++++++++++++----------------------
 3 files changed, 17 insertions(+), 28 deletions(-)
---
diff --git a/data/ui/mainwindow.xml b/data/ui/mainwindow.xml
index 50abcb7..43fd221 100644
--- a/data/ui/mainwindow.xml
+++ b/data/ui/mainwindow.xml
@@ -22,8 +22,6 @@
     </menu>
     <menu action="View">
       <placeholder name="Timeline" />
-      <separator />
-      <menuitem action="WindowizeViewer" />
     </menu>
     <menu action="Library">
       <separator />
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index d21e95f..57c8331 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -285,9 +285,6 @@ class PitiviMainWindow(Gtk.Window, Loggable):
 
         self.main_actions = Gtk.ActionGroup(name="mainwindow")
         self.main_actions.add_actions(actions)
-        self.undock_action = Gtk.Action(name="WindowizeViewer", label=_("Undock Viewer"),
-            tooltip=_("Put the viewer in a separate window"), stock_id=None)
-        self.main_actions.add_action(self.undock_action)
 
         important_actions = ("Undo", "SaveProject", "RenderProject")
         for action in self.main_actions.list_actions():
@@ -391,7 +388,7 @@ class PitiviMainWindow(Gtk.Window, Loggable):
         self.context_tabs.show()
 
         # Viewer
-        self.viewer = ViewerContainer(self.app, undock_action=self.undock_action)
+        self.viewer = ViewerContainer(self.app)
         self.mainhpaned.pack2(self.viewer, resize=False, shrink=False)
 
         # Now, the lower part: the timeline
diff --git a/pitivi/viewer.py b/pitivi/viewer.py
index 16063a2..22d08be 100644
--- a/pitivi/viewer.py
+++ b/pitivi/viewer.py
@@ -78,7 +78,7 @@ class ViewerContainer(Gtk.VBox, Loggable):
 
     INHIBIT_REASON = _("Currently playing")
 
-    def __init__(self, app, undock_action=None):
+    def __init__(self, app):
         Gtk.VBox.__init__(self)
         self.set_border_width(SPACING)
         self.app = app
@@ -98,12 +98,9 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self._haveUI = False
 
         self._createUi()
-        self.undock_action = undock_action
-        if undock_action:
-            self.undock_action.connect("activate", self._toggleDocked)
 
-            if not self.settings.viewerDocked:
-                self.undock()
+        if not self.settings.viewerDocked:
+            self.undock()
 
     @property
     def target(self):
@@ -231,12 +228,18 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self.goToEnd_button.set_sensitive(False)
         bbox.pack_start(self.goToEnd_button, False, True, 0)
 
-        # current time
         self.timecode_entry = TimeWidget()
         self.timecode_entry.setWidgetValue(0)
         self.timecode_entry.set_tooltip_text(_('Enter a timecode or frame number\nand press "Enter" to go to 
that position'))
         self.timecode_entry.connectActivateEvent(self._entryActivateCb)
         bbox.pack_start(self.timecode_entry, False, 10, 0)
+
+        self.undock_button = Gtk.ToolButton()
+        self.undock_button.set_icon_name("view-restore")
+        self.undock_button.connect("clicked", self.undock)
+        self.undock_button.set_tooltip_text(_("Detach the viewer\nYou can re-attach it by closing the newly 
created window."))
+        bbox.pack_start(self.undock_button, False, True, 0)
+
         self._haveUI = True
 
         # Identify widgets for AT-SPI, making our test suite easier to develop
@@ -247,6 +250,7 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self.forward_button.get_accessible().set_name("forward_button")
         self.goToEnd_button.get_accessible().set_name("goToEnd_button")
         self.timecode_entry.get_accessible().set_name("timecode_entry")
+        self.undock_button.get_accessible().set_name("undock_button")
 
         screen = Gdk.Screen.get_default()
         height = screen.get_height()
@@ -329,22 +333,20 @@ class ViewerContainer(Gtk.VBox, Loggable):
 
     ## public methods for controlling playback
 
-    def undock(self):
-        if not self.undock_action:
-            self.error("Cannot undock because undock_action is missing.")
-            return
+    def undock(self, *unused_widget):
         if not self.docked:
+            self.warning("The viewer is already undocked")
             return
 
         self.docked = False
         self.settings.viewerDocked = False
-        self.undock_action.set_label(_("Dock Viewer"))
 
         self.remove(self.buttons_container)
         self.external_vbox.pack_end(self.buttons_container, False, False, 0)
         self.external_window.set_type_hint(Gdk.WindowTypeHint.UTILITY)
         self.external_window.show()
 
+        self.undock_button.hide()
         self.fullscreen_button = Gtk.ToggleToolButton()
         self.fullscreen_button.set_icon_name("view-fullscreen")
         self.fullscreen_button.set_tooltip_text(_("Show this window in fullscreen"))
@@ -360,15 +362,13 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self.external_window.resize(self.settings.viewerWidth, self.settings.viewerHeight)
 
     def dock(self):
-        if not self.undock_action:
-            self.error("Cannot dock because undock_action is missing.")
-            return
         if self.docked:
+            self.warning("The viewer is already docked")
             return
         self.docked = True
         self.settings.viewerDocked = True
-        self.undock_action.set_label(_("Undock Viewer"))
 
+        self.undock_button.show()
         self.fullscreen_button.destroy()
         self.external_vbox.remove(self.buttons_container)
         self.pack_end(self.buttons_container, False, False, 0)
@@ -378,12 +378,6 @@ class ViewerContainer(Gtk.VBox, Loggable):
             self._switch_output_window()
         self.external_window.hide()
 
-    def _toggleDocked(self, unused_action):
-        if self.docked:
-            self.undock()
-        else:
-            self.dock()
-
     def _toggleFullscreen(self, widget):
         if widget.get_active():
             self.external_window.hide()


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