def loadSetup(self): indihostfile = QtCore.QFile( KStandardDirs.locate("data", "kstars/indihosts.xml")) #print(indihostfile.fileName()) if ((indihostfile.size() == 0) or not (indihostfile.open(QtCore.QIODevice.ReadOnly))): return handler = XmlIndiHostHandler(self) xmlreader = QtXml.QXmlSimpleReader() xmlreader.setContentHandler(handler) xmlreader.setErrorHandler(handler) source = QtXml.QXmlInputSource(indihostfile) ok = xmlreader.parse(source, True) #while (source.data() != ""): #source.reset() #ok=xmlreader.parseContinue() #xmlreader=QtCore.QXmlStreamReader(indihostfile) #ok=True #while not(xmlreader.atEnd()): # xmlreader.readNext() # if xmlreader.isStartElement(): # print("xml token name " + xmlreader.name().toString()) #if xmlreader.hasError(): # ok=False if not (ok): print("Failed to load indihosts setup")
def open(self): fileName = QtGui.QFileDialog.getOpenFileName( self, "Open Bookmark File", QtCore.QDir.currentPath(), "XBEL Files (*.xbel *.xml)") if not fileName: return self.treeWidget.clear() handler = XbelHandler(self.treeWidget) reader = QtXml.QXmlSimpleReader() reader.setContentHandler(handler) reader.setErrorHandler(handler) file = QtCore.QFile(fileName) if not file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text): QtGui.QMessageBox.warning( self, "SAX Bookmarks", "Cannot read file %s:\n%s." % (fileName, file.errorString())) return xmlInputSource = QtXml.QXmlInputSource(file) if reader.parse(xmlInputSource): self.statusBar().showMessage("File loaded", 2000)
def __init__(self): QtGui.QTreeWidget.__init__(self) self.header().setResizeMode(QtGui.QHeaderView.Stretch) self.setHeaderLabels(['Title', 'Type']) source = QtXml.QXmlInputSource() source.setData(xml) handler = XmlHandler(self) reader = QtXml.QXmlSimpleReader() reader.setContentHandler(handler) reader.setErrorHandler(handler) reader.parse(source)
def _process_reply(self, reply): try: request, handler, xml = self._active_requests.pop(reply) except KeyError: self.log.error("Error: Request not found for %s" % str(reply.request().url().toString())) return error = int(reply.error()) redirect = reply.attribute( QtNetwork.QNetworkRequest.RedirectionTargetAttribute).toUrl() self.log.debug( "Received reply for %s: HTTP %d (%s)", reply.request().url().toString(), reply.attribute( QtNetwork.QNetworkRequest.HttpStatusCodeAttribute).toInt()[0], reply.attribute(QtNetwork.QNetworkRequest.HttpReasonPhraseAttribute ).toString()) if handler is not None: if error: self.log.error( "Network request error for %s: %s (QT code %d, HTTP code %d)", reply.request().url().toString(), reply.errorString(), error, reply.attribute(QtNetwork.QNetworkRequest. HttpStatusCodeAttribute).toInt()[0]) # Redirect if found and not infinite if not redirect.isEmpty() and not XmlWebService.urls_equivalent( redirect, reply.request().url()): self.log.debug("Redirect to %s requested", redirect.toString()) self.get( str(redirect.host()), redirect.port(80), # retain path, query string and anchors from redirect URL redirect.toString( QUrl.FormattingOption(QUrl.RemoveAuthority | QUrl.RemoveScheme)), handler, xml, priority=True, important=True) elif xml: xml_handler = XmlHandler() xml_handler.init() xml_reader = QtXml.QXmlSimpleReader() xml_reader.setContentHandler(xml_handler) xml_input = QtXml.QXmlInputSource(reply) xml_reader.parse(xml_input) handler(xml_handler.document, reply, error) else: handler(str(reply.readAll()), reply, error) reply.close()
def openSceneBundleFile(self, pPathToSceneBundleMainFile=None): if (pPathToSceneBundleMainFile == None) or (not (os.path.isfile(pPathToSceneBundleMainFile))): CDConstants.printOut( "___ - DEBUG ----- CDSceneBundle: openSceneBundleFile() can not find " + str(pPathToSceneBundleMainFile) + " path.", CDConstants.DebugSparse) return else: self.treeWidget.clear() lXMLHandler = CC3SHandler(self) lXMLReader = QtXml.QXmlSimpleReader() lXMLReader.setContentHandler(lXMLHandler) lXMLReader.setErrorHandler(lXMLHandler) lFile = QtCore.QFile(pPathToSceneBundleMainFile) if not lFile.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text): QtGui.QMessageBox.warning( self, "CC3D Scene Bundle", "Cannot read file %s:\n%s." % (pPathToSceneBundleMainFile, lFile.errorString())) return False xmlInputSource = QtXml.QXmlInputSource(lFile) if lXMLReader.parse(xmlInputSource): self.thePathToSceneBundleDir, self.theSceneBundleMainFileName = os.path.split( str(pPathToSceneBundleMainFile)) CDConstants.printOut( "___ - DEBUG ----- CDSceneBundle: openSceneBundleFile() parsed file "+ \ str(pPathToSceneBundleMainFile) + " self.thePathToSceneBundleDir==" + \ self.thePathToSceneBundleDir + " self.theSceneBundleMainFileName==" + \ self.theSceneBundleMainFileName , CDConstants.DebugAll ) # parsing went fine, show the user what we got: self.show() self.treeWidget.clearFocus() return True else: QtGui.QMessageBox.warning( self, "CC3D Scene Bundle", "Cannot parse file %s" % pPathToSceneBundleMainFile) return False