示例#1
0
def openDatabase(fileName, recordNames=[], recordTypes=[], displayStrings=[], replaceDict={}):
	if (fileName):
		file = open(fileName, "r")
	else:
		#print "openDatabase: No filename specified; nothing done."
		return recordNames

	for rawLine in file :
		global displayInfo
		rawLine = rawLine.lstrip()
		rawLine = dbd.doReplace(rawLine, replaceDict, reverse=True)
		split1 = rawLine.split("(")
		#print "openDatabase: split1=%s" % split1
		if len(split1[0]) > 0 and split1[0][0] == '#':
			continue
		if split1[0] == "record":
			rType = rawLine.split('(')[1].split(',')[0]
			rName = rawLine.split('"') [1]
			#print "openDatabase: found record: '%s'" % rName
			if rName not in recordNames:
				recordNames.append(rName)
				recordTypes.append(rType)
				if rType in displayInfo.keys():
					(prefix, name) = rName.split(':', 1)
					prefix = dbd.doReplace(prefix+':', replaceDict)
					name = dbd.doReplace(name, replaceDict)
					dString = displayInfo[rType][0] + ';'
					dString += displayInfo[rType][1] + '=%s,' % prefix
					dString += displayInfo[rType][2] + '=%s' % name
					displayStrings.append(dString)
				else:
					#print "no displayInfo for record type '%s'" % rType
					displayStrings.append("")
	return (recordNames, recordTypes, displayStrings)
示例#2
0
def writeNewMEDM_RDButtons(fileName,
                           recordNames,
                           recordTypes,
                           displayStrings=[],
                           replaceDict={},
                           EPICS_DISPLAY_PATH=[]):
    if (fileName):
        file = open(fileName, "w")
    else:
        file = sys.stdout
    file.write('\nfile {\n\tname="%s"\n\tversion=030102\n}\n' % fileName)

    file.write(
        'display {\n\tobject {\n\t\tx=%d\n\t\ty=%d\n\t\twidth=%d\n\t\theight=%d\n\t}\n'
        % (100, 100, 200, 20 + len(recordNames) * 25))
    file.write(
        '\tclr=14\n\tbclr=4\n\tcmap=""\n\tgridSpacing=5\n\tgridOn=0\n\tsnapToGrid=0\n}\n'
    )
    writeColorTable(file)
    for i in range(len(recordNames)):
        rName = recordNames[i]
        rType = recordTypes[i]
        displayString = displayStrings[i]
        file.write(
            '"related display" {\n\tobject {\n\t\tx=%d\n\t\ty=%d\n\t\twidth=150\n\t\theight=20\n\t}\n'
            % (10, 10 + i * 25))
        (display, macro) = displayString.split(';')
        newMacro = dbd.doReplace(macro, replaceDict)
        newName = dbd.doReplace(rName, replaceDict)
        file.write(
            '\tdisplay[0] {\n\t\tlabel="%s"\n\t\tname="%s"\n\t\targs="%s"\n\t}\n'
            % (newName, display, newMacro))
        file.write('\tclr=14\n\tbclr=51\n\tlabel="%c%s"\n}\n' % ('-', newName))
    file.close()
示例#3
0
def writeNewMEDM_Composites(fileName, recordNames, recordTypes, displayStrings=[], replaceDict={}, EPICS_DISPLAY_PATH=[]):

	geom=[]
	totalWidth = 0
	totalHeight = 10
	maxWidth = 0
	maxHeight = 0
	for i in range(len(recordNames)):
		rName = recordNames[i]
		rType = recordTypes[i]
		displayString = displayStrings[i]
		(display, macro) = displayString.split(';')
		displayFile = findFileInPath(display, EPICS_DISPLAY_PATH)
		if not displayFile:
			print "Can't find display file '%s' in EPICS_DISPLAY_PATH" % display
			return
		#print "writeNewMEDM_Composites: displayFile = ", displayFile
		dFile = open(displayFile, "r")
		lines = dFile.readlines()
		dFile.close()
		for i in range(len(lines)):
			line = lines[i].lstrip()
			if line.startswith('width'):
				width = int(line.split('=')[1])
				height = int(lines[i+1].lstrip().split('=')[1])
				geom.append((10, totalHeight, width, height))
				maxWidth = max(maxWidth, width)
				maxHeight = max(maxHeight, height)
				totalWidth = max(width, totalWidth)
				totalHeight += height+10
				break
		totalWidth += 20
		#print "writeNewMEDM_Composites: displayFile '%s'; w=%d,h=%d " % (displayFile, width, height)

	(geom, totalWidth, totalHeight) = makeGrid(geom, 10, maxWidth, maxHeight)

	if (fileName):
		fp = open(fileName, "w")
	else:
		fp = sys.stdout
	fp.write('\nfile {\n\tname="%s"\n\tversion=030102\n}\n' % fileName)
	fp.write('display {\n\tobject {\n\t\tx=%d\n\t\ty=%d\n\t\twidth=%d\n\t\theight=%d\n\t}\n' %
		(100, 100, totalWidth, totalHeight))
	fp.write('\tclr=14\n\tbclr=4\n\tcmap=""\n\tgridSpacing=5\n\tgridOn=0\n\tsnapToGrid=0\n}\n')
	writeColorTable(fp)
	for i in range(len(recordNames)):
		rName = recordNames[i]
		rType = recordTypes[i]
		displayString = displayStrings[i]
		(x,y,w,h) = geom[i]
		fp.write('composite {\n\tobject {\n\t\tx=%d\n\t\ty=%d\n\t\twidth=%d\n\t\theight=%d\n\t}\n' % (x,y, w, h))
		(display, macro) = displayString.split(';')
		newMacro = dbd.doReplace(macro, replaceDict)
		newName = dbd.doReplace(rName, replaceDict)
		fp.write('\t"composite name"=""\n')
		fp.write('\t"composite file"="%s;%s"\n}\n' % (display, newMacro))
	fp.close()
示例#4
0
 def addRecordName(self, event):
     rName = str(event.GetString().split(".")[0])
     if rName == "":
         self.SetStatusText("empty record name")
         return
     if HAVE_CA:
         pvName = rName + ".RTYP"
         try:
             rType = epics.caget(pvName)
         except:
             rType = "unknown"
     else:
         #print "rName=", rName
         print "Pretending to do caget('%s')" % (rName + ".RTYP")
         rType = "unknown"
     if rName in self.recordNames:
         self.SetStatusText("'%s' is already in the list of records" %
                            rName)
     else:
         self.recordNames.append(rName)
         self.recordTypes.append(rType)
         if rType in displayInfo.keys():
             (prefix, name) = rName.split(':', 1)
             replaceDict = makeReplaceDict(self.replaceTargets,
                                           self.replaceStrings)
             prefix = dbd.doReplace(prefix + ':', replaceDict)
             name = dbd.doReplace(name, replaceDict)
             del replaceDict
             dString = displayInfo[rType][0] + ';'
             dString += displayInfo[rType][1] + '=%s,' % prefix
             dString += displayInfo[rType][2] + '=%s' % name
             self.displayStrings.append(dString)
         else:
             #print "no displayInfo for record type '%s'" % rType
             self.SetStatusText("no displayInfo for record type '%s'" %
                                rType)
             self.displayStrings.append("")
         #print "add new record: ", rName
         self.mainPanel.Destroy()
         self.mainPanel = MainPanel(self)
         self.fillMainPanel()
         self.SendSizeEvent()
