当前位置: 首页>>代码示例>>Python>>正文


Python SubElement.append方法代码示例

本文整理汇总了Python中elementtree.ElementTree.SubElement.append方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.append方法的具体用法?Python SubElement.append怎么用?Python SubElement.append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elementtree.ElementTree.SubElement的用法示例。


在下文中一共展示了SubElement.append方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: toXML

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import append [as 别名]
	def toXML(self):
		'''Generate the xml representation of the letter matrix'''
		# <control type="panel">
		control = Element('control', type='panel', id=str(CONTROL_PANEL))
		if True:
			SubElement(control, 'posx').text = str(self.posx)
			SubElement(control, 'posy').text = str(self.posy)
			SubElement(control, 'width').text = str(self.width)
			SubElement(control, 'height').text = str(self.height)
			SubElement(control, 'onleft').text = '-'
			SubElement(control, 'onright').text = '-'
			SubElement(control, 'onup').text = '-'
			SubElement(control, 'ondown').text = '-'
			SubElement(control, 'viewtype', label='').text = 'panel'
			SubElement(control, 'pagecontrol').text = '-'
			SubElement(control, 'scrolltime').text = '-'
			SubElement(control, 'hitrect', x=str(-10), y=str(-10), w=str(1), h=str(1))
			# <itemlayout>
			itemlayout = SubElement(control, 'itemlayout', height=str(self.letterHeight), width=str(self.letterWidth))
			if True:
				self.addItemLayout(itemlayout, self.theme.inactive, 1)
				self.addItemLayout(itemlayout, self.theme.active, 2)
			# </itemlayout>
			SubElement(control, 'focusedlayout', height=str(self.height), width=str(self.width))
			# <content>
			content = SubElement(control, 'content')
			if True:
				# <item>
				for letter in self.letters:
					content.append(letter.toXML())
				# </item>
			# </content>
		# </control>
		return control
开发者ID:MrShark,项目名称:unqlocked,代码行数:36,代码来源:gui.py

示例2: gencix

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import append [as 别名]
def gencix(major, minor):
    # First generate first pass at the CILE over all of the lib tree
    cixfile = "activeperl-%d.%d.cix" % (major, minor)
    command = "python ../../../ci2.py scan -n -r -p -l Perl -T /tmp/ActivePerl-%d.%d/perl/lib -i \"*.pm\"> %s" % (major, minor, cixfile)
    retval = os.system(command)
    if retval != 0:
        print "Error scanning ActivePerl library"
        sys.exit(retval)
    #    
    # Grab the output of that scan
    
    root = parse(cixfile).getroot()
    
    newroot = Element("codeintel", version="2.0")
    cixfile = SubElement(newroot, "file", lang="Perl",
                         mtime=str(int(time.time())),
                         path=os.path.basename('perl.cix'))
    
    for file in root.getiterator('file'):
        print >> sys.stderr, "Processing", file.get('path')
        for blob in file:
            if blob.get("src"):
                # Don't want the src string.
                del blob.attrib["src"]
            cixfile.append(blob)
    
    cix = genPerlStdCIX(cixfile, "/tmp/ActivePerl-%d.%d/perl/lib/pod/perlfunc.pod" % (major, minor))
        
    parent_map = dict((c, p) for p in cixfile.getiterator() for c in p)
    for variable in newroot.getiterator('variable'):
        attributes = variable.get('attributes')
        if attributes and '__local__' in variable.get('attributes'):
            parent_map[variable].remove(variable)

    # Generate the CIX.
    print >>sys.stderr, "Prettying"
    prettify(newroot)
    tree = ElementTree(newroot)
    #fname = '../../../lib/codeintel2/stdlibs/perl-%d.%d.cix' % (major, minor)
    fname = 'perl-%d.%d.cix' % (major, minor)
    #os.system('p4 edit %s' % fname)
    stream = open(fname, "w")
    print >>sys.stderr, "Writing"
    stream.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    tree.write(stream)
    stream.close()
开发者ID:Defman21,项目名称:KomodoEdit,代码行数:48,代码来源:genperlcix.py

示例3: __init__

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import append [as 别名]
    def __init__(self, lstData, GeoType, strPath, strFilename, strLayername):
            
            dctWriteKML = {'Point': self.writePoint, 'Polyline': self.writeLine, 'Polygon': self.writePolygon}

            #Create new element tree with a root of KML...
            
            objRoot = Element("{http://earth.google.com/kml/2.1}kml")
            objTree = ElementTree(element=objRoot)
            elemDoc = SubElement(objRoot, 'Document')
            elemDocName = SubElement(elemDoc, 'name')
    #According the KML spec, default Polystyle stuff goes here...
            elemDocName.text = strLayername
            #Add a document name element here...populate from supplied parameters
            for objRow in lstData:
                    elemPlace = SubElement(elemDoc, 'Placemark')
                    elemName =SubElement(elemPlace,'name')
                    elemName.text = objRow['Name']
                    #Add support for the description tag...
                    elemDesc = SubElement(elemPlace, 'description')
                    elemDesc.text = objRow['Description']
                    elemGeo = dctWriteKML.get(GeoType, self.errHandler)(objRow['Geometry'], elemPlace)
                    elemPlace.append(elemGeo)
            self.Write(objTree, strPath, strFilename)
