eric6/QScintilla/MiniEditor.py

changeset 8143
2c730d5fd177
parent 7969
62eff8b34a8d
child 8150
fc1ae39af8c9
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
292 self.__textEdit.modificationChanged.connect(self.__modificationChanged) 292 self.__textEdit.modificationChanged.connect(self.__modificationChanged)
293 self.__textEdit.cursorPositionChanged.connect( 293 self.__textEdit.cursorPositionChanged.connect(
294 self.__cursorPositionChanged) 294 self.__cursorPositionChanged)
295 self.__textEdit.linesChanged.connect(self.__resizeLinenoMargin) 295 self.__textEdit.linesChanged.connect(self.__resizeLinenoMargin)
296 296
297 self.__textEdit.setContextMenuPolicy(Qt.CustomContextMenu) 297 self.__textEdit.setContextMenuPolicy(
298 Qt.ContextMenuPolicy.CustomContextMenu)
298 self.__textEdit.customContextMenuRequested.connect( 299 self.__textEdit.customContextMenuRequested.connect(
299 self.__contextMenuRequested) 300 self.__contextMenuRequested)
300 301
301 self.__textEdit.selectionChanged.connect( 302 self.__textEdit.selectionChanged.connect(
302 lambda: self.__searchWidget.selectionChanged(self.__textEdit)) 303 lambda: self.__searchWidget.selectionChanged(self.__textEdit))
2851 Preferences.getEditorColour("FoldmarginBackground")) 2852 Preferences.getEditorColour("FoldmarginBackground"))
2852 self.__textEdit.setFoldMarkersColors( 2853 self.__textEdit.setFoldMarkersColors(
2853 Preferences.getEditorColour("FoldMarkersForeground"), 2854 Preferences.getEditorColour("FoldMarkersForeground"),
2854 Preferences.getEditorColour("FoldMarkersBackground")) 2855 Preferences.getEditorColour("FoldMarkersBackground"))
2855 else: 2856 else:
2856 self.__textEdit.setFolding(QsciScintilla.NoFoldStyle) 2857 self.__textEdit.setFolding(QsciScintilla.FoldStyle.NoFoldStyle)
2857 2858
2858 def __resizeLinenoMargin(self): 2859 def __resizeLinenoMargin(self):
2859 """ 2860 """
2860 Private slot to resize the line numbers margin. 2861 Private slot to resize the line numbers margin.
2861 """ 2862 """
2891 self.__textEdit.setIndentationGuidesBackgroundColor( 2892 self.__textEdit.setIndentationGuidesBackgroundColor(
2892 Preferences.getEditorColour("IndentationGuidesBackground")) 2893 Preferences.getEditorColour("IndentationGuidesBackground"))
2893 self.__textEdit.setIndentationGuidesForegroundColor( 2894 self.__textEdit.setIndentationGuidesForegroundColor(
2894 Preferences.getEditorColour("IndentationGuidesForeground")) 2895 Preferences.getEditorColour("IndentationGuidesForeground"))
2895 if Preferences.getEditor("ShowWhitespace"): 2896 if Preferences.getEditor("ShowWhitespace"):
2896 self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsVisible) 2897 self.__textEdit.setWhitespaceVisibility(
2898 QsciScintilla.WhitespaceVisibility.WsVisible)
2897 self.__textEdit.setWhitespaceForegroundColor( 2899 self.__textEdit.setWhitespaceForegroundColor(
2898 Preferences.getEditorColour("WhitespaceForeground")) 2900 Preferences.getEditorColour("WhitespaceForeground"))
2899 self.__textEdit.setWhitespaceBackgroundColor( 2901 self.__textEdit.setWhitespaceBackgroundColor(
2900 Preferences.getEditorColour("WhitespaceBackground")) 2902 Preferences.getEditorColour("WhitespaceBackground"))
2901 self.__textEdit.setWhitespaceSize( 2903 self.__textEdit.setWhitespaceSize(
2902 Preferences.getEditor("WhitespaceSize")) 2904 Preferences.getEditor("WhitespaceSize"))
2903 else: 2905 else:
2904 self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsInvisible) 2906 self.__textEdit.setWhitespaceVisibility(
2907 QsciScintilla.WhitespaceVisibility.WsInvisible)
2905 self.__textEdit.setEolVisibility(Preferences.getEditor("ShowEOL")) 2908 self.__textEdit.setEolVisibility(Preferences.getEditor("ShowEOL"))
2906 self.__textEdit.setAutoIndent(Preferences.getEditor("AutoIndentation")) 2909 self.__textEdit.setAutoIndent(Preferences.getEditor("AutoIndentation"))
2907 if Preferences.getEditor("BraceHighlighting"): 2910 if Preferences.getEditor("BraceHighlighting"):
2908 self.__textEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch) 2911 self.__textEdit.setBraceMatching(
2909 else: 2912 QsciScintilla.BraceMatch.SloppyBraceMatch)
2910 self.__textEdit.setBraceMatching(QsciScintilla.NoBraceMatch) 2913 else:
2914 self.__textEdit.setBraceMatching(
2915 QsciScintilla.BraceMatch.NoBraceMatch)
2911 self.__textEdit.setMatchedBraceForegroundColor( 2916 self.__textEdit.setMatchedBraceForegroundColor(
2912 Preferences.getEditorColour("MatchingBrace")) 2917 Preferences.getEditorColour("MatchingBrace"))
2913 self.__textEdit.setMatchedBraceBackgroundColor( 2918 self.__textEdit.setMatchedBraceBackgroundColor(
2914 Preferences.getEditorColour("MatchingBraceBack")) 2919 Preferences.getEditorColour("MatchingBraceBack"))
2915 self.__textEdit.setUnmatchedBraceForegroundColor( 2920 self.__textEdit.setUnmatchedBraceForegroundColor(
2919 if Preferences.getEditor("CustomSelectionColours"): 2924 if Preferences.getEditor("CustomSelectionColours"):
2920 self.__textEdit.setSelectionBackgroundColor( 2925 self.__textEdit.setSelectionBackgroundColor(
2921 Preferences.getEditorColour("SelectionBackground")) 2926 Preferences.getEditorColour("SelectionBackground"))
2922 else: 2927 else:
2923 self.__textEdit.setSelectionBackgroundColor( 2928 self.__textEdit.setSelectionBackgroundColor(
2924 QApplication.palette().color(QPalette.Highlight)) 2929 QApplication.palette().color(QPalette.ColorRole.Highlight))
2925 if Preferences.getEditor("ColourizeSelText"): 2930 if Preferences.getEditor("ColourizeSelText"):
2926 self.__textEdit.resetSelectionForegroundColor() 2931 self.__textEdit.resetSelectionForegroundColor()
2927 elif Preferences.getEditor("CustomSelectionColours"): 2932 elif Preferences.getEditor("CustomSelectionColours"):
2928 self.__textEdit.setSelectionForegroundColor( 2933 self.__textEdit.setSelectionForegroundColor(
2929 Preferences.getEditorColour("SelectionForeground")) 2934 Preferences.getEditorColour("SelectionForeground"))
2930 else: 2935 else:
2931 self.__textEdit.setSelectionForegroundColor( 2936 self.__textEdit.setSelectionForegroundColor(
2932 QApplication.palette().color(QPalette.HighlightedText)) 2937 QApplication.palette().color(
2938 QPalette.ColorRole.HighlightedText))
2933 self.__textEdit.setSelectionToEol( 2939 self.__textEdit.setSelectionToEol(
2934 Preferences.getEditor("ExtendSelectionToEol")) 2940 Preferences.getEditor("ExtendSelectionToEol"))
2935 self.__textEdit.setCaretForegroundColor( 2941 self.__textEdit.setCaretForegroundColor(
2936 Preferences.getEditorColour("CaretForeground")) 2942 Preferences.getEditorColour("CaretForeground"))
2937 self.__textEdit.setCaretLineBackgroundColor( 2943 self.__textEdit.setCaretLineBackgroundColor(
3007 def __printFile(self): 3013 def __printFile(self):
3008 """ 3014 """
3009 Private slot to print the text. 3015 Private slot to print the text.
3010 """ 3016 """
3011 from .Printer import Printer 3017 from .Printer import Printer
3012 printer = Printer(mode=QPrinter.HighResolution) 3018 printer = Printer(mode=QPrinter.PrinterMode.HighResolution)
3013 sb = self.statusBar() 3019 sb = self.statusBar()
3014 printDialog = QPrintDialog(printer, self) 3020 printDialog = QPrintDialog(printer, self)
3015 if self.__textEdit.hasSelectedText(): 3021 if self.__textEdit.hasSelectedText():
3016 printDialog.setOption(QAbstractPrintDialog.PrintSelection, True) 3022 printDialog.setOption(
3017 if printDialog.exec() == QDialog.Accepted: 3023 QAbstractPrintDialog.PrintDialogOption.PrintSelection,
3024 True)
3025 if printDialog.exec() == QDialog.DialogCode.Accepted:
3018 sb.showMessage(self.tr('Printing...')) 3026 sb.showMessage(self.tr('Printing...'))
3019 QApplication.processEvents() 3027 QApplication.processEvents()
3020 if self.__curFile: 3028 if self.__curFile:
3021 printer.setDocName(QFileInfo(self.__curFile).fileName()) 3029 printer.setDocName(QFileInfo(self.__curFile).fileName())
3022 else: 3030 else:
3023 printer.setDocName(self.tr("Untitled")) 3031 printer.setDocName(self.tr("Untitled"))
3024 if printDialog.printRange() == QAbstractPrintDialog.Selection: 3032 if (
3033 printDialog.printRange() ==
3034 QAbstractPrintDialog.PrintRange.Selection
3035 ):
3025 # get the selection 3036 # get the selection
3026 fromLine, fromIndex, toLine, toIndex = ( 3037 fromLine, fromIndex, toLine, toIndex = (
3027 self.__textEdit.getSelection() 3038 self.__textEdit.getSelection()
3028 ) 3039 )
3029 if toIndex == 0: 3040 if toIndex == 0:
3046 Private slot to show a print preview of the text. 3057 Private slot to show a print preview of the text.
3047 """ 3058 """
3048 from PyQt5.QtPrintSupport import QPrintPreviewDialog 3059 from PyQt5.QtPrintSupport import QPrintPreviewDialog
3049 from .Printer import Printer 3060 from .Printer import Printer
3050 3061
3051 printer = Printer(mode=QPrinter.HighResolution) 3062 printer = Printer(mode=QPrinter.PrinterMode.HighResolution)
3052 if self.__curFile: 3063 if self.__curFile:
3053 printer.setDocName(QFileInfo(self.__curFile).fileName()) 3064 printer.setDocName(QFileInfo(self.__curFile).fileName())
3054 else: 3065 else:
3055 printer.setDocName(self.tr("Untitled")) 3066 printer.setDocName(self.tr("Untitled"))
3056 preview = QPrintPreviewDialog(printer, self) 3067 preview = QPrintPreviewDialog(printer, self)
3739 3750
3740 try: 3751 try:
3741 if option == "EOLMode": 3752 if option == "EOLMode":
3742 value = config["end_of_line"] 3753 value = config["end_of_line"]
3743 if value == "lf": 3754 if value == "lf":
3744 value = QsciScintilla.EolUnix 3755 value = QsciScintilla.EolMode.EolUnix
3745 elif value == "crlf": 3756 elif value == "crlf":
3746 value = QsciScintilla.EolWindows 3757 value = QsciScintilla.EolMode.EolWindows
3747 elif value == "cr": 3758 elif value == "cr":
3748 value = QsciScintilla.EolMac 3759 value = QsciScintilla.EolMode.EolMac
3749 else: 3760 else:
3750 value = None 3761 value = None
3751 elif option == "DefaultEncoding": 3762 elif option == "DefaultEncoding":
3752 value = config["charset"] 3763 value = config["charset"]
3753 elif option == "InsertFinalNewline": 3764 elif option == "InsertFinalNewline":
3848 """ 3859 """
3849 Private method to handle the zoom action. 3860 Private method to handle the zoom action.
3850 """ 3861 """
3851 from QScintilla.ZoomDialog import ZoomDialog 3862 from QScintilla.ZoomDialog import ZoomDialog
3852 dlg = ZoomDialog(self.getZoom(), self, None, True) 3863 dlg = ZoomDialog(self.getZoom(), self, None, True)
3853 if dlg.exec() == QDialog.Accepted: 3864 if dlg.exec() == QDialog.DialogCode.Accepted:
3854 value = dlg.getZoomSize() 3865 value = dlg.getZoomSize()
3855 self.__zoomTo(value) 3866 self.__zoomTo(value)
3856 3867
3857 def __zoomTo(self, value): 3868 def __zoomTo(self, value):
3858 """ 3869 """

eric ide

mercurial