eric6/QScintilla/Editor.py

changeset 8243
cc717c2ae956
parent 8240
93b8a353c4bf
child 8245
dce55f623991
equal deleted inserted replaced
8242:aa713ac50c0d 8243:cc717c2ae956
1612 1612
1613 def __checkEncoding(self): 1613 def __checkEncoding(self):
1614 """ 1614 """
1615 Private method to check the selected encoding of the encodings submenu. 1615 Private method to check the selected encoding of the encodings submenu.
1616 """ 1616 """
1617 try: 1617 with contextlib.suppress(AttributeError, KeyError):
1618 (self.supportedEncodings[self.__normalizedEncoding()] 1618 (self.supportedEncodings[self.__normalizedEncoding()]
1619 .setChecked(True)) 1619 .setChecked(True))
1620 except (AttributeError, KeyError):
1621 pass
1622 1620
1623 def __encodingChanged(self, encoding, propagate=True): 1621 def __encodingChanged(self, encoding, propagate=True):
1624 """ 1622 """
1625 Private slot to handle a change of the encoding. 1623 Private slot to handle a change of the encoding.
1626 1624
1669 1667
1670 def __checkEol(self): 1668 def __checkEol(self):
1671 """ 1669 """
1672 Private method to check the selected eol type of the eol submenu. 1670 Private method to check the selected eol type of the eol submenu.
1673 """ 1671 """
1674 try: 1672 with contextlib.suppress(AttributeError, TypeError):
1675 self.supportedEols[self.getLineSeparator()].setChecked(True) 1673 self.supportedEols[self.getLineSeparator()].setChecked(True)
1676 except (AttributeError, TypeError):
1677 pass
1678 1674
1679 def __eolChanged(self): 1675 def __eolChanged(self):
1680 """ 1676 """
1681 Private slot to handle a change of the eol mode. 1677 Private slot to handle a change of the eol mode.
1682 """ 1678 """
1709 def __checkSpellLanguage(self): 1705 def __checkSpellLanguage(self):
1710 """ 1706 """
1711 Private slot to check the selected spell check language action. 1707 Private slot to check the selected spell check language action.
1712 """ 1708 """
1713 language = self.getSpellingLanguage() 1709 language = self.getSpellingLanguage()
1714 try: 1710 with contextlib.suppress(AttributeError, KeyError):
1715 self.supportedSpellLanguages[language].setChecked(True) 1711 self.supportedSpellLanguages[language].setChecked(True)
1716 except (AttributeError, KeyError):
1717 pass
1718 1712
1719 def __spellLanguageChanged(self, language, propagate=True): 1713 def __spellLanguageChanged(self, language, propagate=True):
1720 """ 1714 """
1721 Private slot to handle a change of the spell check language. 1715 Private slot to handle a change of the spell check language.
1722 1716
4525 4519
4526 # set folding margin settings 4520 # set folding margin settings
4527 if Preferences.getEditor("FoldingMargin"): 4521 if Preferences.getEditor("FoldingMargin"):
4528 self.setMarginWidth(self.__foldMargin, 16) 4522 self.setMarginWidth(self.__foldMargin, 16)
4529 folding = Preferences.getEditor("FoldingStyle") 4523 folding = Preferences.getEditor("FoldingStyle")
4530 try: 4524 with contextlib.suppress(AttributeError):
4531 folding = QsciScintilla.FoldStyle(folding) 4525 folding = QsciScintilla.FoldStyle(folding)
4532 except AttributeError:
4533 pass
4534 self.setFolding(folding, self.__foldMargin) 4526 self.setFolding(folding, self.__foldMargin)
4535 self.setFoldMarginColors( 4527 self.setFoldMarginColors(
4536 Preferences.getEditorColour("FoldmarginBackground"), 4528 Preferences.getEditorColour("FoldmarginBackground"),
4537 Preferences.getEditorColour("FoldmarginBackground")) 4529 Preferences.getEditorColour("FoldmarginBackground"))
4538 self.setFoldMarkersColors( 4530 self.setFoldMarkersColors(
4578 self.setIndentationGuidesForegroundColor( 4570 self.setIndentationGuidesForegroundColor(
4579 Preferences.getEditorColour("IndentationGuidesForeground")) 4571 Preferences.getEditorColour("IndentationGuidesForeground"))
4580 if Preferences.getEditor("ShowWhitespace"): 4572 if Preferences.getEditor("ShowWhitespace"):
4581 self.setWhitespaceVisibility( 4573 self.setWhitespaceVisibility(
4582 QsciScintilla.WhitespaceVisibility.WsVisible) 4574 QsciScintilla.WhitespaceVisibility.WsVisible)
4583 try: 4575 with contextlib.suppress(AttributeError):
4584 self.setWhitespaceForegroundColor( 4576 self.setWhitespaceForegroundColor(
4585 Preferences.getEditorColour("WhitespaceForeground")) 4577 Preferences.getEditorColour("WhitespaceForeground"))
4586 self.setWhitespaceBackgroundColor( 4578 self.setWhitespaceBackgroundColor(
4587 Preferences.getEditorColour("WhitespaceBackground")) 4579 Preferences.getEditorColour("WhitespaceBackground"))
4588 self.setWhitespaceSize( 4580 self.setWhitespaceSize(
4589 Preferences.getEditor("WhitespaceSize")) 4581 Preferences.getEditor("WhitespaceSize"))
4590 except AttributeError:
4591 # QScintilla before 2.5 doesn't support this
4592 pass
4593 else: 4582 else:
4594 self.setWhitespaceVisibility( 4583 self.setWhitespaceVisibility(
4595 QsciScintilla.WhitespaceVisibility.WsInvisible) 4584 QsciScintilla.WhitespaceVisibility.WsInvisible)
4596 self.setEolVisibility(Preferences.getEditor("ShowEOL")) 4585 self.setEolVisibility(Preferences.getEditor("ShowEOL"))
4597 self.setAutoIndent(Preferences.getEditor("AutoIndentation")) 4586 self.setAutoIndent(Preferences.getEditor("AutoIndentation"))
4673 self.highlightIndicator, QsciScintilla.INDIC_FULLBOX, 4662 self.highlightIndicator, QsciScintilla.INDIC_FULLBOX,
4674 Preferences.getEditorColour("HighlightMarker")) 4663 Preferences.getEditorColour("HighlightMarker"))
4675 4664
4676 self.setCursorFlashTime(QApplication.cursorFlashTime()) 4665 self.setCursorFlashTime(QApplication.cursorFlashTime())
4677 4666
4678 try: 4667 with contextlib.suppress(AttributeError):
4679 if Preferences.getEditor("AnnotationsEnabled"): 4668 if Preferences.getEditor("AnnotationsEnabled"):
4680 self.setAnnotationDisplay( 4669 self.setAnnotationDisplay(
4681 QsciScintilla.AnnotationDisplay.AnnotationBoxed) 4670 QsciScintilla.AnnotationDisplay.AnnotationBoxed)
4682 else: 4671 else:
4683 self.setAnnotationDisplay( 4672 self.setAnnotationDisplay(
4684 QsciScintilla.AnnotationDisplay.AnnotationHidden) 4673 QsciScintilla.AnnotationDisplay.AnnotationHidden)
4685 except AttributeError:
4686 pass
4687 self.__setAnnotationStyles() 4674 self.__setAnnotationStyles()
4688 4675
4689 if Preferences.getEditor("OverrideEditAreaColours"): 4676 if Preferences.getEditor("OverrideEditAreaColours"):
4690 self.setColor(Preferences.getEditorColour("EditAreaForeground")) 4677 self.setColor(Preferences.getEditorColour("EditAreaForeground"))
4691 self.setPaper(Preferences.getEditorColour("EditAreaBackground")) 4678 self.setPaper(Preferences.getEditorColour("EditAreaBackground"))
4766 Preferences.getEditorColour("CallTipsForeground")) 4753 Preferences.getEditorColour("CallTipsForeground"))
4767 self.setCallTipsHighlightColor( 4754 self.setCallTipsHighlightColor(
4768 Preferences.getEditorColour("CallTipsHighlight")) 4755 Preferences.getEditorColour("CallTipsHighlight"))
4769 self.setCallTipsVisible(Preferences.getEditor("CallTipsVisible")) 4756 self.setCallTipsVisible(Preferences.getEditor("CallTipsVisible"))
4770 calltipsStyle = Preferences.getEditor("CallTipsStyle") 4757 calltipsStyle = Preferences.getEditor("CallTipsStyle")
4771 try: 4758 with contextlib.suppress(AttributeError):
4772 self.setCallTipsPosition( 4759 self.setCallTipsPosition(
4773 Preferences.getEditor("CallTipsPosition")) 4760 Preferences.getEditor("CallTipsPosition"))
4774 except AttributeError:
4775 pass
4776 4761
4777 if Preferences.getEditor("CallTipsEnabled"): 4762 if Preferences.getEditor("CallTipsEnabled"):
4778 if calltipsStyle == QsciScintilla.CallTipsStyle.CallTipsNoContext: 4763 if calltipsStyle == QsciScintilla.CallTipsStyle.CallTipsNoContext:
4779 self.setCallTipsStyle( 4764 self.setCallTipsStyle(
4780 QsciScintilla.CallTipsStyle.CallTipsNoContext) 4765 QsciScintilla.CallTipsStyle.CallTipsNoContext)
6998 self.__processSyntaxCheckError) 6983 self.__processSyntaxCheckError)
6999 6984
7000 if self.spell: 6985 if self.spell:
7001 self.spell.stopIncrementalCheck() 6986 self.spell.stopIncrementalCheck()
7002 6987
7003 try: 6988 with contextlib.suppress(TypeError):
7004 self.project.projectPropertiesChanged.disconnect( 6989 self.project.projectPropertiesChanged.disconnect(
7005 self.__projectPropertiesChanged) 6990 self.__projectPropertiesChanged)
7006 except TypeError:
7007 pass
7008 6991
7009 if self.fileName: 6992 if self.fileName:
7010 self.taskViewer.clearFileTasks(self.fileName, True) 6993 self.taskViewer.clearFileTasks(self.fileName, True)
7011 6994
7012 super().close() 6995 super().close()
7069 self.vm.editActGrp.setEnabled(True) 7052 self.vm.editActGrp.setEnabled(True)
7070 self.vm.editorActGrp.setEnabled(True) 7053 self.vm.editorActGrp.setEnabled(True)
7071 self.vm.copyActGrp.setEnabled(True) 7054 self.vm.copyActGrp.setEnabled(True)
7072 self.vm.viewActGrp.setEnabled(True) 7055 self.vm.viewActGrp.setEnabled(True)
7073 self.vm.searchActGrp.setEnabled(True) 7056 self.vm.searchActGrp.setEnabled(True)
7074 try: 7057 with contextlib.suppress(AttributeError):
7075 self.setCaretWidth(self.caretWidth) 7058 self.setCaretWidth(self.caretWidth)
7076 except AttributeError:
7077 pass
7078 self.__updateReadOnly(False) 7059 self.__updateReadOnly(False)
7079 if ( 7060 if (
7080 self.vm.editorsCheckFocusInEnabled() and 7061 self.vm.editorsCheckFocusInEnabled() and
7081 not self.inReopenPrompt and self.fileName and 7062 not self.inReopenPrompt and self.fileName and
7082 QFileInfo(self.fileName).lastModified().toString() != 7063 QFileInfo(self.fileName).lastModified().toString() !=
7256 @param evt reference to the event 7237 @param evt reference to the event
7257 @type QEvent 7238 @type QEvent
7258 @return flag indiating that the event was handled 7239 @return flag indiating that the event was handled
7259 @rtype bool 7240 @rtype bool
7260 """ 7241 """
7261 try: 7242 with contextlib.suppress(AttributeError):
7262 self.__markerMap.calculateGeometry() 7243 self.__markerMap.calculateGeometry()
7263 except AttributeError:
7264 # ignore this - there seems to be a runtime issue when the editor
7265 # is created
7266 pass
7267 return super().viewportEvent(evt) 7244 return super().viewportEvent(evt)
7268 7245
7269 def __updateReadOnly(self, bForce=True): 7246 def __updateReadOnly(self, bForce=True):
7270 """ 7247 """
7271 Private method to update the readOnly information for this editor. 7248 Private method to update the readOnly information for this editor.
7778 7755
7779 def projectClosed(self): 7756 def projectClosed(self):
7780 """ 7757 """
7781 Public slot to handle the closing of a project. 7758 Public slot to handle the closing of a project.
7782 """ 7759 """
7783 try: 7760 with contextlib.suppress(TypeError):
7784 self.project.projectPropertiesChanged.disconnect( 7761 self.project.projectPropertiesChanged.disconnect(
7785 self.__projectPropertiesChanged) 7762 self.__projectPropertiesChanged)
7786 except TypeError:
7787 pass
7788 7763
7789 ####################################################################### 7764 #######################################################################
7790 ## Spell checking related methods 7765 ## Spell checking related methods
7791 ####################################################################### 7766 #######################################################################
7792 7767
7850 def setAutoSpellChecking(self): 7825 def setAutoSpellChecking(self):
7851 """ 7826 """
7852 Public method to set the automatic spell checking. 7827 Public method to set the automatic spell checking.
7853 """ 7828 """
7854 if Preferences.getEditor("AutoSpellCheckingEnabled"): 7829 if Preferences.getEditor("AutoSpellCheckingEnabled"):
7855 try: 7830 with contextlib.suppress(TypeError):
7856 self.SCN_CHARADDED.connect( 7831 self.SCN_CHARADDED.connect(
7857 self.__spellCharAdded, Qt.ConnectionType.UniqueConnection) 7832 self.__spellCharAdded, Qt.ConnectionType.UniqueConnection)
7858 except TypeError:
7859 pass
7860 self.spell.checkDocumentIncrementally() 7833 self.spell.checkDocumentIncrementally()
7861 else: 7834 else:
7862 try: 7835 with contextlib.suppress(TypeError):
7863 self.SCN_CHARADDED.disconnect(self.__spellCharAdded) 7836 self.SCN_CHARADDED.disconnect(self.__spellCharAdded)
7864 except TypeError:
7865 pass
7866 self.clearAllIndicators(self.spellingIndicator) 7837 self.clearAllIndicators(self.spellingIndicator)
7867 7838
7868 def isSpellCheckRegion(self, pos): 7839 def isSpellCheckRegion(self, pos):
7869 """ 7840 """
7870 Public method to check, if the given position is within a region, that 7841 Public method to check, if the given position is within a region, that

eric ide

mercurial