AttributeError: 'unicode' object has no attribute 'data' on Power Table double-click

I am trying to edit a Power Table which has been successfully populated with data merged from a couple of CSV files.

def UpdateParamEditTable():
	import system
	import sys
	
	window = system.gui.getWindow("Main Windows/ParameterEdit")	
	
	# A new recipe or stations selection has been made. Clear the table.
	tbl = window.rootContainer.getComponent('ptblParams')			# The Power Table.
	customizer = tbl.columnAttributesData							# Save the customizers before we destroy them ...
	# The line above destroys the tblParams customizers which includes the "editable" property of the Setpoint column.
	tbl.columnAttributesData = customizer							# This line restores the customizer. 
	rows = []														# Empty.

	# Code to read the CSV file into rows[] goes in here.

	header = ['Line', 'Description', 'Setpoint', 'Min', 'Max']		# Header rows for the table.
	tbl.data = system.dataset.toDataSet(header, rows)				# Create the table dataset.
	# This works. The table is populated with the CSV data.

So far, so good. The Power Table is populated correctly.

Ignition Power Table data

The Power Table onDoubleClick code starts as follows:

def onDoubleClick(self, rowIndex, colIndex, colName, value, event):
	# Power Table double-click event.
	table = system.gui.getParentWindow(event).getPathForComponent(self)
	data = system.dataset.toDataSet(table.data)  # Line 16.

I’m getting an error:

  File "<extension-method onDoubleClick>", line 16, in onDoubleClick
AttributeError: 'unicode' object has no attribute 'data'

which seems to indicate that the system thinks the Power Table is empty when it is clearly well populated. I’ve tried using system.dataset.toPyDataSet but receive the same error.

What am I not understanding here?

getPathForComponent() returns a string representing the path to the given component, not the component itself.

There are two functions which are very similar in name but return very different things.

#signiture for getPathForComponent()
java.lang.String getPathForComponent(java.awt.component c)

#signiture for getComponentForPath()
javax.swing.JComponent getComponentForPath(java.lang.String path)

It is not that the system thinks the Power Table is empty but that table is not the object you think it is.

Try the following:

def onDoubleClick(self, rowIndex, colIndex, colName, value, event):
     # Power Table double-click event
     table = event.source
     data = table.data

With extension functions you can access all scripting properties with self.propertyName.

Try changing these two lines:

table = system.gui.getParentWindow(event).getPathForComponent(self)
data = system.dataset.toDataSet(table.data)  # Line 16.

to this 1 line:

data = self.data

I see the confusion with trying to use the event parameter because in other cases event is the calling object. I always reference the manual and it looks like the event parameter for the onDoubleClick is the mouse events.

Snippet from the manual:
image

Manual link:
https://docs.inductiveautomation.com/display/DOC80/Vision+-+Power+Table

Psssst!

    table = self
1 Like

He could use this as per @pturmel suggestion :

table = self
data = table.data

@code_skin’s data = self.data worked for me.

Phil’s table = self looks interesting but came in late.

@Irose’s code gave me more attribute errors which I didn’t pursue.

Thank you all. I don’t do enough of this to become proficient and get rather confused sometimes.

I was kind’a hinting that the table variable wasn’t needed at all…

1 Like

Ahh. That hint went over my head for some reason lol.