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
break
# 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.date.now()]
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):
https://docs.inductiveautomation.com/display/DOC79/system.gui.confirm
system.util.invokeLater allows running a defined function (see example in link below) after a specified delay:
https://docs.inductiveautomation.com/display/DOC79/system.util.invokeLater