I have a column in a table called “value”, this can be edited. The edit is done via-scripting on the .cellEdited event handler. All works well.
Now I have added min/max checks to ensure the new value does not exceed these limits. The checks work as expected.
However, if the check fails, the “new” entered value is displayed on the table, as if it wrote to the table, but it really didn’t.
Example:
Current value = 60
Min = 0
Max = 100
New value = 101
Result: Error message appears indicating value exceeds limits.
Cell value = 101 (but it didn’t really write 101 back to my database)
Here is the section of code in question:
if columnName =="Value":
primaryKeyValue = event.source.data.getValueAt(event.row, "No.")
minValue = event.source.data.getValueAt(event.row,"Min")
maxValue = event.source.data.getValueAt(event.row,"Max")
#Check limits
message = "New Value: %s Exceeds Limits, please enter a value between %s and %s" %(event.newValue,minValue,maxValue)
if float(event.newValue) >= minValue:
if float(event.newValue) <= maxValue:
# Check if this is an integer value change or real value change
# Selection parameters are integer values, IsSelection = True indicates integer value
if event.source.IsSelection == 0:
query = "UPDATE viwRecipeEditor SET fltParamValue =? WHERE intPLC=? AND intProg=? AND intParamNumber=?"
else:
query = "UPDATE viwRecipeEditor SET intParamValue =? WHERE intPLC=? AND intProg=? AND intParamNumber=?"
system.db.runPrepUpdate(query, [event.newValue,event.source.data.getValueAt(event.row, "PLC") , event.source.data.getValueAt(event.row, "Prog"), primaryKeyValue],'GEADB')
else:
system.gui.errorBox(message)
else:
system.gui.errorBox(message)
Seems like the table is showing the .newValue attribute on the table. What is the best way to “reset” this? Upon the error I tried to do event.newValue = event.oldValue but that failed because it is a ‘read-only’ attribute’.