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'])) app = QApplication(sys.argv) if len(app.arguments()) != 2: print('Usage: mdpreview <path>') sys.exit(-1) win = MarkdownView(app.arguments()[1]) win.show() sys.exit(app.exec_())