def main(): """ Main entry point into the application. """ global app from PyQt5.QtGui import QGuiApplication QGuiApplication.setDesktopFileName("eric6_browser.desktop") options = [ ("--config=configDir", "use the given directory as the one containing the config files"), ("--private", "start the browser in private browsing mode"), ("--qthelp", "start the browser with support for QtHelp"), ("--quiet", "don't show any startup error messages"), ("--search=word", "search for the given word"), ("--settings=settingsDir", "use the given directory to store the settings files"), ("--single", "start the browser as a single application"), ] appinfo = AppInfo.makeAppInfo(sys.argv, "eric6 Web Browser", "file", "web browser", options) # set the library paths for plugins Startup.setLibraryPaths() if qVersionTuple() >= (5, 12, 0): from PyQt5.QtWebEngineCore import QWebEngineUrlScheme scheme = QWebEngineUrlScheme(b"eric") scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path) scheme.setFlags(QWebEngineUrlScheme.SecureScheme | QWebEngineUrlScheme.ContentSecurityPolicyIgnored) QWebEngineUrlScheme.registerScheme(scheme) if "--qthelp" in sys.argv and qVersionTuple() >= (5, 12, 0): from PyQt5.QtWebEngineCore import QWebEngineUrlScheme scheme = QWebEngineUrlScheme(b"qthelp") scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path) scheme.setFlags(QWebEngineUrlScheme.SecureScheme) QWebEngineUrlScheme.registerScheme(scheme) app = E5Application(sys.argv) if "--private" not in sys.argv: client = WebBrowserSingleApplicationClient() res = client.connect() if res > 0: if len(sys.argv) > 1: client.processArgs(sys.argv[1:]) sys.exit(0) elif res < 0: print("eric6_browser: {0}".format(client.errstr())) # __IGNORE_WARNING_M801__ sys.exit(res) res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget, installErrorHandler=True, app=app) sys.exit(res)
def isEnabled(cls): """ Class method to check, if the web inspector is enabled. @return flag indicating the enabled state @rtype bool """ if qVersionTuple() < (5, 11, 0): if not os.getenv("QTWEBENGINE_REMOTE_DEBUGGING"): return False from WebBrowser.WebBrowserWindow import WebBrowserWindow if not WebBrowserWindow.webSettings().testAttribute( QWebEngineSettings.JavascriptEnabled): return False if qVersionTuple() < (5, 11, 0): return Preferences.getWebBrowser("WebInspectorEnabled") else: return True
def start(self, seconds): """ Public method to start the timer. @param seconds timeout value (integer) """ if qVersionTuple() >= (5, 10, 0): screenGeom = QApplication.screens()[0].geometry() else: screenGeom = QApplication.desktop().screenGeometry() self.move(screenGeom.width() // 2 - self.size().width() // 2, screenGeom.top()) self.__toggle = True self.__time = 0 self.__length = seconds self.__timer.start(1000) self.show()
def enterEvent(self, evt): """ Protected method handling the mouse cursor entering the widget. @param evt enter event (QEvent) """ if qVersionTuple() >= (5, 10, 0): screenGeom = QApplication.screens()[0].geometry() else: screenGeom = QApplication.desktop().screenGeometry() if self.x() == screenGeom.left(): self.move( screenGeom.x() + (screenGeom.width() // 2 - self.size().width() // 2), screenGeom.top()) else: self.move(screenGeom.topLeft())
def __calculateNearbyPoint(self, target): """ Private method to calculate the position to place the popup near the specified rectangle. @param target rectangle to be placed at (QRect) @return position to place the popup (QPoint) """ pos = target.topLeft() x = pos.x() y = pos.y() w = self.minimumSizeHint().width() h = self.minimumSizeHint().height() if qVersionTuple() >= (5, 10, 0): r = (QApplication.screenAt(QPoint(x + w // 2, y + h // 2)).geometry()) else: r = QApplication.desktop().screenGeometry( QPoint(x + w // 2, y + h // 2)) if x < r.center().x(): x += target.width() else: x -= w # It's apparently trying to go off screen, so display it ALL at the # bottom. if (y + h) > r.bottom(): y = r.bottom() - h if (x + w) > r.right(): x = r.right() - w if y < r.top(): y = r.top() if x < r.left(): x = r.left() return QPoint(x, y)
def __init__(self): """ Constructor """ super(NotificationsPage, self).__init__() self.setupUi(self) self.setObjectName("NotificationsPage") minX, maxX = self.xSpinBox.maximum(), self.xSpinBox.minimum() minY, maxY = self.ySpinBox.maximum(), self.ySpinBox.minimum() if qVersionTuple() >= (5, 10, 0): for screen in QApplication.screens(): geom = screen.availableGeometry() minX = min(minX, geom.x()) maxX = max(maxX, geom.x() + geom.width()) minY = min(minY, geom.y()) maxY = max(maxY, geom.y() + geom.height()) else: desk = QApplication.desktop() for screen in range(desk.screenCount()): geom = desk.availableGeometry(screen) minX = min(minX, geom.x()) maxX = max(maxX, geom.x() + geom.width()) minY = min(minY, geom.y()) maxY = max(maxY, geom.y() + geom.height()) self.xSpinBox.setMinimum(minX) self.xSpinBox.setMaximum(maxX) self.ySpinBox.setMinimum(minY) self.ySpinBox.setMaximum(maxY) self.__notification = None # set initial values self.enableCheckBox.setChecked( Preferences.getUI("NotificationsEnabled")) self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout")) point = Preferences.getUI("NotificationPosition") self.xSpinBox.setValue(point.x()) self.ySpinBox.setValue(point.y())
def __installQtDoc(self, name, version, engine): """ Private method to install/update a Qt help document. @param name name of the Qt help document (string) @param version Qt version of the help documens (integer) @param engine reference to the help engine (QHelpEngineCore) @return flag indicating success (boolean) """ versionKey = "qt_version_{0}@@{1}".format(version, name) info = engine.customValue(versionKey, "") lst = info.split('|') dt = QDateTime() if len(lst) and lst[0]: dt = QDateTime.fromString(lst[0], Qt.ISODate) qchFile = "" if len(lst) == 2: qchFile = lst[1] if version == 4: docsPath = QDir( QLibraryInfo.location(QLibraryInfo.DocumentationPath) + QDir.separator() + "qch") elif version == 5: docsPath = QLibraryInfo.location(QLibraryInfo.DocumentationPath) if (not os.path.isdir(docsPath) or len(QDir(docsPath).entryList(["*.qch"])) == 0): # Qt installer is a bit buggy; it's missing a symbolic link docsPathList = QDir.fromNativeSeparators(docsPath).split("/") docsPath = os.sep.join( docsPathList[:-3] + ["Docs", "Qt-{0}.{1}".format(*qVersionTuple())]) docsPath = QDir(docsPath) else: # unsupported Qt version return False files = docsPath.entryList(["*.qch"]) if not files: engine.setCustomValue(versionKey, QDateTime().toString(Qt.ISODate) + '|') return False for f in files: if f.startswith(name + "."): fi = QFileInfo(docsPath.absolutePath() + QDir.separator() + f) namespace = QHelpEngineCore.namespaceName( fi.absoluteFilePath()) if not namespace: continue if (dt.isValid() and namespace in engine.registeredDocumentations() and (fi.lastModified().toString(Qt.ISODate) == dt.toString(Qt.ISODate)) and qchFile == fi.absoluteFilePath()): return False if namespace in engine.registeredDocumentations(): engine.unregisterDocumentation(namespace) if not engine.registerDocumentation(fi.absoluteFilePath()): self.errorMessage.emit( self.tr( """<p>The file <b>{0}</b> could not be""" """ registered. <br/>Reason: {1}</p>""").format( fi.absoluteFilePath, engine.error())) return False engine.setCustomValue( versionKey, fi.lastModified().toString(Qt.ISODate) + '|' + fi.absoluteFilePath()) return True return False
def save(self): """ Public slot to save the Help Viewers configuration. """ Preferences.setWebBrowser( "SingleWebBrowserWindow", self.singleHelpWindowCheckBox.isChecked()) Preferences.setWebBrowser( "SaveGeometry", self.saveGeometryCheckBox.isChecked()) Preferences.setWebBrowser( "WebSearchSuggestions", self.webSuggestionsCheckBox.isChecked()) Preferences.setWebBrowser( "ShowPreview", self.showTabPreviews.isChecked()) Preferences.setWebBrowser( "ErrorPageEnabled", self.errorPageCheckBox.isChecked()) Preferences.setWebBrowser( "ScrollAnimatorEnabled", self.scrollingCheckBox.isChecked()) Preferences.setWebBrowser( "FullScreenSupportEnabled", self.fullscreenCheckBox.isChecked()) if self.screenCaptureCheckBox.isEnabled(): Preferences.setWebBrowser( "ScreenCaptureEnabled", self.screenCaptureCheckBox.isChecked()) Preferences.setWebBrowser( "WebGLEnabled", self.webGLCheckBox.isChecked()) if self.autoplayMediaCheckBox.isEnabled(): Preferences.setWebBrowser( "PlaybackRequiresUserGesture", self.autoplayMediaCheckBox.isChecked()) Preferences.setWebBrowser( "WebRTCPublicInterfacesOnly", self.webRtcPublicOnlyCheckBox.isChecked()) if self.dnsPrefetchCheckBox.isEnabled(): Preferences.setWebBrowser( "DnsPrefetchEnabled", self.dnsPrefetchCheckBox.isChecked()) Preferences.setWebBrowser( "JavaScriptEnabled", self.javaScriptGroup.isChecked()) Preferences.setWebBrowser( "JavaScriptCanOpenWindows", self.jsOpenWindowsCheckBox.isChecked()) if self.jsActivateWindowsCheckBox.isEnabled(): Preferences.setWebBrowser( "AllowWindowActivationFromJavaScript", self.jsActivateWindowsCheckBox.isChecked()) Preferences.setWebBrowser( "JavaScriptCanAccessClipboard", self.jsClipboardCheckBox.isChecked()) if self.jsPasteCheckBox.isEnabled(): Preferences.setWebBrowser( "JavaScriptCanPaste", self.jsPasteCheckBox.isChecked()) Preferences.setWebBrowser( "PluginsEnabled", self.pluginsGroup.isChecked()) if self.pdfViewerCheckBox.isEnabled(): Preferences.setWebBrowser( "PdfViewerEnabled", self.pdfViewerCheckBox.isChecked()) Preferences.setWebBrowser( "DoNotTrack", self.doNotTrackCheckBox.isChecked()) Preferences.setWebBrowser( "RefererSendReferer", self.refererSendComboBox.currentIndex()) Preferences.setWebBrowser( "RefererDefaultPolicy", self.refererDefaultPolicyCcomboBox.currentIndex()) Preferences.setWebBrowser( "RefererTrimmingPolicy", self.refererTrimmingPolicyComboBox.currentIndex()) Preferences.setWebBrowser( "DiskCacheEnabled", self.diskCacheCheckBox.isChecked()) Preferences.setWebBrowser( "DiskCacheSize", self.cacheSizeSpinBox.value()) Preferences.setWebBrowser( "StartupBehavior", self.startupCombo.currentIndex()) Preferences.setWebBrowser( "NewTabBehavior", self.newTabCombo.currentIndex()) Preferences.setWebBrowser( "HomePage", self.homePageEdit.text()) Preferences.setWebBrowser( "LoadTabOnActivation", self.loadTabOnActivationCheckBox.isChecked()) Preferences.setWebBrowser( "SessionAutoSave", self.saveSessionCheckBox.isChecked()) Preferences.setWebBrowser( "SessionAutoSaveInterval", self.sessionTimerSpinBox.value()) Preferences.setWebBrowser( "DefaultScheme", self.defaultSchemeCombo.currentText()) idx = self.expireHistory.currentIndex() if idx == 0: historyLimit = 1 elif idx == 1: historyLimit = 7 elif idx == 2: historyLimit = 14 elif idx == 3: historyLimit = 30 elif idx == 4: historyLimit = 365 elif idx == 5: historyLimit = -1 elif idx == 6: historyLimit = -2 Preferences.setWebBrowser("HistoryLimit", historyLimit) languageIndex = self.languageCombo.currentIndex() if languageIndex > -1: language = self.languageCombo.itemData(languageIndex) else: # fall back to system default language = QLocale.system().language() Preferences.setWebBrowser("SearchLanguage", language) Preferences.setWebBrowser( "ImageSearchEngine", self.imageSearchComboBox.currentText()) Preferences.setWebBrowser( "SpatialNavigationEnabled", self.spatialCheckBox.isChecked()) Preferences.setWebBrowser( "LinksIncludedInFocusChain", self.linksInFocusChainCheckBox.isChecked()) if self.focusOnNavigationCheckBox.isEnabled(): Preferences.setWebBrowser( "FocusOnNavigationEnabled", self.focusOnNavigationCheckBox.isChecked()) Preferences.setWebBrowser( "XSSAuditingEnabled", self.xssAuditingCheckBox.isChecked()) if self.insecureContentsCheckBox.isEnabled(): Preferences.setWebBrowser( "AllowRunningInsecureContent", self.insecureContentsCheckBox.isChecked()) if self.insecureGeolocationCheckBox.isEnabled(): Preferences.setWebBrowser( "AllowGeolocationOnInsecureOrigins", self.insecureGeolocationCheckBox.isChecked()) if self.printBackgroundCheckBox.isEnabled(): Preferences.setWebBrowser( "PrintElementBackgrounds", self.printBackgroundCheckBox.isChecked()) Preferences.setWebBrowser( "AutoScrollEnabled", self.autoScrollGroupBox.isChecked()) Preferences.setWebBrowser( "AutoScrollDivider", self.autoScrollDividerSpinBox.value()) if qVersionTuple() < (5, 11, 0): Preferences.setWebBrowser( "WebInspectorEnabled", self.webInspectorGroup.isChecked()) Preferences.setWebBrowser( "WebInspectorPort", self.webInspectorPortSpinBox.value()) if self.protocolHandlerComboBox.isEnabled(): Preferences.setWebBrowser( "AcceptProtocolHandlerRequest", self.protocolHandlerComboBox.currentIndex()) Preferences.setWebBrowser( "AcceptQuotaRequest", self.requestQuotaComboBox.currentIndex())
def __init__(self, configDialog): """ Constructor @param configDialog reference to the configuration dialog (ConfigurationDialog) """ super(WebBrowserPage, self).__init__() self.setupUi(self) self.setObjectName("WebBrowserPage") self.__configDlg = configDialog mw = configDialog.parent().parent() if hasattr(mw, "helpWindow") and mw.helpWindow is not None: # IDE self.__browserWindow = mw.helpWindow elif hasattr(mw, "currentBrowser"): # Web Browser self.__browserWindow = mw else: self.__browserWindow = None self.setCurrentPageButton.setEnabled(self.__browserWindow is not None) self.imageSearchGroup.setEnabled(self.__browserWindow is not None) defaultSchemes = ["file://", "http://", "https://"] self.defaultSchemeCombo.addItems(defaultSchemes) # set initial values self.singleHelpWindowCheckBox.setChecked( Preferences.getWebBrowser("SingleWebBrowserWindow")) self.saveGeometryCheckBox.setChecked( Preferences.getWebBrowser("SaveGeometry")) self.webSuggestionsCheckBox.setChecked( Preferences.getWebBrowser("WebSearchSuggestions")) self.showTabPreviews.setChecked( Preferences.getWebBrowser("ShowPreview")) self.errorPageCheckBox.setChecked( Preferences.getWebBrowser("ErrorPageEnabled")) self.scrollingCheckBox.setChecked( Preferences.getWebBrowser("ScrollAnimatorEnabled")) self.fullscreenCheckBox.setChecked( Preferences.getWebBrowser("FullScreenSupportEnabled")) try: # Qt 5.7+ self.screenCaptureCheckBox.setChecked( Preferences.getWebBrowser("ScreenCaptureEnabled")) self.webGLCheckBox.setChecked( Preferences.getWebBrowser("WebGLEnabled")) except KeyError: self.screenCaptureCheckBox.setEnabled(False) self.webGLCheckBox.setEnabled(False) try: # Qt 5.11 self.autoplayMediaCheckBox.setChecked( Preferences.getWebBrowser("PlaybackRequiresUserGesture")) self.webRtcPublicOnlyCheckBox.setChecked( Preferences.getWebBrowser("WebRTCPublicInterfacesOnly")) except KeyError: self.autoplayMediaCheckBox.setEnabled(False) self.webRtcPublicOnlyCheckBox.setEnabled(False) try: # Qt 5.12 self.dnsPrefetchCheckBox.setChecked( Preferences.getWebBrowser("DnsPrefetchEnabled")) except KeyError: self.dnsPrefetchCheckBox.setEnabled(False) self.javaScriptGroup.setChecked( Preferences.getWebBrowser("JavaScriptEnabled")) self.jsOpenWindowsCheckBox.setChecked( Preferences.getWebBrowser("JavaScriptCanOpenWindows")) try: # Qt 5.10 self.jsActivateWindowsCheckBox.setChecked( Preferences.getWebBrowser( "AllowWindowActivationFromJavaScript")) except KeyError: self.jsActivateWindowsCheckBox.setEnabled(False) self.jsClipboardCheckBox.setChecked( Preferences.getWebBrowser("JavaScriptCanAccessClipboard")) try: # Qt 5.11 self.jsPasteCheckBox.setChecked( Preferences.getWebBrowser("JavaScriptCanPaste")) except KeyError: self.jsPasteCheckBox.setEnabled(False) self.doNotTrackCheckBox.setChecked( Preferences.getWebBrowser("DoNotTrack")) self.refererSendComboBox.setCurrentIndex( Preferences.getWebBrowser("RefererSendReferer")) self.refererDefaultPolicyCcomboBox.setCurrentIndex( Preferences.getWebBrowser("RefererDefaultPolicy")) self.refererTrimmingPolicyComboBox.setCurrentIndex( Preferences.getWebBrowser("RefererTrimmingPolicy")) self.pluginsGroup.setChecked( Preferences.getWebBrowser("PluginsEnabled")) try: # Qt 5.13 self.pdfViewerCheckBox.setChecked( Preferences.getWebBrowser("PdfViewerEnabled")) except KeyError: self.pdfViewerCheckBox.setEnabled(False) self.diskCacheCheckBox.setChecked( Preferences.getWebBrowser("DiskCacheEnabled")) self.cacheSizeSpinBox.setValue( Preferences.getWebBrowser("DiskCacheSize")) self.startupCombo.setCurrentIndex( Preferences.getWebBrowser("StartupBehavior")) self.newTabCombo.setCurrentIndex( Preferences.getWebBrowser("NewTabBehavior")) self.homePageEdit.setText( Preferences.getWebBrowser("HomePage")) self.loadTabOnActivationCheckBox.setChecked( Preferences.getWebBrowser("LoadTabOnActivation")) self.saveSessionCheckBox.setChecked( Preferences.getWebBrowser("SessionAutoSave")) self.sessionTimerSpinBox.setValue( Preferences.getWebBrowser("SessionAutoSaveInterval")) self.defaultSchemeCombo.setCurrentIndex( self.defaultSchemeCombo.findText( Preferences.getWebBrowser("DefaultScheme"))) historyLimit = Preferences.getWebBrowser("HistoryLimit") idx = 0 if historyLimit == 1: idx = 0 elif historyLimit == 7: idx = 1 elif historyLimit == 14: idx = 2 elif historyLimit == 30: idx = 3 elif historyLimit == 365: idx = 4 elif historyLimit == -1: idx = 5 elif historyLimit == -2: idx = 6 else: idx = 5 self.expireHistory.setCurrentIndex(idx) for language in range(2, QLocale.LastLanguage + 1): countries = [l.country() for l in QLocale.matchingLocales( language, QLocale.AnyScript, QLocale.AnyCountry)] if len(countries) > 0: self.languageCombo.addItem( QLocale.languageToString(language), language) self.languageCombo.model().sort(0) self.languageCombo.insertSeparator(0) self.languageCombo.insertItem(0, QLocale.languageToString(0), 0) index = self.languageCombo.findData( Preferences.getWebBrowser("SearchLanguage")) if index > -1: self.languageCombo.setCurrentIndex(index) if self.__browserWindow: for engineName in ( self.__browserWindow.imageSearchEngine().searchEngineNames() ): self.imageSearchComboBox.addItem( UI.PixmapCache.getIcon( "{0}.png".format(engineName.lower())), engineName) index = self.imageSearchComboBox.findText( Preferences.getWebBrowser("ImageSearchEngine")) if index > -1: self.imageSearchComboBox.setCurrentIndex(index) self.spatialCheckBox.setChecked( Preferences.getWebBrowser("SpatialNavigationEnabled")) self.linksInFocusChainCheckBox.setChecked( Preferences.getWebBrowser("LinksIncludedInFocusChain")) try: # Qt 5.8 self.focusOnNavigationCheckBox.setChecked( Preferences.getWebBrowser("FocusOnNavigationEnabled")) except KeyError: self.focusOnNavigationCheckBox.setEnabled(False) self.xssAuditingCheckBox.setChecked( Preferences.getWebBrowser("XSSAuditingEnabled")) try: # Qt 5.8 self.insecureContentsCheckBox.setChecked( Preferences.getWebBrowser("AllowRunningInsecureContent")) except KeyError: self.insecureContentsCheckBox.setEnabled(False) try: # Qt 5.9 self.insecureGeolocationCheckBox.setChecked( Preferences.getWebBrowser("AllowGeolocationOnInsecureOrigins")) except KeyError: self.insecureGeolocationCheckBox.setEnabled(False) try: # Qt 5.8 self.printBackgroundCheckBox.setChecked( Preferences.getWebBrowser("PrintElementBackgrounds")) except KeyError: self.printBackgroundCheckBox.setEnabled(False) self.autoScrollGroupBox.setChecked( Preferences.getWebBrowser("AutoScrollEnabled")) self.autoScrollDividerSpinBox.setValue( Preferences.getWebBrowser("AutoScrollDivider")) if qVersionTuple() < (5, 11, 0): self.webInspectorGroup.setChecked( Preferences.getWebBrowser("WebInspectorEnabled")) self.webInspectorPortSpinBox.setValue( Preferences.getWebBrowser("WebInspectorPort")) else: self.webInspectorGroup.hide() if qVersionTuple() >= (5, 11, 0): self.protocolHandlerComboBox.setCurrentIndex( Preferences.getWebBrowser("AcceptProtocolHandlerRequest")) self.requestQuotaComboBox.setCurrentIndex( Preferences.getWebBrowser("AcceptQuotaRequest")) else: self.protocolHandlerComboBox.setEnabled(False) self.requestQuotaComboBox.setEnabled(False)