Getting RuntimeError when trying to use confirmDialog

14 views
Skip to first unread message

kiteh

unread,
Jun 13, 2019, 6:37:10 PM6/13/19
to Python Programming for Autodesk Maya
I have 2 files - main.py and utils.py.

In my utils.py, I have created a method:
def prompt_dialog(title, msg):
   res = cmds.confirmDialog(
        title=title,
       message=msg,
       button=['Yes','No'],
       defaultButton='Yes',
       cancelButton='No',
       dismissString='No'
   )
   
return res


In my main.py, there are 2 methods that calls `prompt_dialog` twice but keep getting the error `RuntimeError: Only one confirmDialog may exist at a time.` whenever I did some editing towards my QLineEdit... The other method that uses `prompt_dialog` works fine with no issue.

class MyTool(MayaQWidgetDockableMixin, QtGui.QWidget):
    def __init__(self, parent=None, dockable=True):
        self.connect_signals()
        ...

    def connect_signals(self):
        self.ui.frameLineEdit.editingFinished.connect(self.frameEdited)

    def frameEdited(self):
        # Keeps getting error here
        utils.prompt_dialog("Frame Modified", "You have modified the Frame. Proceed?")

    def importRef(self):
        # No error seen
        if not cmds.objExists("|refGroup"):
            res = utils.prompt_dialog("No Ref. groups found", "Create refGroup for references import?")
            if res == "Yes":
                ...

I tried to replace the `utils.prompt_dialog` with `cmds.confirmDialog` but still, getting the same error.

Could someone shed some light?

Justin Israel

unread,
Jun 13, 2019, 7:07:32 PM6/13/19
to python_in...@googlegroups.com
Do you get this same issue if you use a QMessageBox directly from Qt instead? 
Maya may be doing some internal bookkeeping on the confirmDialog instances, and because you are trigging the modal dialog in a slot callback maybe the bookkeeping hasn't cleaned up the previous confirmDialog reference by the time your slot fires again. I don't think QMessageBox would have that same issue. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dd330d6c-83f0-4b11-ba10-3f4c453be5e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kiteh

unread,
Jun 14, 2019, 8:04:06 PM6/14/19
to Python Programming for Autodesk Maya
Tried with the use of QMessageBox, and it is working fine.
Initially I had thought this would work as I am calling the confirmDialog in frameEditied() (being first) and importRef() would be called on later..

Adding on, I tried to create the same prompt_dialog() in script editor, wrote 2 lines of code, each calling this method with different strings, and was given 2 confirm dialogs and hence the confusion. 
Reply all
Reply to author
Forward
0 new messages