def test_setArrow(self): print "testIFC.test_setArrow" PySpectra.command("cls") PySpectra.command("delete") max = 20 PySpectra.command( "setComment \"Arrows: Current: 5, Misc: 2, SetPoint: 6\"") PySpectra.command("create s1 0 10 %d" % max) gqe = PySpectra.getGqe("s1") gqe.motorNameList = ["eh_mot66"] PySpectra.command("setArrowCurrent s1 position 5.") PySpectra.command("setArrowMisc s1 position 2.") PySpectra.command("setArrowSetPoint s1 position 6.") PySpectra.command("display") PySpectra.processEventsLoop(1) pos = 5 for i in range(20): pos = 5 + float(i) * 0.05 PySpectra.command("setArrowCurrent s1 position %g" % pos) time.sleep(0.1) print "testIFC.test_setArrow DONE" return
def test_setX_Y(self): import random print "testIFC.test_setX_Y" PySpectra.command("cls") PySpectra.command("delete") max = 50 PySpectra.command("create s1 0 10 %d" % max) s1 = PySpectra.getGqe("s1") self.assertEqual(s1.currentIndex, 49) self.assertEqual(s1.lastIndex, -1) PySpectra.command("display") self.assertEqual(s1.lastIndex, (max - 1)) for i in range(max): PySpectra.command("setY s1 %d %g" % (i, random.random() * 10)) PySpectra.command("setX s1 %d %g" % (i, float(i) / 100.)) self.assertEqual(s1.currentIndex, i) PySpectra.command("display") time.sleep(0.1) PySpectra.processEventsLoop(1) print "testIFC.test_setX_Y DONE" return
def testToPyspLocalCompleteImageByImage(self): ''' use Image to transfer a complete image at once ''' print "testZmqIfc.testToPyspLocalCompleteImageByImage" hsh = PySpectra.toPyspLocal({'command': ['cls', 'delete']}) self.assertEqual(hsh['result'], 'done') hsh = PySpectra.toPyspLocal({'command': ['setWsViewport dina5s']}) self.assertEqual(hsh['result'], 'done') # # setTitle # hsh = PySpectra.toPyspLocal({ 'command': ['setTitle "use Imageto transfer the complete image at once"'] }) self.assertEqual(hsh['result'], 'done') (xmin, xmax) = (-2., -0.5) (ymin, ymax) = (0, 1.5) (width, height) = (100, 100) maxiter = 25 # # fill the image, pixel by pixel # r1 = np.linspace(xmin, xmax, width) r2 = np.linspace(ymin, ymax, height) data = np.ndarray((width, height), np.float64) for i in range(width): for j in range(height): res = mandelbrot(r1[i] + 1j * r2[j], maxiter) data[i][j] = int(res) hsh = PySpectra.toPyspLocal({ 'Image': { 'name': "MandelBrot", 'data': data, 'xMin': xmin, 'xMax': xmax, 'yMin': ymin, 'yMax': ymax, } }) self.assertEqual(hsh['result'], 'done') hsh = PySpectra.toPyspLocal({'command': ['cls', 'display']}) self.assertEqual(hsh['result'], 'done') o = PySpectra.getGqe("Mandelbrot") self.assertEqual(o.height, 100) self.assertEqual(o.width, 100) self.assertEqual(o.xMin, xmin) self.assertEqual(o.xMax, xmax) self.assertEqual(o.yMin, ymin) self.assertEqual(o.yMax, ymax) PySpectra.processEventsLoop(2) print "testZmqIfc.testToPyspLocalCompleteImageByImage DONE" return
def test_toPyspLocalScan(self): import random print "testIFC.test_toPyspLocalScan" ret = PySpectra.toPyspLocal({'command': ["cls", "delete"]}) self.assertEqual(ret['result'], 'done') ret = PySpectra.toPyspLocal({ 'command': [ "setTitle \"An important title\"", "setComment \"An interesting comment\"" ] }) self.assertEqual(ret['result'], 'done') max = 101 name = "TestScan" ret = PySpectra.toPyspLocal({ 'Scan': { 'name': name, 'xMin': 0., 'xMax': 100., 'yMin': 0., 'yMax': 1., 'symbol': '+', 'symbolColor': 'red', 'symbolSize': 7, 'lineColor': 'blue', 'nPts': max, 'autoscaleX': False, 'autoscaleY': True } }) self.assertEqual(ret['result'], 'done') o = PySpectra.getGqe(name) self.assertEqual(o.nPts, max) self.assertEqual(o.symbol, '+') self.assertEqual(o.symbolColor, 'red') self.assertEqual(o.symbolSize, 7) self.assertEqual(o.lineColor, 'blue') self.assertEqual(o.lastIndex, -1) self.assertEqual(o.currentIndex, (max - 1)) for i in range(max): pos = float(i) posY = random.random() * 10 PySpectra.toPyspLocal({ 'command': ['setXY %s %d %s %s' % (name, i, repr(pos), repr(posY))] }) PySpectra.toPyspLocal({'command': ["display"]}) self.assertEqual(o.currentIndex, i) time.sleep(0.1) print "testIFC.test_toPyspLocalScan DONE" return
def test_overlay(self): print "testIFC.test_overlay" PySpectra.cls() PySpectra.delete() PySpectra.command("create s1") PySpectra.command("create s2") PySpectra.command("overlay s1 s2") s1 = PySpectra.getGqe('s1') self.assertEqual(s1.overlay, "s2") print "testIFC.test_overlay DONE" return
def _storeMCAData(hsh): ''' handle MCA data - create new Scan, if it does not exist. - otherwise re-use it. for the moment we assume that the whole sequence involving this function starts at pyspDoor. Therefore we treat the case of a non-empty dictionary very relaxed. Just complain and let TK fix it. ''' scan = PySpectra.getGqe(hsh['name']) if scan is None: PySpectra.Scan(**hsh) return True del hsh['name'] del hsh['flagMCA'] if 'y' not in hsh: raise ValueError("zmqIfc._storeMCAData: no data, 'y' is missing") if len(hsh['y']) != len(scan.y): raise ValueError( "zmqIfc._storeMCAData: len( scan.y) %d, len( hsh[ 'y']) %d" % (len(scan.y), len(hsh['y']))) scan.y = hsh['y'][:] del hsh['y'] # # trigger a re-display # scan.lastIndex = -1 if 'x' not in hsh: return True if len(hsh['x']) != len(scan.x): raise ValueError( "zmqIfc._storeMCAData: len( scan.x) %d, len( hsh[ 'x']) %d" % (len(scan.x), len(hsh['x']))) scan.x = hsh['x'][:] del hsh['x'] if 'lineColor' in hsh: scan.lineColor = hsh['lineColor'] del hsh['lineColor'] if hsh: print("zmqIfc._storeMCAData: dct not empty %s" % str(hsh)) return
def getGqe(name): ''' Spectra: 1, if the scan exist, 0 otherwise used by moveMotor() to see whether the signal scan is still existing ''' if spectraInstalled and useSpectra: (sts, ret) = Spectra.gra_decode_int("search_scan( %s)" % name) if sts == 0: raise ValueError("graPyspIfc.getGqe: failed to search for %s" % name) return ret else: return PySpectra.getGqe(name)
def _setArrowMiscCmd(line): ''' handle the arrowMisc setArrowMisc <nameGqe> position <targetPos> setArrowMisc <nameGqe> hide setArrowMisc <nameGqe> show position: the motor target position, maybe from mvsa ''' lst = line.split(' ') o = PySpectra.getGqe(lst[0]) if o is None: raise ValueError(" ifc.setArrowMisc: failed to find %s" % lst[0]) o.setArrowMiscCmd(lst[1:]) return "done"
def _setPixelWorld(line): ''' setPixelWorld <nameGqe> x y value x, y: in world coordinates x >= xMin and x <= xMax y >= yMin and y <= yMax ''' lst = line.split(' ') o = PySpectra.getGqe(lst[0]) if o is None: raise ValueError(" ifc.setPixelWorld: failed to find %s" % lst[0]) x = float(lst[1]) y = float(lst[2]) val = float(lst[3]) o.setPixelWorld(x, y, val) return "done"
def _setPixelImage(line): ''' setPixelImage <nameGqe> <ix> iy value ix, iy: indices, image coordinate frame ix > 0 and ix < width iy > 0 and iy < height ''' lst = line.split(' ') o = PySpectra.getGqe(lst[0]) if o is None: raise ValueError(" ifc.setPixelImage: failed to find %s" % lst[0]) ix = int(lst[1]) iy = int(lst[2]) val = float(lst[3]) o.setPixelImage(ix, iy, val) return "done"
def _setY(line): ''' setY <nameGqe> index y ''' lst = line.split(' ') o = PySpectra.getGqe(lst[0]) if o is None: raise ValueError(" ifc.setY: failed to find %s" % lst[0]) index = int(lst[1]) if index >= o.nPts: raise ValueError(" ifc.setY: %s, index %d > nPts %d" % (lst[0], index, o.nPts)) o.y[index] = float(lst[2]) o.currentIndex = index return "done"
def _move(line): ''' move s1 50 <flagConfirm> <flagConfirm> - specify whether the user is prompted for confirmation before the move is executed, def.: True, safety first ''' lst = line.split(' ') if len(lst) < 2: raise ValueError( "ifc.move: expecting at least a scan name and the destination") gqe = PySpectra.getGqe(lst[0]) flagConfirm = True if len(lst) == 3: if lst[2].upper() == "FALSE": flagConfirm = False tangoIfc.move(gqe, float(lst[1]), flagConfirm=flagConfirm) return "done"
def test_setText(self): print "testIFC.test_setText" PySpectra.command("cls") PySpectra.command("delete") PySpectra.command("create s1") o = PySpectra.getGqe("s1") self.assertEqual(len(o.textList), 0) PySpectra.command( "setText s1 comment string \"this is a comment\" x 0.05 y 0.95 hAlign left vAlign top color blue" ) self.assertEqual(len(o.textList), 1) self.assertEqual(o.textList[0].text, "this is a comment") self.assertEqual(o.textList[0].x, 0.05) self.assertEqual(o.textList[0].y, 0.95) self.assertEqual(o.textList[0].hAlign, 'left') self.assertEqual(o.textList[0].vAlign, 'top') self.assertEqual(o.textList[0].color, 'blue') PySpectra.command("display") PySpectra.display() PySpectra.processEventsLoop(1) print "testIFC.test_setText DONE" return
def getNumberOfGqesToBeDisplayed( nameList): ''' return the number of scans to be displayed. Scans that are overlaid do not require extra space and are therefore not counted. ''' if len( nameList) == 0: nOverlay = 0 for gqe in PySpectra.getGqeList(): if gqe.overlay is not None: nOverlay += 1 nGqe = len( PySpectra.getGqeList()) - nOverlay if nGqe < 1: nGqe = 1 else: nOverlay = 0 for name in nameList: if PySpectra.getGqe( name).overlay is not None: nOverlay += 1 nGqe = len( nameList) - nOverlay if nGqe < 1: nGqe = 1 #print( "graphics.getNoOfGqesToBeDisplayed: nGqe %d" %(nGqe)) return nGqe
def display(nameList=None): ''' display one or more or all scans Parameters ---------- None: display all scans Name: string a list of scans to be displayed Example ------- PySpectra.display( [ 's1', 's2']) display scans s1 and s2 PySpectra.display() display all scans Module: PySpectra.graphics.<graphLib>.graphics.py ''' # # don't want to check for nameList is None below # #print( "mpl_graphics.display, nameList %s" % repr( nameList)) if nameList is None: nameList = [] if Fig is None: _initGraphic() # # Do not put a cls() here because it takes a lot of time, especially when # fast displays are done. # Try /home/kracht/Misc/pySpectra/test/testGQE.py testFillData # # see if the members of nameList arr in the gqeList # for nm in nameList: if PySpectra.getGqe(nm) is None: raise ValueError("graphics.display: %s is not in the gqeList" % nm) gqeList = PySpectra.getGqeList() # # if there is only one scan to be displayed, there is no overlay # flagDisplaySingle = False if len(nameList) == 1 or len(gqeList) == 1: flagDisplaySingle = True # # adjust the graphics window to the number of displayed scans # nDisplay = utils.getNumberOfGqesToBeDisplayed(nameList) _setSizeGraphicsWindow(nDisplay) _adjustFigure(nDisplay) # # set scan.nrow, scan.ncol, scan.nplot # utils.setGqeVPs(nameList, flagDisplaySingle, cls) _displayTitleComment(nameList) _displayImages(nameList) # # --- first pass: run through the scans in gqeList and display # non-overlaid scans # for scan in gqeList: if type(scan) != PySpectra.Scan: continue # # overlay? - don't create a plot for this scan. Plot it # in the second pass. But it is displayed, if it is the only # scan or if it is the only scan mentioned in nameList # if scan.overlay is not None and not flagDisplaySingle: # # maybe the scan.overlay has beed deleted # if PySpectra.getGqe(scan.overlay) is None: scan.overlay = None else: continue if len(nameList) > 0: if scan.name not in nameList: continue # # if we re-use the plotItem ( aka viewport ?), # we can use setData(), see below. That makes things much faster. # if scan.plotItem is None: try: #print( "graphics.display: creating plot for %s" % scan.name) _createPlotItem(scan, nameList) except ValueError as e: print("graphics.display: exception from createPlotItem") print("graphics.display: consider a 'cls'") print("graphics.display %s" % repr(e)) return if type(scan) == PySpectra.Scan and scan.textOnly: continue if scan.doty: xDate = [] # # [ 0.01 , 1.009, 2.008, 3.007, 4.006, 5.005, 6.004, # 7.003, 8.002, 9.001, 10. ] # -> # [ 737060.01 , 737061.009, 737062.008, 737063.007, 737064.006, # 737065.005, 737066.004, 737067.003, 737068.002, 737069.001, 737070.] # for x in scan.x[:(scan.currentIndex + 1)]: xDate.append(_doty2datetime(x)) xDateMpl = matplotlib.dates.date2num(xDate) scan.xDateMpl = xDateMpl[:] hsh = _preparePlotParams(scan) scan.plotDataItem, = scan.plotItem.plot_date( xDateMpl, scan.y[:(scan.currentIndex + 1)], **hsh) # # not doty # else: hsh = _preparePlotParams(scan) scan.plotDataItem, = scan.plotItem.plot( scan.x[:(scan.currentIndex + 1)], scan.y[:(scan.currentIndex + 1)], **hsh) # # setData is the function name in pyqtgraph # scan.plotDataItem.setData = scan.plotDataItem.set_data scan.lastIndex = scan.currentIndex if type(scan) == PySpectra.Scan and scan.textOnly: continue # # modify the scan # scan.plotItem = scan.plotItem # # check, if there is something to display # if scan.lastIndex == scan.currentIndex or \ scan.currentIndex == 0: #print( "mpl_display, currentIndex %s, lastIndex %s, continue" % (scan.currentIndex, scan.lastIndex)) continue if scan.doty: pass #xDate = [] #for x in scan.x[:(scan.currentIndex + 1)]: # xDate.append( _doty2datetime( x)) #xDateMpl = matplotlib.dates.date2num( xDate) #scan.plotItem.plot_date( xDateMpl, scan.y) else: scan.plotDataItem.set_data(scan.x[:(scan.currentIndex + 1)], scan.y[:(scan.currentIndex + 1)]) # # 9.7.2019: setting x-limits of the scan # - for aligning motors the x-axis should be auto-ranged, # in both directions # - for scans the x-axis should be fully visible from the beginning # if scan.autoscaleX: scan.plotItem.set_xlim( min(scan.x[0], scan.x[scan.currentIndex]), max(scan.x[0], scan.x[scan.currentIndex])) scan.plotItem.set_ylim(numpy.min(scan.y[:(scan.currentIndex + 1)]), numpy.max(scan.y[:(scan.currentIndex + 1)])) # # keep track of what has already been displayed # scan.lastIndex = scan.currentIndex # # --- # --- second pass: display overlaid scans # --- # for scan in gqeList: if type(scan) != PySpectra.Scan: continue # # if only one scan is displayed, there is no overlay # if len(nameList) == 1: break if scan.overlay is None: continue # # check, if theren is something to display # if scan.lastIndex == scan.currentIndex: continue if len(nameList) > 0 and scan.name not in nameList: continue target = PySpectra.getGqe(scan.overlay) if target is None or target.plotItem is None: raise ValueError( "mpl_graphics.display: %s tries to overlay to %s" % (scan.name, scan.overlay)) # # instantiate a second axes that shares the same x-axis # scan.plotItem = target.plotItem.twinx() if scan.xLog: scan.plotItem.set_xscale("log") if scan.yLog: scan.plotItem.set_yscale("log") if len( PySpectra.getGqeList()) >= definitions.MANY_GQES or \ scan.yTicksVisible == False: plt.setp(scan.plotItem.get_yticklabels(), visible=False) hsh = _preparePlotParams(scan) # # follow the target scan as far as the axes are concerned # if target.doty: scan.plotItem.plot_date(target.xDateMpl, scan.y, **hsh) else: scan.plotItem.plot(scan.x[:(scan.currentIndex + 1)], scan.y[:(scan.currentIndex + 1)], **hsh) scan.lastIndex = scan.currentIndex if scan.autoscaleY: scan.plotItem.set_autoscaley_on(True) else: scan.plotItem.set_ylim(scan.yMin, scan.yMax) if scan.useTargetWindow: if target.autoscaleY: (mi, ma) = target.plotItem.get_ylim() scan.plotItem.set_ylim(mi, ma) else: scan.plotItem.set_ylim(target.yMin, target.yMax) if not scan.doty: if scan.autoscaleX: scan.plotItem.set_autoscalex_on(True) else: scan.plotItem.set_xlim(scan.xMin, scan.xMax) # # draw() is non-blocking # #plt.draw() Fig.canvas.flush_events() #plt.pause( 0.001) if Canvas is not None: try: Canvas.draw() except Exception as e: print("mpl_graphics.display: caught exception from Canvas.draw") print(repr(e)) return
def setGqeVPs( nameList, flagDisplaySingle, clsFunc): ''' set the gqe viewport, we use the at = (2,3,2) syntax which is (nrow, ncol, nplot) title and comment are ignored here. they are taken care of in createPlotItem() if a gqe has an 'at' field, like (2,2,3), these values have higher priority. clsFunc is specified to be able to distinguish between mpl and pqt ''' global _lenPlotted debug = False gqeList = PySpectra.getGqeList() if debug: print( "\nutils.setGqeVPs.BEGIN: gqeList %s, nameList %s" % \ ( repr( [ gqe.name for gqe in gqeList]), repr( nameList))) if len( nameList) == 0: # # the number of used viewports is (len( gqeList) - numberOfOverlaid) # usedVPs = len( gqeList) - _getNumberOfOverlaid() if usedVPs != _lenPlotted and _lenPlotted != -1: clsFunc() _lenPlotted = usedVPs if usedVPs == 0: return if usedVPs == 1: ncol = 1 nrow = 1 elif usedVPs == 2: ncol = 1 nrow = 2 else: ncol = int( math.ceil( math.sqrt( usedVPs))) if usedVPs > definitions.MANY_GQES: ncol -= 1 nrow = int( math.ceil( (float(usedVPs))/float(ncol))) nplot = 1 elif len( nameList) == 1: if _lenPlotted != 1 and _lenPlotted != -1: clsFunc() _lenPlotted = 1 ncol = 1 nrow = 1 nplot = 1 else: # # the number of used viewports is (len( nameList) - numberOfOverlaid( nameList)) # usedVPs = len( nameList) - _getNumberOfOverlaid( nameList) if usedVPs != _lenPlotted and _lenPlotted != -1: clsFunc() _lenPlotted = usedVPs if usedVPs == 0: return if usedVPs == 1: ncol = 1 nrow = 1 elif usedVPs == 2: ncol = 1 nrow = 2 else: ncol = int( math.ceil( math.sqrt( usedVPs))) if usedVPs > definitions.MANY_GQES: ncol -= 1 nrow = int( math.ceil( (float(usedVPs))/float(ncol))) nplot = 1 if debug: print( "utils.setGqeVPs: after first pass: nrow %d, ncol %d nplot %d" % ( nrow, ncol, nplot)) for gqe in gqeList: # # overlay? - don't create a viewport gqe. # if gqe.overlay is not None and not flagDisplaySingle: # # maybe the gqe.overlay has beed deleted # if PySpectra.getGqe( gqe.overlay) is None: gqe.overlay = None else: continue if len( nameList) > 0: if gqe.name not in nameList: continue if gqe.plotItem is None: if gqe.at is None: gqe.ncol = ncol gqe.nrow = nrow gqe.nplot = nplot else: gqe.nrow = gqe.at[0] gqe.ncol = gqe.at[1] gqe.nplot = gqe.at[2] if gqe.nrow*gqe.ncol < gqe.nplot: raise ValueError( "utils.setGqeVPs: nrow %d * ncol %d < nplot %d, at %s" % \ (gqe.nrow, gqe.ncol, gqe.nplot, gqe.at)) nplot += 1 # # see if 2 GQEs occupie the same cell # for first in gqeList: if first.overlay: continue if len( nameList) > 0: if first.name not in nameList: continue for second in gqeList: if second.overlay: continue if first.name == second.name: continue if len( nameList) > 0: if second.name not in nameList: continue if first.nrow == second.nrow and \ first.ncol == second.ncol and \ first.nplot == second.nplot: raise ValueError( "utils.setGqeVPs: %s and %s in the same cell row, col, nplot: %d %d %d, nameList %s" % \ (first.name, second.name, first.nrow, first.ncol, first.nplot, repr( nameList))) if debug: for gqe in gqeList: if gqe.overlay is None: print( "utils.setGqeVPs.END: %s row, col, nplot: %d %d %d" % \ (gqe.name, gqe.nrow, gqe.ncol, gqe.nplot)) else: print( "utils.setGqeVPs.END: %s overlaid to %s" % \ (gqe.name, gqe.overlay)) return
def testToPyspLocalScan(self): import random print "testZmqIfc.testToPyspLocalScan" hsh = PySpectra.toPyspLocal({'command': ['cls', 'delete']}) self.assertEqual(hsh['result'], 'done') MAX = 25 pos = np.linspace(0, 10, MAX) d1 = np.random.random_sample((len(pos), )) * 1000. d2 = np.random.random_sample((len(pos), )) * 1000. PySpectra.toPyspLocal({'command': ['setTitle "testing Scan command"']}) self.assertEqual(hsh['result'], 'done') hsh = PySpectra.toPyspLocal( {'Scan': { 'name': "d1", 'x': pos, 'y': d1 }}) self.assertEqual(hsh['result'], 'done') hsh = PySpectra.toPyspLocal( {'Scan': { 'name': "d2", 'x': pos, 'y': d2 }}) self.assertEqual(hsh['result'], 'done') PySpectra.toPyspLocal({'command': ['setComment \"a comment\"']}) self.assertEqual(hsh['result'], 'done') PySpectra.toPyspLocal({'command': ['display']}) self.assertEqual(hsh['result'], 'done') PySpectra.processEventsLoop(1) lst = PySpectra.getGqeList() self.assertEqual(len(lst), 2) self.assertEqual(lst[0].name, "d1") self.assertEqual(lst[1].name, "d2") # # retrieve the data and compare # hsh = PySpectra.toPyspLocal({'getData': True}) for i in range(MAX): self.assertEqual(pos[i], hsh['getData']['D1']['x'][i]) self.assertEqual(d1[i], hsh['getData']['D1']['y'][i]) self.assertEqual(d2[i], hsh['getData']['D2']['y'][i]) # # set y-values # PySpectra.toPyspLocal( {'command': ['setTitle "set y-values to linear"']}) self.assertEqual(hsh['result'], 'done') for i in range(MAX): PySpectra.toPyspLocal( {'command': ['setY d1 %d %g' % (i, float(i) / 10.)]}) # # and compare # o = PySpectra.getGqe('d1') for i in range(MAX): self.assertEqual(o.y[i], float(i) / 10.) PySpectra.toPyspLocal({'command': ['cls', 'display']}) self.assertEqual(hsh['result'], 'done') PySpectra.processEventsLoop(1) print "testZmqIfc.testToPyspLocalScan DONE" return
def _setText(line): ''' setText gqeName textName string stringValue ... x xValue y yValue hAlign hAlignValue vAlign vAlignValue color colorValue fontSize fontSizeValue NDC NDCValue setText keyword gqeName the GQE (Scan, Image) which will receive the text textName the name of the textGqe string keyword stringValue the string to be displayed x keyword xValue the x-position y keyword yValue the y-position hAlign keyword hAlignValue left, right, center vAlign keyword vAlignValue top, bottom, center color keyword colorValue red, green, blue, yellow, cyan, magenta, black fontSize keyword fontSizeValue 12 example: setText s1 comment string \"this is a comment\" x 0.1 hAlign left y 0.9 hAlign top color red ''' lst = _mySplit(line) try: o = PySpectra.getGqe(lst[0]) except Exception as e: raise ValueError("ifc.setText: failed to gqeGqe %s" % lst[0]) flag = False # # first run: see, if textName is in textList # for t in o.textList: if t.name == lst[1]: flag = True break # # otherwise create it # if not flag: o.addText(name=lst[1], text=lst[2]) # # set the attributes of the text # # hAlign: 'left', 'right', 'center' # vAlign: 'top', 'bottom', 'center' # color: 'red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'black' # fontSize: e.g. 12 or None # if None, the fontsize is chosen automatically depending on the number of plots # NDC: True, normalized device coordinates # for t in o.textList: if t.name == lst[1]: for k, v in _pairs(lst[2:]): if k == 'string': if v[0] == '"' and v[-1] == '"': v = v[1:-1] t.text = v elif k == 'color': t.color = v elif k == 'fontSize': t.fontSize = int(v) elif k == 'NDC': t.NDC = bool(v) elif k == 'hAlign': t.hAlign = v elif k == 'vAlign': t.vAlign = v elif k == 'x': t.x = float(v) elif k == 'y': t.y = float(v) else: raise ValueError(" ifc.setText: failed to identify %s" % k) flag = True break return "done"