开发者ID:WendyAnthony,项目名称:asset-map,代码行数:25,代码来源:pyGEarthWriteKML.py

示例4: add_task

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import append [as 别名]
 def add_task(self, taskid, tasktype, folder=None):
     """Add a task to the default xml task sheet
         
         Args:
             taskid: unique ID for new task for tracking individual tasks
             tasktype: Identifier to track purpose of task
             folder: Name of output folder if necessary
             
         Returns:
             None
 
         Raises:
             None
     """
     if tasktype == "processSolr":
         if folder == None:
             folder = self.solrFolder
             
             root = self.tree.getroot()
             newTask = SubElement(root, "task")
             newNode = Element("status")
             newNode.text = "pending"
             newTask.append(newNode)
             
             newNode = Element("taskid")
             newNode.text = str(taskid)
             newTask.append(newNode)
             
             newNode = Element("directory")
             newNode.text = str(folder)
             newTask.append(newNode)
             
             self.tree.write("outfile.xml")
             
         elif tasktype == "processTopic":
             print "Processing topic modeling data"
             if folder == None:
                 folder = self.topicFolder
         else:
             print "Unknown task" + tasktype
开发者ID:pete2212,项目名称:Synthosys-Code,代码行数:42,代码来源:xml_parser.py

示例5: main

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import append [as 别名]
def main():
    if len(sys.argv) != 2: 
            print 'Usage: ' + sys.argv[0] + ' <CSV file>' 
            sys.exit(1) 
        
    pathToCSV = sys.argv[1]
    
    f = open(pathToCSV)
    dataDict = csv.DictReader(f)
    intensity = "Resting"
    triggerMethod = "Distance"

    tcxTrackpoints = {}
    earliestEpochMS = earliestTimeInDict(dataDict)
    earliestEpoch = math.floor(int(earliestEpochMS) / 1000)

    root = Element("TrainingCenterDatabase")
    root.set("xsi:schemaLocation", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd")
    root.set("xmlns:ns2", "http://www.garmin.com/xmlschemas/UserProfile/v2")
    root.set("xmlns:ns3", "http://www.garmin.com/xmlschemas/ActivityExtension/v2")
    root.set("xmlns:ns4", "http://www.garmin.com/xmlschemas/ProfileExtension/v1")
    root.set("xmlns:ns5", "http://www.garmin.com/xmlschemas/ActivityGoals/v1")
    root.set("xmlns", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2")
    root.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")

    actsElement = SubElement(root, "Activities")
    actElement = SubElement(actsElement, "Activity", Sport="Running")

    idElement = SubElement(actElement, "Id")
    idElement.text = stringGMTimeFromEpoch(earliestEpoch)

    lastTimeEpoch = 0
    
    lapElement = SubElement(actElement, "Lap", StartTime=stringGMTimeFromEpoch(earliestEpoch))
    
    totalDistanceMeters = 0
    maxSpeed = 0
    calories = 0.0
    maxBPM = 0    
    numRows = 0
    totalBPM = 0
    
    trackpoints = list()
    
    for row in dataDict:
        trackpointElement = Element("Trackpoint")
        trackpoints.append(trackpointElement)
        
        # TIME
        epochMS = row['timestamp_epoch']
        epoch = math.floor(int(epochMS) / 1000)
        timeElement = SubElement(trackpointElement, "Time")
        timeElement.text = stringGMTimeFromEpoch(epoch)

        # POSITION
        latValue = row['LATITUDE']
        longValue = row['LONGITUDE']
        
        if (abs(float(latValue)) <= 180 and abs(float(longValue)) <= 180
            and abs(float(latValue)) > 0.1 and abs(float(longValue)) > 0.1):
            posElement = SubElement(trackpointElement, "Position")
            latElement = SubElement(posElement, "LatitudeDegrees")
            latElement.text = latValue
            longElement = SubElement(posElement, "LongitudeDegrees")
            longElement.text = longValue
        
        # Altitude
        alt = row['ELEVATION']
        altElement = SubElement(trackpointElement, "AltitudeMeters")
        altElement.text = alt

        # DISTANCE
        distanceMeters = row['DISTANCE']
        distElement = SubElement(trackpointElement, "DistanceMeters")
        distElement.text = distanceMeters

        # BPM
        heartRate = math.trunc(float(row['HEARTRATE']))
        # if heartRate > 0:
        bpmElement = SubElement(trackpointElement, 'HeartRateBpm xsi:type=\"HeartRateInBeatsPerMinute_t\"')
        bpmValElement = SubElement(bpmElement, "Value")
        bpmValElement.text = str(heartRate)
                
        extElement = SubElement(trackpointElement, 'Extensions')
        
        # SPEED
        speed = float(row['SPEED'])
        speed *= MPS_TO_MPH
        ns3Element = SubElement(extElement, 'ns3:TPX')
        speedElement = SubElement(ns3Element, 'ns3:Speed')
        speedElement.text = str(speed)
                
        if lastTimeEpoch == 0 or epoch > lastTimeEpoch:
            lastTimeEpoch = epoch

        if totalDistanceMeters == 0 or float(distanceMeters) > float(totalDistanceMeters):
            totalDistanceMeters = distanceMeters

        rowCalories = row['CALORIEBURN']        
        calories = rowCalories
#.........这里部分代码省略.........
开发者ID:chazmatazz,项目名称:MotoACTV-tcx,代码行数:103,代码来源:motoactv_tcx.py

示例6: main

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import append [as 别名]
def main(argv):

    scale = 1.0
    pathToCSV = ""
    forceHRM = False
    removePauses = False
    sport = "Running"
    lat = 0.0
    longt = 0.0
    ylat = 37.337766
    ylong = -121.920347

    try:
        opts, args = getopt.getopt(argv, "hbpYs:i:t:l:",["scale=", "ifile=", "sport=", "location="])
    except getopt.GetoptError:
        usage()
        sys.exit(1)

    for opt, arg in opts:
        if opt == '-h':
            usage()
            sys.exit()
        elif opt in ("-s", "--scale"):
            scale = float(arg)
        elif opt in ("-i", "--ifile"):
            pathToCSV = arg
        elif opt in ("-t", "--sport"):
            sport = arg
        elif opt in ("-l", "--location"):
            lat, longt = arg.split(",")
            lat = float(lat)
            longt = float(longt)
        elif opt == '-Y':
            lat = ylat
            longt = ylong
        elif opt == '-b':
            forceHRM = True
        elif opt == '-p':
            removePauses = True
        
    if pathToCSV == "":
        usage()
        sys.exit(1) 
    
    f = open(pathToCSV)
    dataDict = csv.DictReader(f)
    intensity = "Resting"
    triggerMethod = "Distance"

    tcxTrackpoints = {}
    earliestEpochMS = earliestTimeInDict(dataDict)
    earliestEpoch = math.floor(int(earliestEpochMS) / 1000)

    root = Element("TrainingCenterDatabase")
    root.set("xsi:schemaLocation", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd")
    root.set("xmlns:ns2", "http://www.garmin.com/xmlschemas/UserProfile/v2")
    root.set("xmlns:ns3", "http://www.garmin.com/xmlschemas/ActivityExtension/v2")
    root.set("xmlns:ns4", "http://www.garmin.com/xmlschemas/ProfileExtension/v1")
    root.set("xmlns:ns5", "http://www.garmin.com/xmlschemas/ActivityGoals/v1")
    root.set("xmlns", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2")
    root.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")

    actsElement = SubElement(root, "Activities")
    actElement = SubElement(actsElement, "Activity", Sport=sport)

    idElement = SubElement(actElement, "Id")
    idElement.text = stringGMTimeFromEpoch(earliestEpoch)

    lastTimeEpoch = 0
    
    lapElement = SubElement(actElement, "Lap", StartTime=stringGMTimeFromEpoch(earliestEpoch))
    
    totalDistanceMeters = 0
    maxSpeed = 0
    calories = 0.0
    maxBPM = 0    
    maxSpeed = 0.0
    numRows = 0
    totalBPM = 0
    epochStart = 0
    diff = 0
    
    trackpoints = list()
    
    for row in dataDict:
        speed = scale * float(row['SPEED'])
        stepRate = int(row['STEP_RATE'])
        mCadence = int(row['CADENCE'])

        if speed > maxSpeed:
            maxSpeed = speed

        if not removePauses or (speed > 0 and stepRate > 0):
            if epochStart != 0:
                diff += int(row['timestamp_epoch']) - epochStart
                epochStart = 0

            trackpointElement = Element("Trackpoint")
            trackpoints.append(trackpointElement)
        
#.........这里部分代码省略.........
开发者ID:fifors,项目名称:MotoACTV-tcx,代码行数:103,代码来源:motoactv_tcx.py


注:本文中的elementtree.ElementTree.SubElement.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。