I'm definitely in need of your help guys.. As in really.
My laptop has been stolen and I didn't have a backup of my
pyqt phonon video player that I made a year ago. I forgot how and what to do to recreate it.
I only know some key things to do for it to work. So please help me out.
From what i can remember I need to
Set backend capabilities (set phonon backend to windows media player?)
Install the required codecs (which i dont have a copy of)
Code the program (and sadly I forgot how to play a video)
If there's someone out there who have a working sample python videoplayer,
can you please share it with me?
I'm trying it right now and my sample doesn't work at all
from PyQt4.phonon import Phonon
media_source = phonon.Phonon.MediaSource("C:\\Sample.avi")
self.ui.videoPlayer.load(media_source)
self.ui.videoPlayer.play()
Please help me. And thank you very much to you guys.
I'm using python 2.6 and qt version 4.9. Now I'm coding on a virtual box windows XP
EDIT:
got a following sample with this problem but..
having this error when loading a file.
"The Operation Cannot Be Performed Because the Pins Are Not Connected"
This maybe because I'm using a virtual box in Ubuntu?
Don't forget to show() the videoplayer. For the rest, in my experience Phonon often has trouble finding the codecs needed to play videos on Windows. Installing K-Lite codec pack might work in that situation.
Here's a self-contained example that does work for me (Windows Vista32, Python 2.6.5, PyQt 4.7.3).
import sys
from PyQt4 import QtCore, QtGui
from PyQt4.phonon import Phonon
app = QtGui.QApplication(sys.argv)
vp = Phonon.VideoPlayer()
media = Phonon.MediaSource('C:\\video.mp4')
vp.load(media)
vp.play()
vp.show()
sys.exit(app.exec_())
Edit:
Multiple people have recently commented that the above code no longer gives the desired behavior. I haven't worked with PyQt in ages, but I suspect that one of the updates might have changed Phonon functionality.
According to the commenters, vp.show() now needs to be called before Phonon.MediaSource(), i.e.:
...
vp = Phonon.VideoPlayer()
vp.show()
media = Phonon.MediaSource('C:\\video.mp4')
vp.load(media)
vp.play()
sys.exit(app.exec_())
Related
I am working for the first time towards the implementation of a very simple GUI in PyQt5, which embeds a matplotlib plot and few buttons for interaction.
I do not really know how to work with classes so I'm making a lot of mistakes, i.e. even if the functionality is simple, I have to iterate a lot between small corrections and verification.
For some reason I would like to debug, however, the whole process is made much, much slower by the fact that at any other try, the python kernel dies and it needs restarting (all done automatically) several times.
That is, every time I try something that should last maybe 5 secs, I end up spending a minute.
Anybody know where to look to spot what is causing these constant death/rebirth circles?
I have been using spyder for some time now and I never experienced this behaviour before, so I'm drawn to think it might have to do with PyQt, but that's about how far I can go.
This issue is tracked here
You can learn all the details there, but in a nutshell when running from inside spyder - which itself is a QApplication, the main loop should read:
if __name__ == '__main__':
import sys
from PyQt5 import QtWidgets
fig1 = Figure()
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
else:
app = QtWidgets.QApplication.instance()
main = Main()
main.addmpl(fig1)
main.show()
sys.exit(app.exec_())
The if/then check on the existence of a QApplication avoids a segmentation fault which happens if one tries to launch multiple instances at one time, as explained here
I had a similar problem and found that my application only worked when the graphics settings inside Spyder are set to inline. This can be done at Tools -> Preferences -> IPython console -> Graphics, now change the Backends to inline.
Hope this helps.
I'm trying to migrate an existing PyQt5 app to high-dpi for window 10.
The documentation of Qt5 itself speak about high-dpi scaling here:
http://doc.qt.io/qt-5/highdpi.html
QT_AUTO_SCREEN_SCALE_FACTOR to "1".
But i can't adapt this in python code :/
Any idea ?
Make sure you're on Qt 5.6+, skim the docs to be aware, then change your app init code to include one line before it and one line after it (written in Python) but it would be similar in C++:
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
qapp = QApplication(sys.argv)
qapp.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
I have a script that just returns true/false depending on some conditions, and I need to display this status in the status bar/some topmost window, the script is written in python.
I tried to find a way to display a status bar icon with python but seems all existing wrappers are outdated. I feel that it is not very good solution to create a native app just for displaying an icon and control it with my script.
I thought about using GeekTool for mac, but it can display stuff only on the desktop. Since the desktop is hidden with some windows all the time, that's not very good solution.
Any ideas?
Have found out that
import objc, from Foundation import *
from AppKit import *
from PyObjCTools import AppHelper
solves my problem
I have made a program that has a Toolbar with a few actions on it in Linux. The Toolbar and its actions work perfectly on a Linux OS, but when I run the code on a Windows machine, the actions just don't work. Everything looks the same as on Linux(yes I have PyQt4 installed on the Windows machine), even the toolbar, but when I click an item on the toolbar it just doesn't execute the given handler. I tried and made a basic PyQt4 program with a toolbar only to test if the bug is because of my program, but the results are the same. Here's the basic example program which doesn't work.
from PyQt4 import QtGui, QtCore
import sys
def aTest(obj = None):
print "If this appears, the action works."
app = QtGui.QApplication(sys.argv)
w = QtGui.QMainWindow()
toolBar = w.addToolBar("toolbar")
action = QtGui.QAction(QtGui.QIcon("path to icon here"), "testAction", w)
w.connect(action, QtCore.SIGNAL("activated()"), aTest)
toolBar.addAction(action)
w.show()
app.exec_()
This code works on Linux without a problem, but on Windows the actions just don't react when activated. Ignore the typos in the code.
OS: Windows 7 Ultimate 32-bit (doesn't work on XP either)
Python version: Python 2.7
PyQt4 version: PyQt-Py2.7-x86-gpl-4.8.4-1
I hope someone out there can help me. I thank you all for your interest and help!
Have a nice day!
It's odd that it works in Linux, because I can only get it work on Windows by changing
w.connect(action, QtCore.SIGNAL("activated()"), aTest)
to
w.connect(action, QtCore.SIGNAL("triggered()"), aTest)
The QAction class reference only lists changed(), hovered(), toggled() and triggered() as valid signals. Unfortunately I don't have a Linux box handy to test things out further.
I am fairly new to Python programming, and completely new to cross-platform GUI building (only previous GUI experience is through visual basic and Java).
I've written some python code to screen-scrape data from a website, and now I want to build a GUI that will reside in the Mac OS X menubar, and in Window's task bar (i.e., the system tray).
The most useful general page on cross-plaform Python GUIs for me was this one (despite its name indication Window GUIs). And some stackoverflow questions came in useful as well (especially this one, and the accepted answer of this one about splitting up the GUI and cli code).
I think I will go for either wxPython or QT because I want the GUI to look as native as possible.
However, as I've said the fairly simple GUI will mainly live in the taskbar/menubar.
Should this influence my decision?
Here's an example for PyQt. This works for me on MacOS X; I haven't tried it on other platforms. Note that the QSystemTrayIcon class will raise exceptions if it doesn't have an icon – I grabbed the RSS feed svg from Wiki commons for my icon.svg (but you can give QIcon a PNG directly and not mess around with QtSvg).
import PyQt4
from PyQt4 import QtCore, QtGui, QtSvg
app = QtGui.QApplication([])
i = QtGui.QSystemTrayIcon()
m = QtGui.QMenu()
def quitCB():
QtGui.QApplication.quit()
def aboutToShowCB():
print 'about to show'
m.addAction('Quit', quitCB)
QtCore.QObject.connect(m, QtCore.SIGNAL('aboutToShow()'), aboutToShowCB)
i.setContextMenu(m)
svg = QtSvg.QSvgRenderer('icon.svg')
if not svg.isValid():
raise RuntimeError('bad SVG')
pm = QtGui.QPixmap(16, 16)
painter = QtGui.QPainter(pm)
svg.render(painter)
icon = QtGui.QIcon(pm)
i.setIcon(icon)
i.show()
app.exec_()
del painter, pm, svg # avoid the paint device getting
del i, icon # deleted before the painter
del app
See this related SO answer on how to accomplish Windows system tray/OS X menu bar functionality in wxPython.