示例#5
0
def writeNewMEDM_RDButtons(fileName, recordNames, recordTypes, displayStrings=[], replaceDict={}, EPICS_DISPLAY_PATH=[]):
	if (fileName):
		file = open(fileName, "w")
	else:
		file = sys.stdout
	file.write('\nfile {\n\tname="%s"\n\tversion=030102\n}\n' % fileName)

	file.write('display {\n\tobject {\n\t\tx=%d\n\t\ty=%d\n\t\twidth=%d\n\t\theight=%d\n\t}\n' % (100, 100, 200, 20+len(recordNames)*25))
	file.write('\tclr=14\n\tbclr=4\n\tcmap=""\n\tgridSpacing=5\n\tgridOn=0\n\tsnapToGrid=0\n}\n')
	writeColorTable(file)
	for i in range(len(recordNames)):
		rName = recordNames[i]
		rType = recordTypes[i]
		displayString = displayStrings[i]
		file.write('"related display" {\n\tobject {\n\t\tx=%d\n\t\ty=%d\n\t\twidth=150\n\t\theight=20\n\t}\n' % (10, 10+i*25))
		(display, macro) = displayString.split(';')
		newMacro = dbd.doReplace(macro, replaceDict)
		newName = dbd.doReplace(rName, replaceDict)
		file.write('\tdisplay[0] {\n\t\tlabel="%s"\n\t\tname="%s"\n\t\targs="%s"\n\t}\n' % (newName, display, newMacro))
		file.write('\tclr=14\n\tbclr=51\n\tlabel="%c%s"\n}\n' % ('-', newName))
	file.close()
示例#6
0
	def addRecordName(self, event):
		rName = str(event.GetString().split(".")[0])
		if rName == "":
			self.SetStatusText("empty record name")
			return
		if HAVE_CA:
			pvName = rName+".RTYP"
			try:
				rType = caget(pvName)
			except:
				rType = "unknown"
		else:
			#print "rName=", rName
			print "Pretending to do caget('%s')" % (rName+".RTYP")
			rType = "unknown"
		if rName in self.recordNames:
			self.SetStatusText("'%s' is already in the list of records" % rName)
		else:
			self.recordNames.append(rName)
			self.recordTypes.append(rType)
			if rType in displayInfo.keys():
				(prefix, name) = rName.split(':', 1)
				replaceDict = makeReplaceDict(self.replaceTargets, self.replaceStrings)
				prefix = dbd.doReplace(prefix+':', replaceDict)
				name = dbd.doReplace(name, replaceDict)
				del replaceDict
				dString = displayInfo[rType][0] + ';'
				dString += displayInfo[rType][1] + '=%s,' % prefix
				dString += displayInfo[rType][2] + '=%s' % name
				self.displayStrings.append(dString)
			else:
				#print "no displayInfo for record type '%s'" % rType
				self.SetStatusText("no displayInfo for record type '%s'" % rType)
				self.displayStrings.append("")
			#print "add new record: ", rName
			self.mainPanel.Destroy()
			self.mainPanel = MainPanel(self)
			self.fillMainPanel()
			self.SendSizeEvent()
示例#7
0
def writeNewMEDM_Objects(fileName,
                         recordNames,
                         recordTypes,
                         displayStrings=[],
                         replaceDict={},
                         EPICS_DISPLAY_PATH=[]):

    geom = []
    totalWidth = 0
    totalHeight = 10
    maxWidth = 0
    maxHeight = 0
    for i in range(len(recordNames)):
        rName = recordNames[i]
        rType = recordTypes[i]
        displayString = displayStrings[i]
        (display, macro) = displayString.split(';')
        displayFile = findFileInPath(display, EPICS_DISPLAY_PATH)
        if not displayFile:
            print "Can't find display file '%s' in EPICS_DISPLAY_PATH" % display
            return
        #print "writeNewMEDM_Composites: displayFile = ", displayFile
        dFile = open(displayFile, "r")
        lines = dFile.readlines()
        dFile.close()
        for i in range(len(lines)):
            line = lines[i].lstrip()
            if line.startswith('width'):
                width = int(line.split('=')[1])
                height = int(lines[i + 1].lstrip().split('=')[1])
                geom.append((10, totalHeight, width, height))
                maxWidth = max(maxWidth, width)
                maxHeight = max(maxHeight, height)
                totalWidth = max(width, totalWidth)
                totalHeight += height + 10
                break
        totalWidth += 20
        #print "writeNewMEDM_Composites: displayFile '%s'; w=%d,h=%d " % (displayFile, width, height)

    # Get only the lines we'll use from the medm file
    startLine = 0
    for i in range(len(lines)):
        if (lines[i].startswith('"color map')):
            numColors = int(lines[i + 1].split("=")[1])
            startLine = i + numColors + 5
            #print "start line:", lines[startLine]

    (geom, totalWidth, totalHeight) = makeGrid(geom, 10, maxWidth, maxHeight)

    if (fileName):
        fp = open(fileName, "w")
    else:
        fp = sys.stdout
    fp.write('\nfile {\n\tname="%s"\n\tversion=030102\n}\n' % fileName)
    fp.write(
        'display {\n\tobject {\n\t\tx=%d\n\t\ty=%d\n\t\twidth=%d\n\t\theight=%d\n\t}\n'
        % (100, 100, totalWidth, totalHeight))
    fp.write(
        '\tclr=14\n\tbclr=4\n\tcmap=""\n\tgridSpacing=5\n\tgridOn=0\n\tsnapToGrid=0\n}\n'
    )
    writeColorTable(fp)

    for i in range(len(recordNames)):
        rName = recordNames[i]
        rType = recordTypes[i]
        displayString = displayStrings[i]
        (display, macro) = displayString.split(';')
        macros = macro.split(",")
        rDict = {}
        for m in macros:
            (target, replacement) = m.split("=")
            target = '$(%s)' % target
            rDict[target] = replacement

        (x, y, w, h) = geom[i]
        for line in lines[startLine:]:
            l = dbd.doReplace(line, rDict)
            fp.write(dbd.doReplace(l, replaceDict))
    fp.close()
