System.gui.messageBox and System.gui.confirm issue

When I added System.gui.messageBox to my code it continues to pop up even if you try to close it out. Like it is in a loop. Also wondring how to get the confirmation from System.gui.Confirm to complete the code.

this is what I have. I have both commented out right now.

#get data from dataset
data = event.source.parent.getComponent('Power Table').data

for row in range(data.getRowCount()):
	# Loops though each row and if at least one of the column contains a blank cell, the row will be skipped.
	skipRowFlag = 0
	for col in range(data.getColumnCount()):
		if data.getValueAt(row, col) == "":
			skipRowFlag = 1
	# Insert the row into the database if the every column in that row was good
	#system.gui.confirm("Are you sure?")
	if not skipRowFlag:
		query = "INSERT INTO IngStackAnalysis(StackNbr,ProblemArea, Occurrence, PercentOfTotal, DateTm) VALUES(1,?,?,?,?)"
		args = [data.getValueAt(row, 0), data.getValueAt(row, 1), data.getValueAt(row, 2),]
		system.db.runPrepUpdate(query, args)
    	#system.gui.messageBox("Data Inserted")

event is a mouse click

Your code is completely unreadable. Please add triple-back-quotes on lines by themselves before and after the code so it’ll format neatly. Just edit in place – don’t re-post.

Also, what event is this code activated by?

I tried the quotes, not sure if that worked.

No, you need three of the single reverse quotes, twice, above and below the code block. On US keyboards, to the left of the ‘1’.

See this documentation:

I got it where it is readable now

How many times do your message boxes pop up? It looks from your code that it would be one of each for each row in your table. Try placing them inside the inner if block.

Or consider simply disabling the button until the operator does something in the UI to confirm (clicks a first button), avoiding the need for the “Are you sure?” prompt entirely. Then your code doesn’t need to worry about jumpy operators.

24 times after adding it to the inner if. If I do the extra button, then how do I get the message box for insert to happen once since the code loops through the rolls which I need it to do.

Keep that message box in your code, then. Just don’t indent it so it’s not part of the loop. Set a counter variable to zero at the beginning of the script and increment it inside the inner if block. Then your message can display how many rows were processed.

It seems you are struggling with basic python structure. Consider going through the python tutorial. Just note that the linked tutorial is for python 2.7 where Ignition’s jython is (currently) v2.5.

yes, I am new to Python scripting. I wiill read through this tutorial to see if that gets me a better understanding of it. I can’t seem to get the gui boxs to work so I went at it a different way. I can start a new topic if needed. I added a button before the submit button, when pushed it inserts the data and makes a Label popup based of a tag status = to 1. How do you delay the tag write to 0 say after 5 seconds?

See examples here for system.gui.confirm (it needs to be placed as the condition in an if statement):

system.util.invokeLater allows running a defined function (see example in link below) after a specified delay:

1 Like