Added a configuration option to use the internal help viewer and made that the default. eric7

Wed, 20 Oct 2021 19:47:18 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 20 Oct 2021 19:47:18 +0200
branch
eric7
changeset 8705
327e596607f8
parent 8704
e4042abf2a5b
child 8706
16b25e115ac0

Added a configuration option to use the internal help viewer and made that the default.

eric7/HelpViewer/HelpViewerImpl.py file | annotate | diff | comparison | revisions
eric7/HelpViewer/HelpViewerImplQTB.py file | annotate | diff | comparison | revisions
eric7/HelpViewer/HelpViewerImplQWE.py file | annotate | diff | comparison | revisions
eric7/HelpViewer/HelpViewerWidget.py file | annotate | diff | comparison | revisions
eric7/Preferences/ConfigurationPages/HelpViewersPage.py file | annotate | diff | comparison | revisions
eric7/Preferences/ConfigurationPages/HelpViewersPage.ui file | annotate | diff | comparison | revisions
eric7/Preferences/__init__.py file | annotate | diff | comparison | revisions
eric7/UI/UserInterface.py file | annotate | diff | comparison | revisions
eric7/eric7.py file | annotate | diff | comparison | revisions
--- a/eric7/HelpViewer/HelpViewerImpl.py	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/HelpViewer/HelpViewerImpl.py	Wed Oct 20 19:47:18 2021 +0200
@@ -66,6 +66,17 @@
         raise RuntimeError("Not implemented")
         return ""
     
+    def isEmptyPage(self):
+        """
+        Public method to check, if the current page is the empty page.
+        
+        @return flag indicating an empty page is loaded
+        @rtype bool
+        @exception RuntimeError raised when not implemented
+        """
+        raise RuntimeError("Not implemented")
+        return False
+    
     def gotoHistory(self, index):
         """
         Public method to step through the history.
--- a/eric7/HelpViewer/HelpViewerImplQTB.py	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/HelpViewer/HelpViewerImplQTB.py	Wed Oct 20 19:47:18 2021 +0200
@@ -176,6 +176,15 @@
         
         return titleStr
     
+    def isEmptyPage(self):
+        """
+        Public method to check, if the current page is the empty page.
+        
+        @return flag indicating an empty page is loaded
+        @rtype bool
+        """
+        return self.pageTitle() == self.tr("Empty Page")
+    
     def mousePressEvent(self, evt):
         """
         Protected method called by a mouse press event.
--- a/eric7/HelpViewer/HelpViewerImplQWE.py	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/HelpViewer/HelpViewerImplQWE.py	Wed Oct 20 19:47:18 2021 +0200
@@ -142,6 +142,15 @@
         
         return titleStr
     
+    def isEmptyPage(self):
+        """
+        Public method to check, if the current page is the empty page.
+        
+        @return flag indicating an empty page is loaded
+        @rtype bool
+        """
+        return self.pageTitle() == self.tr("Empty Page")
+    
     #######################################################################
     ## History related methods below
     #######################################################################
--- a/eric7/HelpViewer/HelpViewerWidget.py	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/HelpViewer/HelpViewerWidget.py	Wed Oct 20 19:47:18 2021 +0200
@@ -391,19 +391,28 @@
             url = QUrl(urlStr)
             self.openUrl(url)
     
-    def activate(self, searchWord=None):
+    def activate(self, searchWord=None, url=None):
         """
         Public method to activate the widget and search for a given word.
         
         @param searchWord word to search for (defaults to None)
         @type str (optional)
+        @param url URL to show in a new page
+        @type QUrl
         """
