UI/CodeDocumentationViewer.py

changeset 6505
470d878cbe9f
parent 6475
ed23eb2f20a4
child 6506
ff6172ce89a9
--- a/UI/CodeDocumentationViewer.py	Sun Sep 16 19:13:30 2018 +0200
+++ b/UI/CodeDocumentationViewer.py	Mon Sep 17 19:25:49 2018 +0200
@@ -17,14 +17,11 @@
 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QTimer
 from PyQt5.QtGui import QCursor
 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, \
-    QComboBox, QSizePolicy, QLineEdit, QTextEdit, QToolTip, QToolButton, \
-    QActionGroup, QMenu
+    QComboBox, QSizePolicy, QLineEdit, QTextEdit, QToolTip
 
 from E5Gui.E5TextEditSearchWidget import E5TextEditSearchWidget
-from E5Gui.E5ToolButton import E5ToolButton
 
 import Preferences
-import UI.PixmapCache
 
 from .CodeDocumentationViewerTemplate import \
     prepareDocumentationViewerHtmlDocument, \
@@ -252,62 +249,34 @@
         self.horizontalLayout1.addWidget(self.providerComboBox)
         
         # top row 2 of widgets
-        self.horizontalLayout2 = QHBoxLayout()
-        self.horizontalLayout2.setObjectName("horizontalLayout2")
-        
         self.objectLineEdit = QLineEdit(self)
         self.objectLineEdit.setReadOnly(True)
         self.objectLineEdit.setObjectName("objectLineEdit")
-        self.horizontalLayout2.addWidget(self.objectLineEdit)
         
         self.verticalLayout.addLayout(self.horizontalLayout1)
-        self.verticalLayout.addLayout(self.horizontalLayout2)
+        self.verticalLayout.addWidget(self.objectLineEdit)
         
-        # Plain Text Viewer
-        self.__plainTextViewer = PlainTextDocumentationViewer(self)
-        self.__plainTextViewer.setObjectName("__plainTextViewer")
-        self.verticalLayout.addWidget(self.__plainTextViewer)
-        
-        # Rich Text (Web) Viewer
         try:
+            # Rich Text (Web) Viewer
             self.__richTextViewer = WebViewDocumentationViewer(self)
             self.__richTextViewer.setObjectName("__richTextViewer")
             self.verticalLayout.addWidget(self.__richTextViewer)
+            
+            self.__plainTextViewer = None
+            
+            # backward compatibility for plug-ins before 2018-09-17
+            Preferences.setDocuViewer("ShowInfoAsRichText", True)
         except ImportError:
             # neither QtWebEngineWidgets nor QtWebKitWidgets is available
             self.__richTextViewer = None
-        
-        self.__toolButton = E5ToolButton(self)
-        self.__toolButton.setObjectName(
-            "navigation_supermenu_button")
-        self.__toolButton.setIcon(UI.PixmapCache.getIcon("superMenu.png"))
-        self.__toolButton.setToolTip(self.tr("Main Menu"))
-        self.__toolButton.setPopupMode(QToolButton.InstantPopup)
-        self.__toolButton.setToolButtonStyle(Qt.ToolButtonIconOnly)
-        self.__toolButton.setFocusPolicy(Qt.NoFocus)
-        self.__toolButton.setAutoRaise(True)
-        self.__toolButton.setShowMenuInside(True)
-        
-        self.__optionsActionGroup = QActionGroup(self)
-        self.__optionsActionGroup.setExclusive(True)
-        self.__optionsMenu = QMenu(self)
-        if self.__richTextViewer:
-            self.__richTextAct = self.__optionsMenu.addAction(
-                self.tr("Rich Text"),
-                lambda: self.__showTextViewer(True))
-            self.__richTextAct.setCheckable(True)
-            self.__optionsActionGroup.addAction(self.__richTextAct)
-        else:
-            # neither QtWebEngineWidgets nor QtWebKitWidgets is available
-            self.__richTextAct = None
-        self.__plainTextAct = self.__optionsMenu.addAction(
-            self.tr("Plain Text"),
-            lambda: self.__showTextViewer(False))
-        self.__plainTextAct.setCheckable(True)
-        self.__optionsActionGroup.addAction(self.__plainTextAct)
-        
-        self.__toolButton.setMenu(self.__optionsMenu)
-        self.horizontalLayout2.addWidget(self.__toolButton)
+            
+            # Plain Text Viewer
+            self.__plainTextViewer = PlainTextDocumentationViewer(self)
+            self.__plainTextViewer.setObjectName("__plainTextViewer")
+            self.verticalLayout.addWidget(self.__plainTextViewer)
+            
+            # backward compatibility for plug-ins before 2018-09-17
+            Preferences.setDocuViewer("ShowInfoAsRichText", False)
         
         self.providerComboBox.currentIndexChanged[int].connect(
             self.on_providerComboBox_currentIndexChanged)
