Thanks for your help. I just tried your tip, but the window is still popping up twice and I’m getting an error with it, perhaps I’m doing it wrong, I’ve never experimented with custom functions. Here is what I have in “onCellEdited”:
def onCellEdited(self, rowIndex, colIndex, colName, oldValue, newValue):
"""
Called when the user has edited a cell in the table. It is up to the
implementation of this function to alter the underlying data that drives
the table. This might mean altering the dataset directly, or running a SQL
UPDATE query to update data in a database.
Arguments:
self: A reference to the component that is invoking this function.
rowIndex: Index of the row that was edited, relative to the underlying
dataset
colIndex: Index of the column that was edited, relative to the
underlying dataset
colName: Name of the column in the underlying dataset
oldValue: The old value at the location, before it was edited
newValue: The new value input by the user.
"""
system.util.invokeLater(self.showPopup(rowIndex, colIndex, colName, oldValue, newValue)) #I'm assuming this is how I pass these values into the custom function, but please correct me if it's wrong
Here is what I have in the custom method,(parameters are: colIndex, colName, oldValue, newValue):
def showPopup(self, rowIndex, colIndex, colName, oldValue, newValue):
"""
Arguments:
self: a reference to the component instance this method is invoked on.
"""
customer = self.data.getValueAt(rowIndex, 'Customer')
product = self.data.getValueAt(rowIndex, 'ProductName')
newText = str(newValue)
if system.gui.confirm(u'Really submit entry "' + newText + '" as ' + colName + ', for customer: ' + customer + ', product: ' + product +'? You cannot undo this action!'):
# Get the id of the row we edited.
id = self.data.getValueAt(rowIndex, 'Spec_Index')
# Create our query and arguments. The extension function gives us a colName variable,
# which we can use in our query. The query will then take two arguments.
# The value that we are updating and the id of the row we edited.
query = "UPDATE Product_Specs SET %s = ? WHERE Spec_Index = ?" % (colName)
args = [newValue, id]
# Run the query with the specified arguments.
system.db.runPrepUpdate(query, args)
# Requery the database, so we can ensure it properly updated the table.
system.db.refresh(self, "data")
The error is the following: