--- a/eric6/QScintilla/Editor.py Wed Sep 25 18:25:43 2019 +0200 +++ b/eric6/QScintilla/Editor.py Wed Sep 25 18:37:35 2019 +0200 @@ -12,11 +12,14 @@ import re import difflib -from PyQt5.QtCore import QDir, QTimer, QModelIndex, QFileInfo, pyqtSignal, \ - pyqtSlot, QCryptographicHash, QEvent, QDateTime, QRegExp, Qt, QPoint +from PyQt5.QtCore import ( + QDir, QTimer, QModelIndex, QFileInfo, pyqtSignal, pyqtSlot, + QCryptographicHash, QEvent, QDateTime, QRegExp, Qt, QPoint +) from PyQt5.QtGui import QCursor, QPalette, QFont, QPixmap, QPainter -from PyQt5.QtWidgets import QLineEdit, QActionGroup, QDialog, QInputDialog, \ - QApplication, QMenu +from PyQt5.QtWidgets import ( + QLineEdit, QActionGroup, QDialog, QInputDialog, QApplication, QMenu +) from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog from PyQt5.Qsci import QsciScintilla, QsciMacro, QsciStyledText @@ -309,14 +312,18 @@ self.errorline = self.markerDefine( UI.PixmapCache.getPixmap("errorLineMarker.png")) - self.breakpointMask = (1 << self.breakpoint) | \ - (1 << self.cbreakpoint) | \ - (1 << self.tbreakpoint) | \ - (1 << self.tcbreakpoint) | \ - (1 << self.dbreakpoint) - - self.changeMarkersMask = (1 << self.__changeMarkerSaved) | \ - (1 << self.__changeMarkerUnsaved) + self.breakpointMask = ( + (1 << self.breakpoint) | + (1 << self.cbreakpoint) | + (1 << self.tbreakpoint) | + (1 << self.tcbreakpoint) | + (1 << self.dbreakpoint) + ) + + self.changeMarkersMask = ( + (1 << self.__changeMarkerSaved) | + (1 << self.__changeMarkerUnsaved) + ) self.__markerMap = EditorMarkerMap(self) @@ -346,8 +353,10 @@ self.isResourcesFile = False if editor is None: if self.fileName: - if (QFileInfo(self.fileName).size() // 1024) > \ - Preferences.getEditor("WarnFilesize"): + if ( + (QFileInfo(self.fileName).size() // 1024) > + Preferences.getEditor("WarnFilesize") + ): res = E5MessageBox.yesNo( self, self.tr("Open File"), @@ -504,9 +513,11 @@ # initialize the online change trace timer self.__initOnlineChangeTrace() - if self.fileName and \ - self.project.isOpen() and \ - self.project.isProjectSource(self.fileName): + if ( + self.fileName and + self.project.isOpen() and + self.project.isProjectSource(self.fileName) + ): self.project.projectPropertiesChanged.connect( self.__projectPropertiesChanged) @@ -1011,8 +1022,9 @@ languages = sorted(list(supportedLanguages.keys())) for language in languages: if language != "Guessed": - self.supportedLanguages[language] = \ + self.supportedLanguages[language] = ( supportedLanguages[language][:2] + ) act = menu.addAction( UI.PixmapCache.getIcon(supportedLanguages[language][2]), self.supportedLanguages[language][0]) @@ -1168,10 +1180,11 @@ self.__menuToggleBreakpointEnabled) self.marginMenuActs["NextBreakpoint"] = self.bpMarginMenu.addAction( self.tr('Next breakpoint'), self.menuNextBreakpoint) - self.marginMenuActs["PreviousBreakpoint"] = \ + self.marginMenuActs["PreviousBreakpoint"] = ( self.bpMarginMenu.addAction( self.tr('Previous breakpoint'), self.menuPreviousBreakpoint) + ) self.marginMenuActs["ClearBreakpoint"] = self.bpMarginMenu.addAction( self.tr('Clear all breakpoints'), self.__menuClearBreakpoints) @@ -1181,32 +1194,38 @@ # fold margin self.foldMarginMenu = QMenu() - self.marginMenuActs["ToggleAllFolds"] = \ + self.marginMenuActs["ToggleAllFolds"] = ( self.foldMarginMenu.addAction( self.tr("Toggle all folds"), self.foldAll) - self.marginMenuActs["ToggleAllFoldsAndChildren"] = \ + ) + self.marginMenuActs["ToggleAllFoldsAndChildren"] = ( self.foldMarginMenu.addAction( self.tr("Toggle all folds (including children)"), lambda: self.foldAll(True)) - self.marginMenuActs["ToggleCurrentFold"] = \ + ) + self.marginMenuActs["ToggleCurrentFold"] = ( self.foldMarginMenu.addAction( self.tr("Toggle current fold"), self.toggleCurrentFold) + ) self.foldMarginMenu.addSeparator() - self.marginMenuActs["ExpandChildren"] = \ + self.marginMenuActs["ExpandChildren"] = ( self.foldMarginMenu.addAction( self.tr("Expand (including children)"), self.__contextMenuExpandFoldWithChildren) - self.marginMenuActs["CollapseChildren"] = \ + ) + self.marginMenuActs["CollapseChildren"] = ( self.foldMarginMenu.addAction( self.tr("Collapse (including children)"), self.__contextMenuCollapseFoldWithChildren) + ) self.foldMarginMenu.addSeparator() - self.marginMenuActs["ClearAllFolds"] = \ + self.marginMenuActs["ClearAllFolds"] = ( self.foldMarginMenu.addAction( self.tr("Clear all folds"), self.clearFolds) + ) self.foldMarginMenu.aboutToShow.connect( lambda: self.__showContextMenuMargin(self.foldMarginMenu)) @@ -1214,53 +1233,67 @@ # indicator margin self.indicMarginMenu = QMenu() - self.marginMenuActs["GotoSyntaxError"] = \ + self.marginMenuActs["GotoSyntaxError"] = ( self.indicMarginMenu.addAction( self.tr('Goto syntax error'), self.gotoSyntaxError) - self.marginMenuActs["ShowSyntaxError"] = \ + ) + self.marginMenuActs["ShowSyntaxError"] = ( self.indicMarginMenu.addAction( self.tr('Show syntax error message'), self.__showSyntaxError) - self.marginMenuActs["ClearSyntaxError"] = \ + ) + self.marginMenuActs["ClearSyntaxError"] = ( self.indicMarginMenu.addAction( self.tr('Clear syntax error'), self.clearSyntaxError) + ) self.indicMarginMenu.addSeparator() - self.marginMenuActs["NextWarningMarker"] = \ + self.marginMenuActs["NextWarningMarker"] = ( self.indicMarginMenu.addAction( self.tr("Next warning"), self.nextWarning) - self.marginMenuActs["PreviousWarningMarker"] = \ + ) + self.marginMenuActs["PreviousWarningMarker"] = ( self.indicMarginMenu.addAction( self.tr("Previous warning"), self.previousWarning) - self.marginMenuActs["ShowWarning"] = \ + ) + self.marginMenuActs["ShowWarning"] = ( self.indicMarginMenu.addAction( self.tr('Show warning message'), self.__showWarning) - self.marginMenuActs["ClearWarnings"] = \ + ) + self.marginMenuActs["ClearWarnings"] = ( self.indicMarginMenu.addAction( self.tr('Clear warnings'), self.clearWarnings) + ) self.indicMarginMenu.addSeparator() - self.marginMenuActs["NextCoverageMarker"] = \ + self.marginMenuActs["NextCoverageMarker"] = ( self.indicMarginMenu.addAction( self.tr('Next uncovered line'), self.nextUncovered) - self.marginMenuActs["PreviousCoverageMarker"] = \ + ) + self.marginMenuActs["PreviousCoverageMarker"] = ( self.indicMarginMenu.addAction( self.tr('Previous uncovered line'), self.previousUncovered) + ) self.indicMarginMenu.addSeparator() - self.marginMenuActs["NextTaskMarker"] = \ + self.marginMenuActs["NextTaskMarker"] = ( self.indicMarginMenu.addAction( self.tr('Next task'), self.nextTask) - self.marginMenuActs["PreviousTaskMarker"] = \ + ) + self.marginMenuActs["PreviousTaskMarker"] = ( self.indicMarginMenu.addAction( self.tr('Previous task'), self.previousTask) + ) self.indicMarginMenu.addSeparator() - self.marginMenuActs["NextChangeMarker"] = \ + self.marginMenuActs["NextChangeMarker"] = ( self.indicMarginMenu.addAction( self.tr('Next change'), self.nextChange) - self.marginMenuActs["PreviousChangeMarker"] = \ + ) + self.marginMenuActs["PreviousChangeMarker"] = ( self.indicMarginMenu.addAction( self.tr('Previous change'), self.previousChange) - self.marginMenuActs["ClearChangeMarkers"] = \ + ) + self.marginMenuActs["ClearChangeMarkers"] = ( self.indicMarginMenu.addAction( self.tr('Clear changes'), self.__reinitOnlineChangeTrace) + ) self.indicMarginMenu.aboutToShow.connect( lambda: self.__showContextMenuMargin(self.indicMarginMenu)) @@ -1386,8 +1419,11 @@ @keyparam propagate flag indicating to propagate the change (boolean) """ - if self.lexer_ is not None and \ - (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None): + if ( + self.lexer_ is not None and + (self.lexer_.lexer() == "container" or + self.lexer_.lexer() is None) + ): self.SCN_STYLENEEDED.disconnect(self.__styleNeeded) self.apiLanguage = "" @@ -1487,8 +1523,8 @@ Private method to check the selected encoding of the encodings submenu. """ try: - self.supportedEncodings[self.__normalizedEncoding()]\ - .setChecked(True) + (self.supportedEncodings[self.__normalizedEncoding()] + .setChecked(True)) except (AttributeError, KeyError): pass @@ -1516,9 +1552,12 @@ """ if not encoding: encoding = self.encoding - return encoding.replace("-default", "")\ - .replace("-guessed", "")\ - .replace("-selected", "") + return ( + encoding + .replace("-default", "") + .replace("-guessed", "") + .replace("-selected", "") + ) def __showContextMenuEol(self): """ @@ -1565,16 +1604,21 @@ language (string) @keyparam pyname name of the pygments lexer to use (string) """ - if self.lexer_ is not None and \ - (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None): + if ( + self.lexer_ is not None and + (self.lexer_.lexer() == "container" or + self.lexer_.lexer() is None) + ): self.SCN_STYLENEEDED.disconnect(self.__styleNeeded) language = "" if not self.filetype: if filename: basename = os.path.basename(filename) - if self.project.isOpen() and \ - self.project.isProjectFile(filename): + if ( + self.project.isOpen() and + self.project.isProjectFile(filename) + ): language = self.project.getEditorLexerAssoc(basename) if not language: language = Preferences.getEditorLexerAssoc(basename) @@ -1682,8 +1726,10 @@ names for Pygments (boolean) @return language of the editor (string) """ - if self.apiLanguage == "Guessed" or \ - self.apiLanguage.startswith("Pygments|"): + if ( + self.apiLanguage == "Guessed" or + self.apiLanguage.startswith("Pygments|") + ): lang = self.lexer_.name() if normalized: # adjust some Pygments lexer names @@ -1931,14 +1977,18 @@ if self.filetype == "": line0 = self.text(0) - if line0.startswith("#!") and \ - "ruby" in line0: + if ( + line0.startswith("#!") and + "ruby" in line0 + ): self.filetype = "Ruby" return True - if bool(self.fileName) and \ - os.path.splitext(self.fileName)[1] in \ - self.dbs.getExtensions('Ruby'): + if ( + bool(self.fileName) and + os.path.splitext(self.fileName)[1] in + self.dbs.getExtensions('Ruby') + ): self.filetype = "Ruby" return True @@ -1954,8 +2004,10 @@ return True if self.filetype == "": - if self.fileName and \ - os.path.splitext(self.fileName)[1] == ".js": + if ( + self.fileName and + os.path.splitext(self.fileName)[1] == ".js" + ): self.filetype = "JavaScript" return True @@ -2032,12 +2084,15 @@ @param annotationLinesAdded number of added/deleted annotation lines (integer) """ - if mtype & (self.SC_MOD_INSERTTEXT | self.SC_MOD_DELETETEXT) and \ - linesAdded != 0: + if ( + mtype & (self.SC_MOD_INSERTTEXT | self.SC_MOD_DELETETEXT) and + linesAdded != 0 + ): if self.breaks: bps = [] # list of breakpoints - for handle, (ln, cond, temp, enabled, ignorecount) in \ - self.breaks.items(): + for handle, (ln, cond, temp, enabled, ignorecount) in ( + self.breaks.items() + ): line = self.markerLine(handle) + 1 if ln != line: bps.append((ln, line)) @@ -2109,8 +2164,9 @@ """ for row in range(start, end + 1): index = self.breakpointModel.index(row, 0, parentIndex) - fn, line, cond, temp, enabled, ignorecount = \ + fn, line, cond, temp, enabled, ignorecount = ( self.breakpointModel.getBreakPointByIndex(index)[:6] + ) if fn == self.fileName: self.newBreakpointWithProperties( line, (cond, temp, enabled, ignorecount)) @@ -2171,9 +2227,11 @@ # delete breakpoint or toggle it to the next state index = self.breakpointModel.getBreakPointIndex( self.fileName, line) - if Preferences.getDebugger("ThreeStateBreakPoints") and \ - not self.breakpointModel.isBreakPointTemporaryByIndex( - index): + if ( + Preferences.getDebugger("ThreeStateBreakPoints") and + not self.breakpointModel.isBreakPointTemporaryByIndex( + index) + ): self.breakpointModel.deleteBreakPointByIndex(index) self.__addBreakPoint(line, True) else: @@ -2947,10 +3005,12 @@ modified = False - if (not self.__getEditorConfig("TabForIndentation")) and \ - Preferences.getEditor("ConvertTabsOnLoad") and \ - not (self.lexer_ and - self.lexer_.alwaysKeepTabs()): + if ( + (not self.__getEditorConfig("TabForIndentation")) and + Preferences.getEditor("ConvertTabsOnLoad") and + not (self.lexer_ and + self.lexer_.alwaysKeepTabs()) + ): txtExpanded = txt.expandtabs(self.__getEditorConfig("TabWidth")) if txtExpanded != txt: modified = True @@ -2962,8 +3022,10 @@ self.__processFlags() # perform automatic EOL conversion - if self.__getEditorConfig("EOLMode", nodefault=True) or \ - Preferences.getEditor("AutomaticEOLConversion"): + if ( + self.__getEditorConfig("EOLMode", nodefault=True) or + Preferences.getEditor("AutomaticEOLConversion") + ): self.convertEols(self.eolMode()) else: fileEol = self.detectEolString(txt) @@ -3067,8 +3129,10 @@ """ # save to project, if a project is loaded if self.project.isOpen(): - if self.fileName and \ - self.project.startswithProjectPath(self.fileName): + if ( + self.fileName and + self.project.startswithProjectPath(self.fileName) + ): path = os.path.dirname(self.fileName) else: path = self.project.getProjectPath() @@ -3076,8 +3140,10 @@ if not path and self.fileName: path = os.path.dirname(self.fileName) if not path: - path = Preferences.getMultiProject("Workspace") or \ + path = ( + Preferences.getMultiProject("Workspace") or Utilities.getHomeDir() + ) from . import Lexers if self.fileName: @@ -3135,8 +3201,10 @@ res = self.writeFile(fn) if res: # save to project, if a project is loaded - if self.project.isOpen() and \ - self.project.startswithProjectPath(fn): + if ( + self.project.isOpen() and + self.project.startswithProjectPath(fn) + ): self.project.appendFile(fn) return res @@ -3163,8 +3231,10 @@ newName = fn # save to project, if a project is loaded - if self.project.isOpen() and \ - self.project.startswithProjectPath(fn): + if ( + self.project.isOpen() and + self.project.startswithProjectPath(fn) + ): editorConfigEol = self.__getEditorConfig( "EOLMode", nodefault=True, config=self.__loadEditorConfigObject(fn)) @@ -3196,8 +3266,10 @@ self.editorRenamed.emit(self.fileName) # save to project, if a project is loaded - if self.project.isOpen() and \ - self.project.startswithProjectPath(fn): + if ( + self.project.isOpen() and + self.project.startswithProjectPath(fn) + ): self.project.appendFile(fn) self.addedToProject() @@ -3622,9 +3694,11 @@ # check if line starts with our comment string (i.e. was commented # by our comment...() slots - if self.hasSelectedText() and \ - self.__isCommentedLine(self.text(self.getSelection()[0]), - commentStr): + if ( + self.hasSelectedText() and + self.__isCommentedLine(self.text(self.getSelection()[0]), + commentStr) + ): self.uncommentLineOrSelection() elif not self.__isCommentedLine(self.text(line), commentStr): # it doesn't, so comment the line or selection @@ -3632,14 +3706,18 @@ else: # determine the start of the comment block begline = line - while begline > 0 and \ - self.__isCommentedLine(self.text(begline - 1), commentStr): + while ( + begline > 0 and + self.__isCommentedLine(self.text(begline - 1), commentStr) + ): begline -= 1 # determine the end of the comment block endline = line lines = self.lines() - while endline < lines and \ - self.__isCommentedLine(self.text(endline + 1), commentStr): + while ( + endline < lines and + self.__isCommentedLine(self.text(endline + 1), commentStr) + ): endline += 1 self.setSelection(begline, 0, endline, self.lineLength(endline)) @@ -4268,23 +4346,27 @@ self.setMarginSensitivity(self.__bmMargin, True) self.setMarginMarkerMask(self.__bmMargin, marginBmMask) - marginBpMask = (1 << self.breakpoint) | \ - (1 << self.cbreakpoint) | \ - (1 << self.tbreakpoint) | \ - (1 << self.tcbreakpoint) | \ - (1 << self.dbreakpoint) + marginBpMask = ( + (1 << self.breakpoint) | + (1 << self.cbreakpoint) | + (1 << self.tbreakpoint) | + (1 << self.tcbreakpoint) | + (1 << self.dbreakpoint) + ) self.setMarginWidth(self.__bpMargin, 16) self.setMarginSensitivity(self.__bpMargin, True) self.setMarginMarkerMask(self.__bpMargin, marginBpMask) - marginIndicMask = (1 << self.syntaxerror) | \ - (1 << self.notcovered) | \ - (1 << self.taskmarker) | \ - (1 << self.warning) | \ - (1 << self.__changeMarkerUnsaved) | \ - (1 << self.__changeMarkerSaved) | \ - (1 << self.currentline) | \ - (1 << self.errorline) + marginIndicMask = ( + (1 << self.syntaxerror) | + (1 << self.notcovered) | + (1 << self.taskmarker) | + (1 << self.warning) | + (1 << self.__changeMarkerUnsaved) | + (1 << self.__changeMarkerSaved) | + (1 << self.currentline) | + (1 << self.errorline) + ) self.setMarginWidth(self.__indicMargin, 16) self.setMarginSensitivity(self.__indicMargin, True) self.setMarginMarkerMask(self.__indicMargin, marginIndicMask) @@ -4426,9 +4508,11 @@ self.indicatorDefine( self.searchIndicator, QsciScintilla.INDIC_BOX, Preferences.getEditorColour("SearchMarkers")) - if not Preferences.getEditor("SearchMarkersEnabled") and \ - not Preferences.getEditor("QuickSearchMarkersEnabled") and \ - not Preferences.getEditor("MarkOccurrencesEnabled"): + if ( + not Preferences.getEditor("SearchMarkersEnabled") and + not Preferences.getEditor("QuickSearchMarkersEnabled") and + not Preferences.getEditor("MarkOccurrencesEnabled") + ): self.clearAllIndicators(self.searchIndicator) self.spellingIndicator = QsciScintilla.INDIC_CONTAINER + 1 @@ -4466,9 +4550,11 @@ """ Private method to configure the eol mode of the editor. """ - if self.fileName and \ - self.project.isOpen() and \ - self.project.isProjectFile(self.fileName): + if ( + self.fileName and + self.project.isOpen() and + self.project.isProjectFile(self.fileName) + ): eolMode = self.__getEditorConfig("EOLMode", nodefault=True) if eolMode is None: eolStr = self.project.getEolString() @@ -4527,8 +4613,9 @@ if Preferences.getEditor("CallTipsEnabled"): if calltipsStyle == QsciScintilla.CallTipsNoContext: self.setCallTipsStyle(QsciScintilla.CallTipsNoContext) - elif calltipsStyle == \ - QsciScintilla.CallTipsNoAutoCompletionContext: + elif ( + calltipsStyle == QsciScintilla.CallTipsNoAutoCompletionContext + ): self.setCallTipsStyle( QsciScintilla.CallTipsNoAutoCompletionContext) else: @@ -4580,8 +4667,8 @@ (boolean) """ if enable: - autoCompletionSource = \ - Preferences.getEditor("AutoCompletionSource") + autoCompletionSource = Preferences.getEditor( + "AutoCompletionSource") if autoCompletionSource == QsciScintilla.AcsDocument: self.setAutoCompletionSource(QsciScintilla.AcsDocument) elif autoCompletionSource == QsciScintilla.AcsAPIs: @@ -4610,8 +4697,10 @@ """ char = chr(charNumber) # update code documentation viewer - if char == "(" and \ - Preferences.getDocuViewer("ShowInfoOnOpenParenthesis"): + if ( + char == "(" and + Preferences.getDocuViewer("ShowInfoOnOpenParenthesis") + ): self.vm.showEditorInfo(self) if self.isListActive(): @@ -4624,8 +4713,10 @@ else: self.__acTimer.stop() - if self.callTipsStyle() != QsciScintilla.CallTipsNone and \ - self.lexer_ is not None and chr(charNumber) in '()': + if ( + self.callTipsStyle() != QsciScintilla.CallTipsNone and + self.lexer_ is not None and chr(charNumber) in '()' + ): self.callTip() if not self.isCallTipActive(): @@ -4686,8 +4777,10 @@ @param asynchroneous flag indicating an asynchroneous function @type bool """ - if key in self.__completionListHookFunctions or \ - key in self.__completionListAsyncHookFunctions: + if ( + key in self.__completionListHookFunctions or + key in self.__completionListAsyncHookFunctions + ): # it was already registered E5MessageBox.warning( self, @@ -4742,8 +4835,10 @@ if self.isListActive(): self.cancelList() - if self.__completionListHookFunctions or \ - self.__completionListAsyncHookFunctions: + if ( + self.__completionListHookFunctions or + self.__completionListAsyncHookFunctions + ): # Avoid delayed auto-completion after cursor repositioning self.__acText = self.__getAcText() if auto and Preferences.getEditor("AutoCompletionTimeout"): @@ -4846,8 +4941,10 @@ self.__acWatchdog.stop() # Autocomplete with QScintilla if no results present - if Preferences.getEditor("AutoCompletionScintillaOnFail") and \ - not self.__acCompletions: + if ( + Preferences.getEditor("AutoCompletionScintillaOnFail") and + not self.__acCompletions + ): self.autoCompleteQScintilla() return @@ -5169,9 +5266,12 @@ evt.accept() if self.__marginNumber(evt.x()) == -1: self.spellingMenuPos = self.positionFromPoint(evt.pos()) - if self.spellingMenuPos >= 0 and \ - self.spell is not None and \ - self.hasIndicator(self.spellingIndicator, self.spellingMenuPos): + if ( + self.spellingMenuPos >= 0 and + self.spell is not None and + self.hasIndicator(self.spellingIndicator, + self.spellingMenuPos) + ): self.spellingMenu.popup(evt.globalPos()) else: self.menu.popup(evt.globalPos()) @@ -5208,8 +5308,10 @@ self.menuActs["Show"].setEnabled(True) else: self.menuActs["Show"].setEnabled(False) - if self.fileName and \ - (self.isPyFile() or self.isRubyFile()): + if ( + self.fileName and + (self.isPyFile() or self.isRubyFile()) + ): self.menuActs["Diagrams"].setEnabled(True) else: self.menuActs["Diagrams"].setEnabled(False) @@ -5289,22 +5391,27 @@ coEnable = False # first check if the file belongs to a project - if self.project.isOpen() and \ - self.project.isProjectSource(self.fileName): + if ( + self.project.isOpen() and + self.project.isProjectSource(self.fileName) + ): fn = self.project.getMainScript(True) if fn is not None: tfn = Utilities.getTestFileName(fn) basename = os.path.splitext(fn)[0] tbasename = os.path.splitext(tfn)[0] - prEnable = prEnable or \ - os.path.isfile("{0}.profile".format(basename)) or \ + prEnable = ( + prEnable or + os.path.isfile("{0}.profile".format(basename)) or os.path.isfile("{0}.profile".format(tbasename)) + ) coEnable = ( - coEnable or - os.path.isfile("{0}.coverage".format(basename)) or - os.path.isfile("{0}.coverage".format(tbasename))) and \ + (coEnable or + os.path.isfile("{0}.coverage".format(basename)) or + os.path.isfile("{0}.coverage".format(tbasename))) and (self.project.isPy3Project() or - self.project.isPy2Project()) + self.project.isPy2Project()) + ) # now check ourselves fn = self.getFileName() @@ -5312,14 +5419,17 @@ tfn = Utilities.getTestFileName(fn) basename = os.path.splitext(fn)[0] tbasename = os.path.splitext(tfn)[0] - prEnable = prEnable or \ - os.path.isfile("{0}.profile".format(basename)) or \ + prEnable = ( + prEnable or + os.path.isfile("{0}.profile".format(basename)) or os.path.isfile("{0}.profile".format(tbasename)) + ) coEnable = ( - coEnable or - os.path.isfile("{0}.coverage".format(basename)) or - os.path.isfile("{0}.coverage".format(tbasename))) and \ + (coEnable or + os.path.isfile("{0}.coverage".format(basename)) or + os.path.isfile("{0}.coverage".format(tbasename))) and self.isPyFile() + ) # now check for syntax errors if self.hasSyntaxErrors(): @@ -5339,8 +5449,10 @@ Private slot handling the aboutToShow signal of the diagrams context menu. """ - if self.project.isOpen() and \ - self.project.isProjectSource(self.fileName): + if ( + self.project.isOpen() and + self.project.isProjectSource(self.fileName) + ): self.applicationDiagramMenuAct.setEnabled(True) else: self.applicationDiagramMenuAct.setEnabled(False) @@ -5403,8 +5515,10 @@ self.marginMenuActs["GotoSyntaxError"].setEnabled(hasSyntaxErrors) self.marginMenuActs["ClearSyntaxError"].setEnabled(hasSyntaxErrors) - if hasSyntaxErrors and \ - self.markersAtLine(self.line) & (1 << self.syntaxerror): + if ( + hasSyntaxErrors and + self.markersAtLine(self.line) & (1 << self.syntaxerror) + ): self.marginMenuActs["ShowSyntaxError"].setEnabled(True) else: self.marginMenuActs["ShowSyntaxError"].setEnabled(False) @@ -5413,8 +5527,10 @@ self.marginMenuActs["PreviousWarningMarker"].setEnabled( hasWarnings) self.marginMenuActs["ClearWarnings"].setEnabled(hasWarnings) - if hasWarnings and \ - self.markersAtLine(self.line) & (1 << self.warning): + if ( + hasWarnings and + self.markersAtLine(self.line) & (1 << self.warning) + ): self.marginMenuActs["ShowWarning"].setEnabled(True) else: self.marginMenuActs["ShowWarning"].setEnabled(False) @@ -5538,8 +5654,10 @@ if line1Text in ["", "\r", "\n", "\r\n"]: return - if line0Text.rstrip("\r\n\\ \t").endswith(("'", '"')) and \ - line1Text.lstrip().startswith(("'", '"')): + if ( + line0Text.rstrip("\r\n\\ \t").endswith(("'", '"')) and + line1Text.lstrip().startswith(("'", '"')) + ): # merging multi line strings startChars = "\r\n\\ \t'\"" endChars = " \t'\"" @@ -5594,9 +5712,11 @@ @return flag indicating this editor should be saved (boolean) """ - return bool(self.fileName) and \ - not self.autosaveManuallyDisabled and \ + return ( + bool(self.fileName) and + not self.autosaveManuallyDisabled and not self.isReadOnly() + ) def checkSyntax(self): """ @@ -5607,8 +5727,10 @@ # adjustment for MicroPython fileType = "Python3" - if self.syntaxCheckService is None or \ - fileType not in self.syntaxCheckService.getLanguages(): + if ( + self.syntaxCheckService is None or + fileType not in self.syntaxCheckService.getLanguages() + ): return if Preferences.getEditor("AutoCheckSyntax"): @@ -5709,8 +5831,10 @@ # first check if the file belongs to a project and there is # a project coverage file - if self.project.isOpen() and \ - self.project.isProjectSource(self.fileName): + if ( + self.project.isOpen() and + self.project.isProjectSource(self.fileName) + ): fn = self.project.getMainScript(True) if fn is not None: tfn = Utilities.getTestFileName(fn) @@ -5887,8 +6011,10 @@ # first check if the file belongs to a project and there is # a project profile file - if self.project.isOpen() and \ - self.project.isProjectSource(self.fileName): + if ( + self.project.isOpen() and + self.project.isProjectSource(self.fileName) + ): fn = self.project.getMainScript(True) if fn is not None: tfn = Utilities.getTestFileName(fn) @@ -5981,8 +6107,10 @@ self.syntaxerrorToggled.emit(self) else: for handle in list(self.syntaxerrors.keys()): - if self.markerLine(handle) == line - 1 and \ - (msg, index) not in self.syntaxerrors[handle]: + if ( + self.markerLine(handle) == line - 1 and + (msg, index) not in self.syntaxerrors[handle] + ): self.syntaxerrors[handle].append((msg, index)) if show: self.setCursorPosition(line - 1, index) @@ -6136,8 +6264,10 @@ self.syntaxerrorToggled.emit(self) else: for handle in list(self.warnings.keys()): - if self.markerLine(handle) == line - 1 and \ - warn not in self.warnings[handle]: + if ( + self.markerLine(handle) == line - 1 and + warn not in self.warnings[handle] + ): self.warnings[handle].append(warn) else: for handle in list(self.warnings.keys()): @@ -6304,8 +6434,9 @@ Private slot to define the style used by inline annotations. """ if hasattr(QsciScintilla, "annotate"): - self.annotationWarningStyle = \ + self.annotationWarningStyle = ( QsciScintilla.STYLE_LASTPREDEFINED + 1 + ) self.SendScintilla( QsciScintilla.SCI_STYLESETFORE, self.annotationWarningStyle, @@ -6395,8 +6526,10 @@ """ if hasattr(QsciScintilla, "annotate"): self.clearAnnotations() - for handle in list(self.warnings.keys()) + \ - list(self.syntaxerrors.keys()): + for handle in ( + list(self.warnings.keys()) + + list(self.syntaxerrors.keys()) + ): line = self.markerLine(handle) self.__setAnnotation(line) @@ -6727,18 +6860,20 @@ except AttributeError: pass self.__updateReadOnly(False) - if self.vm.editorsCheckFocusInEnabled() and \ - not self.inReopenPrompt and self.fileName and \ - QFileInfo(self.fileName).lastModified().toString() != \ - self.lastModified.toString(): + if ( + self.vm.editorsCheckFocusInEnabled() and + not self.inReopenPrompt and self.fileName and + QFileInfo(self.fileName).lastModified().toString() != + self.lastModified.toString() + ): self.inReopenPrompt = True if Preferences.getEditor("AutoReopen") and not self.isModified(): self.refresh() else: msg = self.tr( """<p>The file <b>{0}</b> has been changed while it""" - """ was opened in eric6. Reread it?</p>""")\ - .format(self.fileName) + """ was opened in eric6. Reread it?</p>""" + ).format(self.fileName) yesDefault = True if self.isModified(): msg += self.tr( @@ -6785,8 +6920,10 @@ @param evt the event, that was generated (QEvent) """ - if evt.type() == QEvent.WindowStateChange and \ - bool(self.fileName): + if ( + evt.type() == QEvent.WindowStateChange and + bool(self.fileName) + ): if self.windowState() == Qt.WindowStates(Qt.WindowMinimized): cap = os.path.basename(self.fileName) else: @@ -6900,8 +7037,10 @@ if self.fileName == "": return - readOnly = not QFileInfo(self.fileName).isWritable() or \ + readOnly = ( + not QFileInfo(self.fileName).isWritable() or self.isReadOnly() + ) if not bForce and (readOnly == self.isReadOnly()): return @@ -7205,8 +7344,10 @@ if not self.checkDirty(): return - package = os.path.isdir(self.fileName) and \ + package = ( + os.path.isdir(self.fileName) and self.fileName or os.path.dirname(self.fileName) + ) res = E5MessageBox.yesNo( self, self.tr("Package Diagram"), @@ -7225,8 +7366,10 @@ if not self.checkDirty(): return - package = os.path.isdir(self.fileName) and self.fileName \ - or os.path.dirname(self.fileName) + package = ( + os.path.isdir(self.fileName) and + self.fileName or os.path.dirname(self.fileName) + ) res = E5MessageBox.yesNo( self, self.tr("Imports Diagram"), @@ -7372,8 +7515,10 @@ """ Public slot to handle the opening of a project. """ - if self.fileName and \ - self.project.isProjectSource(self.fileName): + if ( + self.fileName and + self.project.isProjectSource(self.fileName) + ): self.project.projectPropertiesChanged.connect( self.__projectPropertiesChanged) self.setSpellingForProject() @@ -7429,9 +7574,11 @@ Public method to set the spell checking options for files belonging to the current project. """ - if self.fileName and \ - self.project.isOpen() and \ - self.project.isProjectSource(self.fileName): + if ( + self.fileName and + self.project.isOpen() and + self.project.isProjectSource(self.fileName) + ): pwl, pel = self.project.getProjectDictionaries() self.__setSpellingLanguage(self.project.getProjectSpellLanguage(), pwl=pwl, pel=pel) @@ -7465,8 +7612,10 @@ if self.__spellCheckStringsOnly: style = self.styleAt(pos) if self.lexer_ is not None: - return self.lexer_.isCommentStyle(style) or \ + return ( + self.lexer_.isCommentStyle(style) or self.lexer_.isStringStyle(style) + ) return True @pyqtSlot(int) @@ -7611,10 +7760,14 @@ and if it is inside a remotely initiated shared edit session (boolean, boolean, boolean, boolean) """ - return bool(self.fileName) and \ - self.project.isOpen() and \ - self.project.isProjectFile(self.fileName), \ - self.__isShared, self.__inSharedEdit, self.__inRemoteSharedEdit + return ( + (bool(self.fileName) and + self.project.isOpen() and + self.project.isProjectFile(self.fileName)), + self.__isShared, + self.__inSharedEdit, + self.__inRemoteSharedEdit + ) def shareConnected(self, connected): """ @@ -7707,8 +7860,10 @@ @param command command string (string) """ if self.__isShared: - if self.__isSyncing and \ - not command.startswith(Editor.SyncToken + Editor.Separator): + if ( + self.__isSyncing and + not command.startswith(Editor.SyncToken + Editor.Separator) + ): self.__receivedWhileSyncing.append(command) else: self.__dispatchCommand(command) @@ -7929,8 +8084,9 @@ dlg = SortOptionsDialog() if dlg.exec_() == QDialog.Accepted: ascending, alnum, caseSensitive = dlg.getData() - origStartLine, origStartIndex, origEndLine, origEndIndex = \ + origStartLine, origStartIndex, origEndLine, origEndIndex = ( self.getRectangularSelection() + ) # convert to upper-left to lower-right startLine = min(origStartLine, origEndLine) startIndex = min(origStartIndex, origEndIndex) @@ -8011,9 +8167,11 @@ self.vm.eventFilter(self, evt) super(Editor, self).mouseReleaseEvent(evt) - if button != Qt.NoButton and \ - Preferences.getEditor("MouseClickHandlersEnabled") and \ - key in self.__mouseClickHandlers: + if ( + button != Qt.NoButton and + Preferences.getEditor("MouseClickHandlersEnabled") and + key in self.__mouseClickHandlers + ): evt.accept() self.__mouseClickHandlers[key][1](self)