How can i show an item selected by a user in a new window(MsgBox)

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
CMT
Posts: 16
Joined: Thu Jan 24, 2019 7:00 pm

How can i show an item selected by a user in a new window(MsgBox)

Post by CMT »

The objectif is to show an item selected by a user in a new window(MsgBox)
For example in this script :

Code: Select all

from PySide import QtGui, QtCore
# UI Class definitions
class ExampleModalGuiClass(QtGui.QDialog):
	""""""
	def __init__(self):
		super(ExampleModalGuiClass, self).__init__()
		self.initUI()
	def initUI(self):
		self.result = userCancelled
		# create our window
		# define window		xLoc,yLoc,xDim,yDim
		self.setGeometry(	250, 250, 400, 350)
		self.setWindowTitle("Our Example Modal Program Window")
		self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
		# set up lists for pop-ups
		self.popupItems1 = ("pizza","apples","candy","cake","potatoes")
		# set up pop-up menu
		self.popup1 = QtGui.QComboBox(self)
		self.popup1.addItems(self.popupItems1)
		self.popup1.setCurrentIndex(self.popupItems1.index("cake"))
		self.popup1.activated[str].connect(self.onPopup1)
		self.popup1.move(210, 115)
		# cancel button
		cancelButton = QtGui.QPushButton('Cancel', self)
		cancelButton.clicked.connect(self.onCancel)
		cancelButton.setAutoDefault(True)
		cancelButton.move(150, 280)
		# OK button
		okButton = QtGui.QPushButton('OK', self)
		okButton.clicked.connect(self.onOk)
		okButton.move(260, 280)
		# now make the window visible
		self.show()
		#

	def onPopup1(self, selectedText):
		if self.label3.text().isspace():
			self.label3.setText(selectedText)
		else:
			self.label3.setText(self.label3.text()+","+selectedText)
	def onCancel(self):
		self.result			= userCancelled
		self.close()
	def onOk(self,text):
		self.result			= userOK
		reply = QtGui.QMessageBox.information(None,"","")
		



# Constant definitions
userCancelled		= "Cancelled"
userOK			= "OK"

# code ***********************************************************************************

form = ExampleModalGuiClass()
form.exec_()
How can i get the item selected by a user and show it in MsgBox
Post Reply