Fixes for python3 + cleanups
authorEinar Jørgen Haraldseid <einar@haraldseid.net>
Fri, 2 Jun 2017 20:26:53 +0000 (22:26 +0200)
committerEinar Jørgen Haraldseid <einar@haraldseid.net>
Fri, 2 Jun 2017 20:26:53 +0000 (22:26 +0200)
example1.py
example2+3.py
example2.py
example3.py

index 9c41425b736a0bdac760385a63becbca5a6c7f53..5916bb4f4a7d3ed028a86744e37e04e4d6c563ac 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # This is a reworked version of the example from Jono Bacon's Python+Gstreamer
 # primer: http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/
 #!/usr/bin/env python
 # This is a reworked version of the example from Jono Bacon's Python+Gstreamer
 # primer: http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/
-# 
+#
 # It uses Gstreamer 1.0, and replaces alsa with pulse for audio output, and
 # drops the use of the GTK main loop, since we're not bothered with a GUI
 # Info on porting python scripts to Gstreamer 1.0 can be found here:
 # It uses Gstreamer 1.0, and replaces alsa with pulse for audio output, and
 # drops the use of the GTK main loop, since we're not bothered with a GUI
 # Info on porting python scripts to Gstreamer 1.0 can be found here:
@@ -9,7 +9,7 @@
 
 import gi
 gi.require_version('Gst', '1.0')
 
 import gi
 gi.require_version('Gst', '1.0')
-from gi.repository import Gst, GObject
+from gi.repository import Gst, GLib
 
 class Main:
   def __init__(self):
 
 class Main:
   def __init__(self):
@@ -33,5 +33,9 @@ class Main:
 
 # Create the pipelie and enter main loop, quit with ctrl+c
 start = Main()
 
 # Create the pipelie and enter main loop, quit with ctrl+c
 start = Main()
-mainloop = GObject.MainLoop()
-mainloop.run()
+mainloop = GLib.MainLoop()
+
+try:
+    mainloop.run()
+except KeyboardInterrupt:
+    exit(0)
index 44da53d1f009bd0240fd3a66f180978f5c264756..9a39c4e6048d7f35115a764a5e29659cb1d80de3 100755 (executable)
@@ -77,23 +77,23 @@ class Main:
         self.win_id = self.mainwindow.get_object("viewport").get_window().get_xid()
 
 
         self.win_id = self.mainwindow.get_object("viewport").get_window().get_xid()
 
 
-    # When we get a message that video is ready to display, set the 
+    # When we get a message that video is ready to display, set the
     # correct window id to hook it to our viewport
     def OnSyncElement(self, bus, message):
         if message.get_structure().get_name() == "prepare-window-handle":
     # correct window id to hook it to our viewport
     def OnSyncElement(self, bus, message):
         if message.get_structure().get_name() == "prepare-window-handle":
-            print "prepare-window-handle"
+            print("prepare-window-handle")
             message.src.set_window_handle(self.win_id)
 
     def OnPlay(self, widget):
             message.src.set_window_handle(self.win_id)
 
     def OnPlay(self, widget):
-        print "play"
+        print("play")
         self.pipeline.set_state(Gst.State.PLAYING)
 
     def OnStop(self, widget):
         self.pipeline.set_state(Gst.State.PLAYING)
 
     def OnStop(self, widget):
-        print "stop"
+        print("stop")
         self.pipeline.set_state(Gst.State.READY)
 
     def OnQuit(self, widget):
         self.pipeline.set_state(Gst.State.READY)
 
     def OnQuit(self, widget):
-        print "quit"
+        print("quit")
         Gtk.main_quit()
 
     # Workaround to get Ctrl+C to terminate from command line
         Gtk.main_quit()
 
     # Workaround to get Ctrl+C to terminate from command line
index 1c8c17ec01abb5996cbee87040584dcf56fa2bb3..7edd1592c5731c36d39dd6bdea5d2c1b4c9be97c 100755 (executable)
@@ -14,12 +14,12 @@ import signal
 
 class Main:
     def __init__(self):
 
 class Main:
     def __init__(self):
-        
+
         # Create gui bits and bobs
 
         self.wTree = Gtk.Builder()
         self.wTree.add_from_file("example2.glade")
         # Create gui bits and bobs
 
         self.wTree = Gtk.Builder()
         self.wTree.add_from_file("example2.glade")
