diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/Plugins/ViewManagerPlugins/Tabview/Tabview.py --- a/src/eric7/Plugins/ViewManagerPlugins/Tabview/Tabview.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Plugins/ViewManagerPlugins/Tabview/Tabview.py Wed Jul 13 14:55:47 2022 +0200 @@ -10,12 +10,25 @@ import os from PyQt6.QtCore import ( - pyqtSlot, QPoint, pyqtSignal, QEvent, QByteArray, QMimeData, Qt, QSize + pyqtSlot, + QPoint, + pyqtSignal, + QEvent, + QByteArray, + QMimeData, + Qt, + QSize, ) from PyQt6.QtGui import QColor, QDrag, QPixmap, QMouseEvent from PyQt6.QtWidgets import ( - QWidget, QHBoxLayout, QSplitter, QTabBar, QApplication, QToolButton, - QMenu, QLabel + QWidget, + QHBoxLayout, + QSplitter, + QTabBar, + QApplication, + QToolButton, + QMenu, + QLabel, ) from EricWidgets.EricApplication import ericApp @@ -40,7 +53,7 @@ class TabBar(EricWheelTabBar): """ Class implementing a customized tab bar supporting drag & drop. - + @signal tabMoveRequested(int, int) emitted to signal a tab move request giving the old and new index position @signal tabRelocateRequested(str, int, int) emitted to signal a tab @@ -52,44 +65,45 @@ @signal tabCopyRequested(int, int) emitted to signal a clone request giving the old and new index position """ + tabMoveRequested = pyqtSignal(int, int) tabRelocateRequested = pyqtSignal(str, int, int) tabCopyRequested = pyqtSignal((str, int, int), (int, int)) - + def __init__(self, parent=None): """ Constructor - + @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setAcceptDrops(True) - + self.__dragStartPos = QPoint() - + def mousePressEvent(self, event): """ Protected method to handle mouse press events. - + @param event reference to the mouse press event @type QMouseEvent """ if event.button() == Qt.MouseButton.LeftButton: self.__dragStartPos = QPoint(event.position().toPoint()) super().mousePressEvent(event) - + def mouseMoveEvent(self, event): """ Protected method to handle mouse move events. - + @param event reference to the mouse move event @type QMouseEvent """ if ( - event.buttons() == Qt.MouseButton.LeftButton and - (event.position().toPoint() - self.__dragStartPos) - .manhattanLength() > QApplication.startDragDistance() + event.buttons() == Qt.MouseButton.LeftButton + and (event.position().toPoint() - self.__dragStartPos).manhattanLength() + > QApplication.startDragDistance() ): drag = QDrag(self) mimeData = QMimeData() @@ -98,41 +112,41 @@ mimeData.setData("action", b"tab-reordering") mimeData.setData("tabbar-id", str(id(self)).encode("utf-8")) mimeData.setData( - "source-index", - QByteArray.number(self.tabAt(self.__dragStartPos))) + "source-index", QByteArray.number(self.tabAt(self.__dragStartPos)) + ) mimeData.setData( - "tabwidget-id", - str(id(self.parentWidget())).encode("utf-8")) + "tabwidget-id", str(id(self.parentWidget())).encode("utf-8") + ) drag.setMimeData(mimeData) if event.modifiers() == Qt.KeyboardModifier.ShiftModifier: drag.exec(Qt.DropAction.CopyAction) elif event.modifiers() == Qt.KeyboardModifier.NoModifier: drag.exec(Qt.DropAction.MoveAction) super().mouseMoveEvent(event) - + def dragEnterEvent(self, event): """ Protected method to handle drag enter events. - + @param event reference to the drag enter event @type QDragEnterEvent """ mimeData = event.mimeData() formats = mimeData.formats() if ( - "action" in formats and - mimeData.data("action") == b"tab-reordering" and - "tabbar-id" in formats and - "source-index" in formats and - "tabwidget-id" in formats + "action" in formats + and mimeData.data("action") == b"tab-reordering" + and "tabbar-id" in formats + and "source-index" in formats + and "tabwidget-id" in formats ): event.acceptProposedAction() super().dragEnterEvent(event) - + def dropEvent(self, event): """ Protected method to handle drop events. - + @param event reference to the drop event @type QDropEvent """ @@ -143,12 +157,12 @@ if oldID != id(self): parentID = int(mimeData.data("tabwidget-id")) if event.proposedAction() == Qt.DropAction.MoveAction: - self.tabRelocateRequested.emit( - str(parentID), fromIndex, toIndex) + self.tabRelocateRequested.emit(str(parentID), fromIndex, toIndex) event.acceptProposedAction() elif event.proposedAction() == Qt.DropAction.CopyAction: self.tabCopyRequested[str, int, int].emit( - str(parentID), fromIndex, toIndex) + str(parentID), fromIndex, toIndex + ) event.acceptProposedAction() else: if fromIndex != toIndex: @@ -165,77 +179,73 @@ """ Class implementing a custimized tab widget. """ + def __init__(self, vm): """ Constructor - + @param vm view manager widget @type Tabview """ super().__init__() - + self.__tabBar = TabBar(self) self.setTabBar(self.__tabBar) iconSize = self.__tabBar.iconSize() - self.__tabBar.setIconSize( - QSize(2 * iconSize.width(), iconSize.height())) - + self.__tabBar.setIconSize(QSize(2 * iconSize.width(), iconSize.height())) + self.setUsesScrollButtons(True) self.setElideMode(Qt.TextElideMode.ElideNone) if isMacPlatform(): self.setDocumentMode(True) - + self.__tabBar.tabMoveRequested.connect(self.moveTab) self.__tabBar.tabRelocateRequested.connect(self.__relocateTab) - self.__tabBar.tabCopyRequested[str, int, int].connect( - self.__copyTabOther) + self.__tabBar.tabCopyRequested[str, int, int].connect(self.__copyTabOther) self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab) - + self.vm = vm self.editors = [] - + self.indicator = EricLed(self) self.setCornerWidget(self.indicator, Qt.Corner.TopLeftCorner) - + self.rightCornerWidget = QWidget(self) self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget) self.rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0) self.rightCornerWidgetLayout.setSpacing(0) - + self.__navigationMenu = QMenu(self) self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) - + self.navigationButton = QToolButton(self) self.navigationButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) self.navigationButton.setToolTip(self.tr("Show a navigation menu")) - self.navigationButton.setPopupMode( - QToolButton.ToolButtonPopupMode.InstantPopup) + self.navigationButton.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup) self.navigationButton.setMenu(self.__navigationMenu) self.navigationButton.setEnabled(False) self.rightCornerWidgetLayout.addWidget(self.navigationButton) - + self.tabCloseRequested.connect(self.__closeRequested) - + self.setCornerWidget(self.rightCornerWidget, Qt.Corner.TopRightCorner) - + self.__initMenu() self.contextMenuEditor = None self.contextMenuIndex = -1 - + self.setTabContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.customTabContextMenuRequested.connect(self.__showContextMenu) - - ericPic = QPixmap( - os.path.join(getConfig('ericPixDir'), 'eric_small.png')) + + ericPic = QPixmap(os.path.join(getConfig("ericPixDir"), "eric_small.png")) self.emptyLabel = QLabel() self.emptyLabel.setPixmap(ericPic) self.emptyLabel.setAlignment( - Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter) - super().addTab( - self.emptyLabel, - UI.PixmapCache.getIcon("empty"), "") - + Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter + ) + super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty"), "") + def __initMenu(self): """ Private method to initialize the tab context menu. @@ -243,75 +253,98 @@ self.__startMenu = QMenu(self.tr("Start"), self) self.__startMenu.addAction( UI.PixmapCache.getIcon("runScript"), - self.tr('Run Script...'), - self.__contextMenuRunScript) + self.tr("Run Script..."), + self.__contextMenuRunScript, + ) self.__startMenu.addAction( UI.PixmapCache.getIcon("debugScript"), - self.tr('Debug Script...'), - self.__contextMenuDebugScript) + self.tr("Debug Script..."), + self.__contextMenuDebugScript, + ) self.__startMenu.addAction( UI.PixmapCache.getIcon("profileScript"), - self.tr('Profile Script...'), - self.__contextMenuProfileScript) + self.tr("Profile Script..."), + self.__contextMenuProfileScript, + ) self.__startMenu.addAction( UI.PixmapCache.getIcon("coverageScript"), - self.tr('Coverage run of Script...'), - self.__contextMenuCoverageScript) - + self.tr("Coverage run of Script..."), + self.__contextMenuCoverageScript, + ) + self.__menu = QMenu(self) self.leftMenuAct = self.__menu.addAction( UI.PixmapCache.getIcon("1leftarrow"), - self.tr('Move Left'), self.__contextMenuMoveLeft) + self.tr("Move Left"), + self.__contextMenuMoveLeft, + ) self.rightMenuAct = self.__menu.addAction( UI.PixmapCache.getIcon("1rightarrow"), - self.tr('Move Right'), self.__contextMenuMoveRight) + self.tr("Move Right"), + self.__contextMenuMoveRight, + ) self.firstMenuAct = self.__menu.addAction( UI.PixmapCache.getIcon("2leftarrow"), - self.tr('Move First'), self.__contextMenuMoveFirst) + self.tr("Move First"), + self.__contextMenuMoveFirst, + ) self.lastMenuAct = self.__menu.addAction( UI.PixmapCache.getIcon("2rightarrow"), - self.tr('Move Last'), self.__contextMenuMoveLast) + self.tr("Move Last"), + self.__contextMenuMoveLast, + ) self.__menu.addSeparator() self.__menu.addAction( UI.PixmapCache.getIcon("tabClose"), - self.tr('Close'), self.__contextMenuClose) + self.tr("Close"), + self.__contextMenuClose, + ) self.closeOthersMenuAct = self.__menu.addAction( UI.PixmapCache.getIcon("tabCloseOther"), - self.tr("Close Others"), self.__contextMenuCloseOthers) - self.__menu.addAction( - self.tr('Close All'), self.__contextMenuCloseAll) + self.tr("Close Others"), + self.__contextMenuCloseOthers, + ) + self.__menu.addAction(self.tr("Close All"), self.__contextMenuCloseAll) self.__menu.addSeparator() self.saveMenuAct = self.__menu.addAction( - UI.PixmapCache.getIcon("fileSave"), - self.tr('Save'), self.__contextMenuSave) + UI.PixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextMenuSave + ) self.__menu.addAction( UI.PixmapCache.getIcon("fileSaveAs"), - self.tr('Save As...'), self.__contextMenuSaveAs) + self.tr("Save As..."), + self.__contextMenuSaveAs, + ) self.__menu.addAction( UI.PixmapCache.getIcon("fileSaveAll"), - self.tr('Save All'), self.__contextMenuSaveAll) + self.tr("Save All"), + self.__contextMenuSaveAll, + ) self.__menu.addSeparator() self.openRejectionsMenuAct = self.__menu.addAction( - self.tr("Open 'rejection' file"), - self.__contextMenuOpenRejections) + self.tr("Open 'rejection' file"), self.__contextMenuOpenRejections + ) self.__menu.addSeparator() self.__startAct = self.__menu.addMenu(self.__startMenu) self.__menu.addSeparator() self.__menu.addAction( UI.PixmapCache.getIcon("printPreview"), - self.tr("Print Preview"), self.__contextMenuPrintPreviewFile) + self.tr("Print Preview"), + self.__contextMenuPrintPreviewFile, + ) self.__menu.addAction( UI.PixmapCache.getIcon("print"), - self.tr('Print'), self.__contextMenuPrintFile) + self.tr("Print"), + self.__contextMenuPrintFile, + ) self.__menu.addSeparator() self.copyPathAct = self.__menu.addAction( - self.tr("Copy Path to Clipboard"), - self.__contextMenuCopyPathToClipboard) - + self.tr("Copy Path to Clipboard"), self.__contextMenuCopyPathToClipboard + ) + def __showContextMenu(self, coord, index): """ Private slot to show the tab context menu. - + @param coord the position of the mouse pointer @type QPoint @param index index of the tab the menu is requested for @@ -322,60 +355,58 @@ if widget is not None: self.contextMenuEditor = widget.getEditor() if self.contextMenuEditor: - self.saveMenuAct.setEnabled( - self.contextMenuEditor.isModified()) + self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) fileName = self.contextMenuEditor.getFileName() self.copyPathAct.setEnabled(bool(fileName)) if fileName: rej = "{0}.rej".format(fileName) - self.openRejectionsMenuAct.setEnabled( - os.path.exists(rej)) - + self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) + ext = os.path.splitext(fileName)[1] self.__startAct.setEnabled( - ext in Preferences.getDebugger( - "Python3Extensions").split() + ext in Preferences.getDebugger("Python3Extensions").split() ) else: self.openRejectionsMenuAct.setEnabled(False) self.__startAct.setEnabled(False) - + self.contextMenuIndex = index self.leftMenuAct.setEnabled(index > 0) self.rightMenuAct.setEnabled(index < self.count() - 1) self.firstMenuAct.setEnabled(index > 0) self.lastMenuAct.setEnabled(index < self.count() - 1) - + self.closeOthersMenuAct.setEnabled(self.count() > 1) - + coord = self.mapToGlobal(coord) self.__menu.popup(coord) - + def __showNavigationMenu(self): """ Private slot to show the navigation button menu. """ self.__navigationMenu.clear() for index in range(self.count()): - act = self.__navigationMenu.addAction(self.tabIcon(index), - self.tabText(index)) + act = self.__navigationMenu.addAction( + self.tabIcon(index), self.tabText(index) + ) act.setData(index) - + def __navigationMenuTriggered(self, act): """ Private slot called to handle the navigation button menu selection. - + @param act reference to the selected action @type QAction """ index = act.data() if index is not None: self.setCurrentIndex(index) - + def showIndicator(self, on): """ Public slot to set the indicator on or off. - + @param on flag indicating the state of the indicator @type bool """ @@ -383,36 +414,36 @@ self.indicator.setColor(QColor("green")) else: self.indicator.setColor(QColor("red")) - + def addTab(self, assembly, title): """ Public method to add a new tab. - + @param assembly editor assembly object to be added @type QScintilla.EditorAssembly.EditorAssembly @param title title for the new tab @type str """ editor = assembly.getEditor() - super().addTab( - assembly, UI.PixmapCache.getIcon("empty"), title) + super().addTab(assembly, UI.PixmapCache.getIcon("empty"), title) self.setTabsClosable(True) self.navigationButton.setEnabled(True) - + if editor not in self.editors: self.editors.append(editor) editor.captionChanged.connect(self.__captionChange) editor.cursorLineChanged.connect( - lambda lineno: self.__cursorLineChanged(lineno, editor)) - + lambda lineno: self.__cursorLineChanged(lineno, editor) + ) + emptyIndex = self.indexOf(self.emptyLabel) if emptyIndex > -1: self.removeTab(emptyIndex) - + def insertWidget(self, index, assembly, title): """ Public method to insert a new tab. - + @param index index position for the new tab @type int @param assembly editor assembly object to be added @@ -424,30 +455,30 @@ """ editor = assembly.getEditor() newIndex = super().insertTab( - index, assembly, - UI.PixmapCache.getIcon("empty"), - title) + index, assembly, UI.PixmapCache.getIcon("empty"), title + ) self.setTabsClosable(True) self.navigationButton.setEnabled(True) - + if editor not in self.editors: self.editors.append(editor) editor.captionChanged.connect(self.__captionChange) editor.cursorLineChanged.connect( - lambda lineno: self.__cursorLineChanged(lineno, editor)) + lambda lineno: self.__cursorLineChanged(lineno, editor) + ) emptyIndex = self.indexOf(self.emptyLabel) if emptyIndex > -1: self.removeTab(emptyIndex) - + return newIndex - + def __captionChange(self, cap, editor): """ Private slot to handle Caption change signals from the editor. - + Updates the tab text and tooltip text to reflect the new caption information. - + @param cap Caption for the editor @type str @param editor Editor to update the caption for @@ -459,24 +490,23 @@ txt = os.path.basename(fn) else: txt = ericApp().getObject("Project").getRelativePath(fn) - - maxFileNameChars = Preferences.getUI( - "TabViewManagerFilenameLength") + + maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") if len(txt) > maxFileNameChars: txt = "...{0}".format(txt[-maxFileNameChars:]) if editor.isReadOnly(): txt = self.tr("{0} (ro)").format(txt) - + assembly = editor.parent() index = self.indexOf(assembly) if index > -1: self.setTabText(index, txt) self.setTabToolTip(index, fn) - + def __cursorLineChanged(self, lineno, editor): """ Private slot to handle a change of the current editor's cursor line. - + @param lineno line number of the editor's cursor (zero based) @type int @param editor reference to the editor @@ -487,11 +517,11 @@ if fn: self.vm.editorLineChanged.emit(fn, lineno + 1) self.vm.editorLineChangedEd.emit(editor, lineno + 1) - + def removeWidget(self, widget): """ Public method to remove a widget. - + @param widget widget to be removed @type QWidget """ @@ -504,18 +534,17 @@ index = self.indexOf(widget) if index > -1: self.removeTab(index) - + if not self.editors: - super().addTab( - self.emptyLabel, UI.PixmapCache.getIcon("empty"), "") + super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty"), "") self.emptyLabel.show() self.setTabsClosable(False) self.navigationButton.setEnabled(False) - + def __relocateTab(self, sourceId, sourceIndex, targetIndex): """ Private method to relocate an editor from another TabWidget. - + @param sourceId id of the TabWidget to get the editor from @type str @param sourceIndex index of the tab in the old tab widget @@ -531,23 +560,23 @@ icon = tw.tabIcon(sourceIndex) whatsThis = tw.tabWhatsThis(sourceIndex) assembly = tw.widget(sourceIndex) - + # step 2: relocate the tab tw.removeWidget(assembly.getEditor()) self.insertWidget(targetIndex, assembly, text) - + # step 3: set the tab data again self.setTabIcon(targetIndex, icon) self.setTabToolTip(targetIndex, toolTip) self.setTabWhatsThis(targetIndex, whatsThis) - + # step 4: set current widget self.setCurrentIndex(targetIndex) - + def __copyTabOther(self, sourceId, sourceIndex, targetIndex): """ Private method to copy an editor from another TabWidget. - + @param sourceId id of the TabWidget to get the editor from @type str @param sourceIndex index of the tab in the old tab widget @@ -559,14 +588,16 @@ if tw is not None: editor = tw.widget(sourceIndex).getEditor() newEditor, assembly = self.vm.cloneEditor( - editor, editor.getFileType(), editor.getFileName()) - self.vm.insertView(assembly, self, targetIndex, - editor.getFileName(), editor.getNoName()) - + editor, editor.getFileType(), editor.getFileName() + ) + self.vm.insertView( + assembly, self, targetIndex, editor.getFileName(), editor.getNoName() + ) + def __copyTab(self, sourceIndex, targetIndex): """ Private method to copy an editor. - + @param sourceIndex index of the tab @type int @param targetIndex index position to place it to @@ -574,14 +605,16 @@ """ editor = self.widget(sourceIndex).getEditor() newEditor, assembly = self.vm.cloneEditor( - editor, editor.getFileType(), editor.getFileName()) - self.vm.insertView(assembly, self, targetIndex, - editor.getFileName(), editor.getNoName()) - + editor, editor.getFileType(), editor.getFileName() + ) + self.vm.insertView( + assembly, self, targetIndex, editor.getFileName(), editor.getNoName() + ) + def currentWidget(self): """ Public method to return a reference to the current page. - + @return reference to the current page @rtype Editor """ @@ -589,20 +622,20 @@ return None else: return super().currentWidget() - + def setCurrentWidget(self, assembly): """ Public method to set the current tab by the given editor assembly. - + @param assembly editor assembly to determine current tab from @type EditorAssembly.EditorAssembly """ super().setCurrentWidget(assembly) - + def indexOf(self, widget): """ Public method to get the tab index of the given editor. - + @param widget widget to get the index for @type QLabel or Editor @return tab index of the editor @@ -611,11 +644,11 @@ if isinstance(widget, QScintilla.Editor.Editor): widget = widget.parent() return super().indexOf(widget) - + def hasEditor(self, editor): """ Public method to check for an editor. - + @param editor editor object to check for @type Editor @return flag indicating, whether the editor to be checked belongs @@ -623,35 +656,34 @@ @rtype bool """ return editor in self.editors - + def hasEditors(self): """ Public method to test, if any editor is managed. - + @return flag indicating editors are managed @rtype bool """ return len(self.editors) > 0 - + def __contextMenuClose(self): """ Private method to close the selected tab. """ if self.contextMenuEditor: self.vm.closeEditorWindow(self.contextMenuEditor) - + def __contextMenuCloseOthers(self): """ Private method to close the other tabs. """ index = self.contextMenuIndex - for i in ( - list(range(self.count() - 1, index, -1)) + - list(range(index - 1, -1, -1)) + for i in list(range(self.count() - 1, index, -1)) + list( + range(index - 1, -1, -1) ): editor = self.widget(i).getEditor() self.vm.closeEditorWindow(editor) - + def __contextMenuCloseAll(self): """ Private method to close all tabs. @@ -659,27 +691,27 @@ savedEditors = self.editors[:] for editor in savedEditors: self.vm.closeEditorWindow(editor) - + def __contextMenuSave(self): """ Private method to save the selected tab. """ if self.contextMenuEditor: self.vm.saveEditorEd(self.contextMenuEditor) - + def __contextMenuSaveAs(self): """ Private method to save the selected tab to a new file. """ if self.contextMenuEditor: self.vm.saveAsEditorEd(self.contextMenuEditor) - + def __contextMenuSaveAll(self): """ Private method to save all tabs. """ self.vm.saveEditorsList(self.editors) - + def __contextMenuOpenRejections(self): """ Private slot to open a rejections file associated with the selected @@ -691,21 +723,21 @@ rej = "{0}.rej".format(fileName) if os.path.exists(rej): self.vm.openSourceFile(rej) - + def __contextMenuPrintFile(self): """ Private method to print the selected tab. """ if self.contextMenuEditor: self.vm.printEditor(self.contextMenuEditor) - + def __contextMenuPrintPreviewFile(self): """ Private method to show a print preview of the selected tab. """ if self.contextMenuEditor: self.vm.printPreviewEditor(self.contextMenuEditor) - + def __contextMenuCopyPathToClipboard(self): """ Private method to copy the file name of the selected tab to the @@ -716,31 +748,31 @@ if fn: cb = QApplication.clipboard() cb.setText(fn) - + def __contextMenuMoveLeft(self): """ Private method to move a tab one position to the left. """ self.moveTab(self.contextMenuIndex, self.contextMenuIndex - 1) - + def __contextMenuMoveRight(self): """ Private method to move a tab one position to the right. """ self.moveTab(self.contextMenuIndex, self.contextMenuIndex + 1) - + def __contextMenuMoveFirst(self): """ Private method to move a tab to the first position. """ self.moveTab(self.contextMenuIndex, 0) - + def __contextMenuMoveLast(self): """ Private method to move a tab to the last position. """ self.moveTab(self.contextMenuIndex, self.count() - 1) - + def __contextMenuRunScript(self): """ Private method to run the editor script. @@ -749,7 +781,7 @@ fn = self.contextMenuEditor.getFileName() if fn: ericApp().getObject("DebugUI").doRun(False, script=fn) - + def __contextMenuDebugScript(self): """ Private method to debug the editor script. @@ -758,7 +790,7 @@ fn = self.contextMenuEditor.getFileName() if fn: ericApp().getObject("DebugUI").doDebug(False, script=fn) - + def __contextMenuProfileScript(self): """ Private method to profile the editor script. @@ -767,7 +799,7 @@ fn = self.contextMenuEditor.getFileName() if fn: ericApp().getObject("DebugUI").doProfile(False, script=fn) - + def __contextMenuCoverageScript(self): """ Private method to run a coverage test of the editor script. @@ -776,26 +808,26 @@ fn = self.contextMenuEditor.getFileName() if fn: ericApp().getObject("DebugUI").doCoverage(False, script=fn) - + def __closeButtonClicked(self): """ Private method to handle the press of the close button. """ self.vm.closeEditorWindow(self.currentWidget().getEditor()) - + def __closeRequested(self, index): """ Private method to handle the press of the individual tab close button. - + @param index index of the tab (integer) """ if index >= 0: self.vm.closeEditorWindow(self.widget(index).getEditor()) - + def mouseDoubleClickEvent(self, event): """ Protected method handling double click events. - + @param event reference to the event object (QMouseEvent) """ self.vm.newEditor() @@ -804,7 +836,7 @@ class Tabview(ViewManager): """ Class implementing a tabbed viewmanager class embedded in a splitter. - + @signal changeCaption(str) emitted if a change of the caption is necessary @signal editorChanged(str) emitted when the current editor has changed @signal editorChangedEd(Editor) emitted when the current editor has changed @@ -840,6 +872,7 @@ @signal editorLineChangedEd(Editor,int) emitted to signal a change of an editor's current line (line is given one based) """ + changeCaption = pyqtSignal(str) editorChanged = pyqtSignal(str) editorChangedEd = pyqtSignal(Editor) @@ -863,20 +896,20 @@ editorTextChanged = pyqtSignal(Editor) editorLineChanged = pyqtSignal(str, int) editorLineChangedEd = pyqtSignal(Editor, int) - + def __init__(self, parent): """ Constructor - + @param parent parent widget @type QWidget """ self.tabWidgets = [] - + self.__splitter = QSplitter(parent) ViewManager.__init__(self) self.__splitter.setChildrenCollapsible(False) - + tw = TabWidget(self) self.__splitter.addWidget(tw) self.tabWidgets.append(tw) @@ -887,71 +920,70 @@ tw.tabBar().installEventFilter(self) self.__splitter.setOrientation(Qt.Orientation.Vertical) self.__inRemoveView = False - - self.maxFileNameChars = Preferences.getUI( - "TabViewManagerFilenameLength") + + self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") - + def mainWidget(self): """ Public method to return a reference to the main Widget of a specific view manager subclass. - + @return reference to the main widget @rtype QWidget """ return self.__splitter - + def canCascade(self): """ Public method to signal if cascading of managed windows is available. - + @return flag indicating cascading of windows is available @rtype bool """ return False - + def canTile(self): """ Public method to signal if tiling of managed windows is available. - + @return flag indicating tiling of windows is available @rtype bool """ return False - + def canSplit(self): """ public method to signal if splitting of the view is available. - + @return flag indicating splitting of the view is available. @rtype bool """ return True - + def tile(self): """ Public method to tile the managed windows. """ pass - + def cascade(self): """ Public method to cascade the managed windows. """ pass - + def _removeAllViews(self): """ Protected method to remove all views (i.e. windows). """ for win in self.editors: self._removeView(win) - + def _removeView(self, win): """ Protected method to remove a view (i.e. window). - + @param win editor window to be removed @type Editor """ @@ -962,13 +994,11 @@ break win.closeIt() self.__inRemoveView = False - + # if this was the last editor in this view, switch to the next, that # still has open editors - for i in ( - list(range(self.tabWidgets.index(tw), -1, -1)) + - list(range(self.tabWidgets.index(tw) + 1, - len(self.tabWidgets))) + for i in list(range(self.tabWidgets.index(tw), -1, -1)) + list( + range(self.tabWidgets.index(tw) + 1, len(self.tabWidgets)) ): if self.tabWidgets[i].hasEditors(): self.currentTabWidget.showIndicator(False) @@ -976,7 +1006,7 @@ self.currentTabWidget.showIndicator(True) self.activeWindow().setFocus() break - + aw = self.activeWindow() fn = aw and aw.getFileName() or None if fn: @@ -986,11 +1016,11 @@ else: self.changeCaption.emit("") self.editorChangedEd.emit(aw) - + def _addView(self, win, fn=None, noName="", addNext=False, indexes=None): """ Protected method to add a view (i.e. window). - + @param win editor assembly to be added @type EditorAssembly @param fn filename of this editor @@ -1027,7 +1057,7 @@ else: txt = ericApp().getObject("Project").getRelativePath(fn) if len(txt) > self.maxFileNameChars: - txt = "...{0}".format(txt[-self.maxFileNameChars:]) + txt = "...{0}".format(txt[-self.maxFileNameChars :]) if not os.access(fn, os.W_OK): txt = self.tr("{0} (ro)").format(txt) if addNext: @@ -1053,11 +1083,11 @@ else: self.changeCaption.emit("") self.editorChangedEd.emit(editor) - + def insertView(self, win, tabWidget, index, fn=None, noName=""): """ Public method to add a view (i.e. window). - + @param win editor assembly to be inserted @type EditorAssembly @param tabWidget reference to the tab widget to insert the editor into @@ -1082,7 +1112,7 @@ else: txt = ericApp().getObject("Project").getRelativePath(fn) if len(txt) > self.maxFileNameChars: - txt = "...{0}".format(txt[-self.maxFileNameChars:]) + txt = "...{0}".format(txt[-self.maxFileNameChars :]) if not os.access(fn, os.W_OK): txt = self.tr("{0} (ro)").format(txt) nindex = tabWidget.insertWidget(index, win, txt) @@ -1097,14 +1127,14 @@ else: self.changeCaption.emit("") self.editorChangedEd.emit(editor) - + self._modificationStatusChanged(editor.isModified(), editor) self._checkActions(editor) - + def _showView(self, win, fn=None): """ Protected method to show a view (i.e. window). - + @param win editor assembly to be shown @type EditorAssembly @param fn filename of this editor @@ -1120,11 +1150,11 @@ self.currentTabWidget.showIndicator(True) break editor.setFocus() - + def activeWindow(self): """ Public method to return the active (i.e. current) window. - + @return reference to the active editor @rtype Editor """ @@ -1133,27 +1163,27 @@ return cw.getEditor() else: return None - + def showWindowMenu(self, windowMenu): """ Public method to set up the viewmanager part of the Window menu. - + @param windowMenu reference to the window menu @type QMenu """ pass - + def _initWindowActions(self): """ Protected method to define the user interface actions for window handling. """ pass - + def setEditorName(self, editor, newName): """ Public method to change the displayed name of the editor. - + @param editor editor window to be changed @type Editor @param newName new name to be shown @@ -1163,10 +1193,9 @@ if self.filenameOnly: tabName = os.path.basename(newName) else: - tabName = ericApp().getObject("Project").getRelativePath( - newName) + tabName = ericApp().getObject("Project").getRelativePath(newName) if len(tabName) > self.maxFileNameChars: - tabName = "...{0}".format(tabName[-self.maxFileNameChars:]) + tabName = "...{0}".format(tabName[-self.maxFileNameChars :]) index = self.currentTabWidget.indexOf(editor) self.currentTabWidget.setTabText(index, tabName) self.currentTabWidget.setTabToolTip(index, newName) @@ -1175,7 +1204,7 @@ def _modificationStatusChanged(self, m, editor): """ Protected slot to handle the modificationStatusChanged signal. - + @param m flag indicating the modification status @type bool @param editor editor window changed @@ -1196,11 +1225,11 @@ keys.append("empty") tw.setTabIcon(index, UI.PixmapCache.getCombinedIcon(keys)) self._checkActions(editor) - + def _syntaxErrorToggled(self, editor): """ Protected slot to handle the syntaxerrorToggled signal. - + @param editor editor that sent the signal @type Editor """ @@ -1218,9 +1247,9 @@ if not keys: keys.append("empty") tw.setTabIcon(index, UI.PixmapCache.getCombinedIcon(keys)) - + ViewManager._syntaxErrorToggled(self, editor) - + def addSplit(self): """ Public method used to split the current view. @@ -1237,21 +1266,22 @@ tw.tabBar().installEventFilter(self) size = ( self.width() - if self.__splitter.orientation() == Qt.Orientation.Horizontal else - self.height() + if self.__splitter.orientation() == Qt.Orientation.Horizontal + else self.height() ) self.__splitter.setSizes( - [int(size / len(self.tabWidgets))] * len(self.tabWidgets)) + [int(size / len(self.tabWidgets))] * len(self.tabWidgets) + ) self.splitRemoveAct.setEnabled(True) self.nextSplitAct.setEnabled(True) self.prevSplitAct.setEnabled(True) - + @pyqtSlot() def removeSplit(self, index=-1): """ Public method used to remove the current split view or a split view by index. - + @param index index of the split to be removed (-1 means to delete the current split) @type int @@ -1293,22 +1323,22 @@ self.nextSplitAct.setEnabled(False) self.prevSplitAct.setEnabled(False) return True - + return False - + def splitCount(self): """ Public method to get the number of splitted views. - + @return number of splitted views @rtype int """ return len(self.tabWidgets) - + def setSplitCount(self, count): """ Public method to set the number of split views. - + @param count number of split views @type int """ @@ -1319,25 +1349,25 @@ while self.splitCount() > count: # use an arbitrarily large index to remove the last one self.removeSplit(index=100) - + def getSplitOrientation(self): """ Public method to get the orientation of the split view. - + @return orientation of the split @rtype Qt.Orientation.Horizontal or Qt.Orientation.Vertical """ return self.__splitter.orientation() - + def setSplitOrientation(self, orientation): """ Public method used to set the orientation of the split view. - + @param orientation orientation of the split @type Qt.Orientation.Horizontal or Qt.Orientation.Vertical """ self.__splitter.setOrientation(orientation) - + def nextSplit(self): """ Public slot used to move to the next split. @@ -1347,7 +1377,7 @@ ind = self.tabWidgets.index(self.currentTabWidget) + 1 if ind == len(self.tabWidgets): ind = 0 - + self.currentTabWidget.showIndicator(False) self.currentTabWidget = self.tabWidgets[ind] self.currentTabWidget.showIndicator(True) @@ -1355,7 +1385,7 @@ aw = self.activeWindow() if aw: aw.setFocus() - + def prevSplit(self): """ Public slot used to move to the previous split. @@ -1365,7 +1395,7 @@ ind = self.tabWidgets.index(self.currentTabWidget) - 1 if ind == -1: ind = len(self.tabWidgets) - 1 - + self.currentTabWidget.showIndicator(False) self.currentTabWidget = self.tabWidgets[ind] self.currentTabWidget.showIndicator(True) @@ -1373,21 +1403,21 @@ aw = self.activeWindow() if aw: aw.setFocus() - + def __currentChanged(self, index): """ Private slot to handle the currentChanged signal. - + @param index index of the current tab @type int """ if index == -1 or not self.editors: return - + editor = self.activeWindow() if editor is None: return - + self._checkActions(editor) editor.setFocus() fn = editor.getFileName() @@ -1395,16 +1425,15 @@ self.changeCaption.emit(fn) if not self.__inRemoveView: self.editorChanged.emit(fn) - self.editorLineChanged.emit( - fn, editor.getCursorPosition()[0] + 1) + self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1) else: self.changeCaption.emit("") self.editorChangedEd.emit(editor) - + def eventFilter(self, watched, event): """ Public method called to filter the event queue. - + @param watched the QObject being watched @type QObject @param event the event that occurred @@ -1413,9 +1442,9 @@ @rtype bool """ if ( - event.type() == QEvent.Type.MouseButtonPress and - isinstance(event, QMouseEvent) and - event.button() != Qt.MouseButton.RightButton + event.type() == QEvent.Type.MouseButtonPress + and isinstance(event, QMouseEvent) + and event.button() != Qt.MouseButton.RightButton ): switched = True self.currentTabWidget.showIndicator(False) @@ -1426,11 +1455,9 @@ switched = watched.parent() is not self.currentTabWidget self.currentTabWidget = watched.parent() if switched: - index = self.currentTabWidget.selectTab( - event.position().toPoint()) + index = self.currentTabWidget.selectTab(event.position().toPoint()) switched = ( - self.currentTabWidget.widget(index) is - self.activeWindow() + self.currentTabWidget.widget(index) is self.activeWindow() ) elif isinstance(watched, QScintilla.Editor.Editor): for tw in self.tabWidgets: @@ -1439,7 +1466,7 @@ self.currentTabWidget = tw break self.currentTabWidget.showIndicator(True) - + aw = self.activeWindow() if aw is not None: self._checkActions(aw) @@ -1449,24 +1476,22 @@ self.changeCaption.emit(fn) if switched: self.editorChanged.emit(fn) - self.editorLineChanged.emit( - fn, aw.getCursorPosition()[0] + 1) + self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) else: self.changeCaption.emit("") self.editorChangedEd.emit(aw) - + return False - + def preferencesChanged(self): """ Public slot to handle the preferencesChanged signal. """ ViewManager.preferencesChanged(self) - - self.maxFileNameChars = Preferences.getUI( - "TabViewManagerFilenameLength") + + self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength") self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly") - + for tabWidget in self.tabWidgets: for index in range(tabWidget.count()): editor = tabWidget.widget(index) @@ -1476,18 +1501,17 @@ if self.filenameOnly: txt = os.path.basename(fn) else: - txt = ericApp().getObject( - "Project").getRelativePath(fn) + txt = ericApp().getObject("Project").getRelativePath(fn) if len(txt) > self.maxFileNameChars: - txt = "...{0}".format(txt[-self.maxFileNameChars:]) + txt = "...{0}".format(txt[-self.maxFileNameChars :]) if not os.access(fn, os.W_OK): txt = self.tr("{0} (ro)").format(txt) tabWidget.setTabText(index, txt) - + def getTabWidgetById(self, id_): """ Public method to get a reference to a tab widget knowing its ID. - + @param id_ id of the tab widget @type int @return reference to the tab widget @@ -1497,14 +1521,14 @@ if id(tw) == id_: return tw return None - + def getOpenEditorsForSession(self): """ Public method to get a lists of all open editors. - + The returned list contains one list per split view. If the view manager cannot split the view, only one list of editors is returned. - + @return list of list of editor references @rtype list of list of Editor """