예제 #1
0
파일: tk_app.py 프로젝트: YQS/eXMLorer
def createNewTagInTree(mainApp, baseTIG, mode, oTag=None, is_comment=False, text=''):
	if baseTIG <> None:
		if baseTIG.parent_id <> '':
			#consigo datos para nuevo tag
			xTag = ''
			if is_comment:
				xTag = 'comment'
				stringXML = xml_man.getStringXML(baseTIG.getTag())
				xText = stringXML[ stringXML.find('\n')+1:]
			elif text <> '':
				xTag = getTagFromUser(mainApp)
				xText = text
			elif oTag == None:
				xTag, xText = getTagFromUser(mainApp, getValue=True)
				
			if (xTag <> '') or (oTag <> None):
				xAttrib = {}
				#consigo datos para crear el TagInTree
				if mode == 'SIBLING':
					xBaseID = baseTIG.parent_id
					xParentTag = baseTIG.parent_tag
					xOrder = baseTIG.getTreeViewIndex() + 1
				elif mode == 'CHILD':
					xBaseID = baseTIG.id
					xParentTag = baseTIG.getTag()
					xOrder = baseTIG.getNumberOfSiblings() + 1
				
				#creo o inserto el tag en el XML
				if is_comment:
					xNewTag = xml_man.newComment(xParentTag, xText, xOrder)
				elif oTag == None:
					xNewTag = xml_man.newElement(xParentTag, xTag, xText, xAttrib, xOrder)
				else:
					if mode == 'SIBLING':
						xml_man.insertElement(xParentTag, oTag, xOrder)
					xNewTag = oTag
				
				#creo el newTagInTree
				if is_comment:
					xID = getIDForTreeView( 'comment', GL.dicTagsInTree)
					newTagInTree = TIG.TagInTree(xBaseID, xID, xNewTag, xParentTag, GL.appTreeView, order = xOrder, is_comment=True)
				else:
					xID = getIDForTreeView( xNewTag.tag, GL.dicTagsInTree)
					newTagInTree = TIG.TagInTree(xBaseID, xID, xNewTag, xParentTag, GL.appTreeView, order = xOrder)
					
				GL.dicTagsInTree[xID] = newTagInTree
				selectAndFocus(xID)
				print 'newTagInTree'
				return newTagInTree
예제 #2
0
파일: tk_app.py 프로젝트: YQS/eXMLorer
def copyTagInTree(oldTagInTree, xLevel, newparent = None):
	if oldTagInTree <> None:
		if newparent == None:
			xParentID = oldTagInTree.parent_id
			xParentTag = oldTagInTree.parent_tag
		else:
			xParentID = newparent.id
			xParentTag = newparent.getTag()
		
		xOrder = oldTagInTree.getTreeViewIndex() + 1
		
		xNewTag = xml_man.newElement( xParentTag,
									  oldTagInTree.getTag().tag,
									  oldTagInTree.getTag().text,
									  oldTagInTree.getTag().attrib,
									  xOrder)
		
		xID = getIDForTreeView( xNewTag.tag, GL.dicTagsInTree)
		
		newTagInTree = TIG.TagInTree(xParentID, xID, xNewTag, xParentTag, GL.appTreeView, order = xOrder)
		GL.dicTagsInTree[xID] = newTagInTree
		
		def getTagInTreeFromTag(xTag, dicTagsInTree):
			xReturn = None
			for xTuple in dicTagsInTree.items():
				#xTuple = (key, value)
				if xTuple[1].getTag() == xTag:
					xReturn = xTuple[1]
					break
			return xReturn
			
		for xChildTag in oldTagInTree.getTag():
			xChildTagInTree = getTagInTreeFromTag(xChildTag, GL.dicTagsInTree)
			copyTagInTree( xChildTagInTree, xLevel + 1, newparent = newTagInTree)
			
		selectAndFocus(xID)
			
	else:
		print 'oldTagInTree is None'