Database table of project properties

I have begun experimenting with using a database table to store project properties (onColor, alarmColor, etc). Works great so far for colors - I don’t have to worry whether I’m using the same shade on different screens, and I can change them all in one swell foop. Plus, I can query the database to change property state rather than enter color numbers.

However, some properties don’t seem so easily defined. For instance, is there some way to specify Border type or Font, etc in a DB cell?

First of all, kudos, this is a wonderful approach, especially for state-to-color and state-to-text lookups.

For the casual forum browser, let me explain how this works real quick. You set up a table in your database that might look something like this:

TABLE: StateLookup ObjectType State Text Color "valve" 0 "Closed" "#BBBBBB" "valve" 1 "Open" "Green" "valve" 2 "Faulted" "Red" "motor" 0 "Off" "#BBBBBB" "motor" 1 "Hand" "Yellow" "motor" 2 "Auto" "Green" "motor" 3 "Faulted" "Red"

Then, for your valves, you set their color to be bound to a query like this:

SELECT Color FROM StateLookup WHERE ObjectType='valve' AND state = {Root Container.MyValve.state}

and the text to

SELECT Text FROM StateLookup WHERE ObjectType='valve' AND state = {Root Container.MyValve.state}

This may seem like a lot of work, but it effectively gives you the ability to define the logic of your objects in one place (the database), so if you ever add a new state or change the verbage or colors, you only change it in one place, not potentially tens or hundreds of on-screen objects.

Ok, back to your question, bds.

Unfortunately you’re right - there isn’t really a way to store borders or fonts in the DB. Even if there were some sort of string encoding for these properties, you currently can’t bind this type of property, so it wouldn’t help you much. Such a thing might be pretty useful, though, so I’ll enter it as a feature request.

Hope this helps,

Just checking on where this as I want to change the border in a script. I can’t find how to define a border in Jython and I can’t find any other reference to this on the boards.

I’m glad you asked. There is now a relatively easy way to do this.

The easiest way is to make use of the expression language’s toBorder() casting function, which is (I just realized) undocumented, so I’ll go over it here.

It takes a string, which is of the format:

border(type; [options; options])

The available types are:
[ul][li]line[/li]
[li]etched[/li]
[li]bevel[/li]
[li]matte[/li]
[li]paneltitled[/li]
[li]etchedtitled[/li]
[li]linetitled[/li]
[li]button[/li]
[li]field[/li][/ul]

Each type can take different options. For example:

border(line;red;5)

will give you a red, 5-pixel thick line border

More complex borders such as the panel titled border can take lots more options. We’ll get these into the docs - let me know what kind of borders you wanted to make in the meantime.

Now, you wanted to use scripting to create those borders. You can use the expression language like I have outlined above by simply binding the border in question to an expression like toBorder({Root Container.MyLabel.borderString}) where borderString is a dynamic property, and then you’d just set that dynamic property via a script.

(as an aside, you can also import javax.swing.border and go straight to the source…)

Now, fonts are a bit more tricky. You need to use Java, like this:

from java.awt import Font label = event.source.parent.getComponent("Label") label.font = Font("Monospaced", Font.BOLD, 14)

Hope this helps,

Bruce,
I think you can accomplish everything you want using styles. I’m at a public terminal now, so I’ll have to check later on all of the properties (font/border) - as I recall, there is a text based encoding that allows you to store/modify them in a database table.

The Styles Training Video provides an example of storing styles in a database.

Thanks Carl, that what I was looking for.

Nathan,

The styles video link just takes you to the video library page; I couldn’t find a video specifically about styles. I think I’ve seen all 14 training webinars and don’t recall one about linking styles to a database. I tried fooling around with it by creating a database table laid out just like a Styles recordset and then binding the styles property to a SQL query of that table instead of using the styles customizer. The query seems to work and if I examine the styles recordset it looks OK, but the state animation doesn’t happen.

For a multi-state indicator, my table looks like this:
state int primary key
animationIndex int
animationDuration int
background varchar(256) - this contains entries like ‘color(225,225,225,255)’
border varchar(256)
foreground varchar(256)
text varchar(256)

It seems like this should work as long as your left-most column is the driving property. Am I barking up the wrong tree trying to use styles? Instead should I set individual properties with scripts as described by Carl?

Thanks.

This should work. Is your driving property actually called “state”?

Yeah, I was first trying it on a multi-state indicator component that has a style customizer set up driven by state…

Can you export the problem window and send it to us?

I should update this… I found the issue was that one of my columns in my styles recordset resulting from my query was capitalized incorrectly. It turns out the columns in the styles table are case-sensitive.