eric6/QScintilla/Editor.py

changeset 7771
787a6b3f8c9f
parent 7759
51aa6c6b66f7
child 7775
4a1db75550bd
equal deleted inserted replaced
7770:49f3377aebf1 7771:787a6b3f8c9f
14 14
15 from PyQt5.QtCore import ( 15 from PyQt5.QtCore import (
16 QDir, QTimer, QModelIndex, QFileInfo, pyqtSignal, pyqtSlot, 16 QDir, QTimer, QModelIndex, QFileInfo, pyqtSignal, pyqtSlot,
17 QCryptographicHash, QEvent, QDateTime, QRegExp, Qt, QPoint 17 QCryptographicHash, QEvent, QDateTime, QRegExp, Qt, QPoint
18 ) 18 )
19 from PyQt5.QtGui import QCursor, QPalette, QFont, QPixmap, QPainter 19 from PyQt5.QtGui import QPalette, QFont, QPixmap, QPainter
20 from PyQt5.QtWidgets import ( 20 from PyQt5.QtWidgets import (
21 QLineEdit, QActionGroup, QDialog, QInputDialog, QApplication, QMenu 21 QLineEdit, QActionGroup, QDialog, QInputDialog, QApplication, QMenu
22 ) 22 )
23 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog 23 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog
24 from PyQt5.Qsci import QsciScintilla, QsciMacro, QsciStyledText 24 from PyQt5.Qsci import QsciScintilla, QsciMacro, QsciStyledText
25 25
26 from E5Gui.E5Application import e5App 26 from E5Gui.E5Application import e5App
27 from E5Gui import E5FileDialog, E5MessageBox 27 from E5Gui import E5FileDialog, E5MessageBox
28 from E5Gui.E5OverrideCursor import E5OverrideCursor
29
28 from E5Utilities.E5Cache import E5Cache 30 from E5Utilities.E5Cache import E5Cache
29 31
30 from .QsciScintillaCompat import QsciScintillaCompat 32 from .QsciScintillaCompat import QsciScintillaCompat
31 from .EditorMarkerMap import EditorMarkerMap 33 from .EditorMarkerMap import EditorMarkerMap
32 from .SpellChecker import SpellChecker 34 from .SpellChecker import SpellChecker
3075 @keyparam createIt flag indicating the creation of a new file, if the 3077 @keyparam createIt flag indicating the creation of a new file, if the
3076 given one doesn't exist (boolean) 3078 given one doesn't exist (boolean)
3077 @keyparam encoding encoding to be used to read the file (string) 3079 @keyparam encoding encoding to be used to read the file (string)
3078 (Note: this parameter overrides encoding detection) 3080 (Note: this parameter overrides encoding detection)
3079 """ 3081 """
3080 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
3081
3082 self.__loadEditorConfig(fileName=fn) 3082 self.__loadEditorConfig(fileName=fn)
3083 3083
3084 try: 3084 try:
3085 if createIt and not os.path.exists(fn): 3085 with E5OverrideCursor():
3086 f = open(fn, "w") 3086 if createIt and not os.path.exists(fn):
3087 f.close() 3087 f = open(fn, "w")
3088 if encoding == "": 3088 f.close()
3089 encoding = self.__getEditorConfig("DefaultEncoding", 3089 if encoding == "":
3090 nodefault=True) 3090 encoding = self.__getEditorConfig("DefaultEncoding",
3091 if encoding: 3091 nodefault=True)
3092 txt, self.encoding = Utilities.readEncodedFileWithEncoding( 3092 if encoding:
3093 fn, encoding) 3093 txt, self.encoding = Utilities.readEncodedFileWithEncoding(
3094 else: 3094 fn, encoding)
3095 txt, self.encoding = Utilities.readEncodedFile(fn) 3095 else:
3096 txt, self.encoding = Utilities.readEncodedFile(fn)
3096 except (UnicodeDecodeError, IOError) as why: 3097 except (UnicodeDecodeError, IOError) as why:
3097 QApplication.restoreOverrideCursor()
3098 E5MessageBox.critical( 3098 E5MessageBox.critical(
3099 self.vm, 3099 self.vm,
3100 self.tr('Open File'), 3100 self.tr('Open File'),
3101 self.tr('<p>The file <b>{0}</b> could not be opened.</p>' 3101 self.tr('<p>The file <b>{0}</b> could not be opened.</p>'
3102 '<p>Reason: {1}</p>') 3102 '<p>Reason: {1}</p>')
3103 .format(fn, str(why))) 3103 .format(fn, str(why)))
3104 QApplication.restoreOverrideCursor()
3105 raise 3104 raise
3106 3105
3107 modified = False 3106 with E5OverrideCursor():
3108 3107 modified = False
3109 self.setText(txt) 3108
3110 3109 self.setText(txt)
3111 # get eric specific flags 3110
3112 self.__processFlags() 3111 # get eric specific flags
3113 3112 self.__processFlags()
3114 # perform automatic EOL conversion 3113
3115 if ( 3114 # perform automatic EOL conversion
3116 self.__getEditorConfig("EOLMode", nodefault=True) or 3115 if (
3117 Preferences.getEditor("AutomaticEOLConversion") 3116 self.__getEditorConfig("EOLMode", nodefault=True) or
3118 ): 3117 Preferences.getEditor("AutomaticEOLConversion")
3119 self.convertEols(self.eolMode()) 3118 ):
3120 else: 3119 self.convertEols(self.eolMode())
3121 fileEol = self.detectEolString(txt) 3120 else:
3122 self.setEolModeByEolString(fileEol) 3121 fileEol = self.detectEolString(txt)
3123 3122 self.setEolModeByEolString(fileEol)
3124 self.extractTasks() 3123
3125 3124 self.extractTasks()
3126 QApplication.restoreOverrideCursor() 3125
3127 3126 self.setModified(modified)
3128 self.setModified(modified) 3127 self.lastModified = QFileInfo(self.fileName).lastModified()
3129 self.lastModified = QFileInfo(self.fileName).lastModified()
3130 3128
3131 def __convertTabs(self): 3129 def __convertTabs(self):
3132 """ 3130 """
3133 Private slot to convert tabulators to spaces. 3131 Private slot to convert tabulators to spaces.
3134 """ 3132 """

eric ide

mercurial