#!/usr/bin/python3 import sys from sgtk import * gi.require_version('Gst', '1.0') from gi.repository import Gst player = None # global msgs = [] templates = '''\ File Open app.file_open Browse file_browse About app.about Engine GStreamer VAAPI engine_gstreamer_vaapi GStreamer engine_gstreamer VLC engine_vlc ''' @Gtk.Template(string=templates) class MainWindow(Gtk.ApplicationWindow): __gtype_name__ = 'MainWindow' picture = Gtk.Template.Child() file_menu = Gtk.Template.Child() @Gtk.Template.Callback() def button_clicked(self, *args): sink = player.get_by_name("gtk4sink") bus = player.get_bus() #paintable = sink.get_property("paintable") def bus_sync_handler(bus, message, window, *args): msgs.append(message) if message.type==Gst.MessageType.HAVE_CONTEXT: #print("MESSAGE TYPE:", message.type) #print("WINDOW:", window) try: paintable = message.src.get_property("paintable") #print("Paintable:", paintable) window.picture.set_paintable(paintable) except Exception as err: pass # print(err) return Gst.BusSyncReply.PASS #PASS, DROP, ASYNC class MyApplication(Adw.Application): """The main application.""" def do_activate(self): #Adw.init() # create a Gtk Window belonging to the application itself #window = Gtk.ApplicationWindow(application=self) window = MainWindow(application=self) #window.set_title("SVPlayer") window.set_size_request(640, 480) window.present() # menu #builder = Gtk.Builder.new_from_string(MENU_XML, -1) popover = Gtk.PopoverMenu() #popover.set_menu_model(builder.get_object("TopMenu")) popover.set_menu_model(window.file_menu) hamburger = Gtk.MenuButton() hamburger.set_popover(popover) hamburger.set_label("File") #hamburger.set_icon_name("open-menu-symbolic") header = Gtk.HeaderBar() window.set_titlebar(header) header.pack_start(hamburger) # actions def test_action(*args): print("TEST", args) action = Gio.SimpleAction(name="file_open") action.connect("activate", test_action) self.add_action(action) # menu bar #window.menu.set_menu_model(builder.get_object("TopMenu")) bus = player.get_bus() bus.set_sync_handler(bus_sync_handler, window) #bus.connect("sync-message", self.sync_message) player.set_state(Gst.State.PLAYING) #def sync_message(self, *args): # print("SYNC", args) if __name__ == '__main__': Gst.init(None) player = Gst.parse_launch( #"videotestsrc ! gtk4paintablesink name=gtk4sink" 'playbin uri=file:///tmp/test.mp4 video-sink="gtk4paintablesink name=gtk4sink"' #'playbin3 uri=file:///tmp/test.mp4 video-sink="gtk4paintablesink name=gtk4sink"' #"videotestsrc ! waylandsink name=gtk4sink" #"videotestsrc ! xvimagesink name=gtk4sink" ) # create and run the application, exit with the value returned by # running the program app = MyApplication() exit_status = app.run(sys.argv) sys.exit(exit_status)