-        
+
         signals = {
             "on_play_clicked" : self.OnPlay,
             "on_stop_clicked" : self.OnStop,
         signals = {
             "on_play_clicked" : self.OnPlay,
             "on_stop_clicked" : self.OnStop,
@@ -53,15 +53,15 @@ class Main:
 
 
     def OnPlay(self, widget):
 
 
     def OnPlay(self, widget):
-        print "play"
+        print("play")
         self.pipeline.set_state(Gst.State.PLAYING)
 
     def OnStop(self, widget):
         self.pipeline.set_state(Gst.State.PLAYING)
 
     def OnStop(self, widget):
-        print "stop"
+        print("stop")
         self.pipeline.set_state(Gst.State.READY)
         self.pipeline.set_state(Gst.State.READY)
-        
+
     def OnQuit(self, widget):
     def OnQuit(self, widget):
-        print "quit"
+        print("quit")
         Gtk.main_quit()
 
     # Workaround to get Ctrl+C to terminate from command line
         Gtk.main_quit()
 
     # Workaround to get Ctrl+C to terminate from command line
index f5af59b29b05e6d6915fa254bb72e1deac1a9cce..3ee0eb57e0fa044ad793a41097a09fb6a21da8de 100755 (executable)
@@ -13,12 +13,12 @@ import signal
 
 class Main:
     def __init__(self):
 
 class Main:
     def __init__(self):
-        
+
         # Create gui bits and bobs
 
         self.mainwindow = Gtk.Builder()
         self.mainwindow.add_from_file("example3.glade")
         # Create gui bits and bobs
 
         self.mainwindow = Gtk.Builder()
         self.mainwindow.add_from_file("example3.glade")
-        
+
         signals = {
             "on_play_clicked" : self.OnPlay,
             "on_stop_clicked" : self.OnStop,
         signals = {
             "on_play_clicked" : self.OnPlay,
             "on_stop_clicked" : self.OnStop,
@@ -37,12 +37,12 @@ class Main:
         self.videotestsrc = Gst.ElementFactory.make("videotestsrc", "videosource")
         self.videotestsrc.set_property("pattern", "snow")
         self.pipeline.add(self.videotestsrc)
         self.videotestsrc = Gst.ElementFactory.make("videotestsrc", "videosource")
         self.videotestsrc.set_property("pattern", "snow")
         self.pipeline.add(self.videotestsrc)
-        
+
         # Add a capsfilter that we want to apply to our videotestsrc
         self.videotestcaps = Gst.ElementFactory.make("capsfilter", "videotestcaps")
         self.videotestcaps.set_property("caps",Gst.Caps.from_string("video/x-raw,width=640,height=480"))
         self.pipeline.add(self.videotestcaps)
         # Add a capsfilter that we want to apply to our videotestsrc
         self.videotestcaps = Gst.ElementFactory.make("capsfilter", "videotestcaps")
         self.videotestcaps.set_property("caps",Gst.Caps.from_string("video/x-raw,width=640,height=480"))
         self.pipeline.add(self.videotestcaps)
-        
+
         # Link the capsfilter to the videotestsrc
         self.videotestsrc.link(self.videotestcaps)
 
         # Link the capsfilter to the videotestsrc
         self.videotestsrc.link(self.videotestcaps)
 
@@ -52,17 +52,17 @@ class Main:
 
         # Link the already linked videotestcaps to the sink
         self.videotestcaps.link(self.videosink)
 
         # Link the already linked videotestcaps to the sink
         self.videotestcaps.link(self.videosink)
-        
+
         # Set up a bus to our pipeline to get notified when the video is ready
         self.bus = self.pipeline.get_bus()
         self.bus.enable_sync_message_emission()
         self.bus.connect("sync-message::element", self.OnSyncElement)
         # Set up a bus to our pipeline to get notified when the video is ready
         self.bus = self.pipeline.get_bus()
         self.bus.enable_sync_message_emission()
         self.bus.connect("sync-message::element", self.OnSyncElement)
-        
+
         # Summon the window and connect the window's close button to quit
         self.window = self.mainwindow.get_object("mainwindow")
         self.window.connect("delete-event", Gtk.main_quit)
         self.window.show_all()
         # Summon the window and connect the window's close button to quit
         self.window = self.mainwindow.get_object("mainwindow")
         self.window.connect("delete-event", Gtk.main_quit)
         self.window.show_all()
-        
+
         # Get window ID of the viewport widget from the GUI
         self.win_id = self.mainwindow.get_object("viewport").get_window().get_xid()
 
         # Get window ID of the viewport widget from the GUI
         self.win_id = self.mainwindow.get_object("viewport").get_window().get_xid()
 
@@ -81,7 +81,7 @@ class Main:
     def OnStop(self, widget):
         print("stop")
         self.pipeline.set_state(Gst.State.READY)
     def OnStop(self, widget):
         print("stop")
         self.pipeline.set_state(Gst.State.READY)
-        
+
     def OnQuit(self, widget):
         print("quit")
         Gtk.main_quit()
     def OnQuit(self, widget):
         print("quit")
         Gtk.main_quit()