Difference between revisions of "Development/Tutorials/Phonon/Introduction/Python"

Jump to: navigation, search
m (Added python code highlighting)
m (Text replace - "<code python>" to "<syntaxhighlight lang="python">")
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
 
This is the Python port of tutorial2.cpp found under [[Development/Tutorials/Phonon/Introduction]].
 
This is the Python port of tutorial2.cpp found under [[Development/Tutorials/Phonon/Introduction]].
  
<code python>
+
<syntaxhighlight lang="python">
 
#This file is part of the KDE project
 
#This file is part of the KDE project
 
#Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
 
#Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
Line 71: Line 71:
 
if __name__ == '__main__':
 
if __name__ == '__main__':
 
     main()
 
     main()
</code>
+
</syntaxhighlight>

Latest revision as of 20:43, 29 June 2011

This is the Python port of tutorial2.cpp found under Development/Tutorials/Phonon/Introduction.

#This file is part of the KDE project
#Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
#adapted 2008 by Thorsten Staerk
#ported to PyQt4 by Christoph Burgmer
 
#Permission to use, copy, modify, and distribute this software
#and its documentation for any purpose and without fee is hereby
#granted, provided that the above copyright notice appear in all
#copies and that both that the copyright notice and this
#permission notice and warranty disclaimer appear in supporting
#documentation, and that the name of the author not be used in
#advertising or publicity pertaining to distribution of the
#software without specific, written prior permission.
 
#The author disclaim all warranties with regard to this
#software, including all implied warranties of merchantability
#and fitness.  In no event shall the author be liable for any
#special, indirect or consequential damages or any damages
#whatsoever resulting from loss of use, data or profits, whether
#in an action of contract, negligence or other tortious action,
#arising out of or in connection with the use or performance of
#this software.
 
 
import sys
 
from PyQt4.QtGui import QApplication, QMainWindow, QDirModel, QColumnView
from PyQt4.QtGui import QFrame
from PyQt4.QtCore import SIGNAL
from PyQt4.phonon import Phonon
 
class MainWindow(QMainWindow):
 
    m_model = QDirModel()
 
    def __init__(self):
        QMainWindow.__init__(self)
        self.m_fileView = QColumnView(self)
        self.m_media = None
 
        self.setCentralWidget(self.m_fileView)
        self.m_fileView.setModel(self.m_model)
        self.m_fileView.setFrameStyle(QFrame.NoFrame)
 
        self.connect(self.m_fileView,
            SIGNAL("updatePreviewWidget(const QModelIndex &)"), self.play)
 
    def play(self, index):
        self.delayedInit()
        #self.m_media.setCurrentSource(self.m_model.filePath(index))
        self.m_media.setCurrentSource(
            Phonon.MediaSource(self.m_model.filePath(index)))
        self.m_media.play()
 
    def delayedInit(self):
        if not self.m_media:
            self.m_media = Phonon.MediaObject(self)
            audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
            Phonon.createPath(self.m_media, audioOutput)
 
def main():
    app = QApplication(sys.argv)
    QApplication.setApplicationName("Phonon Tutorial 2 (Python)")
    mw = MainWindow()
    mw.show()
    sys.exit(app.exec_())
 
if __name__ == '__main__':
    main()

This page was last modified on 29 June 2011, at 20:43. This page has been accessed 10,948 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal