Here’s the Aloys Baillet’s code stripped down and functioning in Maya.
To use:
1. save code to a file called WxMaya.py (or whatever you want to call it) and place in scripts directory
2. in Maya type:
import WxMaya
WxMaya.createMayaFrame()
import os
import wx
import traceback
import win32gui, win32process
class MayaSubFrame(wx.Frame):
_topLvlMayaWinHandle = None
@classmethod
def create(cls,*args,**kw):
app = wx.GetApp()
if app is None:
app = wx.App(redirect=False)
topHandle = MayaSubFrame._getMayaTopWindow()
top = wx.PreFrame()
print topHandle
top.AssociateHandle(topHandle)
top.PostCreate(top)
app.SetTopWindow(top)
try:
frame = cls(top,app,*args,**kw)
frame.Show(True)
except:
print cls.__name__
print traceback.format_exc()
frame = None
top.DissociateHandle()
return frame
@staticmethod
def _getMayaTopWindow():
if MayaSubFrame._topLvlMayaWinHandle is not None:
return MayaSubFrame._topLvlMayaWinHandle
def callback(handle,winList):
winList.append(handle)
return True
wins = []
win32gui.EnumWindows(callback, wins)
currentId = os.getpid()
for handle in wins:
tpid,pid = win32process.GetWindowThreadProcessId(handle)
if pid == currentId:
title = win32gui.GetWindowText(handle)
if title.startswith("Autodesk Maya"):
MayaSubFrame._topLvlMayaWinHandle = handle
return handle
return None
def __init__(self,parent,app,id,title,pos=(150,150),size=(320,240),style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.FRAME_NO_TASKBAR):
wx.Frame.__init__(self,parent,id,title,pos,size,style)
self.app = app
self.panel = None
self.Bind(wx.EVT_CLOSE,self.OnClose)
def OnClose(self,event):
self.Show(False)
self.Destroy()
win32gui.DestroyWindow(self.GetHandle())
win32gui.SetFocus(MayaSubFrame._topLvlMayaWinHandle)
class MayaFrame(MayaSubFrame):
def __init__(self,parent,app):
MayaSubFrame.__init__(self,parent,app,-1,"Maya WxFrame",size=(320,240))
def createMayaFrame():
MayaFrame.create()
return True
Note: Do not copy/paste this to the script editor and try to run it there. The script looks for a process id that returns "Autodesk Maya" and running from the script editor actually returns the id of "Output Window" which will cause the script to fail.
The script is totally stripped down and is only a blank wxFrame. I appologize for the total lack of comments.
I hope that this works as well for everyone else. If you have any sort of issues with this script, please post your results here.