The ignition programming setup is event driven programming, you are correct on that. You only call scripts on events, whether the event is a tag change, a GUI interaction, or something else that is changing or causing an event.
If you make a fresh Tab Strip component, then click on the Tab Data to see what is currently there, youâll see this
These are the columns you need to alias in your SQL SELECT clause which youâll need bounnd to the Tab Data component.
Yes, binding to a SQL query I believe is the way for you to do this especially if you want it dynamic as you can set a SQL polling rate in the situation where you might have users manually changing items in the database that will change the tab appearance.
The important bit here is this - you need to SELECT something as tabPropertyName in your query. So just for the names of the queries you would need to do SELECT myDBColumn as NAME, otherDBColumn as DISPLAY_NAME, ... and in this instance, whatever your otherDBColumn value is is what the Tab will display. The NAME property I believe is used for the selected tab property on the tab strip.
What I am saying is that for your Tab Data property, it makes sense to bind it to a SQL query if you are basing it on a database table.
So you would bind Tab Data to a SQL Query Binding (or Named Query Binding if you already have one), but the important thing is that in your SQL Query or Named query, the columns you select MUST line up with the NAME, DISPLAY_NAME, ENABLED, etc, if you want the results of the query to affect the Tab Strip appearance. You can select additional columns but they wonât affect the Tab Strip appearance.
If your tabs are going to be static, you can also always right click on the tab strip -> customizers -> Tab Customizer, and then enter your tab strip information manually. In fact, perhaps do this for just a few of the tabs you are expecting, and then take a look at the Tab Data property data to see how it affects the columns. It might help illuminate things for you.
Iâm sorry, but I donât understand. How do I get the dataset into a query?
I have a table (binder_topics) with 2 columns: id, topic_name. I want to use the topic_name in my dbtable as the Display_Name in the Tab Strip dataset.
I put this in the property change event on the Tab Strip. It does change the name of the Display Name of row 0 and the remainder of the dataset remains the same. HOWEVER, Ignition Designer comes to a screeching halt and the Console window freezes up.
Your property change event is firing itself, repeatedly; thatâs whatâs causing the lockup. Introduce a custom property running the query, and filter the property change event to that propertyâs name.
I guess I do not grasp the concept. I can capture the âselectedTabâ property in an if statement and can print the selected tab and the dataset each time the selectedTab changes.
But when I change the dataset in the if statement, it goes into the perpetual loop and freezes.
Just saw your message and I totally understand. Work always comes first and I would expect nothing less. Gives me lots of time to read and try stuffâŚ
if event.propertyName == 'topic_list':
# Get the tabstrip component. Since we will be referencing
# it a lot, it's handy to create an easy reference.
tabStrip = event.source
# Get the PyDataSet version of topic_list
topicDataSet = system.dataset.toPyDataSet(tabStrip.topic_list)
# Get the pyDataSet version of the tab format
formatDataSet = system.dataset.toPyDataSet(tabStrip.tabFormat)
# Create format list. It's just everything after the
# tab name and display name. This will get added to the id
# and topic from the topic list dataset
format = list(formatDataSet[0])[2:]
# Get the tabData headers. It's why I kept all the columns
# in for format dataset.
tabDataHeaders = list(formatDataSet.getColumnNames())
dataOut = []
# Iterate through the topics and add the format to it.
for row in topicDataSet:
dataOut.append(list(row) + format)
# Write the new tabData
tabStrip.tabData = system.dataset.toDataSet(tabDataHeaders, dataOut)
This is exactly the function I wanted. Now I understand the custom property. Each time the topic_list changes (or is opened and closed) it is seen as a property change and fires the event.
I know what is happening below, but do not understand how.
Where can I get more details on the list() function. The manual shows list but nothing this detailed.
ok, so we are making a list starting at index 2. However, what is the [0] for? I am assuming it is row 0 of formatDataSet. I did not see that in the Python tutorial or the Ignition manual.
This actually digs a bit deeper into the java classes for datasets and pyDataSets, but the upshot is that pyDataSets can use subscripts and make lists out of the rows, while normal (for lack of a better word) datasets cannot. For me, it's a matter of convenience. You could do the same thing without making it a pyDataSet and using a loop or list comprehension:
formatDataSet = tabStrip.tabFormat
format = [dataset.getValueAt(0,i) for i in range(2,formatDataSet.getColumnCount())]
-or-
formatDataSet = tabStrip.tabFormat
format=[]
for i in range(2,formatDataSet.getColumnCount()):
format.append(dataset.getValueAt(0,i))
Personally, I prefer the subscripts as it's easier for me to read. More of a style preference, really, as each dataset type has its own set of useful features.
Hopefully, I didn't throw more mud in the water for you.
@JordanCClark so I ran into a problem when implementing the tab strip into my project.
The Selected Value of the tabstrip is a string. The query in my table expects an integer. As built, the Selected Value of the tab is actually a number because we use the topic.id(index) of the topic_name.
But because the datatype was a mismatch it would not work.
SO, I created another custom property on the tabstrip, named it selectedTabInt. I then added an expression to selectedTabInt using toInt({Root Container.Topic Tab Strip.selectedTab}, -1).
I then used selectedTabInt as the parameter in the query. Works great.