Skip to content

Commit

Permalink
fix recursive resize in new python examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Oct 10, 2024
1 parent d688641 commit a178549
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
11 changes: 7 additions & 4 deletions src/swig/python/play_gtk.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import gi
import sys
import mlt7 as mlt
Expand All @@ -8,7 +11,7 @@
VIDEO = 'video.mp4'

class VideoPlayer(Gtk.Window):
def __init__(self):
def __init__(self, filename):
super().__init__(title="MLT Video Player")
self.set_default_size(800, 600)
self.connect("destroy", self.on_destroy)
Expand All @@ -20,10 +23,10 @@ def __init__(self):
self.profile = mlt.Profile()

# Create a producer for the video
self.producer = mlt.Producer(self.profile, VIDEO)
self.producer = mlt.Producer(self.profile, filename)
if self.producer.is_valid():
self.profile.from_producer(self.producer)
self.producer = mlt.Producer(self.profile, VIDEO)
self.producer = mlt.Producer(self.profile, filename)

# Create the consumer for rendering using SDL2
self.consumer = mlt.Consumer(self.profile, "sdl2")
Expand Down Expand Up @@ -137,6 +140,6 @@ def on_destroy(self, widget):
Gtk.init(sys.argv)

# Create and run the video player
player = VideoPlayer()
player = VideoPlayer(sys.argv[1] if len(sys.argv) > 1 else VIDEO)
player.show_all()
Gtk.main()
20 changes: 13 additions & 7 deletions src/swig/python/play_pyqt6.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import mlt7 as mlt
import sys

Expand All @@ -8,7 +11,7 @@


class VideoPlayer(QWidget):
def __init__(self):
def __init__(self, filename):
super().__init__()
self.setWindowTitle("MLT Video Player")

Expand All @@ -19,11 +22,14 @@ class video_viewer(QWidget):
def __init__(self):
super().__init__()
self.setMinimumSize(380, 260)
self.blockResize = False

def resizeEvent(self, event):
self.window().consumer.set('window_width', self.width())
self.window().consumer.set('window_height', self.height())
event.accept()
if not self.blockResize:
self.window().consumer.set('window_width', self.width())
self.window().consumer.set('window_height', self.height())
event.accept()
self.blockResize = not self.blockResize

self.video_viewer = video_viewer()
layout.addWidget(self.video_viewer, 1)
Expand Down Expand Up @@ -69,13 +75,13 @@ def resizeEvent(self, event):
self.profile = mlt.Profile()

# Create the producer
self.producer = mlt.Producer(self.profile, VIDEO)
self.producer = mlt.Producer(self.profile, filename)

if self.producer.is_valid():
# Derive a profile based on the producer
self.profile.from_producer(self.producer)
# Reload the producer using the derived profile
self.producer = mlt.Producer(self.profile, VIDEO)
self.producer = mlt.Producer(self.profile, filename)

# Create the consumer
self.consumer = mlt.Consumer(self.profile, "sdl2")
Expand Down Expand Up @@ -137,7 +143,7 @@ def closeEvent(self, event):
if __name__ == "__main__":
app = QApplication(sys.argv)

player = VideoPlayer()
player = VideoPlayer(sys.argv[1] if len(sys.argv) > 1 else VIDEO)
player.show()

sys.exit(app.exec())
20 changes: 13 additions & 7 deletions src/swig/python/play_pyside6.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import mlt7 as mlt
import sys

Expand All @@ -8,7 +11,7 @@


class VideoPlayer(QWidget):
def __init__(self):
def __init__(self, filename):
super().__init__()
self.setWindowTitle("MLT Video Player")

Expand All @@ -18,11 +21,14 @@ class video_viewer(QWidget):
def __init__(self):
super().__init__()
self.setMinimumSize(380, 260)
self.blockResize = False

def resizeEvent(self, event):
self.window().consumer.set('window_width', self.width())
self.window().consumer.set('window_height', self.height())
event.accept()
if not self.blockResize:
self.window().consumer.set('window_width', self.width())
self.window().consumer.set('window_height', self.height())
event.accept()
self.blockResize = not self.blockResize

self.video_viewer = video_viewer()
layout.addWidget(self.video_viewer, 1)
Expand Down Expand Up @@ -68,13 +74,13 @@ def resizeEvent(self, event):
self.profile = mlt.Profile()

# Create the producer
self.producer = mlt.Producer(self.profile, VIDEO)
self.producer = mlt.Producer(self.profile, filename)

if self.producer.is_valid():
# Derive a profile based on the producer
self.profile.from_producer(self.producer)
# Reload the producer using the derived profile
self.producer = mlt.Producer(self.profile, VIDEO)
self.producer = mlt.Producer(self.profile, filename)

# Create the consumer
self.consumer = mlt.Consumer(self.profile, "sdl2")
Expand Down Expand Up @@ -138,7 +144,7 @@ def closeEvent(self, event):

app = QApplication(sys.argv)

player = VideoPlayer()
player = VideoPlayer(sys.argv[1] if len(sys.argv) > 1 else VIDEO)
player.show()

sys.exit(app.exec())

0 comments on commit a178549

Please sign in to comment.