def importSAX(self, fname): error = None fh = None try: handler = SaxMovieHandler(self) parser = QtXml.QXmlSimpleReader() parser.setContentHandler(handler) parser.setErrorHandler(handler) fh = QtCore.QFile(fname) input = QtXml.QXmlInputSource(fh) self.clear(False) if not parser.parse(input): raise ValueError(handler.error) except (IOError, OSError, ValueError) as e: error = "Failed to import: {}".format(e) except Exception as e: error = "Failed to import SAX: {0}".format(e) finally: if fh is not None: fh.close() if error is not None: return False, error self.__fname = "" self.__dirty = True return True, "Imported {} movie records from {}".format( len(self.__movies), QtCore.QFileInfo(fname).fileName())
def open(self): fileName = QtGui.QFileDialog.getOpenFileName( self, "Open Bookmark File", QtCore.QDir.currentPath(), "XBEL Files (*.xbel *.xml)")[0] 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)