2 Demonstrates the menu manager API.
7 def outputMenuItem(item, recurse=True, indent=''):
9 print indent, text
if text
else "----"
10 if item.HasSubMenu
and recurse:
11 outputMenu(item.SubMenu, recurse, indent +
' ')
14 def outputMenu(menu, recurse=True, indent=''):
16 outputMenuItem(i, recurse, indent)
18 somethingHappened =
False
22 global somethingHappened
23 somethingHappened =
True
24 print 'Something happened'
26 action = MaxPlus.ActionFactory.Create(
27 'Do something',
'Python demos', doSomething)
30 def createTestMenu(name):
33 if action._IsValidWrapper():
34 print "Created action"
36 print "Failed to create action"
40 print 'menu created', menu.Title
42 print 'The menu ', name,
' already exists'
45 def getLastMenuItem(menu=MaxPlus.MenuManager.GetMainMenu()):
46 return list(menu.Items)[-1]
49 def testLastItem(text):
50 assert(getLastMenuItem().Title == text)
54 print "Removing any previously left 'menu items'"
57 print "Creating a new menu"
58 testLastItem(
u"&Help")
61 print "Creating a new menu"
62 createTestMenu(
u"Test")
66 assert(
not somethingHappened)
67 mi = getLastMenuItem()
68 mi = list(mi.SubMenu.Items)[0]
71 assert(somethingHappened)
73 print "Unregistering the 'test' menu"
76 testLastItem(
u"&Help")
78 if __name__ ==
'__main__':