-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtriggeredUI.py
93 lines (65 loc) · 2.68 KB
/
triggeredUI.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
from triggered import *
import spaceSwitching
def removeDupes( iterable ):
unique = set()
newIterable = iterable.__class__()
for item in iterable:
if item not in unique:
newIterable.append( item )
unique.add( item )
return newIterable
def buildMenuItems( parent, obj ):
'''
build the menuItems in the dagProcMenu - it is possible to set a "kill menu" attribute
on an object now that will stop the dagMenu building after the objMenu items have been
added
'''
defaultCmdName = "<empty cmd>"
menusFromConnects = False
killState = False
objs = [ obj ] + (listRelatives( obj, pa=True, s=True ) or [])
#the showMenusFromConnects attribute determines whether the object in question should show right click menus from any items connected to this one via triggered connects
if objExists( '%s.showMenusFromConnects' % obj ):
menusFromConnects = getAttr( '%s.showMenusFromConnects' % obj )
if menusFromConnects:
connects = Trigger( obj ).connects()
for connectObj, connectIdx in connects:
objs.append( connectObj )
objs = removeDupes( objs )
#now get a list of objs that have menus - if there are more than one, build section labels, otherwise skip labels
objsWithMenus = []
for obj in objs:
obj = Trigger( obj )
if obj.menus():
objsWithMenus.append( obj )
doLabels = len( objsWithMenus ) > 1
setParent( parent, m=True )
for obj in objsWithMenus:
#if ANY of the objs have the kill state set, turn it on
if getKillState( obj ):
killState = True
tgts, names = spaceSwitching.getSpaceTargetsNames( obj )
names = [ 'parent to %s' % name for name in names ]
if objExists( '%s.parent' % obj ):
curIdx = getAttr( '%s.parent' % obj )
else: curIdx = None
if doLabels:
menuItem( l='---%s Menus---' % str( obj ).split( '|' )[-1].split( ':' )[-1], en=False )
for idx, cmdName, cmdStr in obj.menus( True ):
#we need to construct the menu item using mel - because the tool was originally mel and all existing obj menu commands are written in mel
#so you have to construct the menu item in mel otherwise its assumed the command is python...
menuCmdToks = [ 'menuItem -l "%s"' % (cmdName or defaultCmdName) ]
#so if the menu name starts with "parent to " then it assumed to be a menu item built by zooSpaceSwitching
if cmdStr.startswith( "^parent to " ):
if curIdx is not None:
if idx == curIdx:
menuCmdToks( '-cb 1' )
if cmdStr:
menuCmdToks.append( '-c "%s"' % encodeString(cmdStr) )
mel.eval( ' '.join( menuCmdToks ) )
#should we die after menu build?
if not killState:
menuItem( d=True )
menuItem( d=True )
return killState
#end