Debugging scripts is an important task. Here are some of the techniques to get some basic text output from your scripts.
Using print is probably one of the easiest ways to debug your Python script in Spotfire. However, its limited in its use since Spotfire does not have a standard output where it could print.
In Spotfire, it's possible to run a script directly from where you Create/Edit Scripts. In this case, the print output is shown in the Output window.
In the Analyst client, If you enable Log Level: TRACE In the "Support Diagnostics and Logging" all printing will be written directly into the Analyst debugging logs.
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. # # Print to the output window where you edit your script. Can also be logged by enabling TRACE logging. # print 'Hello Debug!'
Notifications in the status bar
Another possibility is to create Information, Warning and Error Notifications showing up in the status bar of the application.
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. from Spotfire.Dxp.Framework.ApplicationModel import NotificationService # Notification service notify = Application.GetService[NotificationService]() notify.AddWarningNotification("Notification title","Notification summary","Notification details"); #notify.AddInformationNotification("Information Title", "", "") #notify.AddErrorNotification("Error Title", "", "")
Writing to a property
This is the most common method of getting text output when debugging a script.
Create a document property, and write your debugging output to this property. Then show this property in a text area.
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. # # Append information to a document property. # Document.Properties["DebugText"] += "Additional debugging info"
A drawback of this method is that the document property will not be updated until the script has ended. This is due to the script is executed in a transaction.
Messagebox using Forms
WinForms graphical user interface is a component of the .NET Framework and not something supplied by Tibco Spotfire. It's not recommended to implement solutions using Forms, but sometimes it could be handy when debugging. There is no commitment that it will work in future versions of the Analyst client. Forms are not supported on the Web Player.
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. # # A simple MesasgeBox using Forms # import clr clr.AddReference("System.Windows.Forms") from System.Windows.Forms import MessageBox,MessageBoxButtons DebugText="This line is executed" response = MessageBox.Show(DebugText,"Your Caption",MessageBoxButtons.YesNo) print response
License: TIBCO BSD-Style License