Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to install shiboken2?

How to install shiboken2?

The-Digital-Shaman
Advocate Advocate
3,153 Views
2 Replies
Message 1 of 3

How to install shiboken2?

The-Digital-Shaman
Advocate
Advocate

Hi there,

 

I am trying to create an empty fully dockable window using python.

 

None of the scripts from various tutorials work.

Most of them produces: # Error: invalid syntax # 

 

For example this one:

https://www.youtube.com/watch?v=n4i4F2fmK2M

 

********************* empty window script **********************
import maya.cmds as cmds

class MR_Window(object):

#constructor
def __init__(self):

self.window = "MR_Window"
self.title = "Cube Creator"
self.size = (400, 400)

# close old window is open
if cmds.window(self.window, exists = True):
cmds.deleteUI(self.window, window=True)

#create new window
self.window = cmds.window(self.window, title=self.title, widthHeight=self.size)

#display new window
cmds.showWindow()


myWindow = MR_Window()

 

 

 

Or that one (updated):

https://www.youtube.com/watch?v=lBz8lEqHXYM

 

import PySide2 as ps2
import maya.OpenMayaUI as omui
import shiboken2
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin

def mayaMainWindow():
mainWindowPointer = omui.MQtUtil.mainWindow()
return shiboken2.wrapInstance(int(mainWindowPointer), ps2.QtWidgets.QWidget)

class MyWindow(MayaQWidgetDockableMixin, ps2.QtWidgets.QDialog):
def __init__(self, parent=mayaMainWindow()):
super(MyWindow, self).__init__(parent)
self.myButton = ps2.QtWidgets.QPushButton('My Button')
mainLayout = ps2.QtWidgets.QVBoxLayout(self)
mainLayout.addWidget(self.myButton)

if __name__== '__main__':
myWindow = MyWindow()
myWindow.show(dockable=True)

 

 

I'm running out of ideas.

 

Please advise.

 

Cheers,

DS

 

 

 

 

 

0 Likes
Accepted solutions (1)
3,154 Views
2 Replies
Replies (2)
Message 2 of 3

lee.dunham
Collaborator
Collaborator
Accepted solution

`Invalid Syntax` doesnt mean you don't have the library, it means your code is not syntactically correct - meaning python doesn't understand what you're trying to do due to a mistake in your code.

It should give you more information than just Invalid Syntax, usually the line it fails on?

 

For your two code examples, using the correct code block will make it easier to see the problem, as it's difficult to see what exactly you're trying to run.

The first has this,

```

********************* empty window script **********************

```

Which is not valid python code.

 

The second has a spelling mistake on the first line;

`import PySide2 ps ps2`

It should be;

`import PySide2 as ps2`

 

Try fixing the errors you see in the code as you read it word by word and post up the full error message you see if there is still an issue 🙂

0 Likes
Message 3 of 3

The-Digital-Shaman
Advocate
Advocate

Thank you Lee!

 

It's a valuable info, that missing module doesn't produce syntax errors.

 

I corrected the code and it created the window which is dockable!

It's all I need!