|
| 1 | +#!/usr/bin/python3 |
| 2 | +# Pdf Reader v1.0 |
| 3 | +# |
| 4 | + |
| 5 | +from PyQt5.QtWidgets import * |
| 6 | +from PyQt5.QtCore import * |
| 7 | +from PyQt5.QtGui import * |
| 8 | +from PyQt5.QtWebEngineWidgets import * |
| 9 | +import sys |
| 10 | + |
| 11 | +class Window(QMainWindow): |
| 12 | + def __init__(self): |
| 13 | + super(Window,self).__init__() |
| 14 | + global title_ |
| 15 | + title_ = "PDF Reader" |
| 16 | + self.setWindowTitle(title_) |
| 17 | + self.setGeometry(500,70,1000,800) |
| 18 | + menu = QMenuBar(self) |
| 19 | + self.setMenuWidget(menu) |
| 20 | + filemenu = menu.addMenu("File") |
| 21 | + open_file_action = QAction("Open File",self) |
| 22 | + open_file_action.setWhatsThis("Open File") |
| 23 | + open_file_action.setStatusTip("Open File") |
| 24 | + open_file_action.setShortcut("Ctrl+o") |
| 25 | + open_file_action.triggered.connect(self.open_file) |
| 26 | + exit_action = QAction("Exit",self) |
| 27 | + exit_action.setWhatsThis("Exit") |
| 28 | + exit_action.setStatusTip("Exit") |
| 29 | + exit_action.setShortcut("Alt+f4") |
| 30 | + exit_action.triggered.connect(self.close) |
| 31 | + filemenu.addAction(open_file_action) |
| 32 | + filemenu.addSeparator() |
| 33 | + filemenu.addAction(exit_action) |
| 34 | + |
| 35 | + self.webView = QWebEngineView(self) |
| 36 | + self.webView.settings().setAttribute(QWebEngineSettings.PluginsEnabled,True) |
| 37 | + self.webView.settings().setAttribute(QWebEngineSettings.PdfViewerEnabled,True) |
| 38 | + self.setCentralWidget(self.webView) |
| 39 | + |
| 40 | + def open_file(self): |
| 41 | + global file_ |
| 42 | + try: |
| 43 | + file_ = QFileDialog().getOpenFileName(self,"Open PDF File","C:\\","All Files (*.*);;PDF File (.pdf)") |
| 44 | + self.webView.setUrl(QUrl(file_[0])) |
| 45 | + title_ = f"PDF Reader - {file_[0]}" |
| 46 | + self.setWindowTitle(title_) |
| 47 | + except (Exception,) as err: |
| 48 | + print(err) |
| 49 | + |
| 50 | +def main(): |
| 51 | + # PDF Reader v1.0 |
| 52 | + app = QApplication(sys.argv) |
| 53 | + app.setApplicationName("PDF-Reader") |
| 54 | + app.setApplicationVersion("v1.0") |
| 55 | + app.setWindowIcon(QIcon("./icon/pdf-reader-icon.png")) |
| 56 | + window = Window() |
| 57 | + window.show() |
| 58 | + app.exec_() |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + main() |
0 commit comments