src/eric7/QScintilla/Editor.py

branch
eric7-maintenance
changeset 10873
4e8e63df7893
parent 10814
ba20efe10336
parent 10850
d835f48b9908
child 10892
409d010d7cae
equal deleted inserted replaced
10826:0f9c86561033 10873:4e8e63df7893
226 "<": "<>", 226 "<": "<>",
227 ">": "<>", 227 ">": "<>",
228 } 228 }
229 229
230 def __init__( 230 def __init__(
231 self, dbs, fn="", vm=None, filetype="", editor=None, tv=None, parent=None 231 self,
232 dbs,
233 fn="",
234 vm=None,
235 filetype="",
236 editor=None,
237 tv=None,
238 assembly=None,
239 parent=None,
232 ): 240 ):
233 """ 241 """
234 Constructor 242 Constructor
235 243
236 @param dbs reference to the debug server object 244 @param dbs reference to the debug server object
237 @type DebugServer 245 @type DebugServer
238 @param fn name of the file to be opened. If it is None, a new (empty) 246 @param fn name of the file to be opened. If it is None, a new (empty)
239 editor is opened. 247 editor is opened. (defaults to "")
240 @type str 248 @type str (optional)
241 @param vm reference to the view manager object 249 @param vm reference to the view manager object (defaults to None)
242 @type ViewManager 250 @type ViewManager (optional)
243 @param filetype type of the source file 251 @param filetype type of the source file (defaults to "")
244 @type str 252 @type str (optional)
245 @param editor reference to an Editor object, if this is a cloned view 253 @param editor reference to an Editor object, if this is a cloned view
246 @type Editor 254 (defaults to None)
247 @param tv reference to the task viewer object 255 @type Editor (optional)
248 @type TaskViewer 256 @param tv reference to the task viewer object (defaults to None)
249 @param parent reference to the parent widget 257 @type TaskViewer (optional)
250 @type QWidget 258 @param assembly reference to the editor assembly object (defaults to None)
259 @type EditorAssembly (optional)
260 @param parent reference to the parent widget (defaults to None)
261 @type QWidget (optional)
251 @exception OSError raised to indicate an issue accessing the file 262 @exception OSError raised to indicate an issue accessing the file
252 """ 263 """
253 super().__init__(parent) 264 super().__init__(parent)
254 self.setAttribute(Qt.WidgetAttribute.WA_KeyCompression) 265 self.setAttribute(Qt.WidgetAttribute.WA_KeyCompression)
255 self.setUtf8(True) 266 self.setUtf8(True)
256 267
257 self.enableMultiCursorSupport() 268 self.enableMultiCursorSupport()
258 269
270 self.__assembly = assembly
259 self.dbs = dbs 271 self.dbs = dbs
260 self.taskViewer = tv 272 self.taskViewer = tv
261 self.fileName = "" 273 self.fileName = ""
262 self.vm = vm 274 self.vm = vm
263 self.filetype = filetype 275 self.filetype = filetype
315 # true if we are in drop mode 327 # true if we are in drop mode
316 self.inLinesChanged = False 328 self.inLinesChanged = False
317 # true if we are propagating a lines changed event 329 # true if we are propagating a lines changed event
318 self.__hasTaskMarkers = False 330 self.__hasTaskMarkers = False
319 # no task markers present 331 # no task markers present
332 self.__checkExternalModification = True
333 # check and reload or warn when modified externally
320 334
321 self.macros = {} # list of defined macros 335 self.macros = {} # list of defined macros
322 self.curMacro = None 336 self.curMacro = None
323 self.recording = False 337 self.recording = False
324 338
418 ) 432 )
419 433
420 self.changeMarkersMask = (1 << self.__changeMarkerSaved) | ( 434 self.changeMarkersMask = (1 << self.__changeMarkerSaved) | (
421 1 << self.__changeMarkerUnsaved 435 1 << self.__changeMarkerUnsaved
422 ) 436 )
423
424 # configure the margins
425 self.__setMarginsDisplay()
426 self.linesChanged.connect(self.__resizeLinenoMargin)
427
428 self.marginClicked.connect(self.__marginClicked)
429 437
430 # set the eol mode 438 # set the eol mode
431 self.__setEolMode() 439 self.__setEolMode()
432 440
433 # set the text display 441 # set the text display
515 self.lastModified = editor.lastModified 523 self.lastModified = editor.lastModified
516 524
517 self.addClone(editor) 525 self.addClone(editor)
518 editor.addClone(self) 526 editor.addClone(self)
519 527
528 # configure the margins
529 self.__setMarginsDisplay()
530 self.linesChanged.connect(self.__resizeLinenoMargin)
531
532 self.marginClicked.connect(self.__marginClicked)
533
520 self.gotoLine(1) 534 self.gotoLine(1)
521 535
522 # connect the mouse hover signals 536 # connect the mouse hover signals
523 # mouse hover for the editor margins 537 # mouse hover for the editor margins
524 self.SCN_DWELLSTART.connect(self.__marginHoverStart) 538 self.SCN_DWELLSTART.connect(self.__marginHoverStart)
669 683
670 self.grabGesture(Qt.GestureType.PinchGesture) 684 self.grabGesture(Qt.GestureType.PinchGesture)
671 685
672 self.SCN_ZOOM.connect(self.__markerMap.update) 686 self.SCN_ZOOM.connect(self.__markerMap.update)
673 self.__markerMap.update() 687 self.__markerMap.update()
688
689 def getAssembly(self):
690 """
691 Public method to get a reference to the editor assembly object.
692
693 @return reference to the editor assembly object
694 @rtype EditorAssembly
695 """
696 return self.__assembly
674 697
675 def setFileName(self, name): 698 def setFileName(self, name):
676 """ 699 """
677 Public method to set the file name of the current file. 700 Public method to set the file name of the current file.
678 701
1997 bindName = self.__bindName(self.text(0)) 2020 bindName = self.__bindName(self.text(0))
1998 if bindName: 2021 if bindName:
1999 language = Preferences.getEditorLexerAssoc(bindName) 2022 language = Preferences.getEditorLexerAssoc(bindName)
2000 if language == "Python": 2023 if language == "Python":
2001 # correction for Python 2024 # correction for Python
2002 pyVer = PythonUtilities.determinePythonVersion( 2025 language = "Python3"
2003 filename, self.text(0), self
2004 )
2005 language = "Python{0}".format(pyVer)
2006 if language in [ 2026 if language in [
2007 "Python3", 2027 "Python3",
2008 "MicroPython", 2028 "MicroPython",
2009 "Cython", 2029 "Cython",
2010 "Ruby", 2030 "Ruby",
2152 self.completer = None 2172 self.completer = None
2153 2173
2154 filename = os.path.basename(filename) 2174 filename = os.path.basename(filename)
2155 apiLanguage = Preferences.getEditorLexerAssoc(filename) 2175 apiLanguage = Preferences.getEditorLexerAssoc(filename)
2156 if apiLanguage == "": 2176 if apiLanguage == "":
2157 pyVer = self.__getPyVersion() 2177 if PythonUtilities.isPythonSource(self.fileName, self.text(0), self):
2158 if pyVer: 2178 apiLanguage = "Python3"
2159 apiLanguage = "Python{0}".format(pyVer)
2160 elif self.isRubyFile(): 2179 elif self.isRubyFile():
2161 apiLanguage = "Ruby" 2180 apiLanguage = "Ruby"
2162 2181
2163 self.completer = TypingCompleters.getCompleter(apiLanguage, self) 2182 self.completer = TypingCompleters.getCompleter(apiLanguage, self)
2164 2183
2300 @return type of the displayed file or an empty string 2319 @return type of the displayed file or an empty string
2301 @rtype str 2320 @rtype str
2302 """ 2321 """
2303 ftype = self.filetype 2322 ftype = self.filetype
2304 if not ftype: 2323 if not ftype:
2305 pyVer = self.__getPyVersion() 2324 if PythonUtilities.isPythonSource(self.fileName, self.text(0), self):
2306 if pyVer: 2325 ftype = "Python3"
2307 ftype = "Python{0}".format(pyVer)
2308 elif self.isRubyFile(): 2326 elif self.isRubyFile():
2309 ftype = "Ruby" 2327 ftype = "Ruby"
2310 else: 2328 else:
2311 ftype = "" 2329 ftype = ""
2312 2330
2319 @return current encoding 2337 @return current encoding
2320 @rtype str 2338 @rtype str
2321 """ 2339 """
2322 return self.encoding 2340 return self.encoding
2323 2341
2324 def __getPyVersion(self):
2325 """
2326 Private method to return the Python main version or 0 if it's
2327 not a Python file at all.
2328
2329 @return Python version or 0 if it's not a Python file
2330 @rtype int
2331 """
2332 return PythonUtilities.determinePythonVersion(self.fileName, self.text(0), self)
2333
2334 def isPyFile(self): 2342 def isPyFile(self):
2335 """ 2343 """
2336 Public method to return a flag indicating a Python (2 or 3) file. 2344 Public method to return a flag indicating a Python (2 or 3) file.
2337 2345
2338 @return flag indicating a Python3 file 2346 @return flag indicating a Python3 file
2339 @rtype bool 2347 @rtype bool
2340 """ 2348 """
2341 return self.__getPyVersion() == 3 2349 return PythonUtilities.isPythonSource(self.fileName, self.text(0), self)
2342 2350
2343 def isPy3File(self): 2351 def isPy3File(self):
2344 """ 2352 """
2345 Public method to return a flag indicating a Python3 file. 2353 Public method to return a flag indicating a Python3 file.
2346 2354
2347 @return flag indicating a Python3 file 2355 @return flag indicating a Python3 file
2348 @rtype bool 2356 @rtype bool
2349 """ 2357 """
2350 return self.__getPyVersion() == 3 2358 return PythonUtilities.isPythonSource(self.fileName, self.text(0), self)
2351 2359
2352 def isMicroPythonFile(self): 2360 def isMicroPythonFile(self):
2353 """ 2361 """
2354 Public method to return a flag indicating a MicroPython file. 2362 Public method to return a flag indicating a MicroPython file.
2355 2363
8372 ) 8380 )
8373 ) 8381 )
8374 or self.isReadOnly() 8382 or self.isReadOnly()
8375 ) 8383 )
8376 8384
8385 def setCheckExternalModificationEnabled(self, enable):
8386 """
8387 Public method to enable or disable the check for external modifications.
8388
8389 @param enable flag indicating the new enabled state
8390 @type bool
8391 """
8392 self.__checkExternalModification = enable
8393
8377 @pyqtSlot() 8394 @pyqtSlot()
8378 def checkRereadFile(self): 8395 def checkRereadFile(self):
8379 """ 8396 """
8380 Public slot to check, if the file needs to be re-read, and refresh it if 8397 Public slot to check, if the file needs to be re-read, and refresh it if
8381 needed. 8398 needed.
8382 """ 8399 """
8383 if self.checkModificationTime(): 8400 if self.__checkExternalModification and self.checkModificationTime():
8384 if Preferences.getEditor("AutoReopen") and not self.isModified(): 8401 if Preferences.getEditor("AutoReopen") and not self.isModified():
8385 self.__refresh() 8402 self.__refresh()
8386 else: 8403 else:
8387 msg = self.tr( 8404 msg = self.tr(
8388 """<p>The file <b>{0}</b> has been changed while it""" 8405 """<p>The file <b>{0}</b> has been changed while it"""

eric ide

mercurial