-        cv = self.currentViewer()
-        if cv:
-            cv.setFocus(Qt.FocusReason.OtherFocusReason)
-        
-        if searchWord:
-            self.searchQtHelp(searchWord)
+        if url is not None:
+            cv = self.currentViewer()
+            if cv and cv.isEmptyPage():
+                self.openUrl(url)
+            else:
+                self.openUrlNewPage(url)
+        else:
+            cv = self.currentViewer()
+            if cv:
+                cv.setFocus(Qt.FocusReason.OtherFocusReason)
+            
+            if searchWord:
+                self.searchQtHelp(searchWord)
     
     def shutdown(self):
         """
--- a/eric7/Preferences/ConfigurationPages/HelpViewersPage.py	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/Preferences/ConfigurationPages/HelpViewersPage.py	Wed Oct 20 19:47:18 2021 +0200
@@ -34,28 +34,21 @@
         self.customViewerPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
         
         self.helpViewerGroup = QButtonGroup()
-        self.helpViewerGroup.addButton(self.helpBrowserButton)
-        self.helpViewerGroup.addButton(self.qtAssistantButton)
-        self.helpViewerGroup.addButton(self.webBrowserButton)
-        self.helpViewerGroup.addButton(self.customViewerButton)
+        self.helpViewerGroup.addButton(self.internalViewerButton, 0)
+        self.helpViewerGroup.addButton(self.helpBrowserButton, 1)
+        self.helpViewerGroup.addButton(self.qtAssistantButton, 2)
+        self.helpViewerGroup.addButton(self.webBrowserButton, 3)
+        self.helpViewerGroup.addButton(self.customViewerButton, 4)
         
         # set initial values
+        hvId = Preferences.getHelp("HelpViewerType")
         webBrowserVariant = getWebBrowserSupport()
-        if webBrowserVariant == "QtWebEngine":
-            hvId = Preferences.getWebBrowser("HelpViewerType")
-        else:
-            # TODO: change default to internal viewer (= 0)
-            hvId = 3
+        if webBrowserVariant != "QtWebEngine":
+            if hvId == 1:
+                hvId = 0
             self.helpBrowserButton.setEnabled(False)
         
-        if hvId == 1:
-            self.helpBrowserButton.setChecked(True)
-        elif hvId == 2:
-            self.qtAssistantButton.setChecked(True)
-        elif hvId == 3:
-            self.webBrowserButton.setChecked(True)
-        else:
-            self.customViewerButton.setChecked(True)
+        self.helpViewerGroup.button(hvId).setChecked(True)
         self.customViewerPicker.setText(
             Preferences.getHelp("CustomViewer"))
         
@@ -63,16 +56,9 @@
         """
         Public slot to save the Help Viewers configuration.
         """
-        if self.helpBrowserButton.isChecked():
-            hvId = 1
-        elif self.qtAssistantButton.isChecked():
-            hvId = 2
-        elif self.webBrowserButton.isChecked():
-            hvId = 3
-        elif self.customViewerButton.isChecked():
-            hvId = 4
-        Preferences.setHelp("HelpViewerType", hvId)
-        Preferences.setWebBrowser("HelpViewerType", hvId)
+        Preferences.setHelp(
+            "HelpViewerType",
+            self.helpViewerGroup.checkedId())
         Preferences.setHelp(
             "CustomViewer",
             self.customViewerPicker.text())
--- a/eric7/Preferences/ConfigurationPages/HelpViewersPage.ui	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/Preferences/ConfigurationPages/HelpViewersPage.ui	Wed Oct 20 19:47:18 2021 +0200
@@ -10,7 +10,7 @@
     <height>177</height>
    </rect>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_3">
+  <layout class="QVBoxLayout" name="verticalLayout_2">
    <item>
     <widget class="QLabel" name="headerLabel">
      <property name="text">
@@ -36,68 +36,86 @@
      <property name="title">
       <string>Help Viewer</string>
      </property>
-     <layout class="QGridLayout" name="gridLayout">
-      <item row="0" column="0">
-       <widget class="QRadioButton" name="helpBrowserButton">
-        <property name="toolTip">
-         <string>Select to use the Eric Web Browser</string>
-        </property>
-        <property name="text">
-         <string>Eric Web Browser</string>
-        </property>
-        <property name="checked">
-         <bool>true</bool>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="1">
-       <widget class="QRadioButton" name="qtAssistantButton">
-        <property name="toolTip">
-         <string>Select to use Qt Assistant</string>
-        </property>
-        <property name="text">
-         <string>Qt Assistant</string>
-        </property>
-       </widget>
+     <layout class="QVBoxLayout" name="verticalLayout">
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <widget class="QRadioButton" name="internalViewerButton">
+          <property name="toolTip">
+           <string>Select to use the internal help viewer</string>
+          </property>
+          <property name="text">
+           <string>Internal Viewer</string>
+          </property>
+          <property name="checked">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QRadioButton" name="helpBrowserButton">
+          <property name="toolTip">
+           <string>Select to use the Eric Web Browser</string>
+          </property>
+          <property name="text">
+           <string>Eric Web Browser</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QRadioButton" name="qtAssistantButton">
+          <property name="toolTip">
+           <string>Select to use Qt Assistant</string>
+          </property>
+          <property name="text">
+           <string>Qt Assistant</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QRadioButton" name="webBrowserButton">
+          <property name="toolTip">
+           <string>Select to use the configured web browser of the system</string>
+          </property>
+          <property name="text">
+           <string>System Web Browser</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
       </item>
-      <item row="0" column="2">
-       <widget class="QRadioButton" name="webBrowserButton">
-        <property name="toolTip">
-         <string>Select to use the configured web browser of the system</string>
-        </property>
-        <property name="text">
-         <string>System Web Browser</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="3">
-       <widget class="QRadioButton" name="customViewerButton">
-        <property name="toolTip">
-         <string>Select to use a custom viewer</string>
-        </property>
-        <property name="text">
-         <string>Custom</string>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="0" colspan="4">
-       <widget class="EricPathPicker" name="customViewerPicker" native="true">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
-        </property>
-        <property name="focusPolicy">
-         <enum>Qt::StrongFocus</enum>
-        </property>
-        <property name="toolTip">
-         <string>Enter the custom viewer to be used</string>
-        </property>
-       </widget>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QRadioButton" name="customViewerButton">
+          <property name="toolTip">
+           <string>Select to use a custom viewer</string>
+          </property>
+          <property name="text">
+           <string>Custom</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="EricPathPicker" name="customViewerPicker" native="true">
+          <property name="enabled">
+           <bool>false</bool>
+          </property>
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="focusPolicy">
+           <enum>Qt::StrongFocus</enum>
+          </property>
+          <property name="toolTip">
+           <string>Enter the custom viewer to be used</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
       </item>
      </layout>
     </widget>
@@ -126,10 +144,12 @@
   </customwidget>
  </customwidgets>
  <tabstops>
+  <tabstop>internalViewerButton</tabstop>
   <tabstop>helpBrowserButton</tabstop>
   <tabstop>qtAssistantButton</tabstop>
   <tabstop>webBrowserButton</tabstop>
   <tabstop>customViewerButton</tabstop>
+  <tabstop>customViewerPicker</tabstop>
  </tabstops>
  <resources/>
  <connections>
--- a/eric7/Preferences/__init__.py	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/Preferences/__init__.py	Wed Oct 20 19:47:18 2021 +0200
@@ -909,6 +909,7 @@
         "PySide2DocDir": "",
         "PySide6DocDir": "",
         "EricDocDir": "",
+        "HelpViewerType": 0,    # internal help viewer
     }
     
     # defaults for the web browser settings
@@ -1042,12 +1043,6 @@
         "SafeBrowsingUpdateDateTime": QDateTime(),
         "SafeBrowsingUseLookupApi": False,
     }
-    # TODO: change default to internal help viewer (= 0) and move to
-    #       helpDefaults
-    if QWebEngineSettings:
-        webBrowserDefaults["HelpViewerType"] = 1      # eric browser
-    else:
-        webBrowserDefaults["HelpViewerType"] = 2      # Qt Assistant
     
     @classmethod
     def initWebEngineSettingsDefaults(cls):
@@ -2659,8 +2654,12 @@
     @param key the key of the value to get
     @return the requested help setting
     """
