Obter o identificador da janela em PyGI
No meu programa, uso o PyGObject / PyGI e o GStreamer para mostrar um vídeo na minha GUI. O vídeo é mostrado em umGtk.DrawingArea
e, portanto, eu preciso pegá-lo na janelarealize
-sinal-handler. No Linux, entendo esse identificador usando:
drawing_area.get_property('window').get_xid()
Mas como faço para lidar com o Windows?
Pesquisei na internet, mas encontrei apenas exemplos de PyGtk usandowindow.handle
que não funciona usando PyGI.
A documentação do GStreamer fornece umaexemplo que usa oGDK_WINDOW_HWND
macro para obter o identificador. Essa macro usa AFAIKgdk_win32_drawable_get_handle
. Mas como fazê-lo em Python usando PyGI?
Atualização 15-07-28: Adicionado (simplificado) código
Ainda não estou conseguindo que a reprodução de vídeo funcione no Windows.
Problema 1: Não consigo obter o identificador da janela em _on_video_realize ().
Problema 2: O método _on_player_sync_message () nunca é chamado.
class MultimediaPlayer:
def __init__(self):
# ... some init stuff ...
self._drawing_area.connect('realize', self._on_video_realize)
self._drawing_area.connect('unrealize', self._on_video_unrealize)
# GStreamer setup
# ---------------
self._player = Gst.ElementFactory.make('playbin', 'MultimediaPlayer')
bus = self._player.get_bus()
bus.add_signal_watch()
bus.connect('message', self._on_player_message)
bus.enable_sync_message_emission()
bus.connect('sync-message::element', self._on_player_sync_message)
def _on_video_realize(self, widget):
print('----------> _on_video_realize')
# The xid must be retrieved first in GUI-thread and before
# playing pipeline.
if sys.platform == "win32":
self._drawing_area.get_property('window').ensure_native()
# -------------------------------------------------------------
# TODO [PROBLEM 1] How to get handle here?
# self._drawing_area.GetHandle() does not exist!
# -------------------------------------------------------------
else:
self._wnd_hnd = (self._drawing_area.get_property('window')
.get_xid())
def _on_video_unrealize(self, widget):
self._player.set_state(Gst.State.NULL)
def _on_player_message(self, bus, message):
# ... handle some messages here ...
def _on_player_sync_message(self, bus, message):
# ---------------------------------------------------------------------
# TODO [PROBLEM 2] This method is never called on Windows after opening
# a video_file! But on Linux it is!
# ---------------------------------------------------------------------
print('----------> _on_player_sync_message')
if message.get_structure() is None:
return True
if message.get_structure().get_name() == "prepare-window-handle":
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_window_handle(self._wnd_hnd)
def play(self):
self._player.set_state(Gst.State.PLAYING)
def stop(self):
self._player.set_state(Gst.State.NULL)
def set_file(self, file):
# ...
self._player.set_property('uri', "file:///" + file)