Excel-like cell behavior in a table

Hello,

I'm using Ignition version 8.1.26 and I'd like to have Excel-like cell behavior in my table for Tab and Enter keypresses. I thought I could script this with an onKeyPress event but I'm not having any luck.

Here is what I have. I'm really new to python so I'm sure my code is really bad.

def runAction(self, event):
	# Get the currently selected cell coordinates
	#I don't think this part is working.
	selectedRow = self.getSibling('Table1').props.selection.selectedRow
	print(selectedRow)
	selectedColumn = self.getSibling('Table1').props.selection.selectedColumn
	print(selectedColumn)
	
	if event.keyChar == '\t':  # Tab key
	    # Calculate the next column index
	    nextColumn = selectedColumn + 1
	    
	    # Check if we've reached the end of the row
	    if nextColumn >= event.source.data.columnCount:
	        # Move to the first cell of the next row
	        nextRow = selectedRow + 1
	        if nextRow >= event.source.data.rowCount:
	            nextRow = 0  # Cycle back to the first row
	        event.source.selectedRow = nextRow
	        event.source.selectedColumn = 0
	    else:
	        event.source.selectedRow = selectedRow
	        event.source.selectedColumn = nextColumn
	
	elif event.keyChar == '\n':  # Enter key
	    # Calculate the next row index
	    nextRow = selectedRow + 1
	    
	    # Check if we've reached the end of the table
	    if nextRow >= event.source.data.rowCount:
	        nextRow = 0  # Cycle back to the first row
	    
	    event.source.selectedRow = nextRow
	    event.source.selectedColumn = selectedColumn

Thank you,

Are you getting any errors when this runs? What extension function do you have this in? I think you want system.perspective.print to see those values come through. Did you test to see what the event.keyChar is when you press enter or tab? You can always start littering this thing with print statements to see how far your script is getting and what branch it is going down.

I currently have this in the onKeyPress event. I don't know what you mean by extension function.

I changed the print to system.perspective.print() and am now getting an error:

File "function:runAction", line 8, in runAction
AttributeError: 'com.inductiveautomation.ignition.common.script.ada' object has no attribute 'keyChar'

Still nothing printing in the console though. Thanks!

So you were using

print()

Which in perspective will send that to the wrapper log for the gateway.

Like @bkarabinchak.psi mentioned use

system.perspective.print()

That will do to the proper console so you can see it.

2 Likes

I was able to see the onKeyDown event respond to the keys in the diagnostic console using the following script:

	keyCode = event.key
	if keyCode == "Tab":
		system.perspective.print(keyCode)
	elif keyCode == "Enter":
		system.perspective.print(keyCode)

This works consistantly for the enter key, but unfortunately, when the tab key was pressed, the table lost focus, and I was unable to register any subsequent events.