set_menu.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # coding:utf-8
  2. #!/usr/bin/python
  3. #
  4. # Copyright (c) Contributors to the Open 3D Engine Project.
  5. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. #
  10. # -- This line is 75 characters -------------------------------------------
  11. """
  12. Module Documentation:
  13. DccScriptingInterface:: SDK//maya//scripts//set_menu.py
  14. This module creates and manages a DCCsi mainmenu
  15. """
  16. # -------------------------------------------------------------------------
  17. # -- Standard Python modules
  18. # none
  19. # -- External Python modules
  20. # none
  21. # -- DCCsi Extension Modules
  22. import azpy
  23. from constants import OBJ_DCCSI_MAINMENU
  24. from constants import TAG_DCCSI_MAINMENU
  25. # -- maya imports
  26. import pymel.core as pm
  27. # -------------------------------------------------------------------------
  28. # -------------------------------------------------------------------------
  29. from azpy.env_bool import env_bool
  30. from azpy.constants import ENVAR_DCCSI_GDEBUG
  31. from azpy.constants import ENVAR_DCCSI_DEV_MODE
  32. # global space
  33. _DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
  34. _DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
  35. _MODULENAME = r'DCCsi.SDK.Maya.Scripts.set_menu'
  36. _LOGGER = azpy.initialize_logger(_MODULENAME, default_log_level=int(20))
  37. _LOGGER.debug('Invoking:: {0}.'.format({_MODULENAME}))
  38. # -------------------------------------------------------------------------
  39. # -------------------------------------------------------------------------
  40. def menu_cmd_test():
  41. _LOGGER.info('test_func(), is TESTING main menu')
  42. return
  43. # -------------------------------------------------------------------------
  44. # -------------------------------------------------------------------------
  45. def set_main_menu(obj_name=OBJ_DCCSI_MAINMENU, label=TAG_DCCSI_MAINMENU):
  46. _main_window = pm.language.melGlobals['gMainWindow']
  47. _menu_obj = obj_name
  48. _menu_label = label
  49. # check if it already exists and remove (so we don't duplicate)
  50. if pm.menu(_menu_obj, label=_menu_label, exists=True, parent=_main_window):
  51. pm.deleteUI(pm.menu(_menu_obj, e=True, deleteAllItems=True))
  52. # create the main menu object
  53. _custom_tools_menu = pm.menu(_menu_obj,
  54. label=_menu_label,
  55. parent=_main_window,
  56. tearOff=True)
  57. # make a dummpy sub-menu
  58. pm.menuItem(label='Menu Item Stub',
  59. subMenu=True,
  60. parent=_custom_tools_menu,
  61. tearOff=True)
  62. # make a dummy menu item to test
  63. pm.menuItem(label='Test', command=pm.Callback(menu_cmd_test))
  64. return _custom_tools_menu
  65. # ==========================================================================
  66. # Run as LICENSE
  67. #==========================================================================
  68. if __name__ == '__main__':
  69. _custom_menu = set_main_menu()