示例#8
0
def writeNewMEDM_Objects(fileName, recordNames, recordTypes, displayStrings=[], replaceDict={}, EPICS_DISPLAY_PATH=[]):

	geom=[]
	totalWidth = 0
	totalHeight = 10
	maxWidth = 0
	maxHeight = 0
	for i in range(len(recordNames)):
		rName = recordNames[i]
		rType = recordTypes[i]
		displayString = displayStrings[i]
		(display, macro) = displayString.split(';')
		displayFile = findFileInPath(display, EPICS_DISPLAY_PATH)
		if not displayFile:
			print "Can't find display file '%s' in EPICS_DISPLAY_PATH" % display
			return
		#print "writeNewMEDM_Composites: displayFile = ", displayFile
		dFile = open(displayFile, "r")
		lines = dFile.readlines()
		dFile.close()
		for i in range(len(lines)):
			line = lines[i].lstrip()
			if line.startswith('width'):
				width = int(line.split('=')[1])
				height = int(lines[i+1].lstrip().split('=')[1])
				geom.append((10, totalHeight, width, height))
				maxWidth = max(maxWidth, width)
				maxHeight = max(maxHeight, height)
				totalWidth = max(width, totalWidth)
				totalHeight += height+10
				break
		totalWidth += 20
		#print "writeNewMEDM_Composites: displayFile '%s'; w=%d,h=%d " % (displayFile, width, height)

	# Get only the lines we'll use from the medm file
	startLine = 0
	for i in range(len(lines)):
		if (lines[i].startswith('"color map')):
			numColors = int(lines[i+1].split("=")[1])
			startLine = i+numColors+5
			#print "start line:", lines[startLine]

	(geom, totalWidth, totalHeight) = makeGrid(geom, 10, maxWidth, maxHeight)

	if (fileName):
		fp = open(fileName, "w")
	else:
		fp = sys.stdout
	fp.write('\nfile {\n\tname="%s"\n\tversion=030102\n}\n' % fileName)
	fp.write('display {\n\tobject {\n\t\tx=%d\n\t\ty=%d\n\t\twidth=%d\n\t\theight=%d\n\t}\n' %
		(100, 100, totalWidth, totalHeight))
	fp.write('\tclr=14\n\tbclr=4\n\tcmap=""\n\tgridSpacing=5\n\tgridOn=0\n\tsnapToGrid=0\n}\n')
	writeColorTable(fp)

	for i in range(len(recordNames)):
		rName = recordNames[i]
		rType = recordTypes[i]
		displayString = displayStrings[i]
		(display, macro) = displayString.split(';')
		macros = macro.split(",")
		rDict = {}
		for m in macros:
			(target, replacement) = m.split("=")
			target = '$(%s)' % target
			rDict[target] = replacement
		
		(x,y,w,h) = geom[i]
		for line in lines[startLine:]:
			l = dbd.doReplace(line, rDict)
			fp.write(dbd.doReplace(l, replaceDict))
	fp.close()