Question

I have a project with Python, PyGObject (Gtk 3), and GStreamer (0.11)

I have video in my application, so I'm using a Gtk.Overlay widget so I can put other visual elements over the video background. (I need this, trust me.) (Due to the number of widgets, and the need for specific positioning and overlaying of these widgets, I'm using a Gtk.Fixed container.)

However, in using the Gtk.Overlay object with anything added via "overlay.add_overlay(widget)", the video is no longer visible at all. I can still hear it, but I cannot see it.

Code below.

from gi.repository import Gtk, Gdk, GdkPixbuf, GdkX11
import pango
import pygst
pygst.require('0.10')
import gst
import Trailcrest
import os, sys
import cairo
from math import pi

class Video:

    def __init__(self):

        def on_message(bus, message): 
            if message.type == gst.MESSAGE_EOS: 
                # End of Stream 
                player.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, 5000000000, gst.SEEK_TYPE_NONE, 6000000000)
            elif message.type == gst.MESSAGE_ERROR: 
                player.set_state(gst.STATE_NULL) 
                (err, debug) = message.parse_error() 
                print "Error: %s" % err, debug

        def on_sync_message(bus, message):
            if message.structure is None:
                return False
            if message.structure.get_name() == "prepare-xwindow-id":
                Gdk.threads_enter()
                Gdk.Display.get_default().sync()
                win_id = videowidget.get_property('window').get_xid()
                imagesink = message.src
                imagesink.set_property("force-aspect-ratio", True)
                imagesink.set_xwindow_id(win_id)
                Gdk.threads_leave()

        def click_me(event, data=None):
            player.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, 5000000000, gst.SEEK_TYPE_NONE, 6000000000)

        win = Gtk.Window()
        win.set_resizable(False)
        win.set_decorated(False)
        win.set_position(Gtk.WindowPosition.CENTER)

        overlay = Gtk.Overlay()
        win.add(overlay)
        overlay.show()

        videowidget = Gtk.DrawingArea()
        overlay.add(videowidget)
        videowidget.set_halign (Gtk.Align.START)
        videowidget.set_valign (Gtk.Align.START)
        videowidget.set_size_request(640, 480)
        videowidget.show()

        fixed = Gtk.Fixed()
        overlay.add_overlay(fixed)
        fixed.show()

        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("IMG/IMG-MPG-LOGO.png", 250, 50)
        imgMPL = Gtk.Image()
        imgMPL.set_from_pixbuf(pixbuf)
        eb_imgMPL = Gtk.EventBox()
        eb_imgMPL.set_visible_window(False)
        eb_imgMPL.add(imgMPL)
        fixed.put(eb_imgMPL, 10, 10)
        imgMPL.show()
        eb_imgMPL.show()

        win.show_all()

        # Setup GStreamer 
        player = gst.element_factory_make("playbin", "MultimediaPlayer")
        bus = player.get_bus() 
        bus.add_signal_watch() 
        bus.enable_sync_message_emission() 
        #used to get messages that GStreamer emits 
        bus.connect("message", on_message) 
        #used for connecting video to your application 
        bus.connect("sync-message::element", on_sync_message)
        player.set_property("uri", "file://" + os.getcwd() + "/VID/BGA-HABT-001.ogv")
        player.set_state(gst.STATE_PLAYING)


if __name__ == "__main__":
    Gdk.threads_enter()
    Video()
    Gtk.main()

How do I fix this little issue?

Was it helpful?

Solution

Answer derived from GNOME Bugzilla Bug 663589, Comments 1-3.

It is vital to set the valign and halign of any object added via "add_overlay".

Therefore, the revised code for declaring and adding the Gtk.Fixed object is as below.

fixed = Gtk.Fixed()

#The following two lines were added.
fixed.set_halign(Gtk.Align.START)
fixed.set_valign(Gtk.Align.START)

overlay.add_overlay(fixed)
fixed.show()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top