[pitivi] viewer: Make the AspectFrame part of the ViewerWidget



commit 0f0bd6b48075a28d3cd51ea05fde6c4d75e28fcc
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Jan 16 23:58:58 2014 +0100

    viewer: Make the AspectFrame part of the ViewerWidget

 pitivi/mediafilespreviewer.py |   45 ++++++++++++++-------------
 pitivi/viewer.py              |   68 ++++++++++++++++++++--------------------
 2 files changed, 57 insertions(+), 56 deletions(-)
---
diff --git a/pitivi/mediafilespreviewer.py b/pitivi/mediafilespreviewer.py
index 9b3286e..ca51abe 100644
--- a/pitivi/mediafilespreviewer.py
+++ b/pitivi/mediafilespreviewer.py
@@ -68,10 +68,10 @@ acceptable_tags = [
     Gst.TAG_COPYRIGHT]
 
 
-class PreviewWidget(Gtk.VBox, Loggable):
+class PreviewWidget(Gtk.Grid, Loggable):
 
     def __init__(self, instance):
-        Gtk.VBox.__init__(self)
+        Gtk.Grid.__init__(self)
         Loggable.__init__(self)
 
         self.log("Init PreviewWidget")
@@ -101,25 +101,23 @@ class PreviewWidget(Gtk.VBox, Loggable):
 
         # Gui elements:
         # Drawing area for video output
-        self.preview_video = ViewerWidget()
-        self.preview_video.connect("realize", self._on_preview_video_realize_cb)
-        self.preview_video.modify_bg(Gtk.StateType.NORMAL, self.preview_video.get_style().black)
-        self.preview_video.set_double_buffered(False)
-        self.preview_video.show()
-        self.pack_start(self.preview_video, False, True, 0)
+        self.preview_video = ViewerWidget(realizedCb=self._on_preview_video_realize_cb)
+        self.preview_video.props.hexpand = False
+        self.preview_video.props.vexpand = False
+        self.attach(self.preview_video, 0, 0, 1, 1)
 
         # An image for images and audio
         self.preview_image = Gtk.Image()
         self.preview_image.set_size_request(self.settings.FCpreviewWidth, self.settings.FCpreviewHeight)
         self.preview_image.show()
-        self.pack_start(self.preview_image, False, True, 0)
+        self.attach(self.preview_image, 0, 1, 1, 1)
 
         # Play button
         self.bbox = Gtk.HBox()
         self.play_button = Gtk.ToolButton()
         self.play_button.set_icon_name("media-playback-start")
         self.play_button.connect("clicked", self._on_start_stop_clicked_cb)
-        self.bbox.pack_start(self.play_button, False, True, 0)
+        self.bbox.pack_start(self.play_button, False, False, 0)
 
         #Scale for position handling
         self.pos_adj = Gtk.Adjustment()
@@ -141,14 +139,14 @@ class PreviewWidget(Gtk.VBox, Loggable):
         self.bbox.pack_start(self.b_zoom_in, False, True, 0)
         self.bbox.pack_start(self.b_zoom_out, False, True, 0)
         self.bbox.show_all()
-        self.pack_start(self.bbox, False, False, 0)
+        self.attach(self.bbox, 0, 2, 1, 1)
 
         # Label for metadata tags
         self.l_tags = Gtk.Label()
         self.l_tags.set_justify(Gtk.Justification.LEFT)
         self.l_tags.set_ellipsize(Pango.EllipsizeMode.END)
         self.l_tags.show()
-        self.pack_start(self.l_tags, False, False, 0)
+        self.attach(self.l_tags, 0, 3, 1, 1)
 
         # Error handling
         vbox = Gtk.VBox()
@@ -159,7 +157,7 @@ class PreviewWidget(Gtk.VBox, Loggable):
         vbox.pack_start(self.l_error, True, True, 0)
         vbox.pack_start(self.b_details, False, False, 0)
         vbox.show()
-        self.pack_start(vbox, False, False, 0)
+        self.attach(vbox, 0, 4, 1, 1)
 
     def setMinimal(self):
         self.remove(self.l_tags)
@@ -239,9 +237,11 @@ class PreviewWidget(Gtk.VBox, Loggable):
                 self.player.setClipUri(self.current_selected_uri)
                 self.player.setState(Gst.State.PAUSED)
                 self.pos_adj.props.upper = duration
-                w, h = self.__get_best_size((video.get_par_num() / video.get_par_denom()) * 
video.get_width(),
-                    video.get_height())
+                video_width = (video.get_par_num() / video.get_par_denom()) * video.get_width()
+                video_height = video.get_height()
+                w, h = self.__get_best_size(video_width, video_height)
                 self.preview_video.set_size_request(w, h)
+                self.preview_video.setDisplayAspectRatio(float(video_width) / video_height)
                 self.preview_video.show()
                 self.player.connectWithViewer(self.preview_video)
                 self.bbox.show()
@@ -249,9 +249,9 @@ class PreviewWidget(Gtk.VBox, Loggable):
                 self.seeker.show()
                 self.b_zoom_in.show()
                 self.b_zoom_out.show()
-                self.description = _("<b>Resolution</b>: %d×%d") % \
-                    ((video.get_par_num() / video.get_par_denom()) * video.get_width(), video.get_height()) 
+\
-                    "\n" + _("<b>Duration</b>: %s") % pretty_duration + "\n"
+                self.description = "\n".join([
+                    _("<b>Resolution</b>: %d×%d") % (video_width, video_height),
+                    _("<b>Duration</b>: %s") % pretty_duration])
         else:
             self.current_preview_type = 'audio'
             self.preview_video.hide()
@@ -265,8 +265,9 @@ class PreviewWidget(Gtk.VBox, Loggable):
             self.preview_image.set_from_icon_name("audio-x-generic", Gtk.IconSize.DIALOG)
             self.preview_image.show()
             self.preview_image.set_size_request(PREVIEW_WIDTH, PREVIEW_HEIGHT)
-            self.description = beautify_stream(audio) + "\n" + \
-                _("<b>Duration</b>: %s") % pretty_duration + "\n"
+            self.description = "\n".join([
+                beautify_stream(audio),
+                _("<b>Duration</b>: %s") % pretty_duration])
             self.player.setState(Gst.State.NULL)
             self.player.setClipUri(self.current_selected_uri)
             self.player.setState(Gst.State.PAUSED)
@@ -346,7 +347,7 @@ class PreviewWidget(Gtk.VBox, Loggable):
             self.pos_adj.set_value(long(curr_pos))
         return self.is_playing
 
-    def _on_preview_video_realize_cb(self, unused_widget):
+    def _on_preview_video_realize_cb(self, unused_drawing_area, unused_widget):
         if self.current_preview_type == 'video':
             self.player.connectWithViewer(self.preview_video)
 
@@ -415,7 +416,7 @@ class PreviewWidget(Gtk.VBox, Loggable):
         tag_list.foreach(self._appendTag, None)
         keys = self.tags.keys()
         keys.sort()
-        text = self.description + "\n"
+        text = self.description + "\n\n"
         for key in keys:
             text = text + "<b>" + key.capitalize() + "</b>: " + self.tags[key] + "\n"
         self.l_tags.set_markup(text)
diff --git a/pitivi/viewer.py b/pitivi/viewer.py
index b350a18..52a3235 100644
--- a/pitivi/viewer.py
+++ b/pitivi/viewer.py
@@ -173,33 +173,25 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self.settings.viewerX = event.x
         self.settings.viewerY = event.y
 
-    def _videoRealized(self, widget):
-        if widget == self.target:
-            self.log("Widget realized: %s", widget)
+    def _videoRealizedCb(self, unused_drawing_area, viewer):
+        if viewer == self.target:
+            self.log("Viewer widget realized: %s", viewer)
             self._switch_output_window()
 
     def _createUi(self):
         """ Creates the Viewer GUI """
         # Drawing area
-        # The aspect ratio gets overridden on startup by setDisplayAspectRatio
-        self.internal_aframe = Gtk.AspectFrame(xalign=0.5, yalign=1.0,
-                                            ratio=4.0 / 3.0, obey_child=False)
-        self.external_aframe = Gtk.AspectFrame(xalign=0.5, yalign=0.5,
-                                            ratio=4.0 / 3.0, obey_child=False)
-
-        self.internal = ViewerWidget(self.app.settings)
+        self.internal = ViewerWidget(self.app.settings, realizedCb=self._videoRealizedCb)
         # Transformation boxed DISABLED
         # self.internal.init_transformation_events()
-        self.internal_aframe.add(self.internal)
-        self.pack_start(self.internal_aframe, True, True, 0)
+        self.pack_start(self.internal, True, True, 0)
 
         self.external_window = Gtk.Window()
         vbox = Gtk.VBox()
         vbox.set_spacing(SPACING)
         self.external_window.add(vbox)
