< Phonon
Revision as of 18:42, 29 June 2011 by Neverendingo (talk | contribs) (Text replace - "</code>" to "</syntaxhighlight>")


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

  1. This file is part of the KDE project
  2. Copyright (C) 2007 Matthias Kretz <[email protected]>
  3. adapted 2008 by Thorsten Staerk
  4. ported to PyQt4 by Christoph Burgmer
  1. Permission to use, copy, modify, and distribute this software
  2. and its documentation for any purpose and without fee is hereby
  3. granted, provided that the above copyright notice appear in all
  4. copies and that both that the copyright notice and this
  5. permission notice and warranty disclaimer appear in supporting
  6. documentation, and that the name of the author not be used in
  7. advertising or publicity pertaining to distribution of the
  8. software without specific, written prior permission.
  1. The author disclaim all warranties with regard to this
  2. software, including all implied warranties of merchantability
  3. and fitness. In no event shall the author be liable for any
  4. special, indirect or consequential damages or any damages
  5. whatsoever resulting from loss of use, data or profits, whether
  6. in an action of contract, negligence or other tortious action,
  7. arising out of or in connection with the use or performance of
  8. 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):
       self.m_fileView = QColumnView(self)
       self.m_media = None
           SIGNAL("updatePreviewWidget(const QModelIndex &)"), self.play)
   def play(self, index):
   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()

if __name__ == '__main__':



This page was last edited on 11 March 2016, at 19:20. Content is available under Creative Commons License SA 4.0 unless otherwise noted.