Another Maya PyQt conundrum. Oh, the calamity!!!

71 views
Skip to first unread message

Credible Mulk

unread,
Nov 6, 2014, 4:54:42 AM11/6/14
to python_in...@googlegroups.com
I am using Maya 2014 and writing a simple ui in QtDesigner. I copied the PyQt4 folder and the sip.pyd file to the correct location in the Maya install folder. So far, so good. I followed a tutorial that created a simple ui with a button that made a box. Everything was good until I changed the code slightly and attempted to import the ui. 

On trying to import my file, the xml parser did fine but then I received an error: # Error: ImportError: file <string> line 59: No module named ploppy_rc # 

The ui itself is ok, I added some radio buttons (which are not yet linked to anything) and the only difference between my file and the tutorial file is that I created a resource folder with an icon for the ui.

As the script I wrote is only 35 lines long, I was confused by the line 59 error. then I realised that it must be referring to the ui file, so I made a very obvious name change to see if it was erroring where I thought it was. The actual line in the ui script is not line 59 but line 33 where there is a reference to the resource file (ploppy.qrc) as line 59 is a width value

line 33: <iconset theme="flaps" resource="icons/ploppy.qrc">
line 59: <width>41</width>

I have attached the ui file if anyone wants a look.

The import code, which I have as a shelf button is as follows:

import sys
Dir = 'Z:\\ddtest\\Malc\\burrows_MayaTools\\burrowsMirrorTool'
if Dir not in sys.path:
    sys.path.append(Dir)
    #print(sys.path)
try: reload(brrwsMirrorScript)
except: import brrwsMirrorScript
brrwsMirrorScript.main()

main python script code is as follows:

from PyQt4 import QtGui, QtCore, uic

from pymel.core import *
import pymel.core as pm
from pymel import *

#Path to UI file

ui_filename = 'Z:\\ddtest\\Malc\\burrows_MayaTools\\burrowsMirrorTool\\ui\\brrwsMirrorScript.ui'
form_class, base_class = uic.loadUiType(ui_filename)

class brrwsMirrorScript(base_class, form_class):
    def __init__(self):
        super(base_class, self).__init__()
        self.setupUi(self)
        self.setObjectName('brrwsMirrorScript')
        self.setDockNestingEnabled(True)
        self.connectInterface()

    def connectInterface(self):
        QtCore.QObject.connect(self.bttn_mirrorCmd, QtCore.SIGNAL('clicked()'), self.makeMirrorWin)

    def makeMirrorWin(self):
        mel.eval('global proc brrwsMirrorScript(){polyCube;}')
        mel.brrwsMirrorScript()

def main():
    global mirrorUi 
    mirrorUi = brrwsMirrorScript()
    mirrorUi.show()

if __name__ == '__main__':
    main()

Perhaps, I have used designer resource in the wrong way, but I do not think so. I was wondering if  there is an issue with the read in of the ui file as it seems to have replaced the .q from the resource line to an underscore. Anyone have any idea why this is happening

Thanks in advance for any help.
brrwsMirrorScript.ui

Marcus Ottosson

unread,
Nov 6, 2014, 4:57:29 AM11/6/14
to python_in...@googlegroups.com

I copied the PyQt4 folder

Which folder was this?


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/34928a32-9340-4429-aeec-d8de48cc849e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Nov 6, 2014, 5:27:52 AM11/6/14
to python_in...@googlegroups.com

When you use the dynamic uic module with Qt Designer UI files, it translates the xml format into a Python UI module and imports it. Part of this conversion is to also tranlate a reference to a resource qrc file into a python import statement. But what I don't think it is doing for you, is actually converting the qrc file. Forgive me, but I never really use the dynamic UI loading so I can't be certain, but that is my guess.
If you are going to use a qrc file, then I think you will need to convert it using the pyrcc tool from the command line. It is similar to using pyuic from the command line instead of dynamically at import. It expects you to use an output name of ploppy_rc.py
This will produce a module with all of your images encoded into it.
Now there may be the equivalent of a dynamic rcc module to do this at import, but I am not familiar with it. When I was still using Designer, I had always used the pattern of pre-generating my UI and rc files manually as they changed.


--

Credible Mulk

unread,
Nov 6, 2014, 8:32:52 AM11/6/14
to python_in...@googlegroups.com
Hi Justin, thanks for the reply. I will give it a go without a qrc file and see if it works. Currently only using it for a ui icon, so not overly important right now.Do you use QTDesigner for a UI layout? If not, where/how do you create a ui for maya using Python.

Many thanks

Credible Mulk

unread,
Nov 6, 2014, 8:52:59 AM11/6/14
to python_in...@googlegroups.com
Ok, so removing the resource file worked and I have got the ui open in maya but I had to change /omit a line which seems to work in the tutorial file.

# Error: AttributeError: file Z:\ddtest\Malc\burrows_MayaTools\burrowsMirrorTool\brrwsMirrorScript.py line 17: 'brrwsMirrorScript' object has no attribute 'setDockNestingEnabled' # 

if I omit the line from my script and run the tool from the shelf button I have, its ok, if I uncomment the line, I get this error. There must be a logical reason as to why it works in the tutorial, but not in my script. All I have done is to substitute the tutorial name for my own and I have been careful to make sure that where the tutorial has specific names for objects, I have done the same, but I keep getting the error. 

Cheers guys

On Thu, Nov 6, 2014 at 1:32 PM, Credible Mulk <mjearmst...@gmail.com> wrote:
Hi Justin, thanks for the reply. I will give it a go without a qrc file and see if it works. Currently only using it for a ui icon, so not overly important right now.Do you use QTDesigner for a UI layout? If not, where/how do you create a ui for maya using Python.

Many thanks

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/cBSUHDF7-Ag/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/85f95ba1-204c-4bb1-9cf9-371f6edbefe0%40googlegroups.com.

Justin Israel

unread,
Nov 6, 2014, 12:54:40 PM11/6/14
to python_in...@googlegroups.com
I only used Designer when I was first learning Qt, so that I could visually lay out the UI design. Eventually you will find that it is much easier to just write the UI by hand in code. It ends up being less cruft from the autogenerated stuff, and less to manage with needing to convert the UI files. If you use images via the Designer, it will require a resource file. But if you do it by hand in code, you can directly reference the image path. For now you can keep using Designer. But an interesting thing to do would be to convert it outside of Maya, using pyuic, and read what code the Designer ended up creating.

Are you using a QMainWindow as your base class? If not, that would explain the error.

You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJ7OuxeA4qKMmfc6-2UuDoSb5sfswsQASb%3DUN%2BJazhKRDuPWsw%40mail.gmail.com.

Credible Mulk

unread,
Nov 6, 2014, 1:02:58 PM11/6/14
to python_in...@googlegroups.com
I am not using QmainWindow but neither is the original tutorial, so I am not sure. I will look into it. I did originally start using hand written code for ui, but the temptation of designer pulled me away but I will return to hand written code as it will help with the memory and getting to know the qt classes and functionality. Thanks Justin, sound advice yet again. ;)

Hopefully, once I get more involved, I can go back to watching/learning from the CMI Vfx maya python vids I bought a while ago. 

Reply all
Reply to author
Forward
0 new messages