/
animationflipbookui.py
executable file
·308 lines (234 loc) · 7.98 KB
/
animationflipbookui.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
#! /usr/bin/env python
#==============================================================================
#
# Copyright (c) 2012 Eoghan Patrick Cunneen
# All rights reserved.
#
# This file contains confidential and proprietary source code, belonging to
# Eoghan Patrick Cunneen. Its contents may not be disclosed to third parties,
# copied or duplicated in any form, in whole or in part, without prior
# permission.
#
#===============================================================================
""" This is the construction of the UI that the user will use within maya.
...
"""
# Primary module imports:
import logging
# Third party module imports:
try:
import widgets
reload(widgets)
_PYQT_AVAILABLE = True
except ImportError:
_PYQT_AVAILABLE = False
print "No PyQt"
try:
from maya import cmds
except ImportError as e:
logging.info(
'Running outside of Maya mode. Full feature set will '
'not work. Use this for testing front end.\n'
'{0}'.format(e))
# Proprietary module imports:
import animationflipbook
reload(animationflipbook)
def setup_flipbook():
""" Creates the flipbook node if one doesn't exist already.
"""
animationflipbook.setup_animation_flipbook()
def set_framerange(*args):
""" Set the scene's framerange.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
start_frame = cmds.floatFieldGrp("set_framerange_field", query=True, v1=True)
end_frame = cmds.floatFieldGrp("set_framerange_field", query=True, v2=True)
animationflipbook.set_framerange(start_frame, end_frame)
def loop_selected(*args):
""" Loop the selected page.
Loop over the selected pages N times with a gap of M frames
between eack loop. N and M are values taken from the UI.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
num_loops = cmds.floatFieldGrp("set_loop_field", query=True, v1=True)
step = cmds.floatFieldGrp("set_loop_field", query=True, v2=True)
animationflipbook.loop_selection(int(num_loops), int(step))
def select_pencil_tool(*args):
""" Select the pencil tool.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.select_pencil_tool(True)
def deselect_pencil_tool(*args):
""" Deselect the pencil tool.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.select_pencil_tool(False)
def go_to_page(*args):
""" Change the frame to the one specified.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
page_number = cmds.floatFieldGrp("go_to_page_field", v1=True, query=True)
animationflipbook.go_to_page(page_number)
def set_page(*args):
""" Add the selected or none-grouped curves to a new page.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.set_page()
def insert_page(*args):
""" Set the current page.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.add_selection_to_page(duplicate=True)
def delete_page(*args):
""" Delete the current page.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.delete_page()
def save_scene(*args):
""" Set the current page.
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.save_scene()
def playblast_scene(*args):
""" Playblast the current scene.
Playblast the current scene, saving the output in the selected
format and location designated in a JSON configuration file.
:todo: Set up the JSON file to configure playblasts.
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.playblast_scene()
def display_next_page(*args):
""" Display the next available page..
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.display_next_page()
def display_previous_page(*args):
""" Display previous page.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.display_previous_page()
def display_next_pages(*args):
""" Onionskin future pages.
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.display_next_pages()
def display_previous_pages(*args):
""" Onionskin the previous pages
:noindex:
.. note::
This is utilised by the native MEL UI.
"""
animationflipbook.display_previous_pages()
def show_native_ui():
""" This builds the actual native Maya Inteface and displays it.
.. note::
This is utilised by the native MEL UI.
"""
# Set up the flipbook:
setup_flipbook()
# Set the window name:
window_name = "animation_flipbook"
# If it already exists, kill it:
if cmds.window(window_name, exists=True):
cmds.deleteUI(window_name)
if cmds.windowPref(window_name, exists=True):
cmds.windowPref(window_name, remove=True)
# Set up the window and the layout:
cmds.window(window_name, title="Flipbook Animation Tool")
cmds.columnLayout(adjustableColumn=True)
cmds.rowColumnLayout(columnAlign=(1, "left"), nc=1, cw=[(1, 480)])
cmds.floatFieldGrp("set_framerange_field",
numberOfFields=2,
label="Start Frame",
el="End Frame",
pre=1,
v1=1.0,
v2=24.0)
cmds.button(w=10, label="Set Framerange", command=set_framerange)
cmds.text(label="")
# Select/deselect the pencil tool:
cmds.button(w=20, label="Select Pencil Tool", command=select_pencil_tool)
cmds.button(w=20, label="Deselect Pencil Tool", command=deselect_pencil_tool)
cmds.text(label="")
# Set the page:
cmds.button(w=20, label="Set page", command=set_page)
cmds.button(w=20, label="Add to page", command=insert_page)
cmds.button(w=20, label="Delete page", command=delete_page)
cmds.text(label="")
# Go to page:
go_to_page_field = cmds.floatFieldGrp("go_to_page_field",
numberOfFields=1,
columnWidth=(10, 10),
columnAlign2=("left", "left"),
label="Go to frame",
pre=1,
v1=1.0)
cmds.button(w=20, label="Go to page", command=lambda *args: go_to_page(go_to_page_field))
cmds.text(label="")
cmds.button(w=20, label="Display Next Page", command=display_next_page)
cmds.button(w=20, label="Display Previous Page", command=display_previous_page)
cmds.text(label="")
cmds.button(w=20, label="Onion skin future frames", command=display_next_pages)
cmds.button(w=20, label="Onion skin past frames", command=display_previous_pages)
cmds.text(label="")
# Set the framerange:
cmds.floatFieldGrp("set_loop_field",
numberOfFields=2,
w=2,
columnAlign2=("left", "left"),
label="Number of loops",
el="Step",
cw2=(10, 10),
pre=1,
v1=0.0,
v2=0.0)
cmds.button(w=20, label="Loop Selection", command=loop_selected)
cmds.text(label="")
# Playblast:
cmds.button(w=20, label="Playblast", command=playblast_scene)
cmds.text(label="")
# Save:
cmds.button(w=20, label="Save", command=save_scene)
cmds.text(label="")
cmds.setParent("..")
cmds.showWindow(window_name)
def show():
""" Display the PyQt4 UI as the user has QT installed.
:raises: Exception
"""
# Setup the flipbook locator which will hold all of the information:
setup_flipbook()
if _PYQT_AVAILABLE:
try:
global flipbook_dialog
flipbook_dialog = widgets.MayaFlipBookFacade()
flipbook_dialog.show()
except Exception:
show_native_ui()
else:
show_native_ui()
if __name__ == "__main__":
show()