Displaying Images in a Label Property Control


In last week’s post, we learned how to create custom Property Controls in the form of Radio Buttons and Checkboxes.  As it turns out, this solution works well using the Web Player from Internet Explorer, but the wingdings fonts do not display as they should in Firefox or Chrome.  To correct this, and to learn another nice feature, we will replace the wingding fonts with a graphic in the Label Property Control.  

This can be accomplished out of the box using a Data Function, but that requires S+ or R and the TIBCO Spotfire Statistics Server. If you do not have those, or you just want to use something more lightweight, a script can be used. The code below can be used in a script control. It will take an image, specified via a  URL, and will place it in a Binary Document Property.  
 

from System.Drawing import Image
from System import Uri
from System.Net import HttpWebRequest
from Spotfire.Dxp.Data  import BinaryLargeObject

uri = Uri("http://spotfire.tibco.com/community/Downloads/radioOn.png")
request = HttpWebRequest.Create(uri)
response = request.GetResponse()
stream = response.GetResponseStream()
blob = BinaryLargeObject.Create(stream)
Document.Properties["testImage"] = blob

If you then attach this Binary Property to a Label Property Control, the image will appear, and will work in the Web Player as well in all supported browsers. To see the same example as last week updated to work using this new approach, take a look at: http://spottrain.tibco.com/SpotfireWeb/ViewAnalysis.aspx?file=/kevin/TNA

This opens the door for a new set of features, where you can rotate through images based off some logic. This can lead to a custom-traffic light visualization, Radio Button and Checkbox Property Controls, and other solutions where you need to rotate or display different images based off of data.