我有一个Python,PyGObject(Gtk 3)和GStreamer(0.11)的项目
我的应用程序中有视频,因此我使用的是Gtk.Overlay小部件,因此我可以将其他视觉元素放在视频背景上。 (我需要这个,请相信我。)(由于小部件的数量,以及对这些小部件的特定定位和覆盖的需要,我使用的是Gtk.Fixed容器。)
但是,在通过“overlay.add_overlay(widget)”添加任何内容时使用Gtk.Overlay对象时,视频根本不再可见。我仍然可以听到它,但我看不到它。
以下代码。
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()
如何解决这个小问题?
答案 0 :(得分:1)
<强> Answer derived from GNOME Bugzilla Bug 663589, Comments 1-3. 强>
设置通过“add_overlay”添加的任何对象的valign和halign至关重要。
因此,用于声明和添加Gtk.Fixed对象的修订代码如下所示。
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()