whats your approach for integrating Qt Designer files in your workflow

425 views
Skip to first unread message

lala

unread,
Feb 28, 2014, 4:52:54 PM2/28/14
to python_in...@googlegroups.com

in Python Dev (other than cg) , typically standalone apps, i prefer to convert .ui files to .py files via uic command and then subclass the view.

in maya python | pymel, i am trying to figure out easy equivalant workflow. From all searches around yesterday including
i realized
  1. ppl can directly load / use .ui files, rather then converting to py
    • pros : one step less work ( using uic to convert to py )
    • cons: headache of setting up sip and pyqt , uic etc.. (sometimes hard to find for relevant maya version). in my case, its not working ideally. 50%
  2. ppl can even subclass this ( like i do in standalone version), very impressive
  3. ppl can strangly try to connect (child) this to maya windows . is it necessary. ? not sure.
    • it helps in docking etc?
    • any other advantages?

Now i am attaching 3 files
makeCube_ui,py >> relevant .ui file is missing. its from DT. this template works
lmRenamer_Tool.py >> relevant .ui also attached. there are two methods in py file,
def approach1 >> it works , real ui shows. but i don't know how to get controls from ui and bind them function (singals / slots etc) >>its not subclassing etc..
def approach2  >> (similar to other py, template modification) but its not working, empty black ui shows

btw> i m maya 2014 sp2 , x64.
i downloaded PyQt4-4.10.3-gpl-Py2.7-Qt4.8.5-x64 and installed in maya python folder ( C:\Program Files\Autodesk\Maya2014\Python )
i haven't found sip (something).... to replace pyd file>> 
when i tried template approach, (subclassing) i get lot of lengthy log in maya script history place i.e
--------------------------------------
# PyQt4.uic.uiparser : pop layout QVBoxLayout verticalLayout # 
# PyQt4.uic.uiparser : pop widget QWidget centralwidget # 
# PyQt4.uic.uiparser : new topwidget Window # 
# PyQt4.uic.uiparser : push QStatusBar statusbar # 
# PyQt4.uic.uiparser : pop widget QStatusBar statusbar # 
# PyQt4.uic.uiparser : new topwidget Window # 
# PyQt4.uic.uiparser : pop widget QMainWindow Window # 
# PyQt4.uic.uiparser : new topwidget None # 
-----------------------------------------------------------------------
lastly, approach 1, window ui shows nicely.  it won't go behind maya ui, as i click in viewport
where as even in template script (makeCube_ui.py) it works. but goes back (behind) maya windows when i click in viewports .
Final Request
Can someone please explain quick step by step simple way to subclass, or share a simple example?
ideally if i can dock to maya view or windows, its extremely useful
huge thanks

makeCube_ui.py
lmRenamer_Tool.py
lmRenamer_View.ui

Jesse Kretschmer

unread,
Feb 28, 2014, 8:13:25 PM2/28/14
to python_in...@googlegroups.com

On Fri, Feb 28, 2014 at 1:52 PM, lala <lala...@gmail.com> wrote:
lastly, approach 1, window ui shows nicely.  it won't go behind maya ui, as i click in viewport
where as even in template script (makeCube_ui.py) it works. but goes back (behind) maya windows when i click in viewports .

There is a window flag for tool mode to keep a window on top of maya. I usually use QDialog, but it should work on any QWidget. Example:
someDialog.setWindowFlags( QtCore.Qt.Tool )

Here's a full example with that flag: http://pastebin.com/uzu2faY6

I don't often use designer, so I can't comment on a good workflow.

cheers,
jesse

Justin Israel

unread,
Feb 28, 2014, 11:00:02 PM2/28/14
to python_in...@googlegroups.com
cmds.loadUI() is a really limited approach to loading Qt Designer UI files. It immediately converts everything to Maya controls and gives you back a path. This approach kind of expects that you will do the thing where you create dynamic properties inside of Designer, on your widgets, that will be treated as flags when Maya goes to create that equivalent control. Like if you were to create a QPushButton and then add a property called "+command", with a value of "<some python callback>"

In your second approach, it's not really valid code right now. You have Interface class defined to inherit from two objects that don't exist, which you are creating privately from within your function. Typically the approach of using uic to load a UI file dynamically would happen in the root of the module (or importing from another module that is doing it), so that it is available for your to inherit from in your class definition. 

There is also another way, using uic.loadUi() to have it load onto your own class. So if you design a QDialog, and then create a QDialog subclass, it might look like:

class MyClass(QtGui.QDialog):

    def __init__(self, *args, **kwargs):
        super(MyClass, self).__init__(*args, **kwargs)
        uic.loadUi("test.ui", self)

This would be loading the UI every single time a MyClass instance is constructed, as opposed to at import time. Its up to you how you want to organize your approach.

Like Jesse, I don't use Designer anymore, so I don't have too much more to say about it. But when I was using it, I was pre-converting my UI files to py so that I didn't have to deal with resource loading, and just pure python. It gets a lot easier when you end up dropping Designer and writing the UI's directly in your own code. 






--
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/CANESWi3KLsPxh86XF16ZZywutkb5V2hCw84ro%2BPAPf4TX%2BUEbA%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.

Joe Weidenbach

unread,
Mar 1, 2014, 12:38:15 AM3/1/14
to python_in...@googlegroups.com
This actually makes a lot of sense to me as well. I've been fighting
with trying to integrate designer files, and although it works, it
usually seems easier/cleaner to just write them up myself.

lala

unread,
Mar 1, 2014, 3:13:49 PM3/1/14
to python_in...@googlegroups.com
thankyou very much everyone. nice community, i m glad, i found this. a lot to learn.
i almost agreed about dropping designer. but i have to say, in my opinion writing decent UI is always more time taking, then real stuff
and qt designer was 1 of few , which help to create fluid UI extremely quickly. 
seocndly i imidiately found pyqt for maya 2014 on this exact forum ( few posts below ) . he has given everything i possibly needed.

lastly, @ justin, your example makes most sense for me. For right now, i have at least decided, to convert .ui to .py and then subclass and then proceed.

thanks everyone once again. i'll try and might pop up in a day or 2, if i am unable to solve issues
thanks,lala
 
 
 

lala

unread,
Mar 2, 2014, 1:49:15 PM3/2/14
to python_in...@googlegroups.com
Hi Everyone again
i am attaching 2 templates. qdialog template , qwindow template.  only *.tool files should be run, they will import relevant *.view file. with connections (signals etc )

I am almost there, all wish list points are almost done
  • using qt designer files (quick)
  • convert to py files, np
  • subclass from QDialog or QMainWindow with (relevant converted py file)
  • i call this super decent. ( view is like view, and tool is like controller, setting links, etc )
only missing feature is, >> staying on top of maya window. currently its not :(

as per Jesse Kretschmer  comments. i tried setting flags, but its not working , as its subclassing from two base classes, any ideas, how can i fix this or add this feature

huge thanks for support in advance
regards,lala


SimpleDialogTool.py
SimpleWindowTool.py
SimpleWindowView.py
SimpleDialogView.py

Justin Israel

unread,
Mar 2, 2014, 3:17:43 PM3/2/14
to python_in...@googlegroups.com

The tool flag for the window is only one part of what you need. The other part is that you have to tell your window to use the Maya main window as its parent. Otherwise the tool window you create doesn't know what to remain on top of.

#-----
import maya.OpenMayaUI as mui
import sip

def getMayaWindow():
    ptr = mui.MQtUtil.mainWindow()
    return sip.wrapinstance(long(ptr), QtCore.QObject)
#-----

--
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.
Reply all
Reply to author
Forward
0 new messages