-        self.external = ViewerWidget(self.app.settings)
-        self.external_aframe.add(self.external)
-        vbox.pack_start(self.external_aframe, True, True, 0)
+        self.external = ViewerWidget(self.app.settings, realizedCb=self._videoRealizedCb)
+        vbox.pack_start(self.external, True, True, 0)
         self.external_window.connect("delete-event", self._externalWindowDeleteCb)
         self.external_window.connect("configure-event", self._externalWindowConfigureCb)
         self.external_vbox = vbox
@@ -270,27 +262,18 @@ class ViewerContainer(Gtk.VBox, Loggable):
             width = req.width
             height = req.height
             width += 110
-            height = int(width / self.internal_aframe.props.ratio)
-            self.internal_aframe.set_size_request(width, height)
+            height = int(width / self.internal.props.ratio)
+            self.internal.set_size_request(width, height)
 
         self.buttons = bbox
         self.buttons_container = boxalign
-        # Prevent black frames and flickering while resizing or changing focus:
-        self.internal.set_double_buffered(False)
-        self.external.set_double_buffered(False)
-        # We keep the ViewerWidget hidden initially, or the desktop wallpaper
-        # would show through the non-double-buffered widget!
-        self.internal.set_no_show_all(True)
-        self.external.set_no_show_all(True)
-        self.internal.connect("realize", self._videoRealized)
-        self.external.connect("realize", self._videoRealized)
         self.show_all()
         self.external_vbox.show_all()
 
     def setDisplayAspectRatio(self, ratio):
         self.debug("Setting aspect ratio to %f [%r]", float(ratio), ratio)
-        self.internal_aframe.set_property("ratio", float(ratio))
-        self.external_aframe.set_property("ratio", float(ratio))
+        self.internal.setDisplayAspectRatio(ratio)
+        self.external.setDisplayAspectRatio(ratio)
 
     def _entryActivateCb(self, unused_entry):
         self._seekFromTimecodeWidget()
@@ -806,7 +789,7 @@ class TransformationBox():
             self.transformation_properties.connectSpinButtonsToFlush()
 
 
-class ViewerWidget(GtkClutter.Embed, Loggable):
+class ViewerWidget(Gtk.AspectFrame, Loggable):
     """
     Widget for displaying properly GStreamer video sink
 
@@ -816,17 +799,31 @@ class ViewerWidget(GtkClutter.Embed, Loggable):
 
     __gsignals__ = {}
 
-    def __init__(self, settings=None):
-        GtkClutter.Embed.__init__(self)
+    def __init__(self, settings=None, realizedCb=None):
+        # Prevent black frames and flickering while resizing or changing focus:
+        # The aspect ratio gets overridden by setDisplayAspectRatio.
+        Gtk.AspectFrame.__init__(self, xalign=0.5, yalign=1.0,
+                                 ratio=4.0 / 3.0, obey_child=False)
+        Loggable.__init__(self)
+
+        self.drawing_area = GtkClutter.Embed()
+        self.drawing_area.set_double_buffered(False)
+        # We keep the ViewerWidget hidden initially, or the desktop wallpaper
+        # would show through the non-double-buffered widget!
+        if realizedCb:
+            self.drawing_area.connect("realize", realizedCb, self)
+        self.add(self.drawing_area)
+
         layout_manager = Clutter.BinLayout(x_align=Clutter.BinAlignment.FILL, 
y_align=Clutter.BinAlignment.FILL)
-        self.get_stage().set_layout_manager(layout_manager)
+        self.drawing_area.get_stage().set_layout_manager(layout_manager)
         self.texture = Clutter.Texture()
         # This is a trick to make the viewer appear darker at the start.
         self.texture.set_from_rgb_data(data=[0] * 3, has_alpha=False,
                 width=1, height=1, rowstride=3, bpp=3,
                 flags=Clutter.TextureFlags.NONE)
-        self.get_stage().add_child(self.texture)
-        Loggable.__init__(self)
+        self.drawing_area.get_stage().add_child(self.texture)
+        self.drawing_area.show()
+
         self.seeker = Seeker()
         self.settings = settings
         self.box = None
@@ -841,6 +838,9 @@ class ViewerWidget(GtkClutter.Embed, Loggable):
         #for state in range(Gtk.StateType.INSENSITIVE + 1):
             #self.modify_bg(state, self.style.black)
 
+    def setDisplayAspectRatio(self, ratio):
+        self.set_property("ratio", float(ratio))
+
     def init_transformation_events(self):
         self.fixme("TransformationBox disabled")
         """


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