1
- from Qt import QtGui , QtCore , QtWidgets
1
+ from maya . app . general . mayaMixin import MayaQWidgetDockableMixin
2
2
from maya import OpenMayaUI
3
+ from maya import cmds
4
+
3
5
try :
4
- import shiboken
6
+ from PySide6 import QtCore , QtWidgets , QtGui
7
+ import shiboken6 as shiboken
5
8
except ImportError :
9
+ from PySide2 import QtCore , QtWidgets
6
10
import shiboken2 as shiboken
7
11
8
12
9
- def getMayaWindow ():
10
- ptr = OpenMayaUI .MQtUtil .mainWindow ()
11
- return shiboken .wrapInstance (long (ptr ), QtWidgets .QMainWindow )
13
+ def mayaUIContent (parent ):
14
+ """ Contents by Maya standard UI widgets """
15
+
16
+ layout = cmds .columnLayout (adjustableColumn = True , parent = parent )
17
+
18
+ cmds .frameLayout ("Sample Frame 1" , collapsable = True )
19
+ cmds .columnLayout (adjustableColumn = True , rowSpacing = 2 )
20
+ cmds .button ("maya button 1" )
21
+ cmds .button ("maya button 2" )
22
+ cmds .button ("maya button 3" )
23
+ cmds .setParent ('..' )
24
+ cmds .setParent ('..' )
25
+
26
+ cmds .frameLayout ("Sample Frame 2" , collapsable = True )
27
+ cmds .gridLayout (numberOfColumns = 4 , cellWidthHeight = (48 , 48 ))
28
+ cmds .shelfButton (image1 = "polySphere.png" , rpt = True , c = cmds .polySphere )
29
+ cmds .shelfButton (image1 = "sphere.png" , rpt = True , c = cmds .sphere )
30
+ cmds .setParent ('..' )
31
+ cmds .setParent ('..' )
32
+
33
+ cmds .setParent ('..' ) # columnLayout
34
+
35
+ ptr = OpenMayaUI .MQtUtil .findLayout (layout )
36
+ obj = shiboken .wrapInstance (int (ptr ), QtWidgets .QWidget )
37
+
38
+ return obj
12
39
13
40
14
41
class Content (QtWidgets .QWidget ):
@@ -19,12 +46,14 @@ def __init__(self, parent=None):
19
46
20
47
super (Content , self ).__init__ (parent )
21
48
22
- self .button = QtWidgets .QPushButton ("button" )
49
+ self .button1 = QtWidgets .QPushButton ("button1" )
50
+ self .button2 = QtWidgets .QPushButton ("button2" )
23
51
self .le = QtWidgets .QLineEdit ("lineedit" )
24
52
self .textEdit = QtWidgets .QTextEdit ("text edit" )
25
53
26
54
layout = QtWidgets .QBoxLayout (QtWidgets .QBoxLayout .TopToBottom )
27
- layout .addWidget (self .button )
55
+ layout .addWidget (self .button1 )
56
+ layout .addWidget (self .button2 )
28
57
layout .addWidget (self .le )
29
58
layout .addWidget (self .textEdit )
30
59
@@ -46,8 +75,8 @@ def createUI(self):
46
75
""" Crete widgets """
47
76
48
77
self .tabWidget = QtWidgets .QTabWidget ()
49
- self .tabWidget .addTab (Content (), "Tab1" )
50
- self .tabWidget .addTab (Content (), "Tab2" )
78
+ self .tabWidget .addTab (Content (self ), "Tab1" )
79
+ self .tabWidget .addTab (Content (self ), "Tab2" )
51
80
52
81
def layoutUI (self ):
53
82
""" Layout widgets """
@@ -58,31 +87,26 @@ def layoutUI(self):
58
87
self .setLayout (mainLayout )
59
88
60
89
61
- class MainWindow (QtWidgets .QMainWindow ):
62
- """ Main window """
90
+ class MainWindow (MayaQWidgetDockableMixin , QtWidgets .QMainWindow ):
63
91
64
- def closeExistingWindow (self ):
65
- """ Close window if exists """
66
-
67
- for qt in QtWidgets .QApplication .topLevelWidgets ():
68
- try :
69
- if qt .__class__ .__name__ == self .__class__ .__name__ :
70
- qt .close ()
71
- except :
72
- pass
73
-
74
- def __init__ (self , parent = getMayaWindow ()):
92
+ def __init__ (self , parent = None ):
75
93
""" init """
76
94
77
- self .closeExistingWindow ()
78
95
super (MainWindow , self ).__init__ (parent )
79
96
97
+ self .thisObjectName = "testDockWindow"
98
+ self .WindowTitle = "Sample Dockable Widget"
99
+ self .workspaceControlName = self .thisObjectName + "WorkspaceControl"
100
+
101
+ self .setObjectName (self .thisObjectName )
102
+ self .setWindowTitle (self .WindowTitle )
103
+
80
104
self .setWindowFlags (QtCore .Qt .Window )
81
105
self .setAttribute (QtCore .Qt .WA_DeleteOnClose )
82
106
83
107
# Create and set central widget
84
- cw = CentralWidget ()
85
- self .setCentralWidget (cw )
108
+ self . cw = CentralWidget ()
109
+ self .setCentralWidget (self . cw )
86
110
87
111
self .setupMenu ()
88
112
@@ -92,7 +116,7 @@ def setupMenu(self):
92
116
menu = self .menuBar ()
93
117
94
118
# About
95
- aboutAction = QtWidgets .QAction ("&About" , self )
119
+ aboutAction = QtGui .QAction ("&About" , self )
96
120
aboutAction .setStatusTip ('About this script' )
97
121
aboutAction .triggered .connect (self .showAbout )
98
122
@@ -108,83 +132,27 @@ def showAbout(self):
108
132
'About ' ,
109
133
'Awesome window\n ' )
110
134
111
-
112
- def mainWindow (func ):
113
- """ Decorate main/dock fuctions """
114
-
115
- def __wrapper (* args ):
116
-
117
- """ close window if exist """
118
- global win
135
+ def run (self ):
119
136
try :
120
- win . close ( )
121
- except :
137
+ cmds . deleteUI ( self . workspaceControlName )
138
+ except RuntimeError :
122
139
pass
123
140
124
- # New main window object
125
- win = MainWindow ()
126
- func (win )
127
-
128
- return __wrapper
129
-
130
-
131
- @mainWindow
132
- def main (mainWindow ):
133
- """ Show single window
134
- args
135
- mainWindow : QtWidgets.QMainWindow
136
- return
137
- None
138
- """
139
-
140
- mainWindow .show ()
141
- mainWindow .raise_ ()
142
-
143
-
144
- @mainWindow
145
- def dock (mainWindow ):
146
- """ Show dockable window
147
- args
148
- mainWindow : QtWidgets.QMainWindow
149
- return
150
- None
151
- """
152
-
153
- mainWindow .setObjectName ('sampleWindowObject' )
154
-
155
- DOCK_NAME = "dock_name"
156
-
157
- from pymel import all as pm
158
-
159
- if pm .dockControl (DOCK_NAME , q = True , ex = 1 ):
160
- pm .deleteUI (DOCK_NAME )
161
-
162
- if pm .window ('dummyWindow' , q = True , ex = 1 ):
163
- pm .deleteUI ('dummyWindow' )
164
-
165
- # Create dummy window object to keep the layout
166
- pm .window ('dummyWindow' )
141
+ self .show (dockable = True )
142
+ cmds .workspaceControl (
143
+ self .workspaceControlName ,
144
+ edit = True ,
145
+ dockToControl = ['Outliner' , 'right' ])
146
+ self .raise_ ()
167
147
168
- pm .columnLayout ()
169
- floatingLayout = pm .paneLayout (
170
- configuration = 'single' ,
171
- w = 300 )
172
- pm .setParent ('..' )
148
+ # Maya layout widget is added here to be parented under workspaceControl
149
+ self .cw .tabWidget .addTab (mayaUIContent (self .workspaceControlName ), "MayaLayout" )
173
150
174
- # Create new dock
175
- pm .dockControl (
176
- DOCK_NAME ,
177
- aa = ['right' , 'left' ],
178
- a = 'right' ,
179
- fl = False ,
180
- con = floatingLayout ,
181
- label = "Sample Dock" ,
182
- w = 300 )
183
151
184
- # Parent QMainWindow object to the layout
185
- pm .control ('sampleWindowObject' , e = True , parent = floatingLayout )
152
+ def main ():
153
+ w = MainWindow ()
154
+ w .run ()
186
155
187
156
188
157
if __name__ == "__main__" :
189
- # main()
190
- dock ()
158
+ main ()
0 commit comments