First you have to generate the python code for your video.ui
use pyuic4
tool for that.
pyuic4 -x video.ui -o video.py
The above line will generate a module called video.py
that will containg a class named as you named UI_
then you can modify you code like this:
import sys
from PyQt4 import QtCore, QtGui, uic, phonon
from video import UI_MyVideoWindow # Lets call it MyVideoWindow for the example.
class videoPlayer(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.ui = UI_MyVideoWindow()
self.ui.setUp(self) # Now you can access you widgets from self.ui
# Example: self.ui.ppButton
media = phonon.Phonon.MediaObject(self) # this object needs a parent.
playQuery = False
def playVideo():
media.play()
def pauseVideo():
media.pause()
def on_ppButton_clicked():
"""
When you generate code using QtDesigner, connections are made automagically ;)
Just write your slots following the below format:
on_<widget_name>_<signal_name>
"""
if playQuery:
pauseVideo()
else:
playVideo()
def changeVideoSource(target):
media.setCurrentSource(phonon.Phonon.MediaSource(target))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
videoPlayer = videoPlayer()
videoPlayer.show()
app.exec_()
The only issue about this approach is that you have to update you video.py
module each time you modify video.ui
. But that is a very easy job, just generate it again with:
pyuic4 -x video.ui -o video.py
as you saw before.