-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsampleWindow.py
More file actions
158 lines (110 loc) · 4.22 KB
/
sampleWindow.py
File metadata and controls
158 lines (110 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
from maya import OpenMayaUI
from maya import cmds
try:
from PySide6 import QtCore, QtWidgets, QtGui
import shiboken6 as shiboken
except ImportError:
from PySide2 import QtCore, QtWidgets
import shiboken2 as shiboken
def mayaUIContent(parent):
""" Contents by Maya standard UI widgets """
layout = cmds.columnLayout(adjustableColumn=True, parent=parent)
cmds.frameLayout("Sample Frame 1", collapsable=True)
cmds.columnLayout(adjustableColumn=True, rowSpacing=2)
cmds.button("maya button 1")
cmds.button("maya button 2")
cmds.button("maya button 3")
cmds.setParent('..')
cmds.setParent('..')
cmds.frameLayout("Sample Frame 2", collapsable=True)
cmds.gridLayout(numberOfColumns=4, cellWidthHeight=(48, 48))
cmds.shelfButton(image1="polySphere.png", rpt=True, c=cmds.polySphere)
cmds.shelfButton(image1="sphere.png", rpt=True, c=cmds.sphere)
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..') # columnLayout
ptr = OpenMayaUI.MQtUtil.findLayout(layout)
obj = shiboken.wrapInstance(int(ptr), QtWidgets.QWidget)
return obj
class Content(QtWidgets.QWidget):
""" Contents widget for tabs """
def __init__(self, parent=None):
""" Init """
super(Content, self).__init__(parent)
self.button1 = QtWidgets.QPushButton("button1")
self.button2 = QtWidgets.QPushButton("button2")
self.le = QtWidgets.QLineEdit("lineedit")
self.textEdit = QtWidgets.QTextEdit("text edit")
layout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.TopToBottom)
layout.addWidget(self.button1)
layout.addWidget(self.button2)
layout.addWidget(self.le)
layout.addWidget(self.textEdit)
self.setLayout(layout)
class CentralWidget(QtWidgets.QWidget):
""" Central widget """
def __init__(self, parent=None):
""" Init """
super(CentralWidget, self).__init__(parent)
self.createUI()
self.layoutUI()
def createUI(self):
""" Crete widgets """
self.tabWidget = QtWidgets.QTabWidget()
self.tabWidget.addTab(Content(self), "Tab1")
self.tabWidget.addTab(Content(self), "Tab2")
def layoutUI(self):
""" Layout widgets """
mainLayout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.TopToBottom)
mainLayout.addWidget(self.tabWidget)
self.setLayout(mainLayout)
class MainWindow(MayaQWidgetDockableMixin, QtWidgets.QMainWindow):
def __init__(self, parent=None):
""" init """
super(MainWindow, self).__init__(parent)
self.thisObjectName = "testDockWindow"
self.WindowTitle = "Sample Dockable Widget"
self.workspaceControlName = self.thisObjectName + "WorkspaceControl"
self.setObjectName(self.thisObjectName)
self.setWindowTitle(self.WindowTitle)
self.setWindowFlags(QtCore.Qt.Window)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
# Create and set central widget
self.cw = CentralWidget()
self.setCentralWidget(self.cw)
self.setupMenu()
def setupMenu(self):
""" Setup menu """
menu = self.menuBar()
# About
aboutAction = QtGui.QAction("&About", self)
aboutAction.setStatusTip('About this script')
aboutAction.triggered.connect(self.showAbout)
menu.addAction("File")
help_menu = menu.addMenu("&Help")
help_menu.addAction(aboutAction)
def showAbout(self):
""" about message """
QtWidgets.QMessageBox.about(
self,
'About ',
'Awesome window\n')
def run(self):
try:
cmds.deleteUI(self.workspaceControlName)
except RuntimeError:
pass
self.show(dockable=True)
cmds.workspaceControl(
self.workspaceControlName,
edit=True,
dockToControl=['Outliner', 'right'])
self.raise_()
# Maya layout widget is added here to be parented under workspaceControl
self.cw.tabWidget.addTab(mayaUIContent(self.workspaceControlName), "MayaLayout")
def main():
w = MainWindow()
w.run()
if __name__ == "__main__":
main()