Dynamically populating a tree view

I have the python script that is reading files out of a folder, i wanted to dynamically populate a tree view with the data.

What I have done to this point was add a script to the app module that works fine. Then i added an expression to the data/item of the tree view. when it opens i get an error:

Cannot coerce value 'C:\path\file.csv' into type: interface
I am new to ignition and I’m not sure how to link the two. I was wondering if anyone could point me in the right direction, thx.

should probably post your scripts and a better example of what you are trying to accomplish. are you trying to read data out of a csv file and use that data to build a dataset for a treeview component?

Thanks for the reply, im reading a folder on my C drive, taking the filenames out of the folder and I wanted them to display in the treeview.

Here is my app script:

def treeList(path = r'C:\folder\\'): import os, csv, glob #read all the files in a folder files = [] for fileName in glob.glob(os.path.join(path,"*")): files.append(fileName) return files

here is what I have listed in the data > Items script:

runScript("app.Tree_View.treeList()")

Here is the error I’m getting, it is listing the files but tells me:

Cannot coerce value '['C:\\folder\\file1.csv', 'C:\\folder\\file2.csv']' into type: interface

Thanks

Im guessing its the way im trying to link the data to the tree, does anyone have any experience trying to do this? Thanks

yes you need to take a look at the dataset in the treeview component and make whatever data you are pulling from those files formatted to match that dataset.

Thanks Diat150,

I tried formatting my returned values a little, but I am a little unsure how they are supposed to match. I read how I need to have the path along with the name, I believe that those are the only required items. I then changed my python to return (path, name) but it still does not work.

Do i need to keep the names with the value in my script, ie… path => ‘c:/folder’, name => ‘filename.txt’? I’ll try that next and see if it works but I feel like Im spinning my wheels a little, thanks.

I have modified my scripts, I now have a button that calls a script module to populate the tree view for now.

My module script:

[code]def treeList(fpath = r’C:\Folder\’):
import os, csv, glob, system

#read all the files in a folder
rows = []
for fileName in glob.glob(os.path.join(fpath,"*")):
	tail, head = os.path.split(fileName) 
	rows.append([tail, head])
 
return rows[/code]

button script:

[code]import app

rows = app.treeView.treeList()
#create event handler
headers = [“path”, “text”]
fileList = system.dataset.toDataSet(headers, rows)

Use our new dataset to fill in a tree view

#treeV = window.rootContainer.getComponent(name)
treeV = event.source.parent.getComponent(“csvList”)
treeV.data = fileList[/code]

Error:

[code]Traceback (most recent call last):

File “event:actionPerformed”, line 11, in

java.lang.UnsupportedOperationException

java.lang.UnsupportedOperationException: java.lang.UnsupportedOperationException

caused by UnsupportedOperationException

Ignition v7.6.1 (b2278)
Java: Oracle Corporation 1.7.0_25
[/code]

I am now getting a different error that I am not sure what to do with. Hopefully someone can chirp in with some direction, thanks.

I got it working, but I got a list populating. Ill have to work on the tree view later.