UI/CodeDocumentationViewer.py

changeset 5919
d0de2b378b24
parent 5915
4bdac859df60
child 5922
4ee909600092
equal deleted inserted replaced
5918:d89cd224dd1b 5919:d0de2b378b24
22 import Preferences 22 import Preferences
23 import UI.PixmapCache 23 import UI.PixmapCache
24 24
25 from .CodeDocumentationViewerTemplate import \ 25 from .CodeDocumentationViewerTemplate import \
26 prepareDocumentationViewerHtmlDocument, \ 26 prepareDocumentationViewerHtmlDocument, \
27 prepareDocumentationViewerHtmlDocWarningDocument, \
27 prepareDocumentationViewerHtmlWarningDocument 28 prepareDocumentationViewerHtmlWarningDocument
28 29
29 from .data import codeDocumentationViewer_rc # __IGNORE_WARNING__ 30 from .data import codeDocumentationViewer_rc # __IGNORE_WARNING__
30 31
31 32
211 "No source code documentation provider has been registered or" 212 "No source code documentation provider has been registered or"
212 " this function has been disabled.") 213 " this function has been disabled.")
213 214
214 self.__processingThread = DocumentProcessingThread() 215 self.__processingThread = DocumentProcessingThread()
215 self.__processingThread.htmlReady.connect(self.__setHtml) 216 self.__processingThread.htmlReady.connect(self.__setHtml)
217 self.__processingThread.warning.connect(self.__setHtmlWarning)
216 218
217 def __setupUi(self): 219 def __setupUi(self):
218 """ 220 """
219 Private method to generate the UI layout. 221 Private method to generate the UI layout.
220 """ 222 """
297 299
298 def finalizeSetup(self): 300 def finalizeSetup(self):
299 """ 301 """
300 Public method to finalize the setup of the documentation viewer. 302 Public method to finalize the setup of the documentation viewer.
301 """ 303 """
302 self.__showTextViewer(Preferences.getDocuViewer("ShowInfoAsMarkdown")) 304 self.__showTextViewer(Preferences.getDocuViewer("ShowInfoAsRichText"))
303 305
304 self.__startingUp = False 306 self.__startingUp = False
305 provider = Preferences.getDocuViewer("Provider") 307 provider = Preferences.getDocuViewer("Provider")
306 if provider in self.__providers: 308 if provider in self.__providers:
307 index = self.providerComboBox.findData(provider) 309 index = self.providerComboBox.findData(provider)
406 self.__plainTextViewer.clear() 408 self.__plainTextViewer.clear()
407 self.__richTextViewer.clear() 409 self.__richTextViewer.clear()
408 self.__providers[self.__selectedProvider][0](editor) 410 self.__providers[self.__selectedProvider][0](editor)
409 411
410 # TODO: document this hook in the plug-in document 412 # TODO: document this hook in the plug-in document
411 def documentationReady(self, documentationInfo, isWarning=False): 413 def documentationReady(self, documentationInfo, isWarning=False,
414 isDocWarning=False):
412 """ 415 """
413 Public method to provide the documentation info to the viewer. 416 Public method to provide the documentation info to the viewer.
414 417
415 If documentationInfo is a dictionary, it should contains these keys 418 If documentationInfo is a dictionary, it should contains these keys
416 and data: 419 and data:
422 docstring: its documentation string 425 docstring: its documentation string
423 426
424 @param documentationInfo dictionary containing the source docu data 427 @param documentationInfo dictionary containing the source docu data
425 @type dict or str 428 @type dict or str
426 @param isWarning flag indicating a warning page 429 @param isWarning flag indicating a warning page
430 @type bool
431 @param isDocWarning flag indicating a documentation warning page
427 @type bool 432 @type bool
428 """ 433 """
429 self.__ui.activateCodeDocumentationViewer(switchFocus=False) 434 self.__ui.activateCodeDocumentationViewer(switchFocus=False)
430 435
431 self.__lastDocumentation = documentationInfo 436 self.__lastDocumentation = documentationInfo
435 if self.__selectedProvider == self.__disabledProvider: 440 if self.__selectedProvider == self.__disabledProvider:
436 self.documentationReady(self.__disabledString, 441 self.documentationReady(self.__disabledString,
437 isWarning=True) 442 isWarning=True)
438 else: 443 else:
439 self.documentationReady(self.__noDocumentationString, 444 self.documentationReady(self.__noDocumentationString,
440 isWarning=True) 445 isDocWarning=True)
441 return 446 return
442 447
443 if self.__showMarkdown: 448 if self.__showMarkdown:
444 if isWarning: 449 if isWarning:
445 html = prepareDocumentationViewerHtmlWarningDocument( 450 html = prepareDocumentationViewerHtmlWarningDocument(
451 documentationInfo)
452 elif isDocWarning:
453 html = prepareDocumentationViewerHtmlDocWarningDocument(
446 documentationInfo) 454 documentationInfo)
447 elif isinstance(documentationInfo, dict): 455 elif isinstance(documentationInfo, dict):
448 html = prepareDocumentationViewerHtmlDocument( 456 html = prepareDocumentationViewerHtmlDocument(
449 documentationInfo) 457 documentationInfo)
450 else: 458 else:
494 @param html prepared HTML text 502 @param html prepared HTML text
495 @type str 503 @type str
496 """ 504 """
497 self.__richTextViewer.setHtml(html) 505 self.__richTextViewer.setHtml(html)
498 506
507 def __setHtmlWarning(self, warningText):
508 """
509 Private slot to set a display message.
510
511 @param warningText text to be shown as a warning
512 @type str
513 """
514 html = prepareDocumentationViewerHtmlWarningDocument(warningText)
515 self.__richTextViewer.setHtml(html)
516
499 @pyqtSlot(int) 517 @pyqtSlot(int)
500 def on_providerComboBox_currentIndexChanged(self, index): 518 def on_providerComboBox_currentIndexChanged(self, index):
501 """ 519 """
502 Private slot to handle the selection of a provider. 520 Private slot to handle the selection of a provider.
503 521
527 545
528 def preferencesChanged(self): 546 def preferencesChanged(self):
529 """ 547 """
530 Public slot to handle a change of preferences. 548 Public slot to handle a change of preferences.
531 """ 549 """
532 showMarkdown = Preferences.getDocuViewer("ShowInfoAsMarkdown") 550 showMarkdown = Preferences.getDocuViewer("ShowInfoAsRichText")
533 if showMarkdown != self.__showMarkdown: 551 if showMarkdown != self.__showMarkdown:
534 self.__showTextViewer(showMarkdown) 552 self.__showTextViewer(showMarkdown)
535 553
536 provider = Preferences.getDocuViewer("Provider") 554 provider = Preferences.getDocuViewer("Provider")
537 if provider != self.__selectedProvider: 555 if provider != self.__selectedProvider:
558 self.__plainTextAct.setChecked(not richText) 576 self.__plainTextAct.setChecked(not richText)
559 self.__richTextAct.setChecked(richText) 577 self.__richTextAct.setChecked(richText)
560 578
561 self.documentationReady(self.__lastDocumentation) 579 self.documentationReady(self.__lastDocumentation)
562 580
563 Preferences.setDocuViewer("ShowInfoAsMarkdown", richText) 581 Preferences.setDocuViewer("ShowInfoAsRichText", richText)
564 582
565 583
566 class DocumentProcessingThread(QThread): 584 class DocumentProcessingThread(QThread):
567 """ 585 """
568 Class implementing a thread to process some text into HTML usable by the 586 Class implementing a thread to process some text into HTML usable by the
569 viewer. 587 viewer.
570 588
571 @signal htmlReady(str) emitted with the processed HTML to signal the 589 @signal htmlReady(str) emitted with the processed HTML to signal the
572 availability of the processed HTML 590 availability of the processed HTML
591 @signal warning(str) emitted with an error or warning message
573 """ 592 """
574 htmlReady = pyqtSignal(str) 593 htmlReady = pyqtSignal(str)
594 warning = pyqtSignal(str)
575 595
576 def __init__(self, parent=None): 596 def __init__(self, parent=None):
577 """ 597 """
578 Constructor 598 Constructor
579 599
602 language = self.__language 622 language = self.__language
603 text = self.__text 623 text = self.__text
604 624
605 if language == "markdown": 625 if language == "markdown":
606 html = self.__convertMarkdown(text, True, "html5") 626 html = self.__convertMarkdown(text, True, "html5")
627 self.htmlReady.emit(html)
607 else: 628 else:
608 html = "<html><body><p>" 629 html = self.tr("Format <b>{0}</b> is not supported.")\
609 html += self.tr("Format '{0}' is not supported.").format(language) 630 .format(language)
610 html += "</p></body></html>" 631 self.warning.emit(html)
611
612 self.htmlReady.emit(html)
613 632
614 def __convertMarkdown(self, text, convertNewLineToBreak, htmlFormat): 633 def __convertMarkdown(self, text, convertNewLineToBreak, htmlFormat):
615 """ 634 """
616 Private method to convert Markdown text into HTML. 635 Private method to convert Markdown text into HTML.
617 636

eric ide

mercurial