--- a/UI/UserInterface.py Fri Dec 14 19:52:38 2018 +0100 +++ b/UI/UserInterface.py Sat Dec 15 16:21:38 2018 +0100 @@ -28,21 +28,6 @@ from PyQt5.QtNetwork import QNetworkProxyFactory, QNetworkAccessManager, \ QNetworkRequest, QNetworkReply -from Globals import qVersionTuple -try: - from PyQt5 import QtWebKit # __IGNORE_WARNING__ - WEBKIT_AVAILABLE = True -except ImportError: - WEBKIT_AVAILABLE = False -if qVersionTuple() < (5, 6, 0): - WEBENGINE_AVAILABLE = False -else: - try: - from PyQt5 import QtWebEngineWidgets # __IGNORE_WARNING__ - WEBENGINE_AVAILABLE = True - except ImportError: - WEBENGINE_AVAILABLE = False - from .Info import Version, VersionOnly, BugAddress, Program, FeatureAddress from . import Config @@ -72,6 +57,8 @@ from eric6config import getConfig +from Globals import qVersionTuple + class Redirector(QObject): """ @@ -575,19 +562,9 @@ self.toolProcs = [] self.__initExternalToolsActions() - # create a dummy help window for shortcuts handling - # TODO: remove this in favour of standalone web browser - if WEBKIT_AVAILABLE: - from Helpviewer.HelpWindow import HelpWindow - self.dummyHelpViewer = \ - HelpWindow(None, '.', None, 'help viewer', True, True) - else: - self.dummyHelpViewer = None - # redirect handling of http and https URLs to ourselves - if WEBENGINE_AVAILABLE or WEBKIT_AVAILABLE: - QDesktopServices.setUrlHandler("http", self.handleUrl) - QDesktopServices.setUrlHandler("https", self.handleUrl) + QDesktopServices.setUrlHandler("http", self.handleUrl) + QDesktopServices.setUrlHandler("https", self.handleUrl) # register all relevant objects splash.showMessage(self.tr("Registering Objects...")) @@ -603,8 +580,6 @@ if self.templateViewer is not None: e5App().registerObject("TemplateViewer", self.templateViewer) e5App().registerObject("Shell", self.shell) - if self.dummyHelpViewer is not None: - e5App().registerObject("DummyHelpViewer", self.dummyHelpViewer) e5App().registerObject("PluginManager", self.pluginManager) e5App().registerObject("ToolbarManager", self.toolbarManager) if self.cooperation is not None: @@ -722,9 +697,6 @@ self.__networkManager.sslErrors.connect(self.__sslErrors) self.__replies = [] - # attribute for the help window - self.helpWindow = None - # set spellchecker defaults from QScintilla.SpellChecker import SpellChecker SpellChecker.setDefaultLanguage( @@ -1818,29 +1790,28 @@ self.whatsThisAct.triggered.connect(self.__whatsThis) self.actions.append(self.whatsThisAct) - if WEBENGINE_AVAILABLE or WEBKIT_AVAILABLE: - self.helpviewerAct = E5Action( - self.tr('Helpviewer'), - UI.PixmapCache.getIcon("help.png"), - self.tr('&Helpviewer...'), - QKeySequence(self.tr("F1")), - 0, self, 'helpviewer') - self.helpviewerAct.setStatusTip(self.tr( - 'Open the helpviewer window')) - self.helpviewerAct.setWhatsThis(self.tr( - """<b>Helpviewer</b>""" - """<p>Display the eric6 web browser. This window will show""" - """ HTML help files and help from Qt help collections. It""" - """ has the capability to navigate to links, set bookmarks,""" - """ print the displayed help and some more features. You may""" - """ use it to browse the internet as well</p><p>If called""" - """ with a word selected, this word is search in the Qt help""" - """ collection.</p>""" - )) - self.helpviewerAct.triggered.connect(self.__helpViewer) - self.actions.append(self.helpviewerAct) - else: - self.helpviewerAct = None + self.helpviewerAct = E5Action( + self.tr('Helpviewer'), + UI.PixmapCache.getIcon("help.png"), + self.tr('&Helpviewer...'), + QKeySequence(self.tr("F1")), + 0, self, 'helpviewer') + self.helpviewerAct.setStatusTip(self.tr( + 'Open the helpviewer window')) + self.helpviewerAct.setWhatsThis(self.tr( + """<b>Helpviewer</b>""" + """<p>Display the eric6 web browser. This window will show""" + """ HTML help files and help from Qt help collections. It""" + """ has the capability to navigate to links, set bookmarks,""" + """ print the displayed help and some more features. You may""" + """ use it to browse the internet as well</p><p>If called""" + """ with a word selected, this word is search in the Qt help""" + """ collection.</p>""" + )) + self.helpviewerAct.triggered.connect(self.__helpViewer) + self.actions.append(self.helpviewerAct) +## else: +## self.helpviewerAct = None self.__initQtDocActions() self.__initPythonDocActions() @@ -2147,22 +2118,21 @@ self.hexEditorAct.triggered.connect(self.__openHexEditor) self.actions.append(self.hexEditorAct) - if WEBENGINE_AVAILABLE or WEBKIT_AVAILABLE: - self.webBrowserAct = E5Action( - self.tr('eric6 Web Browser'), - UI.PixmapCache.getIcon("ericWeb.png"), - self.tr('eric6 &Web Browser...'), - 0, 0, self, 'web_browser') - self.webBrowserAct.setStatusTip(self.tr( - 'Start the eric6 Web Browser')) - self.webBrowserAct.setWhatsThis(self.tr( - """<b>eric6 Web Browser</b>""" - """<p>Browse the Internet with the eric6 Web Browser.</p>""" - )) - self.webBrowserAct.triggered.connect(self.__startWebBrowser) - self.actions.append(self.webBrowserAct) - else: - self.webBrowserAct = None + self.webBrowserAct = E5Action( + self.tr('eric6 Web Browser'), + UI.PixmapCache.getIcon("ericWeb.png"), + self.tr('eric6 &Web Browser...'), + 0, 0, self, 'web_browser') + self.webBrowserAct.setStatusTip(self.tr( + 'Start the eric6 Web Browser')) + self.webBrowserAct.setWhatsThis(self.tr( + """<b>eric6 Web Browser</b>""" + """<p>Browse the Internet with the eric6 Web Browser.</p>""" + )) + self.webBrowserAct.triggered.connect(self.__startWebBrowser) + self.actions.append(self.webBrowserAct) +## else: +## self.webBrowserAct = None self.iconEditorAct = E5Action( self.tr('Icon Editor'), @@ -3368,16 +3338,20 @@ .format(sip_version_str) versionText += """<tr><td><b>QScintilla</b></td><td>{0}</td></tr>"""\ .format(QSCINTILLA_VERSION_STR) - if WEBENGINE_AVAILABLE: + try: from WebBrowser.Tools import WebBrowserTools chromeVersion = WebBrowserTools.getWebEngineVersions()[0] versionText += \ """<tr><td><b>WebEngine</b></td><td>{0}</td></tr>"""\ .format(chromeVersion) - if WEBKIT_AVAILABLE: + except ImportError: + pass + try: from PyQt5.QtWebKit import qWebKitVersion versionText += """<tr><td><b>WebKit</b></td><td>{0}</td></tr>"""\ .format(qWebKitVersion()) + except ImportError: + pass versionText += """<tr><td><b>{0}</b></td><td>{1}</td></tr>"""\ .format(Program, Version) versionText += self.tr("""</table>""") @@ -5236,10 +5210,7 @@ if home.endswith(".chm"): self.__chmViewer(home) else: - if WEBENGINE_AVAILABLE: - hvType = Preferences.getWebBrowser("HelpViewerType") - else: - hvType = Preferences.getHelp("HelpViewerType") + hvType = Preferences.getWebBrowser("HelpViewerType") if hvType == 1: self.launchHelpViewer(home) elif hvType == 2: @@ -5300,10 +5271,7 @@ if home.endswith(".chm"): self.__chmViewer(home) else: - if WEBENGINE_AVAILABLE: - hvType = Preferences.getWebBrowser("HelpViewerType") - else: - hvType = Preferences.getHelp("HelpViewerType") + hvType = Preferences.getWebBrowser("HelpViewerType") if hvType == 1: self.launchHelpViewer(home) elif hvType == 2: @@ -5369,10 +5337,7 @@ else: home = "file://" + home - if WEBENGINE_AVAILABLE: - hvType = Preferences.getWebBrowser("HelpViewerType") - else: - hvType = Preferences.getHelp("HelpViewerType") + hvType = Preferences.getWebBrowser("HelpViewerType") if hvType == 1: self.launchHelpViewer(home) elif hvType == 2: @@ -5434,10 +5399,7 @@ else: home = pyqt4DocDir - if WEBENGINE_AVAILABLE: - hvType = Preferences.getWebBrowser("HelpViewerType") - else: - hvType = Preferences.getHelp("HelpViewerType") + hvType = Preferences.getWebBrowser("HelpViewerType") if hvType == 1: self.launchHelpViewer(home) elif hvType == 2: @@ -5501,10 +5463,7 @@ else: home = pyqt5DocDir - if WEBENGINE_AVAILABLE: - hvType = Preferences.getWebBrowser("HelpViewerType") - else: - hvType = Preferences.getHelp("HelpViewerType") + hvType = Preferences.getWebBrowser("HelpViewerType") if hvType == 1: self.launchHelpViewer(home) elif hvType == 2: @@ -5541,10 +5500,7 @@ else: home = "file://" + home - if WEBENGINE_AVAILABLE: - hvType = Preferences.getWebBrowser("HelpViewerType") - else: - hvType = Preferences.getHelp("HelpViewerType") + hvType = Preferences.getWebBrowser("HelpViewerType") if hvType == 1: self.launchHelpViewer(home) elif hvType == 2: @@ -5610,10 +5566,7 @@ else: home = pysideDocDir - if WEBENGINE_AVAILABLE: - hvType = Preferences.getWebBrowser("HelpViewerType") - else: - hvType = Preferences.getHelp("HelpViewerType") + hvType = Preferences.getWebBrowser("HelpViewerType") if hvType == 1: self.launchHelpViewer(home) elif hvType == 2: @@ -5655,45 +5608,9 @@ if not homeUrl.scheme(): home = QUrl.fromLocalFile(home).toString() - if WEBENGINE_AVAILABLE: - self.__launchExternalWebBrowser(home, searchWord=searchWord) - - elif WEBKIT_AVAILABLE: - # TODO: change to use external web browser in single mode - single = useSingle - if WEBKIT_AVAILABLE: - single = single or Preferences.getHelp("SingleHelpWindow") - if not single or self.helpWindow is None: - if WEBKIT_AVAILABLE: - from Helpviewer.HelpWindow import HelpWindow - browser = HelpWindow(home, '.', None, 'help viewer', True, - searchWord=searchWord) - - if QApplication.desktop().width() > 400 and \ - QApplication.desktop().height() > 500: - browser.show() - else: - browser.showMaximized() - - if single: - self.helpWindow = browser - try: - self.helpWindow.webBrowserWindowClosed.connect( - self.__helpClosed) - except AttributeError: - self.helpWindow.helpClosed.connect(self.__helpClosed) - self.preferencesChanged.connect( - self.helpWindow.preferencesChanged) - self.masterPasswordChanged.connect( - self.helpWindow.masterPasswordChanged) - elif searchWord is not None: - self.helpWindow.search(searchWord) - self.helpWindow.raise_() - else: - self.helpWindow.newTab(home) - self.helpWindow.raise_() - - else: + launchResult = self.__launchExternalWebBrowser( + home, searchWord=searchWord) + if not launchResult: self.__webBrowser(home) def __launchExternalWebBrowser(self, home, searchWord=None): @@ -5705,54 +5622,53 @@ @type str @keyparam searchWord word to search for @type str - """ - from WebBrowser.WebBrowserSingleApplication import \ - WebBrowserSingleApplicationClient - + @return flag indicating a successful launch + @rtype bool + """ clientArgs = [] if searchWord: clientArgs.append("--search={0}".format(searchWord)) if self.__webBrowserProcess is None: - process = QProcess() - args = [ + webBrowsers = [ os.path.join( os.path.dirname(__file__), "..", "eric6_browser.py"), - "--qthelp", - "--single", - "--name={0}".format(self.__webBrowserSAName) + # QtWebEngine based web browser + os.path.join( + os.path.dirname(__file__), "..", "eric6_webbrowser.py"), + # QtWebKit based web browser ] - process.start(sys.executable, args) - if not process.waitForStarted(): - E5MessageBox.warning( - self, - self.tr("Start Web Browser"), - self.tr("""The eric6 web browser could not be started.""")) - return + process = QProcess() + for browser in webBrowsers: + args = [ + browser, + "--quiet", + "--qthelp", + "--single", + "--name={0}".format(self.__webBrowserSAName) + ] + process.start(sys.executable, args) + if not process.waitForStarted(): + E5MessageBox.warning( + self, + self.tr("Start Web Browser"), + self.tr("""The eric6 web browser could not be""" + """ started.""")) + return False + + res = self.__connectToWebBrowser(process) + if res == 1: + # connection unsuccessful + return False + elif res == 0: + # successful + break + else: + return False process.finished.connect(self.__webBrowserFinished) self.__webBrowserProcess = process - self.__webBrowserClient = WebBrowserSingleApplicationClient( - self.__webBrowserSAName) - connectCount = 30 - while connectCount: - res = self.__webBrowserClient.connect() - if res != 0: - break - else: - connectCount -= 1 - QThread.msleep(1000) - if res <= 0: - E5MessageBox.warning( - self, - self.tr("Start Web Browser"), - self.tr("""<p>The eric6 web browser is not started.</p>""" - """<p>Reason: {0}</p>""").format( - self.__webBrowserClient.errstr()) - ) - return - if home: clientArgs.append(home) else: @@ -5760,6 +5676,50 @@ if clientArgs: self.__webBrowserClient.processArgs(clientArgs, disconnect=False) + + return True + + def __connectToWebBrowser(self, process): + """ + Private method to connect to a started web browser. + + @param process reference to the started web browser process + @type QProcess + @return error indication (1 = connection not possible, 0 = ok, + -1 = server exited with an error code) + @rtype int + """ + from WebBrowser.WebBrowserSingleApplication import \ + WebBrowserSingleApplicationClient + + webBrowserClient = WebBrowserSingleApplicationClient( + self.__webBrowserSAName) + connectCount = 30 + while connectCount: + res = webBrowserClient.connect() + if res != 0: + break + else: + connectCount -= 1 + QThread.msleep(1000) + QApplication.processEvents() + if process.state() == QProcess.NotRunning and \ + process.exitStatus() == QProcess.NormalExit and \ + process.exitCode() == 100: + # Process exited prematurely due to missing pre-requisites + return -1 + if res <= 0: + E5MessageBox.warning( + self, + self.tr("Start Web Browser"), + self.tr("""<p>The eric6 web browser is not started.</p>""" + """<p>Reason: {0}</p>""").format( + webBrowserClient.errstr()) + ) + return 1 + + self.__webBrowserClient = webBrowserClient + return 0 def __webBrowserFinished(self): """ @@ -5776,21 +5736,6 @@ """ self.__webBrowserClient.processArgs(["--shutdown"], disconnect=False) - def __helpClosed(self): - """ - Private slot to handle the helpClosed signal of the help window. - """ - if WEBENGINE_AVAILABLE: - single = Preferences.getWebBrowser("SingleWebBrowserWindow") - elif WEBKIT_AVAILABLE: - single = Preferences.getHelp("SingleHelpWindow") - if single: - self.preferencesChanged.disconnect( - self.helpWindow.preferencesChanged) - self.masterPasswordChanged.disconnect( - self.helpWindow.masterPasswordChanged) - self.helpWindow = None - def __helpViewer(self): """ Private slot to start an empty help viewer/web browser. @@ -5814,23 +5759,6 @@ self.tr('Open Browser'), self.tr('Could not start a web browser')) - def getHelpViewer(self, preview=False): - """ - Public method to get a reference to the help window instance. - - @keyparam preview flag indicating to get a help window for preview - (boolean) - @return reference to the help window instance (HelpWindow) - """ - # TODO: check if this method is used somewhere - if WEBENGINE_AVAILABLE or WEBKIT_AVAILABLE: - if self.helpWindow is None: - self.launchHelpViewer("", useSingle=True) - self.helpWindow.raise_() - return self.helpWindow - else: - return None - @pyqtSlot() @pyqtSlot(str) def showPreferences(self, pageName=None): @@ -5843,7 +5771,6 @@ dlg = ConfigurationDialog( self, 'Configuration', expandedEntries=self.__expandedConfigurationEntries, - webEngine=WEBENGINE_AVAILABLE, ) dlg.preferencesChanged.connect(self.__preferencesChanged) dlg.masterPasswordChanged.connect(self.__masterPasswordChanged) @@ -5953,19 +5880,21 @@ @param oldPassword current master password (string) @param newPassword new master password (string) """ + import Globals + self.masterPasswordChanged.emit(oldPassword, newPassword) Preferences.convertPasswords(oldPassword, newPassword) - if self.helpWindow is None: - if WEBENGINE_AVAILABLE: - from WebBrowser.Passwords.PasswordManager import \ - PasswordManager - pwManager = PasswordManager() - pwManager.masterPasswordChanged(oldPassword, newPassword) - elif WEBKIT_AVAILABLE: - from Helpviewer.Passwords.PasswordManager import \ - PasswordManager - pwManager = PasswordManager() - pwManager.masterPasswordChanged(oldPassword, newPassword) + variant = Globals.getWebBrowserSupport() + if variant == "QtWebEngine": + from WebBrowser.Passwords.PasswordManager import \ + PasswordManager + pwManager = PasswordManager() + pwManager.masterPasswordChanged(oldPassword, newPassword) + elif variant == "QtWebKit": + from Helpviewer.Passwords.PasswordManager import \ + PasswordManager + pwManager = PasswordManager() + pwManager.masterPasswordChanged(oldPassword, newPassword) Utilities.crypto.changeRememberedMaster(newPassword) def __reloadAPIs(self): @@ -6644,10 +6573,6 @@ if self.shutdownCalled: return True - if self.helpWindow is not None: - if not self.helpWindow.shutdown(): - return False - if self.__webBrowserProcess is not None: self.__webBrowserShutdown()