-    return Prefs.settings.value("Help/" + key,
-                                Prefs.helpDefaults[key])
+    if key in ("HelpViewerType", ):
+        return int(Prefs.settings.value(
+            "Help/" + key, Prefs.helpDefaults[key]))
+    else:
+        return Prefs.settings.value(
+            "Help/" + key, Prefs.helpDefaults[key])
 
 
 def setHelp(key, value):
@@ -2748,13 +2747,6 @@
         return pwConvert(Prefs.settings.value(
             "WebBrowser/" + key, Prefs.webBrowserDefaults[key]),
             encode=False)
-    elif key == "HelpViewerType":
-        # special treatment to adjust for missing QtWebEngine
-        value = int(Prefs.settings.value(
-            "WebBrowser/" + key, Prefs.webBrowserDefaults[key]))
-        if QWebEngineSettings is None:
-            value = Prefs.webBrowserDefaults[key]
-        return value
     elif key in ["StartupBehavior", "HistoryLimit",
                  "DownloadManagerRemovePolicy", "SyncType", "SyncFtpPort",
                  "SyncFtpIdleTimeout", "SyncEncryptionKeyLength",
--- a/eric7/UI/UserInterface.py	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/UI/UserInterface.py	Wed Oct 20 19:47:18 2021 +0200
@@ -5899,9 +5899,10 @@
         if home.endswith(".chm"):
             self.__chmViewer(home)
         else:
-            # TODO: add logic for internal help viewer (= 0)
-            hvType = Preferences.getWebBrowser("HelpViewerType")
-            if hvType == 1:
+            hvType = Preferences.getHelp("HelpViewerType")
+            if hvType == 0:
+                self.__activateHelpViewerWidget(urlStr=home)
+            elif hvType == 1:
                 self.launchHelpViewer(home)
             elif hvType == 2:
                 if home.startswith("qthelp://"):
@@ -5954,9 +5955,10 @@
             else:
                 home = "file://" + home
         
-        # TODO: add logic for internal help viewer (= 0)
-        hvType = Preferences.getWebBrowser("HelpViewerType")
-        if hvType == 1:
+        hvType = Preferences.getHelp("HelpViewerType")
+        if hvType == 0:
+            self.__activateHelpViewerWidget(urlStr=home)
+        elif hvType == 1:
             self.launchHelpViewer(home)
         elif hvType == 2:
             if home.startswith("qthelp://"):
@@ -6023,9 +6025,10 @@
         else:
             home = pyqtDocDir
         
-        # TODO: add logic for internal help viewer (= 0)
-        hvType = Preferences.getWebBrowser("HelpViewerType")
-        if hvType == 1:
+        hvType = Preferences.getHelp("HelpViewerType")
+        if hvType == 0:
+            self.__activateHelpViewerWidget(urlStr=home)
+        elif hvType == 1:
             self.launchHelpViewer(home)
         elif hvType == 2:
             if home.startswith("qthelp://"):
@@ -6061,9 +6064,10 @@
             else:
                 home = "file://" + home
         
-        # TODO: add logic for internal help viewer (= 0)
-        hvType = Preferences.getWebBrowser("HelpViewerType")
-        if hvType == 1:
+        hvType = Preferences.getHelp("HelpViewerType")
+        if hvType == 0:
+            self.__activateHelpViewerWidget(urlStr=home)
+        elif hvType == 1:
             self.launchHelpViewer(home)
         elif hvType == 2:
             if home.startswith("qthelp://"):
@@ -6120,9 +6124,10 @@
         else:
             home = pysideDocDir
         
-        # TODO: add logic for internal help viewer (= 0)
-        hvType = Preferences.getWebBrowser("HelpViewerType")
-        if hvType == 1:
+        hvType = Preferences.getHelp("HelpViewerType")
+        if hvType == 0:
+            self.__activateHelpViewerWidget(urlStr=home)
+        elif hvType == 1:
             self.launchHelpViewer(home)
         elif hvType == 2:
             if home.startswith("qthelp://"):
@@ -7036,9 +7041,12 @@
         self.__vcsStatusWidget.setFocus(
             Qt.FocusReason.ActiveWindowFocusReason)
     
-    def __activateHelpViewerWidget(self):
+    def __activateHelpViewerWidget(self, urlStr=None):
         """
         Private method to activate the embedded Help Viewer window.
+        
+        @param urlStr URL to be shown
+        @type str
         """
         if self.__layoutType == "Toolboxes":
             self.rToolboxDock.show()
@@ -7048,11 +7056,21 @@
             self.rightSidebar.setCurrentWidget(self.__helpViewerWidget)
         self.__helpViewerWidget.setFocus(
             Qt.FocusReason.ActiveWindowFocusReason)
-            
-        searchWord = self.viewmanager.textForFind(False)
-        if searchWord == "":
-            searchWord = None
-        self.__helpViewerWidget.activate(searchWord=searchWord)
+        
+        url = None
+        searchWord = None
+        
+        if urlStr:
+            url = QUrl(urlStr)
+            if not url.isValid():
+                url = None
+        
+        if url is None:
+            searchWord = self.viewmanager.textForFind(False)
+            if searchWord == "":
+                searchWord = None
+        
+        self.__helpViewerWidget.activate(searchWord=searchWord, url=url)
     
     ##########################################################
     ## Below are slots to handle StdOut and StdErr
--- a/eric7/eric7.py	Wed Oct 20 19:45:22 2021 +0200
+++ b/eric7/eric7.py	Wed Oct 20 19:47:18 2021 +0200
@@ -422,8 +422,3 @@
 
 if __name__ == '__main__':
     main()
-
-#
-# Generic TODOs:
-#
-# TODO: add an embedded help viewer based on QWebEngineView/QTextBrowser (right side)

eric ide

mercurial