eric6/QScintilla/MiniEditor.py

changeset 7267
aedc309827c7
parent 7229
53054eb5b15a
child 7278
1820a0344b62
equal deleted inserted replaced
7266:d001bc703c29 7267:aedc309827c7
9 9
10 10
11 import os 11 import os
12 import re 12 import re
13 13
14 from PyQt5.QtCore import QSignalMapper, QPoint, QTimer, QFileInfo, \ 14 from PyQt5.QtCore import (
15 pyqtSignal, QSize, QRegExp, Qt, QCoreApplication 15 QSignalMapper, QPoint, QTimer, QFileInfo, pyqtSignal, QSize, QRegExp, Qt,
16 QCoreApplication
17 )
16 from PyQt5.QtGui import QCursor, QKeySequence, QPalette, QFont 18 from PyQt5.QtGui import QCursor, QKeySequence, QPalette, QFont
17 from PyQt5.QtWidgets import QWidget, QWhatsThis, QActionGroup, QDialog, \ 19 from PyQt5.QtWidgets import (
18 QInputDialog, QApplication, QMenu, QVBoxLayout, QLabel 20 QWidget, QWhatsThis, QActionGroup, QDialog, QInputDialog, QApplication,
21 QMenu, QVBoxLayout, QLabel
22 )
19 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog 23 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog
20 from PyQt5.Qsci import QsciScintilla 24 from PyQt5.Qsci import QsciScintilla
21 25
22 from E5Gui.E5Action import E5Action, createActionGroup 26 from E5Gui.E5Action import E5Action, createActionGroup
23 from E5Gui import E5MessageBox, E5FileDialog 27 from E5Gui import E5MessageBox, E5FileDialog
2340 QApplication.restoreOverrideCursor() 2344 QApplication.restoreOverrideCursor()
2341 return 2345 return
2342 2346
2343 modified = False 2347 modified = False
2344 2348
2345 if (not self.__getEditorConfig("TabForIndentation")) and \ 2349 if (
2346 Preferences.getEditor("ConvertTabsOnLoad") and \ 2350 not self.__getEditorConfig("TabForIndentation") and
2347 not (self.lexer_ and 2351 Preferences.getEditor("ConvertTabsOnLoad") and
2348 self.lexer_.alwaysKeepTabs()): 2352 not (self.lexer_ and
2353 self.lexer_.alwaysKeepTabs())
2354 ):
2349 txtExpanded = txt.expandtabs(self.__getEditorConfig("TabWidth")) 2355 txtExpanded = txt.expandtabs(self.__getEditorConfig("TabWidth"))
2350 if txtExpanded != txt: 2356 if txtExpanded != txt:
2351 modified = True 2357 modified = True
2352 txt = txtExpanded 2358 txt = txtExpanded
2353 2359
2755 printer.setDocName(QFileInfo(self.__curFile).fileName()) 2761 printer.setDocName(QFileInfo(self.__curFile).fileName())
2756 else: 2762 else:
2757 printer.setDocName(self.tr("Untitled")) 2763 printer.setDocName(self.tr("Untitled"))
2758 if printDialog.printRange() == QAbstractPrintDialog.Selection: 2764 if printDialog.printRange() == QAbstractPrintDialog.Selection:
2759 # get the selection 2765 # get the selection
2760 fromLine, fromIndex, toLine, toIndex = \ 2766 fromLine, fromIndex, toLine, toIndex = (
2761 self.__textEdit.getSelection() 2767 self.__textEdit.getSelection()
2768 )
2762 if toIndex == 0: 2769 if toIndex == 0:
2763 toLine -= 1 2770 toLine -= 1
2764 # Qscintilla seems to print one line more than told 2771 # Qscintilla seems to print one line more than told
2765 res = printer.printRange(self.__textEdit, fromLine, toLine - 1) 2772 res = printer.printRange(self.__textEdit, fromLine, toLine - 1)
2766 else: 2773 else:
2854 self.supportedLanguages = {} 2861 self.supportedLanguages = {}
2855 supportedLanguages = Lexers.getSupportedLanguages() 2862 supportedLanguages = Lexers.getSupportedLanguages()
2856 languages = sorted(list(supportedLanguages.keys())) 2863 languages = sorted(list(supportedLanguages.keys()))
2857 for language in languages: 2864 for language in languages:
2858 if language != "Guessed": 2865 if language != "Guessed":
2859 self.supportedLanguages[language] = \ 2866 self.supportedLanguages[language] = (
2860 supportedLanguages[language][:2] 2867 supportedLanguages[language][:2]
2868 )
2861 act = menu.addAction( 2869 act = menu.addAction(
2862 UI.PixmapCache.getIcon(supportedLanguages[language][2]), 2870 UI.PixmapCache.getIcon(supportedLanguages[language][2]),
2863 self.supportedLanguages[language][0]) 2871 self.supportedLanguages[language][0])
2864 act.setCheckable(True) 2872 act.setCheckable(True)
2865 act.setData(language) 2873 act.setData(language)
2935 2943
2936 def __resetLanguage(self): 2944 def __resetLanguage(self):
2937 """ 2945 """
2938 Private method used to reset the language selection. 2946 Private method used to reset the language selection.
2939 """ 2947 """
2940 if self.lexer_ is not None and \ 2948 if (
2941 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None): 2949 self.lexer_ is not None and
2950 (self.lexer_.lexer() == "container" or
2951 self.lexer_.lexer() is None)
2952 ):
2942 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded) 2953 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
2943 2954
2944 self.apiLanguage = "" 2955 self.apiLanguage = ""
2945 self.lexer_ = None 2956 self.lexer_ = None
2946 self.__textEdit.setLexer() 2957 self.__textEdit.setLexer()
2975 """ 2986 """
2976 Public method to retrieve the language of the editor. 2987 Public method to retrieve the language of the editor.
2977 2988
2978 @return language of the editor (string) 2989 @return language of the editor (string)
2979 """ 2990 """
2980 if self.apiLanguage == "Guessed" or \ 2991 if (
2981 self.apiLanguage.startswith("Pygments|"): 2992 self.apiLanguage == "Guessed" or
2993 self.apiLanguage.startswith("Pygments|")
2994 ):
2982 return self.lexer_.name() 2995 return self.lexer_.name()
2983 else: 2996 else:
2984 return self.apiLanguage 2997 return self.apiLanguage
2985 2998
2986 def __checkLanguage(self): 2999 def __checkLanguage(self):
3004 3017
3005 @param filename filename used to determine the associated lexer 3018 @param filename filename used to determine the associated lexer
3006 language (string) 3019 language (string)
3007 @keyparam pyname name of the pygments lexer to use (string) 3020 @keyparam pyname name of the pygments lexer to use (string)
3008 """ 3021 """
3009 if self.lexer_ is not None and \ 3022 if (
3010 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None): 3023 self.lexer_ is not None and
3024 (self.lexer_.lexer() == "container" or
3025 self.lexer_.lexer() is None)
3026 ):
3011 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded) 3027 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
3012 3028
3013 filename = os.path.basename(filename) 3029 filename = os.path.basename(filename)
3014 language = Preferences.getEditorLexerAssoc(filename) 3030 language = Preferences.getEditorLexerAssoc(filename)
3015 if language == "Python": 3031 if language == "Python":
3061 if self.filetype in ["Python", "Python2"]: 3077 if self.filetype in ["Python", "Python2"]:
3062 return True 3078 return True
3063 3079
3064 if self.filetype == "": 3080 if self.filetype == "":
3065 line0 = self.__textEdit.text(0) 3081 line0 = self.__textEdit.text(0)
3066 if line0.startswith("#!") and \ 3082 if (
3067 ("python2" in line0 or 3083 line0.startswith("#!") and
3068 ("python" in line0 and "python3" not in line0)): 3084 ("python2" in line0 or
3085 ("python" in line0 and "python3" not in line0))
3086 ):
3069 return True 3087 return True
3070 3088
3071 if self.__curFile is not None: 3089 if self.__curFile is not None:
3072 exts = [] 3090 exts = []
3073 for ext in Preferences.getDebugger("PythonExtensions").split(): 3091 for ext in Preferences.getDebugger("PythonExtensions").split():

eric ide

mercurial