Dynamic Tab Strip

Hey guys,

I’m trying to dynamically build a tab strip dataset so that different production lines show tabs relevant to the line. To give a brief rundown, each line has between 7-10 processes and I want each process to have its own tab based upon the line selected.

Right now I have two datasets: One is queried from a databse table and returns all the process names for a given line (line is a dynamic property on the root container). The second is my tab strip data, containing all the options for process tabs (created using the tab strip customizer so it has all 22 columns of tab strip configuration).

All I want to do is have the pertinent tab names show up in the tab strip, but am having trouble with the script. This was my first attempt, using a property change event on the tab strip:

“Processes” is a custom property querying the process names based upon line number
“Tabs” is a custom property which has all possibilities for tabs and includes tab strip data (22 columns)

[code]if event.source.propertyName == “Processes”:
headersOut = system.dataset.getColumnHeaders(event.source.Tabs)
Names = event.source.Processes
tabInfo = event.source.Tabs

for row in Names:
	for rowNum in tabInfo:
		if row["Name"] == rowNum["DISPLAY_NAME"]:
			system.dataset.addRow(tabData,rowNum)
			
event.source.tabData = system.dataset.toDataSet(data)[/code]

This gave no error, but didn’t change the tabData either. So I tried another similar method after looking in the forums:

if event.source.propertyName == "Processes": row = list(system.dataset.toPyDataSet(event.source.Tabs)[0]) Names = event.source.Processes for num in range(Names.rowCount): row[1] = rowNum[0] event.source.tabData = system.dataset.addRow(event.source.tabData, num, row)

But this won’t work either. Any advice? Thanks.

If the second dataset is what you want in the tabstrip data, and you stated it it has all 22 columns, can’t you just push that data in?

I would watch that property “Tabs” vice the first property “Processes” since Tabs has all the data.

if event.source.propertyName == "Tabs":
   event.source.tabData = event.source.Tabs

Cheers,
Chris

Tabs has ALL possibilities, and I’m trying to pick and choose the tabs I want to show up.

Here’s a general example:
Say, for instance, the Tabs property has tab A,B,C,D, and E configured. If I select line 1 I only want tab A,C, and E to show up. Line 2 may be tab A,B,C, and E.

That is where Processes comes in. I can query the database table that has the relationship between line and the tabs I want shown. I just need a way to say “ok, Processes gave me table A,B,and C to display for line #, now I’m going to push tab A,B,and C from Tabs into tab data”

Apologies for not being clear in the original post.

The script will have an easier time iterating through the datasets if they’re PyDatsets.

Something more like:

[code]if event.source.propertyName == “Processes”:
headersOut = system.dataset.getColumnHeaders(event.source.Tabs)
Names = event.source.Processes
tabInfo = system.dataset.toPyDataSet(event.source.Tabs)

tabsOut=[]

for row in Names:
for rowNum in tabInfo:
if row[“Name”] == rowNum[“DISPLAY_NAME”]:
tabsOut.append(rowNum)

event.source.tabData = system.dataset.toDataSet(headersOut,tabsOut)[/code]

Also, if Names is a list, you can use something like:

for rowNum in tabInfo: if len(set(Names).intersection(rowNum["DISPLAY_NAME"])): tabsOut.append(rowNum)

Ok, made a few changes, but I am getting an error when trying to combine the header and new data into tabData. Here’s the error:

[quote]Traceback (most recent call last):

File “event:propertyChange”, line 14, in

java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PyObjectDerived cannot be cast to org.python.core.PySequence
[/quote]

And here’s the updated code:

[code]if event.propertyName == “Processes”:

Names = system.dataset.toPyDataSet(event.source.Processes)
tabInfo = system.dataset.toPyDataSet(event.source.Tabs)

headersOut = system.dataset.getColumnHeaders(event.source.Tabs)
tabsOut = []

for nameRow in Names:
	for tabRow in tabInfo:
		if nameRow["Bath"] == tabRow["DISPLAY_NAME"]:
			tabsOut.append(tabRow)

event.source.tabData = system.dataset.toDataSet(headersOut,tabsOut)[/code]

Looks like toDataSet isn’t playing nice with tabsOut, but I can’t think why tabsOut wouldn’t be a PySequence?

Is tabRow a list?
EDIT: Nevermind. Getting tired… :wink:

I do see that the headersOut declaration on Line 6 is indented by one space.

If you could, post up a copy of the Window. Maybe we can get a better idea on where things are going awry.

On the copy, if there’s any bound properties outside of the window, like a query or whatever, go ahead and unbind it. The data from the query will be left behind. :thumb_right:

Ok, here’s a .proj of the window which is what I think you were talking about? Script changed ever so slightly so that the script will trigger on custom property “lineSelected” instead of processes (which was queried), so you can just put in a random number there to test. Really appreciate the help, thanks.
ProcessNavigation.proj (12.1 KB)

Hi there,

The problem is that the “tabRow” variable is not a Python list, so make it one like this:

if nameRow["Bath"] == tabRow["DISPLAY_NAME"]:
    tabsOut.append(list(tabRow))

JordanCClark was right that “tabRow” is not a Python list. So no, not nevermind.

Best,