The following piece of code simulates a scan using toPyspMonitor(). 7.2.2 shows the final plot, 7.2.2 the main widget.
#!/usr/bin/env python3
#
# this script simulates a scan. Pairs of x- and y-values are sent
# to the pyspMonitor.
#
import random, time
import PySpectra, HasyUtils
def main():
(status, wasLaunched) = PySpectra.assertPyspMonitorRunning()
ret = PySpectra.toPyspMonitor( { 'command': ["cls", "delete"]})
if ret[ 'result'].upper() != 'DONE':
print( "error from pyspMonitor %s" % ret[ 'result'])
return
ret = PySpectra.toPyspMonitor( { 'command': ["setTitle \"An important title\"",
"setComment \"An interesting comment\""]})
max = 101
name = "TestScan"
ret = PySpectra.toPyspMonitor( {'Scan': { 'name': name,
'xMin': 0., 'xMax': 100.,
'yMin': 0., 'yMax': 1.,
'symbol': '+','symbolColor': 'red',
'symbolSize': 7, 'lineColor': 'blue',
'nPts': max,
'autoscaleX': False, 'autoscaleY': True}})
for i in range( max):
pos = float(i)
posY = random.random()*10
PySpectra.toPyspMonitor( { 'command': ['setXY %s %d %s %s' % (name, i, repr(pos), repr(posY))]})
PySpectra.toPyspMonitor( { '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.toPyspMonitor( { 'command': [ 'exit']})
return
if __name__ == "__main__":
main()