Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import xml.etree.ElementTree as xml
  2. from cStringIO import StringIO
  3.  
  4. import PySide.QtCore as QtCore
  5. import PySide.QtGui as QtGui
  6. import pysideuic
  7. import shiboken
  8.  
  9. import maya.OpenMayaUI
  10.  
  11.  
  12. def get_pyside_class( ui_file ):
  13. """
  14. Pablo Winant
  15. """
  16. parsed = xml.parse( ui_file )
  17. widget_class = parsed.find( 'widget' ).get( 'class' )
  18. form_class = parsed.find( 'class' ).text
  19.  
  20. with open( ui_file, 'r' ) as f:
  21. o = StringIO()
  22. frame = {}
  23.  
  24. pysideuic.compileUi( f, o, indent = 0 )
  25. pyc = compile( o.getvalue(), '<string>', 'exec' )
  26. exec pyc in frame
  27.  
  28. # Fetch the base_class and form class based on their type in the xml from designer
  29. form_class = frame['Ui_{0}'.format( form_class )]
  30. base_class = eval( 'QtGui.{0}'.format( widget_class ) )
  31.  
  32. return form_class, base_class
  33.  
  34.  
  35. def wrapinstance( ptr, base = None ):
  36. """
  37. Nathan Horne
  38. """
  39. if ptr is None:
  40. return None
  41.  
  42. ptr = long( ptr ) #Ensure type
  43. if globals().has_key( 'shiboken' ):
  44. if base is None:
  45. qObj = shiboken.wrapInstance( long( ptr ), QtCore.QObject )
  46. metaObj = qObj.metaObject()
  47. cls = metaObj.className()
  48. superCls = metaObj.superClass().className()
  49. if hasattr( QtGui, cls ):
  50. base = getattr( QtGui, cls )
  51.  
  52. elif hasattr( QtGui, superCls ):
  53. base = getattr( QtGui, superCls )
  54.  
  55. else:
  56. base = QtGui.QWidget
  57.  
  58. return shiboken.wrapInstance( long( ptr ), base )
  59.  
  60. elif globals().has_key( 'sip' ):
  61. base = QtCore.QObject
  62.  
  63. return sip.wrapinstance( long( ptr ), base )
  64.  
  65. else:
  66. return None
  67.  
  68. def get_maya_window():
  69. maya_window_util = maya.OpenMayaUI.MQtUtil.mainWindow()
  70. maya_window = wrapinstance( long( maya_window_util ), QtGui.QWidget )
  71.  
  72. return maya_window
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement