78 @return filename of the displayed file |
78 @return filename of the displayed file |
79 @rtype str |
79 @rtype str |
80 """ |
80 """ |
81 return self.mw.getFileName() |
81 return self.mw.getFileName() |
82 |
82 |
|
83 def editorCommand(self, cmd): |
|
84 """ |
|
85 Public method to perform a simple editor command. |
|
86 |
|
87 @param cmd the scintilla command to be performed (integer) |
|
88 """ |
|
89 if cmd == QsciScintilla.SCI_DELETEBACK: |
|
90 line, index = self.getCursorPosition() |
|
91 text = self.text(line)[index - 1:index + 1] |
|
92 matchingPairs = ['()', '[]', '{}', '<>', "''", '""'] |
|
93 # __IGNORE_WARNING_M613__ |
|
94 if text in matchingPairs: |
|
95 self.delete() |
|
96 |
|
97 super(MiniScintilla, self).editorCommand(cmd) |
|
98 |
83 def keyPressEvent(self, ev): |
99 def keyPressEvent(self, ev): |
84 """ |
100 """ |
85 Protected method to handle the user input a key at a time. |
101 Protected method to handle the user input a key at a time. |
86 |
102 |
87 @param ev key event |
103 @param ev key event |
292 self.__textEdit.modificationChanged.connect(self.__modificationChanged) |
308 self.__textEdit.modificationChanged.connect(self.__modificationChanged) |
293 self.__textEdit.cursorPositionChanged.connect( |
309 self.__textEdit.cursorPositionChanged.connect( |
294 self.__cursorPositionChanged) |
310 self.__cursorPositionChanged) |
295 self.__textEdit.linesChanged.connect(self.__resizeLinenoMargin) |
311 self.__textEdit.linesChanged.connect(self.__resizeLinenoMargin) |
296 |
312 |
297 self.__textEdit.setContextMenuPolicy(Qt.CustomContextMenu) |
313 self.__textEdit.setContextMenuPolicy( |
|
314 Qt.ContextMenuPolicy.CustomContextMenu) |
298 self.__textEdit.customContextMenuRequested.connect( |
315 self.__textEdit.customContextMenuRequested.connect( |
299 self.__contextMenuRequested) |
316 self.__contextMenuRequested) |
300 |
317 |
301 self.__textEdit.selectionChanged.connect( |
318 self.__textEdit.selectionChanged.connect( |
302 lambda: self.__searchWidget.selectionChanged(self.__textEdit)) |
319 lambda: self.__searchWidget.selectionChanged(self.__textEdit)) |
762 #################################################################### |
779 #################################################################### |
763 ## Below follow the actions for QScintilla standard commands. |
780 ## Below follow the actions for QScintilla standard commands. |
764 #################################################################### |
781 #################################################################### |
765 |
782 |
766 self.esm = QSignalMapper(self) |
783 self.esm = QSignalMapper(self) |
767 self.esm.mapped[int].connect(self.__textEdit.editorCommand) |
784 try: |
|
785 self.esm.mappedInt.connect(self.__textEdit.editorCommand) |
|
786 except AttributeError: |
|
787 # pre Qt 5.15 |
|
788 self.esm.mapped[int].connect(self.__textEdit.editorCommand) |
768 |
789 |
769 self.editorActGrp = createActionGroup(self) |
790 self.editorActGrp = createActionGroup(self) |
770 |
791 |
771 act = E5Action( |
792 act = E5Action( |
772 QCoreApplication.translate('ViewManager', |
793 QCoreApplication.translate('ViewManager', |
2851 Preferences.getEditorColour("FoldmarginBackground")) |
2872 Preferences.getEditorColour("FoldmarginBackground")) |
2852 self.__textEdit.setFoldMarkersColors( |
2873 self.__textEdit.setFoldMarkersColors( |
2853 Preferences.getEditorColour("FoldMarkersForeground"), |
2874 Preferences.getEditorColour("FoldMarkersForeground"), |
2854 Preferences.getEditorColour("FoldMarkersBackground")) |
2875 Preferences.getEditorColour("FoldMarkersBackground")) |
2855 else: |
2876 else: |
2856 self.__textEdit.setFolding(QsciScintilla.NoFoldStyle) |
2877 self.__textEdit.setFolding(QsciScintilla.FoldStyle.NoFoldStyle) |
2857 |
2878 |
2858 def __resizeLinenoMargin(self): |
2879 def __resizeLinenoMargin(self): |
2859 """ |
2880 """ |
2860 Private slot to resize the line numbers margin. |
2881 Private slot to resize the line numbers margin. |
2861 """ |
2882 """ |
2891 self.__textEdit.setIndentationGuidesBackgroundColor( |
2912 self.__textEdit.setIndentationGuidesBackgroundColor( |
2892 Preferences.getEditorColour("IndentationGuidesBackground")) |
2913 Preferences.getEditorColour("IndentationGuidesBackground")) |
2893 self.__textEdit.setIndentationGuidesForegroundColor( |
2914 self.__textEdit.setIndentationGuidesForegroundColor( |
2894 Preferences.getEditorColour("IndentationGuidesForeground")) |
2915 Preferences.getEditorColour("IndentationGuidesForeground")) |
2895 if Preferences.getEditor("ShowWhitespace"): |
2916 if Preferences.getEditor("ShowWhitespace"): |
2896 self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsVisible) |
2917 self.__textEdit.setWhitespaceVisibility( |
|
2918 QsciScintilla.WhitespaceVisibility.WsVisible) |
2897 self.__textEdit.setWhitespaceForegroundColor( |
2919 self.__textEdit.setWhitespaceForegroundColor( |
2898 Preferences.getEditorColour("WhitespaceForeground")) |
2920 Preferences.getEditorColour("WhitespaceForeground")) |
2899 self.__textEdit.setWhitespaceBackgroundColor( |
2921 self.__textEdit.setWhitespaceBackgroundColor( |
2900 Preferences.getEditorColour("WhitespaceBackground")) |
2922 Preferences.getEditorColour("WhitespaceBackground")) |
2901 self.__textEdit.setWhitespaceSize( |
2923 self.__textEdit.setWhitespaceSize( |
2902 Preferences.getEditor("WhitespaceSize")) |
2924 Preferences.getEditor("WhitespaceSize")) |
2903 else: |
2925 else: |
2904 self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsInvisible) |
2926 self.__textEdit.setWhitespaceVisibility( |
|
2927 QsciScintilla.WhitespaceVisibility.WsInvisible) |
2905 self.__textEdit.setEolVisibility(Preferences.getEditor("ShowEOL")) |
2928 self.__textEdit.setEolVisibility(Preferences.getEditor("ShowEOL")) |
2906 self.__textEdit.setAutoIndent(Preferences.getEditor("AutoIndentation")) |
2929 self.__textEdit.setAutoIndent(Preferences.getEditor("AutoIndentation")) |
2907 if Preferences.getEditor("BraceHighlighting"): |
2930 if Preferences.getEditor("BraceHighlighting"): |
2908 self.__textEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch) |
2931 self.__textEdit.setBraceMatching( |
2909 else: |
2932 QsciScintilla.BraceMatch.SloppyBraceMatch) |
2910 self.__textEdit.setBraceMatching(QsciScintilla.NoBraceMatch) |
2933 else: |
|
2934 self.__textEdit.setBraceMatching( |
|
2935 QsciScintilla.BraceMatch.NoBraceMatch) |
2911 self.__textEdit.setMatchedBraceForegroundColor( |
2936 self.__textEdit.setMatchedBraceForegroundColor( |
2912 Preferences.getEditorColour("MatchingBrace")) |
2937 Preferences.getEditorColour("MatchingBrace")) |
2913 self.__textEdit.setMatchedBraceBackgroundColor( |
2938 self.__textEdit.setMatchedBraceBackgroundColor( |
2914 Preferences.getEditorColour("MatchingBraceBack")) |
2939 Preferences.getEditorColour("MatchingBraceBack")) |
2915 self.__textEdit.setUnmatchedBraceForegroundColor( |
2940 self.__textEdit.setUnmatchedBraceForegroundColor( |
2919 if Preferences.getEditor("CustomSelectionColours"): |
2944 if Preferences.getEditor("CustomSelectionColours"): |
2920 self.__textEdit.setSelectionBackgroundColor( |
2945 self.__textEdit.setSelectionBackgroundColor( |
2921 Preferences.getEditorColour("SelectionBackground")) |
2946 Preferences.getEditorColour("SelectionBackground")) |
2922 else: |
2947 else: |
2923 self.__textEdit.setSelectionBackgroundColor( |
2948 self.__textEdit.setSelectionBackgroundColor( |
2924 QApplication.palette().color(QPalette.Highlight)) |
2949 QApplication.palette().color(QPalette.ColorRole.Highlight)) |
2925 if Preferences.getEditor("ColourizeSelText"): |
2950 if Preferences.getEditor("ColourizeSelText"): |
2926 self.__textEdit.resetSelectionForegroundColor() |
2951 self.__textEdit.resetSelectionForegroundColor() |
2927 elif Preferences.getEditor("CustomSelectionColours"): |
2952 elif Preferences.getEditor("CustomSelectionColours"): |
2928 self.__textEdit.setSelectionForegroundColor( |
2953 self.__textEdit.setSelectionForegroundColor( |
2929 Preferences.getEditorColour("SelectionForeground")) |
2954 Preferences.getEditorColour("SelectionForeground")) |
2930 else: |
2955 else: |
2931 self.__textEdit.setSelectionForegroundColor( |
2956 self.__textEdit.setSelectionForegroundColor( |
2932 QApplication.palette().color(QPalette.HighlightedText)) |
2957 QApplication.palette().color( |
|
2958 QPalette.ColorRole.HighlightedText)) |
2933 self.__textEdit.setSelectionToEol( |
2959 self.__textEdit.setSelectionToEol( |
2934 Preferences.getEditor("ExtendSelectionToEol")) |
2960 Preferences.getEditor("ExtendSelectionToEol")) |
2935 self.__textEdit.setCaretForegroundColor( |
2961 self.__textEdit.setCaretForegroundColor( |
2936 Preferences.getEditorColour("CaretForeground")) |
2962 Preferences.getEditorColour("CaretForeground")) |
2937 self.__textEdit.setCaretLineBackgroundColor( |
2963 self.__textEdit.setCaretLineBackgroundColor( |
2974 self.__textEdit.setPaper( |
3000 self.__textEdit.setPaper( |
2975 Preferences.getEditorColour("EditAreaBackground")) |
3001 Preferences.getEditorColour("EditAreaBackground")) |
2976 |
3002 |
2977 self.__textEdit.setVirtualSpaceOptions( |
3003 self.__textEdit.setVirtualSpaceOptions( |
2978 Preferences.getEditor("VirtualSpaceOptions")) |
3004 Preferences.getEditor("VirtualSpaceOptions")) |
|
3005 |
|
3006 # to avoid errors due to line endings by pasting |
|
3007 self.__textEdit.SendScintilla( |
|
3008 QsciScintilla.SCI_SETPASTECONVERTENDINGS, True) |
2979 |
3009 |
2980 def __setEolMode(self): |
3010 def __setEolMode(self): |
2981 """ |
3011 """ |
2982 Private method to configure the eol mode of the editor. |
3012 Private method to configure the eol mode of the editor. |
2983 """ |
3013 """ |
3007 def __printFile(self): |
3037 def __printFile(self): |
3008 """ |
3038 """ |
3009 Private slot to print the text. |
3039 Private slot to print the text. |
3010 """ |
3040 """ |
3011 from .Printer import Printer |
3041 from .Printer import Printer |
3012 printer = Printer(mode=QPrinter.HighResolution) |
3042 printer = Printer(mode=QPrinter.PrinterMode.HighResolution) |
3013 sb = self.statusBar() |
3043 sb = self.statusBar() |
3014 printDialog = QPrintDialog(printer, self) |
3044 printDialog = QPrintDialog(printer, self) |
3015 if self.__textEdit.hasSelectedText(): |
3045 if self.__textEdit.hasSelectedText(): |
3016 printDialog.setOption(QAbstractPrintDialog.PrintSelection, True) |
3046 printDialog.setOption( |
3017 if printDialog.exec() == QDialog.Accepted: |
3047 QAbstractPrintDialog.PrintDialogOption.PrintSelection, |
|
3048 True) |
|
3049 if printDialog.exec() == QDialog.DialogCode.Accepted: |
3018 sb.showMessage(self.tr('Printing...')) |
3050 sb.showMessage(self.tr('Printing...')) |
3019 QApplication.processEvents() |
3051 QApplication.processEvents() |
3020 if self.__curFile: |
3052 if self.__curFile: |
3021 printer.setDocName(QFileInfo(self.__curFile).fileName()) |
3053 printer.setDocName(QFileInfo(self.__curFile).fileName()) |
3022 else: |
3054 else: |
3023 printer.setDocName(self.tr("Untitled")) |
3055 printer.setDocName(self.tr("Untitled")) |
3024 if printDialog.printRange() == QAbstractPrintDialog.Selection: |
3056 if ( |
|
3057 printDialog.printRange() == |
|
3058 QAbstractPrintDialog.PrintRange.Selection |
|
3059 ): |
3025 # get the selection |
3060 # get the selection |
3026 fromLine, fromIndex, toLine, toIndex = ( |
3061 fromLine, fromIndex, toLine, toIndex = ( |
3027 self.__textEdit.getSelection() |
3062 self.__textEdit.getSelection() |
3028 ) |
3063 ) |
3029 if toIndex == 0: |
3064 if toIndex == 0: |
3046 Private slot to show a print preview of the text. |
3081 Private slot to show a print preview of the text. |
3047 """ |
3082 """ |
3048 from PyQt5.QtPrintSupport import QPrintPreviewDialog |
3083 from PyQt5.QtPrintSupport import QPrintPreviewDialog |
3049 from .Printer import Printer |
3084 from .Printer import Printer |
3050 |
3085 |
3051 printer = Printer(mode=QPrinter.HighResolution) |
3086 printer = Printer(mode=QPrinter.PrinterMode.HighResolution) |
3052 if self.__curFile: |
3087 if self.__curFile: |
3053 printer.setDocName(QFileInfo(self.__curFile).fileName()) |
3088 printer.setDocName(QFileInfo(self.__curFile).fileName()) |
3054 else: |
3089 else: |
3055 printer.setDocName(self.tr("Untitled")) |
3090 printer.setDocName(self.tr("Untitled")) |
3056 preview = QPrintPreviewDialog(printer, self) |
3091 preview = QPrintPreviewDialog(printer, self) |
3362 self.__textEdit.setLexer(self.lexer_) |
3397 self.__textEdit.setLexer(self.lexer_) |
3363 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None: |
3398 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None: |
3364 self.__textEdit.SCN_STYLENEEDED.connect(self.__styleNeeded) |
3399 self.__textEdit.SCN_STYLENEEDED.connect(self.__styleNeeded) |
3365 |
3400 |
3366 # get the font for style 0 and set it as the default font |
3401 # get the font for style 0 and set it as the default font |
3367 key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) |
3402 if pyname and pyname.startswith("Pygments|"): |
|
3403 key = 'Scintilla/Guessed/style0/font' |
|
3404 else: |
|
3405 key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) |
3368 fdesc = Preferences.Prefs.settings.value(key) |
3406 fdesc = Preferences.Prefs.settings.value(key) |
3369 if fdesc is not None: |
3407 if fdesc is not None: |
3370 font = QFont(fdesc[0], int(fdesc[1])) |
3408 font = QFont(fdesc[0], int(fdesc[1])) |
3371 self.lexer_.setDefaultFont(font) |
3409 self.lexer_.setDefaultFont(font) |
3372 self.lexer_.readSettings(Preferences.Prefs.settings, "Scintilla") |
3410 self.lexer_.readSettings(Preferences.Prefs.settings, "Scintilla") |
3739 |
3777 |
3740 try: |
3778 try: |
3741 if option == "EOLMode": |
3779 if option == "EOLMode": |
3742 value = config["end_of_line"] |
3780 value = config["end_of_line"] |
3743 if value == "lf": |
3781 if value == "lf": |
3744 value = QsciScintilla.EolUnix |
3782 value = QsciScintilla.EolMode.EolUnix |
3745 elif value == "crlf": |
3783 elif value == "crlf": |
3746 value = QsciScintilla.EolWindows |
3784 value = QsciScintilla.EolMode.EolWindows |
3747 elif value == "cr": |
3785 elif value == "cr": |
3748 value = QsciScintilla.EolMac |
3786 value = QsciScintilla.EolMode.EolMac |
3749 else: |
3787 else: |
3750 value = None |
3788 value = None |
3751 elif option == "DefaultEncoding": |
3789 elif option == "DefaultEncoding": |
3752 value = config["charset"] |
3790 value = config["charset"] |
3753 elif option == "InsertFinalNewline": |
3791 elif option == "InsertFinalNewline": |
3848 """ |
3886 """ |
3849 Private method to handle the zoom action. |
3887 Private method to handle the zoom action. |
3850 """ |
3888 """ |
3851 from QScintilla.ZoomDialog import ZoomDialog |
3889 from QScintilla.ZoomDialog import ZoomDialog |
3852 dlg = ZoomDialog(self.getZoom(), self, None, True) |
3890 dlg = ZoomDialog(self.getZoom(), self, None, True) |
3853 if dlg.exec() == QDialog.Accepted: |
3891 if dlg.exec() == QDialog.DialogCode.Accepted: |
3854 value = dlg.getZoomSize() |
3892 value = dlg.getZoomSize() |
3855 self.__zoomTo(value) |
3893 self.__zoomTo(value) |
3856 |
3894 |
3857 def __zoomTo(self, value): |
3895 def __zoomTo(self, value): |
3858 """ |
3896 """ |