def __init__(self, mainWindow): super(WebView, self).__init__() self.mainWindow = mainWindow self.windowType = Util.getConfigValue('newWindowType') #mypage page = WebPage(self) self.setPage(page) #webchannel self.webPrinter = Printer(self, mainWindow) self.channel = QWebChannel() self.channel.registerObject('printer', self.webPrinter) self.page().setWebChannel(self.channel) #event self.loadStarted.connect(self.on_loadStarted) self.loadFinished.connect(self.on_loadFinished) self.urlChanged.connect(self.on_urlChanged) self.page().profile().setHttpUserAgent(Util.getUserAgent()) self.page().profile().downloadRequested.connect( self.on_downloadRequested) self.page().printRequested.connect(self.webPrinter.on_printRequested) self.page().pdfPrintingFinished.connect( self.webPrinter.on_pdfPrintingFinished) self.page().windowCloseRequested.connect( self.webPrinter.on_windowCloseRequested) self.loadProgress.connect(self.on_loadProgress) #self.setZoomFactor(1) if Util.getConfigValue('closeByEscape'): esc_action = QAction(self) esc_action.setShortcut(QKeySequence(Qt.Key_Escape)) self.addAction(esc_action) esc_action.triggered.connect(self.esc)
def createWindow(self, QWebEnginePage_WebWindowType): if self.windowType == 'window': #print('createWindow=>%d' % QWebEnginePage_WebWindowType) mainWnd = MainWindow(isMain=False) mainWnd.setWindowTitle( Util.getWindowTitle(Util.lang('loading', 'Loading...'))) mainWnd.setWindowIcon(Icon.getLogoIcon()) mainWnd.resizeCenter(Util.getConfigValue('width'), Util.getConfigValue('height')) #webview webview = WebView(mainWnd) webview.page().profile().setHttpUserAgent(Util.getUserAgent(True)) mainWnd.setWidget(webview) mainWnd.webview = webview mainWnd.show() #loading mainWnd.spinner = Loading(mainWnd) mainWnd.spinner.start() mainWnd.index = Util.getTicker() return webview elif self.windowType == 'tab': #tab tab = QWidget() self.mainWindow.tabWidget.addTab( tab, Util.getTabTitle(Util.lang('loading', 'Loading...'))) self.mainWindow.tabWidget.setCurrentWidget(tab) layout = QHBoxLayout(tab) layout.setContentsMargins(0, 0, 0, 0) #webview mainWnd = tab mainWnd.tabWidget = self.mainWindow.tabWidget #webview new_webview = WebView(mainWnd) new_webview.page().profile().setHttpUserAgent( Util.getUserAgent(True)) layout.addWidget(new_webview) mainWnd.webview = new_webview mainWnd.show() mainWnd.spinner = self.mainWindow.spinner mainWnd.spinner.start() if mainWnd.tabWidget.count() > 1: mainWnd.tabWidget.tabBar().show() mainWnd.index = Util.getTicker() return new_webview else: MessageBox.alert( Util.lang('invalid_window_type', 'Opening a new window is not supported.'))