def widgetActive(path,xmlfile="data.xml",configfile="config.cfg",screenname="InfoBar"):
	xml = ""
	try:
		raw_xml = metrixTools.getFile(path+"/"+xmlfile)
		#Read config file
		skinpartconfig = ConfigParser.RawConfigParser()
		skinpartconfig.read(path+"/"+configfile)
		
		try:
			target = skinpartconfig.get("screen",screenname.lower())
			if target == "" or target == None:
				skinPartNode = False
		except Exception, e:
			metrixTools.log("No config.cfg found in "+path)	
	except Exception, e:
		metrixTools.log("Error parsing SkinPart!",e)
		skinPartNode = None
def widgetActive(path,
                 xmlfile="data.xml",
                 configfile="config.cfg",
                 screenname="InfoBar"):
    xml = ""
    try:
        raw_xml = metrixTools.getFile(path + "/" + xmlfile)
        #Read config file
        skinpartconfig = ConfigParser.RawConfigParser()
        skinpartconfig.read(path + "/" + configfile)

        try:
            target = skinpartconfig.get("screen", screenname.lower())
            if target == "" or target == None:
                skinPartNode = False
        except Exception, e:
            metrixTools.log("No config.cfg found in " + path)
    except Exception, e:
        metrixTools.log("Error parsing SkinPart!", e)
        skinPartNode = None
def parseSkinPart(path,xmlfile="data.xml",configfile="config.cfg",screenname="InfoBar",isScreen=True):
	xml = ""
	try:
		raw_xml = metrixTools.getFile(path+"/"+xmlfile)
		raw_xml = replaceGlobalVariables(raw_xml)
		if isScreen:
			raw_xml = raw_xml.replace("%SCREENNAME%",screenname)
		#Read config file
		skinpartconfig = ConfigParser.RawConfigParser()
		skinpartconfig.read(path+"/"+configfile)
		tempxml = parseString(raw_xml)
		
		raw_xml = raw_xml.replace('SKINPART/', path + "/images/")
		vars = {}
		try:
			for item in skinpartconfig.items("variable"):
				raw_xml = raw_xml.replace("%"+item[0]+"%",item[1])
			
				vars[item[0]] = item[1]
		except ConfigParser.NoSectionError:
			for var in tempxml.getElementsByTagName('variable'):
				if str(var.getAttributeNode('type').nodeValue) != "static":
					variable = str(var.getAttributeNode('name').nodeValue)
					value = str(var.getAttributeNode('value').nodeValue)
					raw_xml = raw_xml.replace("%"+variable+"%",value)
					vars[variable] = value
		for var in tempxml.getElementsByTagName('variable'):
			if str(var.getAttributeNode('type').nodeValue) == "static":
				variable = str(var.getAttributeNode('name').nodeValue)
				value = str(var.getAttributeNode('value').nodeValue)
				raw_xml = raw_xml.replace("%"+variable+"%",value)
				vars[variable] = value
		
		
		### Parse XML
		xml = parseString(raw_xml)	
		try:
			skinPartNode = xml.getElementsByTagName('screen')[0]
		except:
			skinPartNode = xml.getElementsByTagName('skinpartwidget')[0]
			skinPartNode.setAttribute('screenname',getTargetScreens(skinpartconfig,skinPartNode.getAttribute('screenname')))


		for ifNode in skinPartNode.getElementsByTagName('if'):
			variable = str(ifNode.getAttributeNode('variable').nodeValue)
			value = str(ifNode.getAttributeNode('value').nodeValue)
			if value == vars[variable]:
				for child in ifNode.childNodes:
					newchild = child.cloneNode(True)
					skinPartNode.appendChild(newchild)
			skinPartNode.removeChild(ifNode)
		for ifNode in skinPartNode.getElementsByTagName('ifnot'):
			variable = str(ifNode.getAttributeNode('variable').nodeValue)
			value = str(ifNode.getAttributeNode('value').nodeValue)
			if value != vars[variable]:
				for child in ifNode.childNodes:
					newchild = child.cloneNode(True)
					skinPartNode.appendChild(newchild)
			skinPartNode.removeChild(ifNode)
		
		
		for varNode in skinPartNode.getElementsByTagName('variable'):
			skinPartNode.removeChild(varNode)
			
		## RELATIVE POSITIONING SETTINGS	
		for node in skinPartNode.childNodes:
			try:
				position = node.getAttribute('position').split(",")
				x = int(position[0]) + skinpartconfig.getint("rel_position","posx")
				y = int(position[1]) + skinpartconfig.getint("rel_position","posy")
				node.setAttribute('position',str(x)+","+str(y))
			except:
				pass
	
	except Exception, e:
		metrixTools.log("Error parsing SkinPart!",e)
		skinPartNode = None
def parseSkinPart(path,
                  xmlfile="data.xml",
                  configfile="config.cfg",
                  screenname="InfoBar",
                  isScreen=True):
    xml = ""
    try:
        raw_xml = metrixTools.getFile(path + "/" + xmlfile)
        raw_xml = replaceGlobalVariables(raw_xml)
        if isScreen:
            raw_xml = raw_xml.replace("%SCREENNAME%", screenname)
        #Read config file
        skinpartconfig = ConfigParser.RawConfigParser()
        skinpartconfig.read(path + "/" + configfile)
        tempxml = parseString(raw_xml)

        raw_xml = raw_xml.replace('SKINPART/', path + "/images/")
        vars = {}
        try:
            for item in skinpartconfig.items("variable"):
                raw_xml = raw_xml.replace("%" + item[0] + "%", item[1])

                vars[item[0]] = item[1]
        except ConfigParser.NoSectionError:
            for var in tempxml.getElementsByTagName('variable'):
                if str(var.getAttributeNode('type').nodeValue) != "static":
                    variable = str(var.getAttributeNode('name').nodeValue)
                    value = str(var.getAttributeNode('value').nodeValue)
                    raw_xml = raw_xml.replace("%" + variable + "%", value)
                    vars[variable] = value
        for var in tempxml.getElementsByTagName('variable'):
            if str(var.getAttributeNode('type').nodeValue) == "static":
                variable = str(var.getAttributeNode('name').nodeValue)
                value = str(var.getAttributeNode('value').nodeValue)
                raw_xml = raw_xml.replace("%" + variable + "%", value)
                vars[variable] = value

        ### Parse XML
        xml = parseString(raw_xml)
        try:
            skinPartNode = xml.getElementsByTagName('screen')[0]
        except:
            skinPartNode = xml.getElementsByTagName('skinpartwidget')[0]
            skinPartNode.setAttribute(
                'screenname',
                getTargetScreens(skinpartconfig,
                                 skinPartNode.getAttribute('screenname')))

        for ifNode in skinPartNode.getElementsByTagName('if'):
            variable = str(ifNode.getAttributeNode('variable').nodeValue)
            value = str(ifNode.getAttributeNode('value').nodeValue)
            if value == vars[variable]:
                for child in ifNode.childNodes:
                    newchild = child.cloneNode(True)
                    skinPartNode.appendChild(newchild)
            skinPartNode.removeChild(ifNode)
        for ifNode in skinPartNode.getElementsByTagName('ifnot'):
            variable = str(ifNode.getAttributeNode('variable').nodeValue)
            value = str(ifNode.getAttributeNode('value').nodeValue)
            if value != vars[variable]:
                for child in ifNode.childNodes:
                    newchild = child.cloneNode(True)
                    skinPartNode.appendChild(newchild)
            skinPartNode.removeChild(ifNode)

        for varNode in skinPartNode.getElementsByTagName('variable'):
            skinPartNode.removeChild(varNode)

        ## RELATIVE POSITIONING SETTINGS
        for node in skinPartNode.childNodes:
            try:
                position = node.getAttribute('position').split(",")
                x = int(position[0]) + skinpartconfig.getint(
                    "rel_position", "posx")
                y = int(position[1]) + skinpartconfig.getint(
                    "rel_position", "posy")
                node.setAttribute('position', str(x) + "," + str(y))
            except:
                pass

    except Exception, e:
        metrixTools.log("Error parsing SkinPart!", e)
        skinPartNode = None