42 self.__verticalLayout.setContentsMargins(0, 0, 0, 0) |
48 self.__verticalLayout.setContentsMargins(0, 0, 0, 0) |
43 |
49 |
44 self.__contents = QTextEdit(self) |
50 self.__contents = QTextEdit(self) |
45 self.__contents.setTabChangesFocus(True) |
51 self.__contents.setTabChangesFocus(True) |
46 self.__contents.setReadOnly(True) |
52 self.__contents.setReadOnly(True) |
|
53 self.__contents.setLineWrapMode(QTextEdit.NoWrap) |
47 self.__contents.setObjectName("contents") |
54 self.__contents.setObjectName("contents") |
48 self.__verticalLayout.addWidget(self.__contents) |
55 self.__verticalLayout.addWidget(self.__contents) |
49 |
56 |
50 self.__searchWidget = E5TextEditSearchWidget(self) |
57 self.__searchWidget = E5TextEditSearchWidget(self) |
51 self.__searchWidget.setFocusPolicy(Qt.WheelFocus) |
58 self.__searchWidget.setFocusPolicy(Qt.WheelFocus) |
97 self.__verticalLayout = QVBoxLayout(self) |
104 self.__verticalLayout = QVBoxLayout(self) |
98 self.__verticalLayout.setObjectName("verticalLayout") |
105 self.__verticalLayout.setObjectName("verticalLayout") |
99 self.__verticalLayout.setContentsMargins(0, 0, 0, 0) |
106 self.__verticalLayout.setContentsMargins(0, 0, 0, 0) |
100 |
107 |
101 try: |
108 try: |
102 from PyQt5.QtWebEngineWidgets import QWebEngineView |
109 from PyQt5.QtWebEngineWidgets import QWebEngineView, \ |
|
110 QWebEngineSettings |
103 self.__contents = QWebEngineView(self) |
111 self.__contents = QWebEngineView(self) |
104 self.__contents.page().linkHovered.connect(self.__showLink) |
112 self.__contents.page().linkHovered.connect(self.__showLink) |
|
113 try: |
|
114 self.__contents.settings().setAttribute( |
|
115 QWebEngineSettings.FocusOnNavigationEnabled, False) |
|
116 except AttributeError: |
|
117 # pre Qt 5.8 |
|
118 pass |
105 self.__usesWebKit = False |
119 self.__usesWebKit = False |
106 except ImportError: |
120 except ImportError: |
107 from PyQt5.QtWebKitWidgets import QWebPage, QWebView |
121 from PyQt5.QtWebKitWidgets import QWebPage, QWebView |
108 self.__contents = QWebView(self) |
122 self.__contents = QWebView(self) |
109 self.__contents.page().setLinkDelegationPolicy( |
123 self.__contents.page().setLinkDelegationPolicy( |
186 |
202 |
187 self.__shuttingDown = False |
203 self.__shuttingDown = False |
188 self.__startingUp = True |
204 self.__startingUp = True |
189 |
205 |
190 self.__lastDocumentation = None |
206 self.__lastDocumentation = None |
|
207 self.__requestingEditor = None |
191 |
208 |
192 self.__noDocumentationString = self.tr("No documentation available") |
209 self.__noDocumentationString = self.tr("No documentation available") |
193 self.__disabledString = self.tr( |
210 self.__disabledString = self.tr( |
194 "No source code documentation provider has been registered or" |
211 "No source code documentation provider has been registered or" |
195 " this function has been disabled.") |
212 " this function has been disabled.") |
388 self.__plainTextViewer.clear() |
405 self.__plainTextViewer.clear() |
389 self.__richTextViewer.clear() |
406 self.__richTextViewer.clear() |
390 self.__providers[self.__selectedProvider][0](editor) |
407 self.__providers[self.__selectedProvider][0](editor) |
391 |
408 |
392 # TODO: document this hook in the plug-in document |
409 # TODO: document this hook in the plug-in document |
393 def documentationReady(self, documentationInfo): |
410 def documentationReady(self, documentationInfo, isWarning=False): |
394 """ |
411 """ |
395 Public method to provide the documentation info to the viewer. |
412 Public method to provide the documentation info to the viewer. |
396 |
413 |
397 If documentationInfo is a dictionary, it should contains these keys |
414 If documentationInfo is a dictionary, it should contains these keys |
398 and data: |
415 and data: |
403 the module it belongs to. |
420 the module it belongs to. |
404 docstring: its documentation string |
421 docstring: its documentation string |
405 |
422 |
406 @param documentationInfo dictionary containing the source docu data |
423 @param documentationInfo dictionary containing the source docu data |
407 @type dict or str |
424 @type dict or str |
|
425 @param isWarning flag indicating a warning page |
|
426 @type bool |
408 """ |
427 """ |
409 self.__ui.activateCodeDocumentationViewer(switchFocus=False) |
428 self.__ui.activateCodeDocumentationViewer(switchFocus=False) |
410 |
429 |
411 self.__lastDocumentation = documentationInfo |
430 self.__lastDocumentation = documentationInfo |
412 |
431 |
413 if documentationInfo is not None: |
432 if documentationInfo is not None: |
414 if not documentationInfo: |
433 if not documentationInfo: |
415 if self.__selectedProvider == self.__disabledProvider: |
434 if self.__selectedProvider == self.__disabledProvider: |
416 fullText = self.__disabledString |
435 self.documentationReady(self.__disabledString, |
|
436 isWarning=True) |
417 else: |
437 else: |
418 fullText = self.__noDocumentationString |
438 self.documentationReady(self.__noDocumentationString, |
419 elif isinstance(documentationInfo, str): |
439 isWarning=True) |
|
440 return |
|
441 |
|
442 if self.__showMarkdown: |
|
443 if isWarning: |
|
444 html = prepareDocumentationViewerHtmlWarningDocument( |
|
445 documentationInfo) |
|
446 elif isinstance(documentationInfo, dict): |
|
447 html = prepareDocumentationViewerHtmlDocument( |
|
448 documentationInfo) |
|
449 else: |
|
450 html = "" |
|
451 if html: |
|
452 self.__setHtml(html) |
|
453 return |
|
454 |
|
455 if isinstance(documentationInfo, str): |
420 fullText = documentationInfo |
456 fullText = documentationInfo |
421 elif isinstance(documentationInfo, dict): |
457 elif isinstance(documentationInfo, dict): |
422 # format the text with markdown syntax |
|
423 name = documentationInfo["name"] |
458 name = documentationInfo["name"] |
424 if name: |
459 if name: |
425 title = "".join([name, "\n", |
460 title = "".join([name, "\n", |
426 "=" * len(name), "\n\n"]) |
461 "=" * len(name), "\n\n"]) |
427 else: |
462 else: |
428 title = "" |
463 title = "" |
429 |
464 |
430 if documentationInfo["argspec"]: |
465 if documentationInfo["argspec"]: |
431 if self.__showMarkdown: |
466 definition = self.tr("Definition: {0}{1}\n").format( |
432 definition = self.tr( |
467 name, documentationInfo["argspec"]) |
433 "**Definition**: {0}{1}\n", |
|
434 "string with markdown syntax").format( |
|
435 name, documentationInfo["argspec"]) |
|
436 else: |
|
437 definition = self.tr( |
|
438 "Definition: {0}{1}\n", |
|
439 "string as plain text").format( |
|
440 name, documentationInfo["argspec"]) |
|
441 else: |
468 else: |
442 definition = '' |
469 definition = '' |
443 |
470 |
444 if documentationInfo["note"]: |
471 if documentationInfo["note"]: |
445 if self.__showMarkdown: |
472 note = self.tr("Info: {0}\n\n----\n\n").format( |
446 note = self.tr( |
473 documentationInfo["note"]) |
447 "**Info**: {0}\n\n----\n\n", |
|
448 "string with markdown syntax").format( |
|
449 documentationInfo["note"]) |
|
450 else: |
|
451 note = self.tr( |
|
452 "Info: {0}\n\n----\n\n", |
|
453 "string as plain text").format( |
|
454 documentationInfo["note"]) |
|
455 else: |
474 else: |
456 note = "" |
475 note = "" |
457 |
476 |
458 if documentationInfo["docstring"] is None: |
477 if documentationInfo["docstring"] is None: |
459 docString = "" |
478 docString = "" |
489 self.__richTextViewer.clear() |
508 self.__richTextViewer.clear() |
490 self.objectLineEdit.clear() |
509 self.objectLineEdit.clear() |
491 |
510 |
492 provider = self.providerComboBox.itemData(index) |
511 provider = self.providerComboBox.itemData(index) |
493 if provider == self.__disabledProvider: |
512 if provider == self.__disabledProvider: |
494 self.documentationReady(self.__disabledString) |
513 self.documentationReady(self.__disabledString, isWarning=True) |
495 else: |
514 else: |
496 self.__lastDocumentation = None |
515 self.__lastDocumentation = None |
497 |
516 |
498 Preferences.setDocuViewer("Provider", provider) |
517 Preferences.setDocuViewer("Provider", provider) |
499 self.__selectedProvider = provider |
518 self.__selectedProvider = provider |