一半君的总结纸

听话只听一半君

使用自动build script编译PyQt 4.11.4 for Maya 2015 with Phonon

好像网上没看到2015的, lz来做一个
预先准备好

  1. 自动build script在 https://github.com/oglops/Maya-PyQt-Scripts/tree/master/win_mega,把他clone下来,然后把上面需要的材料都解压放好之后,看起来是这样

    pyqt_2015_1

  2. devkit需要做如下准备
    • 把Maya安装目录下的include/qt-4.8.5-include.tar.gz解压放到include/Qt里
    • 把mkspecs/qt-4.8.5-mkspecs.tar.gz解压到当前目录下
    • 把include/python2.7里的内容放到Python/include里

  3. setup.bat顶部设置稍作修改
    set MAYAVERSION=2015
    set ADSKQTVERSION=4.8.5
    set SIPVERSION=4.18
    set PYQTVERSION=4.11.4
    set QSCINTILLAVERSION=2.9.2
    
    ...
    
    set "INCLUDE=%INCLUDE%;C:\Python27\include;c:\Program Files\PostgreSQL\9.5\include;C:\Program Files\MySQL\MySQL Server 5.7\include;C:\OpenSSL-Win64\include"
    set "LIB=%LIB%;C:\Python27\libs;c:\Program Files\PostgreSQL\9.5\lib;C:\Program Files\MySQL\MySQL Server 5.7\lib;C:\OpenSSL-Win64\lib"
    
    #可能此外还有一些修改,请见机行事 orz
    

    lz想要个大而全的,所以lz装了PostgreSQL / MySQL server / openssl

  4. 打开ConEMu,进到pyqt_2015目录, 执行buildall.bat,然后开始祈祷
  5. 编译完成后lz使用pyqt自带的PyQt4-Qt4.nsi进行了打包,当然需要编辑一下这个文件,原版和lz修改版在这里diff比较

测试:
安装后有点小问题

    • lz在virtualbox虚拟机里测试安装的时候,pyuic4.bat里的路径x:\要相应的改成你python的安装路径,lz没看出.nsi script哪里错了,换了台机器安装似乎又没事,大概也许是因为在虚拟机里安装的时候是直接双击了shared folder里的安装文件?
    • 此外lz把C:\Python27\Lib\site-packages\PyQt4\phonon4.dll移动到C:\Python27\DLLs下,然后修改PyQt4的__init__.py

      其实就是如果在Maya里,就用Maya自己带的phonon4.dll,如果在外面,就用C:\Python27\DLLs下面的(lz也不太确定这样乱搞对不对哈)

    • 但是这样有个副作用,就是你从开始菜单里开designer的时候,左侧工具栏里的phonon widget没了,所以你可以把designer快捷方式里的命令改改,这样会闪一下,但是你把窗口改成Minimized就看不到闪了
      cmd /c "set ^"PATH=C:\python27\DLLs;%PATH%^" && start  C:\python27\Lib\site-packages\PyQt4\designer.exe"
      # ^" 是escape char,就是"
      

    试用Benjamin Rhoades大神的代码(lz加了个滑条)

    from PyQt4 import QtCore
    from PyQt4 import QtGui
    from PyQt4.phonon import Phonon
    
    import sip
    import maya.OpenMayaUI as omu
    
    def maya_main_window():
    
        ptr = omu.MQtUtil.mainWindow()
        return sip.wrapinstance(long(ptr), QtCore.QObject)
    
    class Window(QtGui.QWidget):
        def __init__(self, parent = maya_main_window()):
    
            QtGui.QWidget.__init__(self)
            self.media = Phonon.MediaObject(self)
            self.media.stateChanged.connect(self.handleStateChanged)
            self.video = Phonon.VideoWidget(self)
            self.video.setMinimumSize(400, 400)
            self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self)
            Phonon.createPath(self.media, self.audio)
            Phonon.createPath(self.media, self.video)
            self.button = QtGui.QPushButton('Choose File', self)
            self.button.clicked.connect(self.handleButton)
            self.list = QtGui.QListWidget(self)
            self.list.addItems(Phonon.BackendCapabilities.availableMimeTypes())
            self.slider = Phonon.SeekSlider(self.media , self)
            self.play_pause = QtGui.QPushButton('Play / Pause')
            self.play_pause.clicked.connect(self.playClicked)
            slider_layout=QtGui.QHBoxLayout()
    
            slider_layout.addWidget(self.slider)
            slider_layout.addWidget(self.play_pause)
            layout = QtGui.QVBoxLayout(self)
            layout.addWidget(self.video, 1)
            layout.addLayout(slider_layout)
            layout.addWidget(self.button)
            layout.addWidget(self.list)
    
        def handleButton(self):
            if self.media.state() == Phonon.PlayingState:
                self.media.stop()
            else:
                path = QtGui.QFileDialog.getOpenFileName(self, self.button.text())
                if path:
                    self.media.setCurrentSource(Phonon.MediaSource(path))
                    self.media.play()
    
        def playClicked(self):
            if self.media.state() == Phonon.PlayingState:
                self.media.pause()
            else:
                self.media.play()
    
        def handleStateChanged(self, newstate, oldstate):
            if newstate == Phonon.PlayingState:
                self.button.setText('Stop')
            elif (newstate != Phonon.LoadingState and
                  newstate != Phonon.BufferingState):
                self.button.setText('Choose File')
                if newstate == Phonon.ErrorState:
                    source = self.media.currentSource().fileName()
                    print ('ERROR: could not play:', source.toLocal8Bit().data())
                    print ('  %s' % self.media.errorString().toLocal8Bit().data())
    
    if __name__ == '__main__':
        window = Window()
        window.show()
    

    你还需要个 K-Lite Codec Pack lz装了个最大的… K-Lite Mega Codec Pack

    当然

    PYTHONPATH=C:\Python27\Lib\site-packages
    

    要在系统环境变量里

    编译出来的安装包下载:
    qt-plugins-qt-4.8.6-phonon-sqldrivers.rar 解压放到maya安装目录下的qt-plugins目录下
    PyQt4-4.11.4-gpl-Py2.7-Qt4.8.5-x64-maya-2015.exe

    phonon_2015

    参考:
    Building SIP, and PyQt for Maya 2015
    “S1023” error when you install the DirectX SDK (June 2010)
    如何才能在Maya里用Phonon – 编译Qt 顺带试验编译PyQt4 for Maya 2014
    Windows8.1下编译Maya 2016用的PyQt4 续 – 使用外部Python以及自行编译Qt

    Advertisements

2 responses to “使用自动build script编译PyQt 4.11.4 for Maya 2015 with Phonon

  1. 上官云恒 七月 6, 2016 @ 8:33 上午

    怎么会想到要编译pyqt4呢?不是有pyside么?

    • 一半君 七月 6, 2016 @ 9:06 上午

      因为pyqt比较主流,lz呆过的两家(i*m so*y)都用pyqt,大概是因为在pyside被加进maya之前,无数鼠标民工们已经写出太多pyqt的工具了吧

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: