UI/CodeDocumentationViewer.py

changeset 5962
a339eed93b19
parent 5961
2a5232311a65
child 5963
14522ec8cd08
--- a/UI/CodeDocumentationViewer.py	Sun Nov 05 17:16:40 2017 +0100
+++ b/UI/CodeDocumentationViewer.py	Mon Nov 06 20:00:42 2017 +0100
@@ -254,6 +254,22 @@
         self.objectLineEdit.setObjectName("objectLineEdit")
         self.horizontalLayout2.addWidget(self.objectLineEdit)
         
+        self.verticalLayout.addLayout(self.horizontalLayout1)
+        self.verticalLayout.addLayout(self.horizontalLayout2)
+        
+        # Plain Text Viewer
+        self.__plainTextViewer = PlainTextDocumentationViewer(self)
+        self.__plainTextViewer.setObjectName("__plainTextViewer")
+        self.verticalLayout.addWidget(self.__plainTextViewer)
+        
+        # Rich Text (Web) Viewer
+        try:
+            self.__richTextViewer = WebViewDocumentationViewer(self)
+            self.__richTextViewer.setObjectName("__richTextViewer")
+            self.verticalLayout.addWidget(self.__richTextViewer)
+        except ImportError:
+            self.__richTextViewer = None
+        
         self.__toolButton = E5ToolButton(self)
         self.__toolButton.setObjectName(
             "navigation_supermenu_button")
@@ -265,36 +281,24 @@
         self.__toolButton.setAutoRaise(True)
         self.__toolButton.setShowMenuInside(True)
         
+        self.__optionsActionGroup = QActionGroup(self)
+        self.__optionsActionGroup.setExclusive(True)
         self.__optionsMenu = QMenu(self)
-        self.__richTextAct = self.__optionsMenu.addAction(
-            self.tr("Rich Text"),
-            lambda: self.__showTextViewer(True))
-        self.__richTextAct.setCheckable(True)
+        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)
         self.__plainTextAct = self.__optionsMenu.addAction(
             self.tr("Plain Text"),
             lambda: self.__showTextViewer(False))
         self.__plainTextAct.setCheckable(True)
-        self.__optionsActionGroup = QActionGroup(self)
-        self.__optionsActionGroup.setExclusive(True)
-        self.__optionsActionGroup.addAction(self.__richTextAct)
         self.__optionsActionGroup.addAction(self.__plainTextAct)
         
         self.__toolButton.setMenu(self.__optionsMenu)
         self.horizontalLayout2.addWidget(self.__toolButton)
         
-        self.verticalLayout.addLayout(self.horizontalLayout1)
-        self.verticalLayout.addLayout(self.horizontalLayout2)
-        
-        # Plain Text Viewer
-        self.__plainTextViewer = PlainTextDocumentationViewer(self)
-        self.__plainTextViewer.setObjectName("__plainTextViewer")
-        self.verticalLayout.addWidget(self.__plainTextViewer)
-        
-        # Rich Text (Web) Viewer
-        self.__richTextViewer = WebViewDocumentationViewer(self)
-        self.__richTextViewer.setObjectName("__richTextViewer")
-        self.verticalLayout.addWidget(self.__richTextViewer)
-        
         self.providerComboBox.currentIndexChanged[int].connect(
             self.on_providerComboBox_currentIndexChanged)
     
@@ -302,7 +306,11 @@
         """
         Public method to finalize the setup of the documentation viewer.
         """
-        self.__showTextViewer(Preferences.getDocuViewer("ShowInfoAsRichText"))
+        if self.__richTextViewer:
+            self.__showTextViewer(
+                Preferences.getDocuViewer("ShowInfoAsRichText"))
+        else:
+            self.__showTextViewer(False)
         
         self.__startingUp = False
         provider = Preferences.getDocuViewer("Provider")
@@ -409,7 +417,7 @@
         
         if self.__selectedProvider != self.__disabledProvider:
             self.__plainTextViewer.clear()
-            self.__richTextViewer.clear()
+            self.__richTextViewer and self.__richTextViewer.clear()
             self.__providers[self.__selectedProvider][0](editor)
     
     # TODO: document this hook in the plug-in document
@@ -533,7 +541,8 @@
         @param html prepared HTML text
         @type str
         """
-        self.__richTextViewer.setHtml(html)
+        if self.__richTextViewer:
+            self.__richTextViewer.setHtml(html)
     
     def __setHtmlWarning(self, warningText):
         """
@@ -542,8 +551,9 @@
         @param warningText text to be shown as a warning
         @type str
         """
-        html = prepareDocumentationViewerHtmlWarningDocument(warningText)
-        self.__richTextViewer.setHtml(html)
+        if self.__richTextViewer:
+            html = prepareDocumentationViewerHtmlWarningDocument(warningText)
+            self.__richTextViewer.setHtml(html)
     
     @pyqtSlot(int)
     def on_providerComboBox_currentIndexChanged(self, index):
@@ -555,7 +565,7 @@
         """
         if not self.__shuttingDown and not self.__startingUp:
             self.__plainTextViewer.clear()
-            self.__richTextViewer.clear()
+            self.__richTextViewer and self.__richTextViewer.clear()
             self.objectLineEdit.clear()
             
             provider = self.providerComboBox.itemData(index)
@@ -578,9 +588,12 @@
         """
         Public slot to handle a change of preferences.
         """
-        showMarkdown = Preferences.getDocuViewer("ShowInfoAsRichText")
-        if showMarkdown != self.__showMarkdown:
-            self.__showTextViewer(showMarkdown)
+        if self.__richTextViewer:
+            showMarkdown = Preferences.getDocuViewer("ShowInfoAsRichText")
+            if showMarkdown != self.__showMarkdown:
+                self.__showTextViewer(showMarkdown)
+        else:
+            self.__showTextViewer(False)
         
         provider = Preferences.getDocuViewer("Provider")
         if provider != self.__selectedProvider:
@@ -599,13 +612,13 @@
         self.__showMarkdown = richText
         
         self.__plainTextViewer.clear()
-        self.__richTextViewer.clear()
+        self.__richTextViewer and self.__richTextViewer.clear()
         
         self.__plainTextViewer.setVisible(not richText)
-        self.__richTextViewer.setVisible(richText)
+        self.__richTextViewer and self.__richTextViewer.setVisible(richText)
         
         self.__plainTextAct.setChecked(not richText)
-        self.__richTextAct.setChecked(richText)
+        self.__richTextViewer and self.__richTextAct.setChecked(richText)
         
         self.documentationReady(self.__lastDocumentation)
         

eric ide

mercurial