-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHitchAnimationUI.py
369 lines (298 loc) · 13.3 KB
/
HitchAnimationUI.py
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import maya.cmds as cmds
import pymel.core as pm
import maya.OpenMaya as om
import maya.OpenMayaUI as mui
import shiboken as shi
from PySide import QtCore as qc
from PySide import QtGui as qg
from functools import partial
import time
import random
from HitchAnimationModule.Widgets import spliter
from HitchAnimationModule.Widgets import Tabs
from HitchAnimationModule.Widgets import button
from HitchAnimationModule.SubClasses import viewportClass
from HitchAnimationModule.SubClasses import HeadPicker
from HitchAnimationModule.SubClasses import BodyPicker
from HitchAnimationModule.SubClasses import BookMarks
from HitchAnimationModule.SubClasses import ColtMenu
from HitchAnimationModule.SubClasses import DockColt
from HitchAnimationModule.SubClasses import TopPanel
from HitchAnimationModule.SubClasses import LeftPanel
from HitchAnimationModule.LogicData import refreshUI
from HitchAnimationModule.SubClasses import ImportReference
import os
import sys
reload(TopPanel)
reload(viewportClass)
reload(button)
reload(spliter)
reload(HeadPicker)
reload(BodyPicker)
reload(Tabs)
reload(LeftPanel)
#---------------------------------------------------------------------------------#
HITCH_UI = None
windowTitle = "Hitch Animation Manager"
windowObject = "HitchAnimationUI_Object"
STYLESHEET = os.path.join(pm.internalVar(usd=1), 'HitchAnimationModule', 'StyleSheets', 'scheme.txt')
HEADERPIXMAP = os.path.join(pm.internalVar(usd=1), 'HitchAnimationModule', 'Icons', 'hitchNameUIHeaderNoBackground.png')
WINDOWICON = os.path.join(pm.internalVar(usd=1), 'HitchAnimationModule', 'Icons', 'Hitch_FaceForLogo.png')
#---------------------------------------------------------------------------------#
# delete ANY maya child with given object name to mantain clean the memory
#
def deleteFromGlobal():
mayaMainWindowPtr = mui.MQtUtil.mainWindow()
mayaMainWindow = shi.wrapInstance(long(mayaMainWindowPtr), qg.QMainWindow) # Important that it's QMainWindow, and not QWidget
try:
# Go through main window's children to find any previous instances
for obj in mayaMainWindow.children():
# print(obj.objectName())
if isinstance(obj, qg.QMainWindow):
if obj.objectName() == windowObject:
# print obj
# print obj.objectName()
obj.setParent(None)
obj.deleteLater()
del(obj)
print('Object Deleted')
except:
pass
#---------------------------------------------------------------------------------#
def getMayaWindow():
mainWinPtr = mui.MQtUtil.mainWindow()
return shi.wrapInstance(long(mainWinPtr), qg.QWidget)
#---------------------------------------------------------------------------------#
# This is where everything starts
class HitchAnimUI(qg.QMainWindow):
def __init__(self, parent=getMayaWindow()):
super(HitchAnimUI, self).__init__(parent)
self.setAttribute(qc.Qt.WA_DeleteOnClose)
self.extraDialog = ''
self.tabIndex = None
style_sheet_file = STYLESHEET
with open(style_sheet_file, 'r') as styleSheet:
data = str(styleSheet.read())
self.setStyleSheet(data)
self.setObjectName(windowObject)
self.setWindowTitle(windowTitle)
self.setMinimumWidth(1000)
self.setMinimumHeight(500)
self.resize(1650, 1000) # re-size the window
self.setWindowIcon(qg.QIcon(os.path.join('icon', WINDOWICON)))
centralWidget = qg.QWidget()
centralWidget.setObjectName('centralWidget')
mainHhorizontal_lyt = qg.QHBoxLayout()
mainHhorizontal_lyt.setContentsMargins(5, 5, 5, 5)
mainHhorizontal_lyt.setSpacing(0)
centralWidget.setLayout(mainHhorizontal_lyt)
mainHhorizontal_lyt.setObjectName('mainHhorizontal_lyt')
central_layout = qg.QVBoxLayout()
central_layout.setContentsMargins(0, 0, 0, 0)
central_layout.setObjectName('central_layout')
self._importDialog_open = False
####################
# QGraphics Escene
#
self.graphics_scene = qg.QGraphicsScene()
self.graphics_view = qg.QGraphicsView()
self.graphics_view.cacheMode()
self.graphics_view.setCacheMode(qg.QGraphicsItem. DeviceCoordinateCache)
self.graphics_view.setOptimizationFlags(qg.QGraphicsView.DontSavePainterState)
self.graphics_view.setScene(self.graphics_scene)
self.graphics_view.setHorizontalScrollBarPolicy(qc.Qt.ScrollBarAlwaysOff)
self.graphics_view.setVerticalScrollBarPolicy(qc.Qt.ScrollBarAlwaysOff)
self.graphics_view.setFocusPolicy(qc.Qt.NoFocus)
self.graphics_view.setStyleSheet("QGraphicsView {border-style: none;}")
self.graphics_view.setSizePolicy(qg.QSizePolicy.Minimum, qg.QSizePolicy.Minimum)
self.setCentralWidget(self.graphics_view)
self.graphics_view.setLayout(mainHhorizontal_lyt)
###########################################
# Left Menu Panel
#
leftPanel = LeftPanel.LeftPanel()
mainHhorizontal_lyt.addWidget(leftPanel)
mainHhorizontal_lyt.addLayout(central_layout)
###########################################
# Menu Bar and action gestion ..
#
menuBar = qg.QMenuBar()
File_menu = ColtMenu.ColtMenu('File')
Colt_menu = ColtMenu.ColtMenu('About Me')
menuBar.addMenu(File_menu)
menuBar.addMenu(Colt_menu)
referenceAction = qg.QAction('Import Reference', self)
refreshAction = qg.QAction('Refresh UI', self)
closeAction = qg.QAction('Exit', self)
ExportAnimAction = qg.QAction('Export Animation', self)
AboutMeAction = qg.QAction('About NestorColt', self)
File_menu.addAction(referenceAction)
File_menu.addAction(refreshAction)
File_menu.addAction(closeAction)
Colt_menu.addAction(AboutMeAction)
menuBar.addSeparator()
self.setMenuBar(menuBar)
# connect Accions from menu bar
#
# referenceAction.triggered.connect(self.importReferenceRig)
closeAction.triggered.connect(self.close)
refreshAction.triggered.connect(self.refreshScene)
referenceAction.triggered.connect(self.importReferenceUI)
AboutMeAction.triggered.connect(lambda: AboutMeDialog(parent=self))
############################
# widget for dockWidget
#
self.insideDock_wgt = qg.QWidget()
self.insideDock_wgt_lyt = qg.QVBoxLayout(self.insideDock_wgt)
self.dockTab_dgt = Tabs.ColtTab()
self.dockTab_dgt.setObjectName('DockTabWidget')
self.restore_btn = button.CustomButton(' Restore ')
self.insideDock_wgt_lyt.addWidget(self.restore_btn)
self.insideDock_wgt_lyt.addWidget(self.dockTab_dgt)
self.insideDock_wgt_lyt.setSpacing(10)
self.insideDock_wgt_lyt.setContentsMargins(0, 0, 0, 0)
self.restore_btn.setEnabled(False)
############################
# Q Dock Widgets
#
self.dock = DockColt.DockColt('Dock Area', self)
self.addDockWidget(qc.Qt.RightDockWidgetArea, self.dock)
self.dock.setWidget(self.insideDock_wgt)
#############################
# Animation of layouts
#
###########################################
# Top Menu Panel
#
topPanel = TopPanel.TopPanel()
central_layout.addWidget(topPanel)
central_layout.addSpacing(5)
######################
# tab container
#
self.tabWidget = Tabs.ColtTab()
self.tabWidget.setObjectName('self.tabWidget')
self.tab_layout = qg.QVBoxLayout(self.tabWidget)
self.tab_layout.setObjectName('tab_layout')
central_layout.addWidget(self.tabWidget)
#######################
# ViewportTab
#
self.viewport_tab = viewportClass.ViewportTab()
self.tabWidget.addTab(self.viewport_tab, '- 1 Viewport ')
#######################
# Face picker Tab
#
self.facePicker = HeadPicker.HeadPicker()
self.tabWidget.addTab(self.facePicker, '- 2 FacePicker ')
#######################
# Body Picker Tab
#
self.bodyPicker = BodyPicker.BodyPicker()
self.tabWidget.addTab(self.bodyPicker, '- 3 BodyPicker ')
#######################
# BookMarks Tab
#
self.bookMarks = BookMarks.BookMarks()
self.tabWidget.addTab(self.bookMarks, '- 4 Bookmarks ')
#---------------------------------------------------------------------------------#
# connect widgets slots
self.dockTab_dgt.currentChanged.connect(self.activateButtons)
self.restore_btn.clicked.connect(self.restore_tabsFunction)
self.tabWidget.currentChanged.connect(self.fix_some_focuses)
###########################
# Callback fron escene
#
self._callBackID = om.MEventMessage.addEventCallback('SceneOpened', self.re_openScene)
delCallBack = partial(om.MMessage.removeCallback, self._callBackID)
self.destroyed.connect(delCallBack)
#----------------------------------------------------------------------------------#
def fix_some_focuses(self):
self.bodyPicker.clear_focus()
self.facePicker.clear_focus()
def importReferenceUI(self):
if not self._importDialog_open:
self._importDialog_open = True
UI = ImportReference.ImportReferenceWindow(parent=self)
UI.show()
def re_openScene(self, *args, **kwargs):
widgetPort = self.findChildren(qg.QWidget, 'ViewportClass')[0]
widgetPort.re_create_panel()
self.refreshScene()
def refreshScene(self):
refreshUI.refresh()
def activateButtons(self):
count = self.dockTab_dgt.count()
if count > 0:
self.restore_btn.setEnabled(True)
else:
self.restore_btn.setEnabled(False)
def restore_tabsFunction(self):
count = self.dockTab_dgt.count()
tabs = []
for idx in range(count):
obj = [lt for lt in self.dockTab_dgt.tabText(idx) if lt.isdigit()]
num = int(obj[0])
tabs.append([num, self.dockTab_dgt.widget(idx), self.dockTab_dgt.tabText(idx)])
def getKey(item):
return item[0]
for tab in sorted(tabs, key=getKey):
self.tabWidget.insertTab(tab[0] - 1, tab[1], tab[2])
#---------------------------------------------------------------------------------------------------------------------------------------#
def showEvent(self, event):
super(HitchAnimUI, self).showEvent(event)
# maya can lag in how it repaints UI. Force it to repaint
# when we show the window.
self.viewport_tab.Viewport_maya.repaint()
def closeEvent(self, event):
super(HitchAnimUI, self).closeEvent(event)
deleteFromGlobal()
#---------------------------------------------------------------------------------#
class AboutMeDialog(qg.QDialog):
leftClick = False
def __init__(self, parent):
super(AboutMeDialog, self).__init__(parent)
self.setLayout(qg.QStackedLayout(self))
self.layout().setContentsMargins(0, 0, 0, 0)
self.setFixedWidth(800)
self.setFixedHeight(440)
self.setStyleSheet("background-color: rgba(1,1,1,200);")
self.setAttribute(qc.Qt.WA_DeleteOnClose)
self.setModal(True)
route = os.path.join(pm.internalVar(usd=1), 'HitchAnimationModule', 'Icons', 'Hitch_UI_aboutMe.jpg')
pixmap = qg.QPixmap(route)
scaled = pixmap.scaled(self.width(), self.height(), qc.Qt.KeepAspectRatio, qc.Qt.SmoothTransformation)
self.frame = qg.QLabel()
self.frame.setPixmap(scaled)
self.frame.setSizePolicy(qg.QSizePolicy.Expanding, qg.QSizePolicy.Expanding)
self.layout().addWidget(self.frame)
frame_lyt = qg.QVBoxLayout(self.frame)
frame_lyt.setContentsMargins(0, 0, 0, 0)
self.layout().setStackingMode(qg.QStackedLayout.StackAll)
self.close_btn = button.CloseButton()
self.close_btn.setParent(self)
self.close_btn.clicked.connect(lambda: self.close())
self.show()
def resizeEvent(self, event):
self.close_btn.move(self.width() - 30, self.y() - 288)
pixmap = qg.QPixmap(self.size())
pixmap.fill(qc.Qt.transparent)
painter = qg.QPainter(pixmap)
painter.setBrush(qc.Qt.black)
painter.drawRoundedRect(pixmap.rect(), 12, 12)
painter.end()
self.setMask(pixmap.mask())
def closeEvent(self, event):
self.deleteLater()
del (self)
#---------------------------------------------------------------------------------#
def run():
deleteFromGlobal()
global HITCH_UI
if HITCH_UI is None:
HITCH_UI = HitchAnimUI()
HITCH_UI.show()
#---------------------------------------------------------------------------------#
if __name__ == '__main__':
run()
print ('UI Created...')