def readSettings ( self ): # read XML by QXmlStreamReader # fix changed locations between versions try: from PyQt4.QtCore import QXmlStreamReader except: from PyQt4.QtXml import QXmlStreamReader from PyQt4.QtCore import QXmlStreamReader if ( self.file.open( QtCore.QIODevice.ReadWrite | QtCore.QIODevice.Text ) ) : xml = QXmlStreamReader( self.file ) label = '' while not xml.atEnd(): token = xml.readNext() if token == QXmlStreamReader.StartElement: name = xml.name() attr = xml.attributes() if name == 'preset' : label = str( "%s" % attr.value('name').toString() ) #print "label = %s" % label self.presets[ label ] = {} elif name in self.key_list.keys() : section = str( name.toString() ) #print "section = %s" % section item_list = {} for key in self.key_list[ section ] : value = str( "%s" % attr.value( key ).toString() ) item_list[key] = value #print "%s = %s" % (key, value) self.presets[ label ].setdefault( section, item_list.copy() ) self.file.close()
def parseHtml(self, htmlTemplate): # reload smartObject each time self.smartObject = self.entryModel.getSmartObject() #TODO remove QString reader = QXmlStreamReader(htmlTemplate) tmpList = [] while not reader.atEnd(): reader.readNext() name = unicode(reader.name().toString()) if reader.isStartElement(): attributes = reader.attributes() if name == "ldapobject": tmpList.append(self.createStringFromTemplate(attributes)) else: if not attributes.isEmpty(): size = attributes.size() list = [] for i in range(0, size): attribute = attributes.at(i) attributeName = unicode( attribute.name().toString()) attributeValue = unicode( attribute.value().toString()) attributeString = '%s="%s"' % (attributeName, attributeValue) list.append(attributeString) attributesString = ' '.join(list) tag = "<%s %s>" % (name, attributesString) tmpList.append(tag) else: tag = "<%s>" % name tmpList.append(tag) elif reader.isEndElement(): if not (name == "ldapobject"): tag = "</%s>" % name tmpList.append(tag) elif reader.isCharacters(): if not (unicode(reader.name()) == "ldapobject"): tmpList.append(unicode(reader.text().toString())) if reader.hasError(): return reader.errorString() return ''.join(tmpList)
def parseHtml(self, htmlTemplate): # reload smartObject each time self.smartObject = self.entryModel.getSmartObject() #TODO remove QString reader = QXmlStreamReader(htmlTemplate) tmpList = [] while not reader.atEnd(): reader.readNext() name = unicode(reader.name().toString()) if reader.isStartElement(): attributes = reader.attributes() if name == "ldapobject": tmpList.append(self.createStringFromTemplate(attributes)) else: if not attributes.isEmpty(): size = attributes.size() list = [] for i in range(0, size): attribute = attributes.at(i) attributeName = unicode(attribute.name().toString()) attributeValue = unicode(attribute.value().toString()) attributeString = '%s="%s"' % (attributeName, attributeValue) list.append(attributeString) attributesString = ' '.join(list) tag = "<%s %s>" % (name, attributesString) tmpList.append(tag) else: tag = "<%s>" % name tmpList.append(tag) elif reader.isEndElement(): if not (name == "ldapobject"): tag = "</%s>" % name tmpList.append(tag) elif reader.isCharacters(): if not (unicode(reader.name()) == "ldapobject"): tmpList.append(unicode(reader.text().toString())) if reader.hasError(): return reader.errorString() return ''.join(tmpList)
class CXmlReading: def __init__(self): self._xmlReader = QXmlStreamReader() def readNext(self): return self._xmlReader.readNext() def atEnd(self): return self._xmlReader.atEnd() def name(self): return self._xmlReader.name() def readElementText(self): return self._xmlReader.readElementText() def isStartElement(self): return self._xmlReader.isStartElement() def isEndElement(self): return self._xmlReader.isEndElement()
def readNext(self): QXmlStreamReader.readNext(self) self.parent.progressBar.setValue(self.device().pos())
def readNext(self): QXmlStreamReader.readNext(self) if hasattr(self.parent, "progressBar"): self.parent.progressBar.setValue(self.device().pos())