diff -r 10554f5fac78 -r 096b3ebc1409 eric6/ViewManager/ViewManager.py --- a/eric6/ViewManager/ViewManager.py Sat Oct 03 11:14:23 2020 +0200 +++ b/eric6/ViewManager/ViewManager.py Sun Nov 01 11:15:18 2020 +0100 @@ -4,15 +4,15 @@ # """ -Module implementing the viewmanager base class. +Module implementing the view manager base class. """ - +import re import os from PyQt5.QtCore import ( - pyqtSignal, pyqtSlot, QSignalMapper, QTimer, QFileInfo, QRegExp, Qt, - QCoreApplication, QPoint + pyqtSignal, pyqtSlot, Qt, QSignalMapper, QTimer, QFileInfo, QPoint, + QCoreApplication ) from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap from PyQt5.QtWidgets import ( @@ -29,7 +29,6 @@ import Preferences from QScintilla.Editor import Editor -from QScintilla.QsciScintillaCompat import QSCINTILLA_VERSION import Utilities @@ -90,10 +89,10 @@ class ViewManager(QWidget): """ - Base class inherited by all specific viewmanager classes. + Base class inherited by all specific view manager classes. It defines the interface to be implemented by specific - viewmanager classes and all common methods. + view manager classes and all common methods. @signal changeCaption(str) emitted if a change of the caption is necessary @signal editorChanged(str) emitted when the current editor has changed @@ -309,7 +308,7 @@ if aw is not None: menu = aw.getMenu("Languages") if menu is not None: - menu.exec_(pos) + menu.exec(pos) def __showEolMenu(self, pos): """ @@ -321,7 +320,7 @@ if aw is not None: menu = aw.getMenu("Eol") if menu is not None: - menu.exec_(pos) + menu.exec(pos) def __showEncodingsMenu(self, pos): """ @@ -333,7 +332,7 @@ if aw is not None: menu = aw.getMenu("Encodings") if menu is not None: - menu.exec_(pos) + menu.exec(pos) ########################################################################### ## methods below need to be implemented by a subclass @@ -2146,18 +2145,17 @@ act.triggered.connect(self.esm.map) self.editActions.append(act) - if QSCINTILLA_VERSION() >= 0x020B00: - act = E5Action( - QCoreApplication.translate('ViewManager', - 'Reverse selected lines'), - QCoreApplication.translate('ViewManager', - 'Reverse selected lines'), - QKeySequence(QCoreApplication.translate('ViewManager', - 'Meta+Alt+R')), - 0, self.editorActGrp, 'vm_edit_reverse selected_lines') - self.esm.setMapping(act, QsciScintilla.SCI_LINEREVERSE) - act.triggered.connect(self.esm.map) - self.editActions.append(act) + act = E5Action( + QCoreApplication.translate('ViewManager', + 'Reverse selected lines'), + QCoreApplication.translate('ViewManager', + 'Reverse selected lines'), + QKeySequence(QCoreApplication.translate('ViewManager', + 'Meta+Alt+R')), + 0, self.editorActGrp, 'vm_edit_reverse selected_lines') + self.esm.setMapping(act, QsciScintilla.SCI_LINEREVERSE) + act.triggered.connect(self.esm.map) + self.editActions.append(act) act = E5Action( QCoreApplication.translate('ViewManager', 'Cut current line'), @@ -5388,7 +5386,7 @@ """ from .BookmarkedFilesDialog import BookmarkedFilesDialog dlg = BookmarkedFilesDialog(self.bookmarked, self.ui) - if dlg.exec_() == QDialog.Accepted: + if dlg.exec() == QDialog.Accepted: self.bookmarked = dlg.getBookmarkedFiles() def __clearBookmarked(self): @@ -5927,12 +5925,14 @@ line, index = aw.getCursorPosition() text = aw.text(line) - reg = QRegExp(r'[^\w_]') - end = reg.indexIn(text, index) - if end > index: - ext = text[index:end] - txt += ext - self.quickFindtextCombo.lineEdit().setText(txt) + rx = re.compile(r'[^\w_]') + match = rx.search(text, index) + if match: + end = match.start() + if end > index: + ext = text[index:end] + txt += ext + self.quickFindtextCombo.lineEdit().setText(txt) def showSearchWidget(self): """ @@ -5997,7 +5997,7 @@ lines = aw.lines() curLine = aw.getCursorPosition()[0] + 1 dlg = GotoDialog(lines, curLine, self.ui, None, True) - if dlg.exec_() == QDialog.Accepted: + if dlg.exec() == QDialog.Accepted: aw.gotoLine(dlg.getLinenumber(), expand=True) def __gotoBrace(self): @@ -6083,19 +6083,13 @@ if aw: aw.zoomOut() self.sbZoom.setValue(aw.getZoom()) - + def __zoomReset(self): """ Private method to reset the zoom factor. """ - if QApplication.focusWidget() == e5App().getObject("Shell"): - e5App().getObject("Shell").zoomTo(0) - else: - aw = self.activeWindow() - if aw: - aw.zoomTo(0) - self.sbZoom.setValue(aw.getZoom()) - + self.__zoomTo(0) + def __zoom(self): """ Private method to handle the zoom action. @@ -6107,7 +6101,7 @@ if aw: from QScintilla.ZoomDialog import ZoomDialog dlg = ZoomDialog(aw.getZoom(), self.ui, None, True) - if dlg.exec_() == QDialog.Accepted: + if dlg.exec() == QDialog.Accepted: value = dlg.getZoomSize() self.__zoomTo(value) @@ -6589,9 +6583,8 @@ """ if os.path.exists(dictionaryFile): try: - f = open(dictionaryFile, "r", encoding="utf-8") - data = f.read() - f.close() + with open(dictionaryFile, "r", encoding="utf-8") as f: + data = f.read() except (IOError, OSError) as err: E5MessageBox.critical( self.ui, @@ -6616,12 +6609,11 @@ QCoreApplication.translate('ViewManager', "Editing {0}") .format(fileInfo), self.ui) - if dlg.exec_() == QDialog.Accepted: + if dlg.exec() == QDialog.Accepted: data = dlg.getData() try: - f = open(dictionaryFile, "w", encoding="utf-8") - f.write(data) - f.close() + with open(dictionaryFile, "w", encoding="utf-8") as f: + f.write(data) except (IOError, OSError) as err: E5MessageBox.critical( self.ui, @@ -7195,12 +7187,12 @@ self.activeWindow().getFileName() ): ext = os.path.splitext(self.activeWindow().getFileName())[1] - rx = QRegExp(r".*\*\.{0}[ )].*".format(ext[1:])) + rx = re.compile(r".*\*\.{0}[ )].*".format(ext[1:])) import QScintilla.Lexers filters = QScintilla.Lexers.getOpenFileFiltersList() index = -1 for i in range(len(filters)): - if rx.exactMatch(filters[i]): + if rx.fullmatch(filters[i]): index = i break if index == -1: