def nodeParents(dom, node): parents = [] parent = xpath.findnode('..', node) while parent and not isinstance(parent, minidom.Document): parents.append(parent) parent = xpath.findnode('..', parent) return parents
def nodeParents(dom,node): parents = [] parent = xpath.findnode('..',node) while parent and not isinstance(parent,minidom.Document): parents.append(parent) parent = xpath.findnode('..',parent) return parents
def getVariable(self,name): var = xpath.findnode(".//variable[attribute::name='{0}']".format(name),xpath.findnode('includes',self.xml)) if not var: return '' for val in xpath.find('.//value',var): conditionAttr = val.attributes.get('condition') if not conditionAttr: return val.childNodes[0].data or '' else: if xbmc.getCondVisibility(conditionAttr.value): #print condition #print repr(val.string) return val.childNodes[0].data or '' return ''
def getVariable(self, name): var = xpath.findnode(".//variable[attribute::name='{0}']".format(name), xpath.findnode('includes', self.xml)) if not var: return '' for val in xpath.find('.//value', var): conditionAttr = val.attributes.get('condition') if not conditionAttr: return val.childNodes[0].data or '' else: if xbmc.getCondVisibility(conditionAttr.value): #print condition #print repr(val.string) return val.childNodes[0].data or '' return ''
def processIncludes(self): self.includes = Includes() for i in xpath.find('//include',self.xml): conditionAttr = i.attributes.get('condition') if conditionAttr and not xbmc.getCondVisibility(conditionAttr.value): xpath.findnode('..',i).removeChild(i) continue matchingInclude = self.includes.getInclude(i.childNodes[0].data) if not matchingInclude: #print 'INCLUDE NOT FOUND: %s' % i.string continue #print 'INCLUDE FOUND: %s' % i.string new = matchingInclude.cloneNode(True) xpath.findnode('..',i).replaceChild(new,i)
def processIncludes(self): self.includes = Includes() for i in xpath.find('//include', self.xml): conditionAttr = i.attributes.get('condition') if conditionAttr and not xbmc.getCondVisibility( conditionAttr.value): xpath.findnode('..', i).removeChild(i) continue matchingInclude = self.includes.getInclude(i.childNodes[0].data) if not matchingInclude: #print 'INCLUDE NOT FOUND: %s' % i.string continue #print 'INCLUDE FOUND: %s' % i.string new = matchingInclude.cloneNode(True) xpath.findnode('..', i).replaceChild(new, i)
def controlIsVisible(self,control): visible = xpath.findnode('visible',control) if not visible: return True if not visible.childNodes: return True condition = visible.childNodes[0].data if self.currentControl: condition = condition.replace('ListItem.Property','Container({0}).ListItem.Property'.format(self.currentControl)) if not xbmc.getCondVisibility(condition): return False else: return True
def loadIncludesFiles(self): if self._includesFilesLoaded: return basePath = getXBMCSkinPath('') for i in xpath.find('//include',xpath.findnode('//includes',self.xml)): fileAttr = i.attributes.get('file') if fileAttr: xmlName = xbmc.validatePath(fileAttr.value) p = os.path.join(basePath,xmlName) if not os.path.exists(p): continue xml = minidom.parse(p) includes = xpath.findnode('includes',xml) xpath.findnode('..',i).replaceChild(includes,i) for sub_i in xpath.find('.//include',includes): nameAttr = sub_i.attributes.get('name') if nameAttr: self.includesMap[nameAttr.value] = sub_i else: nameAttr = i.attributes.get('name') if nameAttr: self.includesMap[nameAttr.value] = i.cloneNode(True) self._includesFilesLoaded = True
def getLabelText(self,label): l = xpath.findnode('label',label) text = None if label.attributes.get('id'): #Try getting programatically set label first. text = xbmc.getInfoLabel('Control.GetLabel({0})'.format(label.attributes.get('id').value)).decode('utf-8') if not text or text == '-': text = None if l and l.childNodes: text = l.childNodes[0].data if text: if text.isdigit(): text = '$LOCALIZE[{0}]'.format(text) else: i = xpath.findnode('info',label) if i and i.childNodes: text = i.childNodes[0].data if text.isdigit(): text = '$LOCALIZE[{0}]'.format(text) else: text = '$INFO[{0}]'.format(text) if not text: return None return tagRE.sub('',text).replace('[CR]','... ').strip(' .')
def controlIsVisible(self, control): visible = xpath.findnode('visible', control) if not visible: return True if not visible.childNodes: return True condition = visible.childNodes[0].data if self.currentControl: condition = condition.replace( 'ListItem.Property', 'Container({0}).ListItem.Property'.format(self.currentControl)) if not xbmc.getCondVisibility(condition): return False else: return True
def getLabelText(self, label): l = xpath.findnode('label', label) text = None if label.attributes.get('id'): #Try getting programatically set label first. text = xbmc.getInfoLabel('Control.GetLabel({0})'.format( label.attributes.get('id').value)).decode('utf-8') if not text or text == '-': text = None if l and l.childNodes: text = l.childNodes[0].data if text: if text.isdigit(): text = '$LOCALIZE[{0}]'.format(text) else: i = xpath.findnode('info', label) if i and i.childNodes: text = i.childNodes[0].data if text.isdigit(): text = '$LOCALIZE[{0}]'.format(text) else: text = '$INFO[{0}]'.format(text) if not text: return None return tagRE.sub('', text).replace('[CR]', '... ').strip(' .')
def loadIncludesFiles(self): if self._includesFilesLoaded: return basePath = getXBMCSkinPath('') for i in xpath.find('//include', xpath.findnode('//includes', self.xml)): fileAttr = i.attributes.get('file') if fileAttr: xmlName = xbmc.validatePath(fileAttr.value) p = os.path.join(basePath, xmlName) if not os.path.exists(p): continue xml = minidom.parse(p) includes = xpath.findnode('includes', xml) xpath.findnode('..', i).replaceChild(includes, i) for sub_i in xpath.find('.//include', includes): nameAttr = sub_i.attributes.get('name') if nameAttr: self.includesMap[nameAttr.value] = sub_i else: nameAttr = i.attributes.get('name') if nameAttr: self.includesMap[nameAttr.value] = i.cloneNode(True) self._includesFilesLoaded = True
def getListItemTexts(self,controlID): self.currentControl = controlID try: clist = self.getControl(controlID) if not clist: return None fl = xpath.findnode("focusedlayout",clist) if not fl: return None lt = xpath.find("//control[attribute::type='label' or attribute::type='fadelabel' or attribute::type='textbox']",fl) texts = [] for l in lt: if not self.controlIsVisibleGlobally(l): continue text = self.getLabelText(l) if text and not text in texts: texts.append(text) return self.processTextList(texts) finally: self.currentControl = None
def getListItemTexts(self, controlID): self.currentControl = controlID try: clist = self.getControl(controlID) if not clist: return None fl = xpath.findnode("focusedlayout", clist) if not fl: return None lt = xpath.find( "//control[attribute::type='label' or attribute::type='fadelabel' or attribute::type='textbox']", fl) texts = [] for l in lt: if not self.controlIsVisibleGlobally(l): continue text = self.getLabelText(l) if text and not text in texts: texts.append(text) return self.processTextList(texts) finally: self.currentControl = None
def getControl(self, controlID): return xpath.findnode( "//control[attribute::id='{0}']".format(controlID), self.xml)
def getControl(self,controlID): return xpath.findnode("//control[attribute::id='{0}']".format(controlID),self.xml)