def __init__(self, path, parent=None, encoding='utf8'): QWebView.__init__(self, parent) self.path = path self.encoding = encoding self.__watcher = QFileSystemWatcher(self) self.__watcher.fileChanged.connect(self.loadFile) self.__watcher.directoryChanged.connect(self.loadFile) self.__watcher.addPath(self.path) self.__watcher.addPath(QFileInfo(self.path).path()) self.setWindowTitle(self.path) self.loadFile()
class MarkdownView(QWebView): def __init__(self, path, parent=None, encoding='utf8'): QWebView.__init__(self, parent) self.path = path self.encoding = encoding self.__watcher = QFileSystemWatcher(self) self.__watcher.fileChanged.connect(self.loadFile) self.__watcher.directoryChanged.connect(self.loadFile) self.__watcher.addPath(self.path) self.__watcher.addPath(QFileInfo(self.path).path()) self.setWindowTitle(self.path) self.loadFile() def loadFile(self): if not QFileInfo(self.path).exists(): return inp = open(self.path).read().decode(self.encoding) self.setHtml(markdown.markdown(inp, extensions=['meta', 'codehilite']))