The function toPyspViewer() sends commands and data to a detached pyspViewer processes. The pyspViewer process may have been started 'by hand' or by the function PySpectra.assertPyspViewerRunning().
The function is used by applications not running in the context of Sardana, applications that only need to display some data.
This function is also used by the Bluesky docHandler, see here
#!/usr/bin/env python3 # # this script simulates a scan using am MCA and a counter # import random, time import PySpectra, HasyUtils import numpy as np def main(): (status, wasLaunched) = PySpectra.assertPyspViewerRunning() ret = PySpectra.toPyspViewer( { 'command': ["cls", "delete"]}) if ret[ 'result'].upper() != 'DONE': print( "error from pyspMonitor %s" % ret[ 'result']) return ret = PySpectra.toPyspViewer( { 'command': ["setTitle \"An important title\"", "setComment \"An interesting comment\""]}) name = "TestScan" max = 101 MAX = 1024 ret = PySpectra.toPyspViewer( {'Scan': { 'name': name, 'xMin': 0., 'xMax': 100., 'yMin': 0., 'yMax': 1., 'symbol': '+','symbolColor': 'red', 'symbolSize': 7, 'lineColor': 'blue', 'nPts': max, 'autoscaleX': False, 'autoscaleY': True}}) x = np.linspace(0, 1023, MAX) y = np.random.random_sample( (len( x), ))*1000. ret = PySpectra.toPyspViewer( {'Scan': { 'name': "MCA", 'flagMCA': True, 'lineColor': 'blue', 'x': x, 'y': y}}) for i in range( max): # # send a new MCA spectrum for every scan point # y = np.random.random_sample( (len( x), ))*1000. ret = PySpectra.toPyspViewer( {'Scan': { 'name': "MCA", 'flagMCA': True, 'lineColor': 'blue', 'x': x, 'y': y}}) pos = float(i) posY = random.random()*10 PySpectra.toPyspViewer( { 'command': ['setXY %s %d %s %s' % (name, i, repr(pos), repr(posY))]}) PySpectra.toPyspViewer( { 'command': ["display"]}) time.sleep( 0.1) print( "Press <space> to continue") while 1: key = HasyUtils.inkey() if key == 32: break time.sleep( 0.1) # # if the pyspMonitor was launched by this script, kill it. # if wasLaunched: hshRet = PySpectra.toPyspViewer( { 'command': [ 'exit']}) return if __name__ == "__main__": main()