#!/usr/bin/python

try:
    import psyco
    psyco.full()
except:
    print '[WW] No Psyco installed'

import sys
from PyQt4 import QtGui, QtCore

class Player( QtCore.QObject ):
    def __init__(self, gui):
        QtCore.QObject.__init__(self)
        self.gui = gui
        wid = self.gui.container.winId()

        #self.opt_list = ['test.mpeg', '-wid', str(wid), '-ao', 'null', '-slave', '-quiet', '-vo', 'gl', '-vf' 'rotate=1']
        self.opt_list = ['test.mov', '-wid', str(wid), '-ao', 'null', '-slave', '-quiet', '-vo', 'gl', '-vf', 'rotate=1']
        self.proc = QtCore.QProcess()
        self.connect(self.proc, QtCore.SIGNAL('readyReadStandardOutput()'), self.proc.readAllStandardOutput)
        self.connect(self.proc, QtCore.SIGNAL('stateChanged (QProcess::ProcessState)'), self.state)

    def state(self, argv):
        self.gui.update()
        if argv == 0:
            print 'mplayer stop normally'
        elif argv == 1:
            print 'mplayer start'
        elif argv == 2:
            print 'mplayer running'

    def run(self):
        self.proc.start('mplayer', self.opt_list)

class Main( QtGui.QWidget ):
    def __init__(self):
        QtGui.QWidget.__init__(self)

        self.mainFrame = QtGui.QFrame(self)
        self.mainFrame.resize(480, 720)

        self.buttonPlay = QtGui.QPushButton('PLAY', self.mainFrame)
        self.buttonPlay.setGeometry(0, 0, 62, 100)
        self.buttonQuit = QtGui.QPushButton('QUIT', self.mainFrame)
        self.buttonQuit.setGeometry(100, 0, 62, 100)

        self.container = QtGui.QX11EmbedContainer(self.mainFrame)
        self.container.setGeometry(0, 120, 480, 700)

        self.player = Player(self)
        self.connect(self.buttonPlay, QtCore.SIGNAL('clicked()'), self.player.run)
        self.connect(self.buttonQuit, QtCore.SIGNAL('clicked()'), QtGui.qApp, QtCore.SLOT('quit()'))
        self.resize(480, 720)

######################
######################
######################
if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)

    run = Main()
    run.show()

    app.exec_()