开发者

Setting the source for Phonon::VideoPlayer

Here is the link to my .ui file. And here is the code to start the GUI:

import sys
from PyQt4 import QtCore, QtGui
from gui import Ui_Form

class StartQT4(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = StartQT4()
    myapp.show()
    sys.exit(app.exec_())

py And here is the GUI Class Code (.py):

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'FinalGUI.ui'
#
# Created: Mon Oct  3 21:53:33 2011
#      by: PyQt4 UI code generator 4.8.5
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(599, 557)
        Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget = QtGui.QTabWidget(Form)
        self.tabWidget.setGeometry(QtCore.QRect(0, 0, 601, 561))
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.intro = QtGui.QWidget()
        self.intro.setObjectName(_fromUtf8("intro"))
        self.frame = QtGui.QFrame(self.intro)
        self.frame.setGeometry(QtCore.QRect(10, 10, 561, 511))
        self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtGui.QFrame.Raised)
        self.frame.setObjectName(_fromUtf8("frame"))
        self.textBrowser = QtGui.QTextBrowser(self.frame)
        self.textBrowser.setGeometry(QtCore.QRect(10, 10, 541, 361))
        self.textBrowser.setHtml(QtGui.QApplication.translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt; font-weight:600; text-decoration: underline;\">Revolution of Music</span></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; text-decoration: underline; vertical-align:sub;\">By Casey and Caleb</span></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt; vertical-align:sub;\">Coded with Python</span></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt; font-weight:600; vertical-align:sub;\">[INSERT INTRODUCTION PARAGRAH]</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt; vertical-align:sub;\"></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><img src=\":/musicPic/Current-Music.jpg\" /></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.textBrowser.setObjectName(_fromUtf8("textBrowser"))
        self.checkBox = QtGui.QCheckBox(self.frame)
        self.checkBox.setGeometry(QtCore.QRect(190, 430, 81, 17))
        self.checkBox.setText(QtGui.QApplication.translate("Form", "Project Idea", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox.setObjectName(_fromUtf8("checkBox"))
        self.checkBox_2 = QtGui.QCheckBox(self.frame)
        self.checkBox_2.setGeometry(QtCore.QRect(190, 450, 81, 17))
        self.checkBox_2.setText(QtGui.QApplication.translate("Form", "Research", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
        self.checkBox_3 = QtGui.QCheckBox(self.frame)
        self.checkBox_3.setGeometry(QtCore.QRect(190, 470, 70, 17))
        self.checkBox_3.setText(QtGui.QApplication.translate("Form", "Written", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_3.setObjectName(_fromUtf8("checkBox_3"))
        self.checkBox_4 = QtGui.QCheckBox(self.frame)
        self.checkBox_4.setGeometry(QtCore.QRect(190, 490, 70, 17))
        self.checkBox_4.setText(QtGui.QApplication.translate("Form", "Done!", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_4.setObjectName(_fromUtf8("checkBox_4"))
        self.textBrowser_2 = QtGui.QTextBrowser(self.frame)
        self.textBrowser_2.setGeometry(QtCore.QRect(180, 390, 191, 31))
        self.textBrowser_2.setHtml(QtGui.QApplication.translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt; font-weight:600;\">Project Goals</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.textBrowser_2.setObjectName(_fromUtf8("textBrowser_2"))
        self.line = QtGui.QFrame(self.frame)
        self.line.setGeometry(QtCore.QRect(280, 440, 3, 61))
        self.line.setFrameShape(QtGui.QFrame.VLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName(_fromUtf8("line"))
        self.checkBox_5 = QtGui.QCheckBox(self.frame)
        self.checkBox_5.setGeometry(QtCore.QRect(290, 430, 81, 17))
        self.checkBox_5.setText(QtGui.QApplication.translate("Form", "Learn PyQt", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_5.setObjectName(_fromUtf8("checkBox_5"))
        self.checkBox_6 = QtGui.QCheckBox(self.frame)
        self.checkBox_6.setGeometry(QtCore.QRect(290, 450, 91, 17))
        self.checkBox_6.setText(QtGui.QApplication.translate("Form", "Code Program", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_6.setObjectName(_fromUtf8("checkBox_6"))
        self.checkBox_7 = QtGui.QCheckBox(self.frame)
        开发者_如何转开发self.checkBox_7.setGeometry(QtCore.QRect(290, 470, 70, 17))
        self.checkBox_7.setText(QtGui.QApplication.translate("Form", "Compile", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_7.setObjectName(_fromUtf8("checkBox_7"))
        self.checkBox_8 = QtGui.QCheckBox(self.frame)
        self.checkBox_8.setGeometry(QtCore.QRect(290, 490, 70, 17))
        self.checkBox_8.setText(QtGui.QApplication.translate("Form", "Finished", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_8.setObjectName(_fromUtf8("checkBox_8"))
        self.tabWidget.addTab(self.intro, _fromUtf8(""))
        self.vidTest = QtGui.QWidget()
        self.vidTest.setObjectName(_fromUtf8("vidTest"))
        self.videoPlayer = phonon.Phonon.VideoPlayer(self.vidTest)
        self.videoPlayer.setGeometry(QtCore.QRect(10, 10, 571, 431))
        self.videoPlayer.setObjectName(_fromUtf8("videoPlayer"))
        self.seekSlider = phonon.Phonon.SeekSlider(self.vidTest)
        self.seekSlider.setGeometry(QtCore.QRect(10, 450, 84, 21))
        self.seekSlider.setObjectName(_fromUtf8("seekSlider"))
        self.volumeSlider = phonon.Phonon.VolumeSlider(self.vidTest)
        self.volumeSlider.setGeometry(QtCore.QRect(470, 450, 109, 22))
        self.volumeSlider.setObjectName(_fromUtf8("volumeSlider"))
        self.pushButton_2 = QtGui.QPushButton(self.vidTest)
        self.pushButton_2.setGeometry(QtCore.QRect(260, 450, 75, 23))
        self.pushButton_2.setText(QtGui.QApplication.translate("Form", "Pause", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.pushButton_3 = QtGui.QPushButton(self.vidTest)
        self.pushButton_3.setGeometry(QtCore.QRect(390, 450, 75, 23))
        self.pushButton_3.setText(QtGui.QApplication.translate("Form", "Stop", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.radioButton = QtGui.QRadioButton(self.vidTest)
        self.radioButton.setGeometry(QtCore.QRect(130, 450, 82, 17))
        self.radioButton.setText(QtGui.QApplication.translate("Form", "Play", None, QtGui.QApplication.UnicodeUTF8))
        self.radioButton.setObjectName(_fromUtf8("radioButton"))
        self.tabWidget.addTab(self.vidTest, _fromUtf8(""))
        self.billHaley = QtGui.QWidget()
        self.billHaley.setObjectName(_fromUtf8("billHaley"))
        self.textBrowser_3 = QtGui.QTextBrowser(self.billHaley)
        self.textBrowser_3.setGeometry(QtCore.QRect(10, 30, 381, 491))
        self.textBrowser_3.setHtml(QtGui.QApplication.translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.textBrowser_3.setObjectName(_fromUtf8("textBrowser_3"))
        self.frame_2 = QtGui.QFrame(self.billHaley)
        self.frame_2.setGeometry(QtCore.QRect(400, 30, 191, 491))
        self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_2.setObjectName(_fromUtf8("frame_2"))
        self.graphicsView = QtGui.QGraphicsView(self.frame_2)
        self.graphicsView.setGeometry(QtCore.QRect(10, 60, 171, 341))
        self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
        self.pushButton_4 = QtGui.QPushButton(self.frame_2)
        self.pushButton_4.setGeometry(QtCore.QRect(60, 410, 75, 23))
        self.pushButton_4.setText(QtGui.QApplication.translate("Form", "Source", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
        self.tabWidget.addTab(self.billHaley, _fromUtf8(""))
        self.tab_4 = QtGui.QWidget()
        self.tab_4.setObjectName(_fromUtf8("tab_4"))
        self.tabWidget.addTab(self.tab_4, _fromUtf8(""))

        self.retranslateUi(Form)
        self.tabWidget.setCurrentIndex(2)
        QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(_fromUtf8("clicked()")), self.videoPlayer.pause)
        QtCore.QObject.connect(self.pushButton_3, QtCore.SIGNAL(_fromUtf8("clicked()")), self.videoPlayer.stop)
        QtCore.QObject.connect(self.radioButton, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.videoPlayer.play)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.intro), QtGui.QApplication.translate("Form", "Introduction", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.vidTest), QtGui.QApplication.translate("Form", "Video Test", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.billHaley), QtGui.QApplication.translate("Form", "Bill Haley", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), QtGui.QApplication.translate("Form", "Blank :P ", None, QtGui.QApplication.UnicodeUTF8))

from PyQt4 import phonon

My question is, how can I get the video player to load the url so that when I toggle the radio button, labeled, play, to start the music?

Sorry, but I am a novice, and really need this to be done. Please explain it since I need to implement it on a lot of other tabs later. Also, how is the scaling in PyQt4 Designer?

Just need to know so I can make the right dimensions for a picture.


Without getting into TOO much detail about how the Phonon package works, here is a quick snippet:

from PyQt4.phonon import Phonon

...

source = Phonon.MediaSource("http://vsyamuzika.narod.ru/tvist/Rock_around_the_clock.mp3")
self.ui.videoPlayer.mediaObject().setCurrentSource(source)
self.ui.videoPlayer.play()

You can just create a list of MediaSource objects, and swap them into the player.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