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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
from ThirdParty.Qt import QtGui, QtCore, QtWidgets
from functools import partial
import maya.cmds as cmds
import os
import System.utils as utils
class ART_PinModules():
def __init__(self, mainUI):
#get the directory path of the tools
settings = QtCore.QSettings("Epic Games", "ARTv2")
self.toolsPath = settings.value("toolsPath")
self.iconsPath = settings.value("iconPath")
self.mainUI = mainUI
#build the UI
self.buildUI()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def buildUI(self):
if cmds.window("ART_PinModulesWin", exists = True):
cmds.deleteUI("ART_PinModulesWin", wnd = True)
#launch a UI to get the name information
self.window = QtWidgets.QMainWindow(self.mainUI)
#load stylesheet
styleSheetFile = utils.returnNicePath(self.toolsPath, "Core/Scripts/Interfaces/StyleSheets/mainScheme.qss")
f = open(styleSheetFile, "r")
self.style = f.read()
f.close()
self.window.setStyleSheet(self.style)
#size policies
mainSizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
#create the main widget
self.mainWidget = QtWidgets.QWidget()
self.window.setCentralWidget(self.mainWidget)
#set qt object name
self.window.setObjectName("ART_PinModulesWin")
self.window.setWindowTitle("Pin Modules")
#create the mainLayout for the rig creator UI
self.mainLayout = QtWidgets.QVBoxLayout(self.mainWidget)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.window.resize(400, 250)
self.window.setSizePolicy(mainSizePolicy)
self.window.setMinimumSize(QtCore.QSize( 400, 250 ))
self.window.setMaximumSize(QtCore.QSize( 400, 250 ))
#create the background image
self.frame = QtWidgets.QFrame()
self.mainLayout.addWidget(self.frame)
#create the layout for the widgets
self.widgetLayout = QtWidgets.QHBoxLayout(self.frame)
self.widgetLayout.setContentsMargins(5, 5, 5, 5)
#left side == list of modules in scene. for each item in list, will do something similar to aim mode, where we will toggle an icon for pin state
self.moduleList = QtWidgets.QListWidget()
self.widgetLayout.addWidget(self.moduleList)
self.moduleList.setMinimumSize(QtCore.QSize( 265, 200 ))
self.moduleList.setMaximumSize(QtCore.QSize( 265, 200 ))
self.moduleList.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.moduleList.setSpacing(3)
#right side layout == select all, clear selection, Pin Selected buttons
self.buttonLayout = QtWidgets.QVBoxLayout()
self.widgetLayout.addLayout(self.buttonLayout)
self.buttonLayout.setContentsMargins(5, 20, 5, 20)
#add the selection buttons
self.selectAllButton = QtWidgets.QPushButton("Select All")
self.selectAllButton.setMinimumSize(QtCore.QSize( 115, 25 ))
self.selectAllButton.setMaximumSize(QtCore.QSize( 115, 25 ))
self.buttonLayout.addWidget(self.selectAllButton)
self.selectAllButton.clicked.connect(self.moduleList.selectAll)
self.selectAllButton.setObjectName("blueButton")
self.selectNoneButton = QtWidgets.QPushButton("Clear Selection")
self.selectNoneButton.setMinimumSize(QtCore.QSize( 115, 25 ))
self.selectNoneButton.setMaximumSize(QtCore.QSize( 115, 25 ))
self.buttonLayout.addWidget(self.selectNoneButton)
self.selectNoneButton.clicked.connect(self.moduleList.clearSelection)
self.selectNoneButton.setObjectName("blueButton")
#spacer
spacerItem = QtWidgets.QSpacerItem(20, 80, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.buttonLayout.addItem(spacerItem)
#add the buttons for reset settings and reset transforms
self.pinBtn = QtWidgets.QPushButton("Pin Selected")
self.pinBtn.setMinimumSize(QtCore.QSize( 115, 25 ))
self.pinBtn.setMaximumSize(QtCore.QSize( 115, 25 ))
self.buttonLayout.addWidget(self.pinBtn)
self.pinBtn.setToolTip("Pin the selected modules so that parent module movements do not effect the pinned module")
self.pinBtn.clicked.connect(partial(self.toggleLock, True))
self.pinBtn.setObjectName("blueButton")
self.unpinBtn = QtWidgets.QPushButton("Unpin Selected")
self.unpinBtn.setMinimumSize(QtCore.QSize( 115, 25 ))
self.unpinBtn.setMaximumSize(QtCore.QSize( 115, 25 ))
self.buttonLayout.addWidget(self.unpinBtn)
self.unpinBtn.setToolTip("Unpin modules to resume normal module behavior")
self.unpinBtn.clicked.connect(partial(self.toggleLock, False))
self.unpinBtn.setObjectName("blueButton")
#populate the list widget
modules = utils.returnRigModules()
for module in modules:
#get module name
moduleName = cmds.getAttr(module + ".moduleName")
#font
headerFont = QtGui.QFont()
headerFont.setPointSize(10)
headerFont.setBold(True)
#create the listWidgetItem
icon = QtGui.QIcon(os.path.join(self.iconsPath, "System/locked.png"))
iconOff = QtGui.QIcon(os.path.join(self.iconsPath, "System/unlocked.png"))
item = QtWidgets.QListWidgetItem(iconOff, " " + moduleName)
item.setFont(headerFont)
item.setData(QtCore.Qt.UserRole, [icon, iconOff])
pinState = cmds.getAttr(module + ".pinned")
if pinState:
item.setIcon(icon)
self.moduleList.addItem(item)
#show the window
self.window.show()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def toggleLock(self, state):
selected = self.moduleList.selectedItems()
items = []
for each in selected:
items.append(each.text())
if state:
each.setIcon(each.data(QtCore.Qt.UserRole)[0])
for inst in self.mainUI.moduleInstances:
name = inst.name
if each.text().strip() == name:
networkNode = inst.returnNetworkNode
cmds.setAttr(networkNode + ".pinned", lock = False)
cmds.setAttr(networkNode + ".pinned", True, lock = True)
inst.pinModule(True)
if not state:
each.setIcon(each.data(QtCore.Qt.UserRole)[1])
for inst in self.mainUI.moduleInstances:
name = inst.name
if each.text().strip() == name:
networkNode = inst.returnNetworkNode
cmds.setAttr(networkNode + ".pinned", lock = False)
cmds.setAttr(networkNode + ".pinned", False, lock = True)
inst.pinModule(False)
#clear selection
self.moduleList.clearSelection()
|