15 basestring = str |
15 basestring = str |
16 |
16 |
17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QTimer |
17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QTimer |
18 from PyQt5.QtGui import QCursor |
18 from PyQt5.QtGui import QCursor |
19 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, \ |
19 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, \ |
20 QComboBox, QSizePolicy, QLineEdit, QTextEdit, QToolTip, QToolButton, \ |
20 QComboBox, QSizePolicy, QLineEdit, QTextEdit, QToolTip |
21 QActionGroup, QMenu |
|
22 |
21 |
23 from E5Gui.E5TextEditSearchWidget import E5TextEditSearchWidget |
22 from E5Gui.E5TextEditSearchWidget import E5TextEditSearchWidget |
24 from E5Gui.E5ToolButton import E5ToolButton |
|
25 |
23 |
26 import Preferences |
24 import Preferences |
27 import UI.PixmapCache |
|
28 |
25 |
29 from .CodeDocumentationViewerTemplate import \ |
26 from .CodeDocumentationViewerTemplate import \ |
30 prepareDocumentationViewerHtmlDocument, \ |
27 prepareDocumentationViewerHtmlDocument, \ |
31 prepareDocumentationViewerHtmlDocWarningDocument, \ |
28 prepareDocumentationViewerHtmlDocWarningDocument, \ |
32 prepareDocumentationViewerHtmlWarningDocument |
29 prepareDocumentationViewerHtmlWarningDocument |
250 self.tr("Select the code info provider")) |
247 self.tr("Select the code info provider")) |
251 self.providerComboBox.addItem(self.tr("<disabled>"), "disabled") |
248 self.providerComboBox.addItem(self.tr("<disabled>"), "disabled") |
252 self.horizontalLayout1.addWidget(self.providerComboBox) |
249 self.horizontalLayout1.addWidget(self.providerComboBox) |
253 |
250 |
254 # top row 2 of widgets |
251 # top row 2 of widgets |
255 self.horizontalLayout2 = QHBoxLayout() |
|
256 self.horizontalLayout2.setObjectName("horizontalLayout2") |
|
257 |
|
258 self.objectLineEdit = QLineEdit(self) |
252 self.objectLineEdit = QLineEdit(self) |
259 self.objectLineEdit.setReadOnly(True) |
253 self.objectLineEdit.setReadOnly(True) |
260 self.objectLineEdit.setObjectName("objectLineEdit") |
254 self.objectLineEdit.setObjectName("objectLineEdit") |
261 self.horizontalLayout2.addWidget(self.objectLineEdit) |
|
262 |
255 |
263 self.verticalLayout.addLayout(self.horizontalLayout1) |
256 self.verticalLayout.addLayout(self.horizontalLayout1) |
264 self.verticalLayout.addLayout(self.horizontalLayout2) |
257 self.verticalLayout.addWidget(self.objectLineEdit) |
265 |
258 |
266 # Plain Text Viewer |
|
267 self.__plainTextViewer = PlainTextDocumentationViewer(self) |
|
268 self.__plainTextViewer.setObjectName("__plainTextViewer") |
|
269 self.verticalLayout.addWidget(self.__plainTextViewer) |
|
270 |
|
271 # Rich Text (Web) Viewer |
|
272 try: |
259 try: |
|
260 # Rich Text (Web) Viewer |
273 self.__richTextViewer = WebViewDocumentationViewer(self) |
261 self.__richTextViewer = WebViewDocumentationViewer(self) |
274 self.__richTextViewer.setObjectName("__richTextViewer") |
262 self.__richTextViewer.setObjectName("__richTextViewer") |
275 self.verticalLayout.addWidget(self.__richTextViewer) |
263 self.verticalLayout.addWidget(self.__richTextViewer) |
|
264 |
|
265 self.__plainTextViewer = None |
|
266 |
|
267 # backward compatibility for plug-ins before 2018-09-17 |
|
268 Preferences.setDocuViewer("ShowInfoAsRichText", True) |
276 except ImportError: |
269 except ImportError: |
277 # neither QtWebEngineWidgets nor QtWebKitWidgets is available |
270 # neither QtWebEngineWidgets nor QtWebKitWidgets is available |
278 self.__richTextViewer = None |
271 self.__richTextViewer = None |
279 |
272 |
280 self.__toolButton = E5ToolButton(self) |
273 # Plain Text Viewer |
281 self.__toolButton.setObjectName( |
274 self.__plainTextViewer = PlainTextDocumentationViewer(self) |
282 "navigation_supermenu_button") |
275 self.__plainTextViewer.setObjectName("__plainTextViewer") |
283 self.__toolButton.setIcon(UI.PixmapCache.getIcon("superMenu.png")) |
276 self.verticalLayout.addWidget(self.__plainTextViewer) |
284 self.__toolButton.setToolTip(self.tr("Main Menu")) |
277 |
285 self.__toolButton.setPopupMode(QToolButton.InstantPopup) |
278 # backward compatibility for plug-ins before 2018-09-17 |
286 self.__toolButton.setToolButtonStyle(Qt.ToolButtonIconOnly) |
279 Preferences.setDocuViewer("ShowInfoAsRichText", False) |
287 self.__toolButton.setFocusPolicy(Qt.NoFocus) |
|
288 self.__toolButton.setAutoRaise(True) |
|
289 self.__toolButton.setShowMenuInside(True) |
|
290 |
|
291 self.__optionsActionGroup = QActionGroup(self) |
|
292 self.__optionsActionGroup.setExclusive(True) |
|
293 self.__optionsMenu = QMenu(self) |
|
294 if self.__richTextViewer: |
|
295 self.__richTextAct = self.__optionsMenu.addAction( |
|
296 self.tr("Rich Text"), |
|
297 lambda: self.__showTextViewer(True)) |
|
298 self.__richTextAct.setCheckable(True) |
|
299 self.__optionsActionGroup.addAction(self.__richTextAct) |
|
300 else: |
|
301 # neither QtWebEngineWidgets nor QtWebKitWidgets is available |
|
302 self.__richTextAct = None |
|
303 self.__plainTextAct = self.__optionsMenu.addAction( |
|
304 self.tr("Plain Text"), |
|
305 lambda: self.__showTextViewer(False)) |
|
306 self.__plainTextAct.setCheckable(True) |
|
307 self.__optionsActionGroup.addAction(self.__plainTextAct) |
|
308 |
|
309 self.__toolButton.setMenu(self.__optionsMenu) |
|
310 self.horizontalLayout2.addWidget(self.__toolButton) |
|
311 |
280 |
312 self.providerComboBox.currentIndexChanged[int].connect( |
281 self.providerComboBox.currentIndexChanged[int].connect( |
313 self.on_providerComboBox_currentIndexChanged) |
282 self.on_providerComboBox_currentIndexChanged) |
314 |
283 |
315 def finalizeSetup(self): |
284 def finalizeSetup(self): |
316 """ |
285 """ |
317 Public method to finalize the setup of the documentation viewer. |
286 Public method to finalize the setup of the documentation viewer. |
318 """ |
287 """ |
319 if self.__richTextViewer is None: |
|
320 showRichText = False |
|
321 else: |
|
322 showRichText = Preferences.getDocuViewer("ShowInfoAsRichText") |
|
323 self.__showTextViewer(showRichText) |
|
324 |
|
325 self.__startingUp = False |
288 self.__startingUp = False |
326 provider = Preferences.getDocuViewer("Provider") |
289 provider = Preferences.getDocuViewer("Provider") |
327 if provider in self.__providers: |
290 if provider in self.__providers: |
328 index = self.providerComboBox.findData(provider) |
291 index = self.providerComboBox.findData(provider) |
329 else: |
292 else: |
441 # try again one index before |
404 # try again one index before |
442 word = editor.getWord(line, index - 1) |
405 word = editor.getWord(line, index - 1) |
443 self.objectLineEdit.setText(word) |
406 self.objectLineEdit.setText(word) |
444 |
407 |
445 if self.__selectedProvider != self.__disabledProvider: |
408 if self.__selectedProvider != self.__disabledProvider: |
446 self.__plainTextViewer.clear() |
|
447 if self.__richTextViewer: |
409 if self.__richTextViewer: |
448 self.__richTextViewer.clear() |
410 self.__richTextViewer.clear() |
|
411 else: |
|
412 self.__plainTextViewer.clear() |
449 self.__providers[self.__selectedProvider][0](editor) |
413 self.__providers[self.__selectedProvider][0](editor) |
450 |
414 |
451 def documentationReady(self, documentationInfo, isWarning=False, |
415 def documentationReady(self, documentationInfo, isWarning=False, |
452 isDocWarning=False): |
416 isDocWarning=False): |
453 """ |
417 """ |
569 @type str |
533 @type str |
570 """ |
534 """ |
571 if self.__richTextViewer: |
535 if self.__richTextViewer: |
572 self.__richTextViewer.setHtml(html) |
536 self.__richTextViewer.setHtml(html) |
573 |
537 |
574 def __setHtmlWarning(self, warningText): |
|
575 """ |
|
576 Private slot to set a display message. |
|
577 |
|
578 @param warningText text to be shown as a warning |
|
579 @type str |
|
580 """ |
|
581 if self.__richTextViewer: |
|
582 html = prepareDocumentationViewerHtmlWarningDocument(warningText) |
|
583 self.__richTextViewer.setHtml(html) |
|
584 |
|
585 @pyqtSlot(int) |
538 @pyqtSlot(int) |
586 def on_providerComboBox_currentIndexChanged(self, index): |
539 def on_providerComboBox_currentIndexChanged(self, index): |
587 """ |
540 """ |
588 Private slot to handle the selection of a provider. |
541 Private slot to handle the selection of a provider. |
589 |
542 |
590 @param index index of the selected provider |
543 @param index index of the selected provider |
591 @type int |
544 @type int |
592 """ |
545 """ |
593 if not self.__shuttingDown and not self.__startingUp: |
546 if not self.__shuttingDown and not self.__startingUp: |
594 self.__plainTextViewer.clear() |
|
595 if self.__richTextViewer: |
547 if self.__richTextViewer: |
596 self.__richTextViewer.clear() |
548 self.__richTextViewer.clear() |
|
549 else: |
|
550 self.__plainTextViewer.clear() |
597 self.objectLineEdit.clear() |
551 self.objectLineEdit.clear() |
598 |
552 |
599 provider = self.providerComboBox.itemData(index) |
553 provider = self.providerComboBox.itemData(index) |
600 if provider == self.__disabledProvider: |
554 if provider == self.__disabledProvider: |
601 self.__showDisabledMessage() |
555 self.__showDisabledMessage() |
636 if provider != self.__selectedProvider: |
583 if provider != self.__selectedProvider: |
637 index = self.providerComboBox.findData(provider) |
584 index = self.providerComboBox.findData(provider) |
638 if index < 0: |
585 if index < 0: |
639 index = 0 |
586 index = 0 |
640 self.providerComboBox.setCurrentIndex(index) |
587 self.providerComboBox.setCurrentIndex(index) |
641 |
|
642 def __showTextViewer(self, richText): |
|
643 """ |
|
644 Private slot to show the selected viewer. |
|
645 |
|
646 @param richText flag indicating the rich text viewer |
|
647 @type bool |
|
648 """ |
|
649 self.__showMarkdown = richText |
|
650 |
|
651 self.__plainTextViewer.clear() |
|
652 self.__plainTextViewer.setVisible(not richText) |
|
653 |
|
654 if self.__richTextViewer: |
|
655 self.__richTextViewer.clear() |
|
656 self.__richTextViewer.setVisible(richText) |
|
657 |
|
658 self.__plainTextAct.setChecked(not richText) |
|
659 if self.__richTextAct: |
|
660 self.__richTextAct.setChecked(richText) |
|
661 |
|
662 self.documentationReady(self.__lastDocumentation) |
|
663 |
|
664 Preferences.setDocuViewer("ShowInfoAsRichText", richText) |
|