--- a/WebBrowser/WebBrowserWindow.py Wed Dec 12 19:43:53 2018 +0100 +++ b/WebBrowser/WebBrowserWindow.py Wed Dec 12 19:52:24 2018 +0100 @@ -84,7 +84,6 @@ BrowserWindows = [] - _fromEric = False _useQtHelp = QTHELP_AVAILABLE _isPrivate = False @@ -116,10 +115,10 @@ _performingShutdown = False _lastActiveWindow = None - def __init__(self, home, path, parent, name, fromEric=False, + def __init__(self, home, path, parent, name, initShortcutsOnly=False, searchWord=None, private=False, qthelp=False, settingsDir="", - restoreSession=False, single=False): + restoreSession=False, single=False, saname=""): """ Constructor @@ -131,9 +130,6 @@ @type QWidget @param name name of this window @type str - @param fromEric flag indicating whether it was called from within - eric6 - @type bool @keyparam initShortcutsOnly flag indicating to just initialize the keyboard shortcuts @type bool @@ -149,6 +145,8 @@ @type bool @param single flag indicating to start in single application mode @type bool + @param saname name to be used for the single application server + @type str """ self.__hideNavigationTimer = None @@ -160,8 +158,6 @@ self.setWindowTitle(self.tr("eric6 Web Browser")) self.__settingsDir = settingsDir - self.__fromEric = fromEric - WebBrowserWindow._fromEric = fromEric self.__initShortcutsOnly = initShortcutsOnly self.setWindowIcon(UI.PixmapCache.getIcon("ericWeb.png")) @@ -170,12 +166,13 @@ WebBrowserWindow._isPrivate = private + self.__shortcutsDialog = None + self.__eventMouseButtons = Qt.NoButton self.__eventKeyboardModifiers = Qt.NoModifier if self.__initShortcutsOnly: - WebBrowserWindow.setUseQtHelp( - self.__fromEric or qthelp or bool(searchWord)) + WebBrowserWindow.setUseQtHelp(qthelp or bool(searchWord)) self.__initActions() else: if qVersionTuple() < (5, 11, 0) and \ @@ -183,8 +180,7 @@ os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = \ str(Preferences.getWebBrowser("WebInspectorPort")) - WebBrowserWindow.setUseQtHelp( - self.__fromEric or qthelp or bool(searchWord)) + WebBrowserWindow.setUseQtHelp(qthelp or bool(searchWord)) self.webProfile(private) self.networkManager() @@ -207,13 +203,12 @@ from .Navigation.NavigationContainer import NavigationContainer from .Bookmarks.BookmarksToolBar import BookmarksToolBar - if not self.__fromEric: - self.setStyle(Preferences.getUI("Style"), - Preferences.getUI("StyleSheet")) - - # initialize some SSL stuff - from E5Network.E5SslUtilities import initSSL - initSSL() + self.setStyle(Preferences.getUI("Style"), + Preferences.getUI("StyleSheet")) + + # initialize some SSL stuff + from E5Network.E5SslUtilities import initSSL + initSSL() if WebBrowserWindow._useQtHelp: self.__helpEngine = QHelpEngine( @@ -415,7 +410,7 @@ if not Preferences.getWebBrowser("StatusBarVisible"): self.statusBar().hide() - if not self.__fromEric and len(WebBrowserWindow.BrowserWindows): + if len(WebBrowserWindow.BrowserWindows): QDesktopServices.setUrlHandler( "http", WebBrowserWindow.BrowserWindows[0].urlHandler) QDesktopServices.setUrlHandler( @@ -471,9 +466,11 @@ self.__toolbarStates = self.saveState() if single: - self.SAServer = WebBrowserSingleApplicationServer() + self.SAServer = WebBrowserSingleApplicationServer(saname) self.SAServer.loadUrl.connect(self.__saLoadUrl) + self.SAServer.newTab.connect(self.__saNewTab) self.SAServer.search.connect(self.__saSearchWord) + self.SAServer.shutdown.connect(self.shutdown) else: self.SAServer = None @@ -517,16 +514,6 @@ """ return self.__tabWidget - def fromEric(self): - """ - Public method to check, if the web browser was called from within the - eric IDE. - - @return flag indicating that the browserw as opened from within eric - @rtype bool - """ - return self.__fromEric - def __setIconDatabasePath(self, enable=True): """ Private method to set the favicons path. @@ -969,10 +956,7 @@ """<p>Quit the eric6 Web Browser.</p>""" )) if not self.__initShortcutsOnly: - if self.__fromEric: - self.exitAct.triggered.connect(self.close) - else: - self.exitAct.triggered.connect(self.shutdown) + self.exitAct.triggered.connect(self.shutdown) self.__actions.append(self.exitAct) self.backAct = E5Action( @@ -1989,13 +1973,28 @@ self.virustotalScanCurrentAct.setEnabled(False) self.virustotalIpReportAct.setEnabled(False) self.virustotalDomainReportAct.setEnabled(False) + + self.shortcutsAct = E5Action( + self.tr('Keyboard Shortcuts'), + UI.PixmapCache.getIcon("configureShortcuts.png"), + self.tr('Keyboard &Shortcuts...'), + 0, 0, + self, 'webbrowser_keyboard_shortcuts') + self.shortcutsAct.setStatusTip(self.tr( + 'Set the keyboard shortcuts')) + self.shortcutsAct.setWhatsThis(self.tr( + """<b>Keyboard Shortcuts</b>""" + """<p>Set the keyboard shortcuts of the application""" + """ with your prefered values.</p>""" + )) + self.shortcutsAct.triggered.connect(self.__configShortcuts) + self.__actions.append(self.shortcutsAct) self.backAct.setEnabled(False) self.forwardAct.setEnabled(False) # now read the keyboard shortcuts for the actions - Shortcuts.readShortcuts( - helpViewer=self, helpViewerCategory="webBrowser") + Shortcuts.readShortcuts(helpViewer=self) def getActions(self): """ @@ -2004,7 +2003,16 @@ @return list of all actions (list of E5Action) """ return self.__actions[:] - + + def getActionsCategory(self): + """ + Public method to get the category of the defined actions. + + @return category of the actions + @rtype str + """ + return "WebBrowser" + def __initMenus(self): """ Private method to create the menus. @@ -2117,6 +2125,9 @@ menu = mb.addMenu(self.tr('&Settings')) menu.addAction(self.prefAct) + menu.addSeparator() + menu.addAction(self.shortcutsAct) + menu.addSeparator() menu.addAction(self.acceptedLanguagesAct) menu.addAction(self.cookiesAct) menu.addAction(self.flashCookiesAct) @@ -2240,6 +2251,8 @@ self.__superMenu.addAction(self.prefAct) menu = self.__superMenu.addMenu(self.tr('Settings')) + menu.addAction(self.shortcutsAct) + menu.addSeparator() menu.addAction(self.acceptedLanguagesAct) menu.addAction(self.cookiesAct) menu.addAction(self.flashCookiesAct) @@ -2522,7 +2535,7 @@ else: linkName = link h = WebBrowserWindow(linkName, ".", self.parent(), "webbrowser", - self.__fromEric, private=self.isPrivate(), + private=self.isPrivate(), restoreSession=restoreSession) h.show() @@ -2850,13 +2863,12 @@ self.__isClosing = True - if not self.__fromEric: - if not WebBrowserWindow._performingShutdown and \ - len(WebBrowserWindow.BrowserWindows) == 1 and \ - not WebBrowserWindow.isPrivate(): - # shut down the session manager in case the last window is - # about to be closed - self.sessionManager().shutdown() + if not WebBrowserWindow._performingShutdown and \ + len(WebBrowserWindow.BrowserWindows) == 1 and \ + not WebBrowserWindow.isPrivate(): + # shut down the session manager in case the last window is + # about to be closed + self.sessionManager().shutdown() self.__bookmarksToolBar.setModel(None) @@ -2887,7 +2899,7 @@ try: browserIndex = WebBrowserWindow.BrowserWindows.index(self) - if not self.__fromEric and len(WebBrowserWindow.BrowserWindows): + if len(WebBrowserWindow.BrowserWindows): if browserIndex == 0: if len(WebBrowserWindow.BrowserWindows) > 1: # first window will be deleted @@ -2900,18 +2912,17 @@ else: QDesktopServices.unsetUrlHandler("http") QDesktopServices.unsetUrlHandler("https") - if self.__fromEric or len(WebBrowserWindow.BrowserWindows) > 0: + if len(WebBrowserWindow.BrowserWindows) > 0: del WebBrowserWindow.BrowserWindows[browserIndex] except ValueError: pass - if not self.__fromEric: - Preferences.syncPreferences() - if not WebBrowserWindow._performingShutdown and \ - len(WebBrowserWindow.BrowserWindows) == 0: - # shut down the browser in case the last window was - # simply closed - self.shutdown() + Preferences.syncPreferences() + if not WebBrowserWindow._performingShutdown and \ + len(WebBrowserWindow.BrowserWindows) == 0: + # shut down the browser in case the last window was + # simply closed + self.shutdown() return True @@ -2938,14 +2949,9 @@ .format(windowCount, tabCount), modal=True, parent=self) - if self.fromEric: - quitButton = mb.addButton( - self.tr("&Close"), E5MessageBox.AcceptRole) - quitButton.setIcon(UI.PixmapCache.getIcon("close.png")) - else: - quitButton = mb.addButton( - self.tr("&Quit"), E5MessageBox.AcceptRole) - quitButton.setIcon(UI.PixmapCache.getIcon("exit.png")) + quitButton = mb.addButton( + self.tr("&Quit"), E5MessageBox.AcceptRole) + quitButton.setIcon(UI.PixmapCache.getIcon("exit.png")) mb.addButton(E5MessageBox.Cancel) mb.exec_() return mb.clickedButton() == quitButton @@ -3272,9 +3278,8 @@ """ Public slot to handle a change of preferences. """ - if not self.__fromEric: - self.setStyle(Preferences.getUI("Style"), - Preferences.getUI("StyleSheet")) + self.setStyle(Preferences.getUI("Style"), + Preferences.getUI("StyleSheet")) self.__initWebEngineSettings() @@ -3336,7 +3341,7 @@ @type bool """ self.passwordManager().masterPasswordChanged(oldPassword, newPassword) - if self.__fromEric and local: + if local: # we were called from our local configuration dialog Preferences.convertPasswords(oldPassword, newPassword) Utilities.crypto.changeRememberedMaster(newPassword) @@ -4798,23 +4803,19 @@ (None = use configured timeout, 0 = indefinitely) @type int """ - if cls._fromEric: - e5App().getObject("UserInterface").showNotification( - icon, heading, text, timeout) - else: - if Preferences.getUI("NotificationsEnabled"): - if cls._notification is None: - from UI.NotificationWidget import NotificationWidget - cls._notification = NotificationWidget() - cls._notification.setPixmap(icon) - cls._notification.setHeading(heading) - cls._notification.setText(text) - if timeout is None: - timeout = Preferences.getUI("NotificationTimeout") - cls._notification.setTimeout(timeout) - cls._notification.move( - Preferences.getUI("NotificationPosition")) - cls._notification.show() + if Preferences.getUI("NotificationsEnabled"): + if cls._notification is None: + from UI.NotificationWidget import NotificationWidget + cls._notification = NotificationWidget() + cls._notification.setPixmap(icon) + cls._notification.setHeading(heading) + cls._notification.setText(text) + if timeout is None: + timeout = Preferences.getUI("NotificationTimeout") + cls._notification.setTimeout(timeout) + cls._notification.move( + Preferences.getUI("NotificationPosition")) + cls._notification.show() @classmethod def notificationsEnabled(cls): @@ -4823,10 +4824,7 @@ @return flag indicating, if notifications are enabled (boolean) """ - if cls._fromEric: - return e5App().getObject("UserInterface").notificationsEnabled() - else: - return Preferences.getUI("NotificationsEnabled") + return Preferences.getUI("NotificationsEnabled") ###################################### ## Support for global status bar below @@ -4846,8 +4844,6 @@ """ if cls.BrowserWindows: return cls.BrowserWindows[0].statusBar() - elif cls._fromEric: - return e5App().getObject("UserInterface").statusBar() else: return None @@ -5026,6 +5022,18 @@ self.__linkActivated(url) @pyqtSlot(str) + def __saNewTab(self, urlStr): + """ + Private slot to load an URL received via the single application + protocol in a new tab. + + @param urlStr URL to be loaded + @type str + """ + url = QUrl.fromUserInput(urlStr) + self.newTab(url) + + @pyqtSlot(str) def __saSearchWord(self, word): """ Private slot to search for the given word. @@ -5036,3 +5044,17 @@ if WebBrowserWindow._useQtHelp: self.__searchWord = word self.__searchForWord() + + ###################################################### + ## Methods below implement shortcuts related functions + ###################################################### + + def __configShortcuts(self): + """ + Private slot to configure the keyboard shortcuts. + """ + if self.__shortcutsDialog is None: + from Preferences.ShortcutsDialog import ShortcutsDialog + self.__shortcutsDialog = ShortcutsDialog(self) + self.__shortcutsDialog.populate(helpViewer=self) + self.__shortcutsDialog.show()