Skip to content

Commit

Permalink
added check if menu already exists and return if so
Browse files Browse the repository at this point in the history
  • Loading branch information
aardschok committed Sep 4, 2017
1 parent 605fa9a commit 0f527ce
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions python/scriptsmenu/launchformaya.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import maya.cmds as cmds
import maya.mel as mel

Expand Down Expand Up @@ -72,13 +74,17 @@ def _find_scripts_menu(title, parent):
Check if the menu exists with the given title in the parent
:param title: the title name of the scripts menu
:param parent: QtWidgets.QMenuBar
:type title: str
:param parent: the menubar to check
:type parent: QtWidgets.QMenuBar
:return: QtWidgets.QMenu or None
"""

menu = [i for i in parent.children() if isinstance(i, QtWidgets.QMenu)
and _check_title(i) == title]
menu = [i for i in parent.children() if
isinstance(i, scriptsmenu.ScriptsMenu)
and i.title() == title]

assert len(menu) < 2, "Multiple instances of {} in menu bar".format(title)
if len(menu) == 1:
Expand All @@ -88,6 +94,16 @@ def _find_scripts_menu(title, parent):


def main(title="Scripts", parent=None):
"""Build the main scripts menu in Maya
:param title: name of the menu in the application
:type title: str
:param parent: the parent object for the menu
:type parent: QtWidgets.QtMenuBar
:return: scriptsmenu.ScriptsMenu instance
"""

mayamainbar = parent or _maya_main_menubar()
try:
Expand Down

0 comments on commit 0f527ce

Please sign in to comment.