Opening a new dialog when clicking accept

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
mathia
Posts: 10
Joined: Sun Oct 08, 2017 8:05 pm

Opening a new dialog when clicking accept

Post by mathia »

Hi,

I have task that requires the user to make multiple choices. The first dialog (in the task menu) pops up and gives the user a drop down menu, the user clicks accept, and then the user should be taken to the next dialog. A minimal example would be:

Code: Select all

class PanelA:
    def accept(self):
        pb = PanelB()
        FreeCADGui.Control.closeDialog()
        FreeCADGui.Control.showDialog(pb)


class PanelB:
    def accept(self):
        FreeCADGui.Control.closeDialog()
then calling

Code: Select all

Gui.Control.showDialog(PanelA())
and clicking accept. This used to work in FreeCAD 0.16 and would show me panel b, but after this fix: https://github.com/FreeCAD/FreeCAD/comm ... ef62caf236 to postpone deletion of the dialog, this is no longer possible.

Does anyone have any suggestions for how I can get this behavior again?
wmayer
Founder
Posts: 20317
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Opening a new dialog when clicking accept

Post by wmayer »

The trick is to also delay the execution of the 2nd task panel.

Code: Select all

from PySide import QtCore

class PanelA:
    def accept(self):
        FreeCADGui.Control.closeDialog()
        QtCore.QTimer.singleShot(0, lambda: FreeCADGui.Control.showDialog(PanelB()))


class PanelB:
    def accept(self):
        FreeCADGui.Control.closeDialog()


Gui.Control.showDialog(PanelA())
mathia
Posts: 10
Joined: Sun Oct 08, 2017 8:05 pm

Re: Opening a new dialog when clicking accept

Post by mathia »

That worked perfectly!
Thanks! I've never seen that function before.
Post Reply