PySide Dialog

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

PySide Dialog

Post by keithsloan52 »

I am trying to use a Dialog to set some options when the user imports or opens a file.

I am following the info here https://www.freecadweb.org/wiki/PySide_ ... r_Examples
More Than 2 Buttons.

When I use it sets the option okay but after selecting a button the Dialog seems to redisplay
and the Combo Panel has switched to Task with a Cancel Okay Dialog

OS: Ubuntu 18.04.3 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.3.
Build type: Release
Python version: 3.6.8
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)

Code: Select all

from PySide import QtGui, QtCore

class importPrompt(QtGui.QDialog):
    def __init__(self, *args):
        super(importPrompt, self).__init__()
        self.initUI()

    def initUI(self):
        importButton = QtGui.QPushButton('Import')
        importButton.clicked.connect(self.onImport)
        scanButton = QtGui.QPushButton('Scan Vol')
        scanButton .clicked.connect(self.onScan)
        #
        buttonBox = QtGui.QDialogButtonBox()
        #buttonBox = Qt.QDialogButtonBox(QtCore.Qt.Vertical)
        buttonBox.addButton(importButton, QtGui.QDialogButtonBox.ActionRole)
        buttonBox.addButton(scanButton, QtGui.QDialogButtonBox.ActionRole)
        #
        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(buttonBox)
        self.setLayout(mainLayout)
        # define window         xLoc,yLoc,xDim,yDim
        self.setGeometry(       650, 650, 0, 50)
        self.setWindowTitle("Choose an Option")
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

    def onImport(self):
        self.retStatus = 1
        self.close()

    def onScan(self):
        self.retStatus = 2
        self.close()

Code: Select all

if prompt :
       dialog = importPrompt()
       dialog.exec_()
       FreeCADGui.Control.showDialog(dialog)
       if dialog.retStatus == 1 :
          print('Import')

keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: PySide Dialog

Post by keithsloan52 »

Okay fixed - Did not need the second ShowDialog
Post Reply