@@ -316,12 +285,6 @@
         """
         Public method to finalize the setup of the documentation viewer.
         """
-        if self.__richTextViewer is None:
-            showRichText = False
-        else:
-            showRichText = Preferences.getDocuViewer("ShowInfoAsRichText")
-        self.__showTextViewer(showRichText)
-        
         self.__startingUp = False
         provider = Preferences.getDocuViewer("Provider")
         if provider in self.__providers:
@@ -443,9 +406,10 @@
         self.objectLineEdit.setText(word)
         
         if self.__selectedProvider != self.__disabledProvider:
-            self.__plainTextViewer.clear()
             if self.__richTextViewer:
                 self.__richTextViewer.clear()
+            else:
+                self.__plainTextViewer.clear()
             self.__providers[self.__selectedProvider][0](editor)
     
     def documentationReady(self, documentationInfo, isWarning=False,
@@ -482,7 +446,7 @@
                 self.documentationReady(self.tr("No documentation available"),
                                         isDocWarning=True)
         else:
-            if self.__showMarkdown:
+            if self.__richTextViewer:
                 if isWarning:
                     html = prepareDocumentationViewerHtmlWarningDocument(
                         documentationInfo)
@@ -571,17 +535,6 @@
         if self.__richTextViewer:
             self.__richTextViewer.setHtml(html)
     
-    def __setHtmlWarning(self, warningText):
-        """
-        Private slot to set a display message.
-        
-        @param warningText text to be shown as a warning
-        @type str
-        """
-        if self.__richTextViewer:
-            html = prepareDocumentationViewerHtmlWarningDocument(warningText)
-            self.__richTextViewer.setHtml(html)
-    
     @pyqtSlot(int)
     def on_providerComboBox_currentIndexChanged(self, index):
         """
@@ -591,9 +544,10 @@
         @type int
         """
         if not self.__shuttingDown and not self.__startingUp:
-            self.__plainTextViewer.clear()
             if self.__richTextViewer:
                 self.__richTextViewer.clear()
+            else:
+                self.__plainTextViewer.clear()
             self.objectLineEdit.clear()
             
             provider = self.providerComboBox.itemData(index)
@@ -616,13 +570,6 @@
         """
         Public slot to handle a change of preferences.
         """
-        if self.__richTextViewer is None:
-            showRichText = False
-        else:
-            showRichText = Preferences.getDocuViewer("ShowInfoAsRichText")
-        if showRichText != self.__showMarkdown:
-            self.__showTextViewer(showRichText)
-        
         provider = Preferences.getDocuViewer("Provider")
         self.__selectProvider(provider)
     
@@ -638,27 +585,3 @@
             if index < 0:
                 index = 0
             self.providerComboBox.setCurrentIndex(index)
-    
-    def __showTextViewer(self, richText):
-        """
-        Private slot to show the selected viewer.
-        
-        @param richText flag indicating the rich text viewer
-        @type bool
-        """
-        self.__showMarkdown = richText
-        
-        self.__plainTextViewer.clear()
-        self.__plainTextViewer.setVisible(not richText)
-        
-        if self.__richTextViewer:
-            self.__richTextViewer.clear()
-            self.__richTextViewer.setVisible(richText)
-        
-        self.__plainTextAct.setChecked(not richText)
-        if self.__richTextAct:
-            self.__richTextAct.setChecked(richText)
-        
-        self.documentationReady(self.__lastDocumentation)
-        
-        Preferences.setDocuViewer("ShowInfoAsRichText", richText)

eric ide

mercurial