https://techbase.kde.org/api.php?action=feedcontributions&user=Dominiks&feedformat=atomKDE TechBase - User contributions [en]2024-03-19T09:53:02ZUser contributionsMediaWiki 1.40.2https://techbase.kde.org/index.php?title=Phonon/Python&diff=52821Phonon/Python2010-07-29T07:09:59Z<p>Dominiks: Added python code highlighting</p>
<hr />
<div>This is the Python port of tutorial2.cpp found under [[Development/Tutorials/Phonon/Introduction]].<br />
<br />
<code python><br />
#This file is part of the KDE project<br />
#Copyright (C) 2007 Matthias Kretz <kretz@kde.org><br />
#adapted 2008 by Thorsten Staerk<br />
#ported to PyQt4 by Christoph Burgmer<br />
<br />
#Permission to use, copy, modify, and distribute this software<br />
#and its documentation for any purpose and without fee is hereby<br />
#granted, provided that the above copyright notice appear in all<br />
#copies and that both that the copyright notice and this<br />
#permission notice and warranty disclaimer appear in supporting<br />
#documentation, and that the name of the author not be used in<br />
#advertising or publicity pertaining to distribution of the<br />
#software without specific, written prior permission.<br />
<br />
#The author disclaim all warranties with regard to this<br />
#software, including all implied warranties of merchantability<br />
#and fitness. In no event shall the author be liable for any<br />
#special, indirect or consequential damages or any damages<br />
#whatsoever resulting from loss of use, data or profits, whether<br />
#in an action of contract, negligence or other tortious action,<br />
#arising out of or in connection with the use or performance of<br />
#this software.<br />
<br />
<br />
import sys<br />
<br />
from PyQt4.QtGui import QApplication, QMainWindow, QDirModel, QColumnView<br />
from PyQt4.QtGui import QFrame<br />
from PyQt4.QtCore import SIGNAL<br />
from PyQt4.phonon import Phonon<br />
<br />
class MainWindow(QMainWindow):<br />
<br />
m_model = QDirModel()<br />
<br />
def __init__(self):<br />
QMainWindow.__init__(self)<br />
self.m_fileView = QColumnView(self)<br />
self.m_media = None<br />
<br />
self.setCentralWidget(self.m_fileView)<br />
self.m_fileView.setModel(self.m_model)<br />
self.m_fileView.setFrameStyle(QFrame.NoFrame)<br />
<br />
self.connect(self.m_fileView,<br />
SIGNAL("updatePreviewWidget(const QModelIndex &)"), self.play)<br />
<br />
def play(self, index):<br />
self.delayedInit()<br />
#self.m_media.setCurrentSource(self.m_model.filePath(index))<br />
self.m_media.setCurrentSource(<br />
Phonon.MediaSource(self.m_model.filePath(index)))<br />
self.m_media.play()<br />
<br />
def delayedInit(self):<br />
if not self.m_media:<br />
self.m_media = Phonon.MediaObject(self)<br />
audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)<br />
Phonon.createPath(self.m_media, audioOutput)<br />
<br />
def main():<br />
app = QApplication(sys.argv)<br />
QApplication.setApplicationName("Phonon Tutorial 2 (Python)")<br />
mw = MainWindow()<br />
mw.show()<br />
sys.exit(app.exec_())<br />
<br />
if __name__ == '__main__':<br />
main()<br />
</code></div>Dominiks