Ejemplo n.º 1
0
	def openFile(self, pth):
		if not os.path.exists(pth):
			dabo.ui.stop("The file '%s' does not exist" % pth)
			return
		self._menuFile = pth
		xml = open(pth).read()
		try:
			dct = xtd.xmltodict(xml)
		except:
			raise IOError(_("This does not appear to be a valid menu file."))
		self.makeMenuBar(dct)
		self.layout()
		self.saveState()
Ejemplo n.º 2
0
	def openFile(self, pth):
		if not os.path.exists(pth):
			dabo.ui.stop("The file '%s' does not exist" % pth)
			return
		self._menuFile = pth
		xml = open(pth).read()
		try:
			dct = xtd.xmltodict(xml)
		except:
			raise IOError(_("This does not appear to be a valid menu file."))
		self.makeMenuBar(dct)
		self.layout()
		self.saveState()
Ejemplo n.º 3
0
	def importXmlSrc(self, src):
		"""This will read in an XML source. The parameter can be a
		file path, an open file object, or the raw XML. It will look for
		a matching code file and, if found, import that code.
		"""
		parseCode = True
		if isinstance(src, file):
			xml = src.read()
			self._srcFile = src.name
		else:
			xml = src
			if not src.startswith("<"):
				xml = src = utils.resolvePathAndUpdate(src)
			if os.path.exists(src):
				self._srcFile = src
			else:
				parseCode = False
				self._srcFile = os.getcwd()
		return xtd.xmltodict(xml)
Ejemplo n.º 4
0
	def importXmlSrc(self, src):
		"""This will read in an XML source. The parameter can be a
		file path, an open file object, or the raw XML. It will look for
		a matching code file and, if found, import that code.
		"""
		parseCode = True
		if isinstance(src, file):
			xml = src.read()
			self._srcFile = src.name
		else:
			xml = src
			if not src.startswith("<"):
				xml = src = utils.resolvePathAndUpdate(src)
			if os.path.exists(src):
				self._srcFile = src
			else:
				parseCode = False
				self._srcFile = os.getcwd()
		return xtd.xmltodict(xml)
Ejemplo n.º 5
0
def pt2f(pt):
    return float(pt.strip("'").split()[0])

def get_attrib_val(obj, attrib):
    for attribs in obj['children']:
        if attribs['name']==attrib:
            return attribs['cdata']

def set_attrib_val(obj, attrib, val):
    for attribs in obj['children']:
        if attribs['name']==attrib:
            attribs['cdata'] = val

# get master copy into a dict
rf=open('badge.rfxml').read()
rfd=xmltodict.xmltodict(rf)

objs=rfd['children'][7]['children'][1]['children']
newobjs=copy.deepcopy(objs)

for obj in newobjs:
    x = pt2f(get_attrib_val(obj,'x'))
    y = pt2f(get_attrib_val(obj,'y'))
    comment = get_attrib_val(obj,'Comment')
    if x <= 290 and y >=370 and comment == "'copy badge'":
        print comment
        # found a badge object, copy it, shift it 288 points to the right.
        newobj=copy.deepcopy(obj)
        x = get_attrib_val(obj,'x')
        newx = "'%s pt'" % (pt2f(x)+288)
        set_attrib_val(newobj, 'x', newx )