Pyside with UI file > Make dockable


#1

I’ve been playing with the Qt designer generated UI file and it worked really well following this post

http://www.timsportfolio.co.uk/opening-qt-ui-designer-xml-files-with-pyside/

And now I am trying make it dock-able following this guide from Autodesk

But I can’t get it to work together. Any idea how to make Tim’s script dockable?

Any help would be very much appreciated!


#2

This has been my workflow for creating UI’s dockable using a UI file.

        Now I've done away with the whole loading the UI dynamically with QUiLoader() and here's why. I prefer to convert the UI file into a py file with pyside-uic and then load the UI class object into my UI code. This allows me to directly access all the UI objects in my code.
        
        To do this I open up a cmd prompt and navigate to the folder that has the .ui file. Then I'll run for example:
pyside-uic myTool.ui -o myTool_ui.py
        Then in my import declarations I'll import the UI class.
from myTool_ui import Ui_myTool
  • My formatting may be off a bit so you’ll have to tweak it if you copy and paste.
    For the dockable stuff you import this:
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
       This would be my boiler-plate UI class: 
from shiboken import wrapInstance
    from PySide import QtGui, QtCore
    import maya.OpenMayaUI as OpenMayaUI
    from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
    
    def getMayaWindow():
    	"""
    	Get Maya window
    	:return: maya wnd
    	"""
    	mayaMainWindowPtr = OpenMayaUI.MQtUtil.mainWindow()
    	return wrapInstance(long(mayaMainWindowPtr), QtGui.QWidget)
    
    
    class MayaDockUI(MayaQWidgetDockableMixin, QtGui.QDialog):
    	def __init__(self, parent=getMayaWindow(), *args, **kwargs):
    		super(MayaDockUI, self).__init__(parent=parent, *args, **kwargs)
    
    		self.setWindowFlags(QtCore.Qt.Tool)
    		self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    
    	def dockCloseEventTriggered(self):
    		"""
    		Handle stuff when the dock is closed
    		"""
    		self.close()
    		self.deleteLater()
           
       Then I'd import this class as well as my converted UI class into my tool class:
from mayaDockUI import MayaDockUI
  from myTool_ui import Ui_myTool
           
           class MySimpleWindow(MayaDockUI, UI_myTool):
           	def __init__(self, parent=None):
           		super(MySimpleWindow, self).__init__(parent=parent)
       Then in my main() function I set the docking up:
def main():
           
           	global dialog 
           	try:
           		dialog.dockCloseEventTriggered()
           	except:
           		pass
           
           	dialog  = MySimpleWindow()
           	dialog.show()
           	dialog.setDockableParameters(dockable=True, floating=True, area='right', allowedArea='right')
           	
           	# Make sure the docked UI pops up to the front
           	dialog.raise_()

Hope that’s clear and helps.
Cheers,
-Sean


#3

:keenly:

Wow! Thank you so much for taking the time to reply. I haven’t tried this yet but learning so much already. Thank you so much once again!!! NowI can’t wait to go home and try this.


#4

Sure thing. :thumbsup:


#5

Hi

Can I ask for a complete example with files if it is not too much?

Thanks


#6

Thank you so much !
(4y later but still)