moviepy icon indicating copy to clipboard operation
moviepy copied to clipboard

Bad interaction with QT QLineEdit widget

Open John-Hollingum opened this issue 2 years ago • 4 comments

This is a minimal case of a program that demonstrates the bug

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from moviepy.editor import VideoFileClip, AudioFileClip, CompositeAudioClip
import sys

class AmenicMain(QMainWindow):
	def __init__(self):
		super().__init__()
		self.initUI()

	def initUI(self):

		self.setWindowTitle('Amenic')
		self.resize(900,500)

		ssLabel = QLabel('Sound Source',self)
		self.ssFileShow= QLineEdit(self)

		hbox2 = QHBoxLayout()
		hbox2.addWidget(ssLabel)
		hbox2.addWidget(self.ssFileShow)
		container = QWidget()
		container.setLayout(hbox2)

		self.setCentralWidget(container)

if __name__ == '__main__':
	app = QApplication(sys.argv)
	main = AmenicMain()
	main.show()
	sys.exit(app.exec_())

This program should display a window with a label and a line edit widget that allows normal entry of text.

What actually happens is that the window is displayed as expected, but normal editing is not possible. When a regular alphanumeric key is pressed the corresponding character appears twice in the line edit. Delete left does nothing. Delete right (ctrl-d) appears to replace the char to the right of the cursor with a space. I daresay there are other weirdnesses, but that'll do to be getting on with.

If the MoviePy import line is commented out, it works fine.

To reproduce the problem, run the program and start typing

Specifications

Python 3.10.2

Name: moviepy Version: 1.0.3

Model Name: iMac Model Identifier: iMac14,3 Processor Name: Quad-Core Intel Core i5 Processor Speed: 2.9 GHz Number of Processors: 1 Total Number of Cores: 4

MacOS Catalina System Version: macOS 10.15.7 (19H1824) Kernel Version: Darwin 19.6.0

John-Hollingum avatar Apr 08 '22 09:04 John-Hollingum

How are cases like this treated? Should it be reported as a bug to qt?

I've got a very crude workaround at present. After the list of imports, I have this code: if len(sys.argv) == 2: if sys.argv[1] != 'e': mode = 'export' else: mode = 'edit' else: mode = 'export' if mode == 'export': from moviepy.editor import VideoFileClip, AudioFileClip, CompositeAudioClip Which is to say, depending on a command line argument, I either start my program in a state where it can export but not much else or where it can do everything except export.

John-Hollingum avatar Apr 28 '22 10:04 John-Hollingum

Apart from the import statement, I don't see you using any moviepy code in the sample you provided, are we missing the actually relevant bits?

More info on how you use/run the code might also be helpful for debugging.

keikoro avatar May 04 '22 22:05 keikoro

There's nothing missing from the code required to demonstrate the problem. It is only necessary to import moviepy for it to affect the function of qt. You don't have to use any of the moviepy functions. Literally, just run that code and type something and you should see the characters getting echoed back twice in the QLineEdit widget

John-Hollingum avatar May 05 '22 14:05 John-Hollingum

Well in that case I would suggest there's some overriding/redefining of variable or function names going on because you are not explicitly importing from PyQt5.

keikoro avatar May 09 '22 20:05 keikoro

Closing this issue since it doesn't seem to be related to MoviePy per se.

keikoro avatar Aug 23 '22 18:08 keikoro

There's nothing missing from the code required to demonstrate the problem. It is only necessary to import moviepy for it to affect the function of qt. You don't have to use any of the moviepy functions. Literally, just run that code and type something and you should see the characters getting echoed back twice in the QLineEdit widget

This is definitely a bug, I don't think this should be labeled as invalid.

It seems have something to do with the fact that preview use pygame, which gets in the way of signal of user input, yes, all it takes is to import moviepy.editor here is another similar issue https://github.com/Zulko/moviepy/issues/1886#issue-1515415429

I found another simpler work around, just quit the pygame after the App init_ui(),

class SomeApp(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()
#here is the work around
        pygame.quit()

if you want to use something like preview later, this hack wouldn't get in the way, probably it's just gonna start another pygame instance

holytony avatar Jan 16 '24 03:01 holytony