--- a/Plugins/ViewManagerPlugins/Tabview/Tabview.py Thu Jan 18 11:10:57 2018 +0100 +++ b/Plugins/ViewManagerPlugins/Tabview/Tabview.py Thu Jan 18 18:57:40 2018 +0100 @@ -11,8 +11,8 @@ import os -from PyQt5.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, \ - QMimeData, Qt, QSize +from PyQt5.QtCore import pyqtSlot, QPoint, QFileInfo, pyqtSignal, QEvent, \ + QByteArray, QMimeData, Qt, QSize from PyQt5.QtGui import QColor, QDrag, QPixmap from PyQt5.QtWidgets import QWidget, QHBoxLayout, QSplitter, QTabBar, \ QApplication, QToolButton, QMenu, QLabel @@ -23,6 +23,7 @@ import QScintilla.Editor from QScintilla.Editor import Editor +from QScintilla.EditorAssembly import EditorAssembly import UI.PixmapCache @@ -58,7 +59,8 @@ """ Constructor - @param parent reference to the parent widget (QWidget) + @param parent reference to the parent widget + @type QWidget """ super(TabBar, self).__init__(parent) self.setAcceptDrops(True) @@ -69,7 +71,8 @@ """ Protected method to handle mouse press events. - @param event reference to the mouse press event (QMouseEvent) + @param event reference to the mouse press event + @type QMouseEvent """ if event.button() == Qt.LeftButton: self.__dragStartPos = QPoint(event.pos()) @@ -79,7 +82,8 @@ """ Protected method to handle mouse move events. - @param event reference to the mouse move event (QMouseEvent) + @param event reference to the mouse move event + @type QMouseEvent """ if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \ (event.pos() - self.__dragStartPos).manhattanLength() > \ @@ -107,7 +111,8 @@ """ Protected method to handle drag enter events. - @param event reference to the drag enter event (QDragEnterEvent) + @param event reference to the drag enter event + @type QDragEnterEvent """ mimeData = event.mimeData() formats = mimeData.formats() @@ -123,7 +128,8 @@ """ Protected method to handle drop events. - @param event reference to the drop event (QDropEvent) + @param event reference to the drop event + @type QDropEvent """ mimeData = event.mimeData() oldID = int(mimeData.data("tabbar-id")) @@ -158,7 +164,8 @@ """ Constructor - @param vm view manager widget (Tabview) + @param vm view manager widget + @type Tabview """ super(TabWidget, self).__init__() @@ -286,8 +293,10 @@ """ Private slot to show the tab context menu. - @param coord the position of the mouse pointer (QPoint) - @param index index of the tab the menu is requested for (integer) + @param coord the position of the mouse pointer + @type QPoint + @param index index of the tab the menu is requested for + @type int """ if self.editors: self.contextMenuEditor = self.widget(index).getEditor() @@ -327,7 +336,8 @@ """ Private slot called to handle the navigation button menu selection. - @param act reference to the selected action (QAction) + @param act reference to the selected action + @type QAction """ index = act.data() if index is not None: @@ -337,7 +347,8 @@ """ Public slot to set the indicator on or off. - @param on flag indicating the dtate of the indicator (boolean) + @param on flag indicating the state of the indicator + @type bool """ if on: self.indicator.setColor(QColor("green")) @@ -349,8 +360,9 @@ Public method to add a new tab. @param assembly editor assembly object to be added - (QScintilla.EditorAssembly.EditorAssembly) - @param title title for the new tab (string) + @type QScintilla.EditorAssembly.EditorAssembly + @param title title for the new tab + @type str """ editor = assembly.getEditor() super(TabWidget, self).addTab( @@ -374,11 +386,14 @@ """ Public method to insert a new tab. - @param index index position for the new tab (integer) + @param index index position for the new tab + @type int @param assembly editor assembly object to be added - (QScintilla.EditorAssembly.EditorAssembly) - @param title title for the new tab (string) - @return index of the inserted tab (integer) + @type QScintilla.EditorAssembly.EditorAssembly + @param title title for the new tab + @type str + @return index of the inserted tab + @rtype int """ editor = assembly.getEditor() newIndex = super(TabWidget, self).insertTab( @@ -409,7 +424,9 @@ information. @param cap Caption for the editor + @type str @param editor Editor to update the caption for + @type Editor """ fn = editor.getFileName() if fn: @@ -436,6 +453,7 @@ Private slot to handle a change of the current editor's cursor line. @param lineno line number of the current editor's cursor (zero based) + @type int """ editor = self.sender() if editor and isinstance(editor, QScintilla.Editor.Editor): @@ -447,7 +465,8 @@ """ Public method to remove a widget. - @param widget widget to be removed (QWidget) + @param widget widget to be removed + @type QWidget """ if isinstance(widget, QScintilla.Editor.Editor): widget.cursorLineChanged.disconnect(self.__cursorLineChanged) @@ -473,9 +492,12 @@ """ Private method to relocate an editor from another TabWidget. - @param sourceId id of the TabWidget to get the editor from (string) - @param sourceIndex index of the tab in the old tab widget (integer) - @param targetIndex index position to place it to (integer) + @param sourceId id of the TabWidget to get the editor from + @type str + @param sourceIndex index of the tab in the old tab widget + @type int + @param targetIndex index position to place it to + @type int """ tw = self.vm.getTabWidgetById(int(sourceId)) if tw is not None: @@ -502,9 +524,12 @@ """ Private method to copy an editor from another TabWidget. - @param sourceId id of the TabWidget to get the editor from (string) - @param sourceIndex index of the tab in the old tab widget (integer) - @param targetIndex index position to place it to (integer) + @param sourceId id of the TabWidget to get the editor from + @type str + @param sourceIndex index of the tab in the old tab widget + @type int + @param targetIndex index position to place it to + @type int """ tw = self.vm.getTabWidgetById(int(sourceId)) if tw is not None: @@ -518,8 +543,10 @@ """ Private method to copy an editor. - @param sourceIndex index of the tab (integer) - @param targetIndex index position to place it to (integer) + @param sourceIndex index of the tab + @type int + @param targetIndex index position to place it to + @type int """ editor = self.widget(sourceIndex).getEditor() newEditor, assembly = self.vm.cloneEditor( @@ -531,7 +558,8 @@ """ Public method to return a reference to the current page. - @return reference to the current page (Editor) + @return reference to the current page + @rtype Editor """ if not self.editors: return None @@ -543,7 +571,7 @@ Public method to set the current tab by the given editor assembly. @param assembly editor assembly to determine current tab from - (EditorAssembly.EditorAssembly) + @type EditorAssembly.EditorAssembly """ super(TabWidget, self).setCurrentWidget(assembly) @@ -551,8 +579,10 @@ """ Public method to get the tab index of the given editor. - @param widget widget to get the index for (QLabel or Editor) - @return tab index of the editor (integer) + @param widget widget to get the index for + @type QLabel or Editor + @return tab index of the editor + @rtype int """ if isinstance(widget, QScintilla.Editor.Editor): widget = widget.parent() @@ -563,8 +593,10 @@ 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 to the list of editors managed by this tab widget. + @rtype bool """ return editor in self.editors @@ -573,6 +605,7 @@ Public method to test, if any editor is managed. @return flag indicating editors are managed + @rtype bool """ return len(self.editors) > 0 @@ -758,7 +791,8 @@ """ Constructor - @param parent parent widget (QWidget) + @param parent parent widget + @type QWidget """ self.tabWidgets = [] @@ -796,6 +830,7 @@ Public method to signal if cascading of managed windows is available. @return flag indicating cascading of windows is available + @rtype bool """ return False @@ -804,6 +839,7 @@ Public method to signal if tiling of managed windows is available. @return flag indicating tiling of windows is available + @rtype bool """ return False @@ -812,6 +848,7 @@ public method to signal if splitting of the view is available. @return flag indicating splitting of the view is available. + @rtype bool """ return True @@ -839,6 +876,7 @@ Protected method to remove a view (i.e. window). @param win editor window to be removed + @type Editor """ self.__inRemoveView = True for tw in self.tabWidgets: @@ -870,15 +908,22 @@ self.changeCaption.emit("") self.editorChangedEd.emit(aw) - def _addView(self, win, fn=None, noName="", addNext=False): + 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 - @param fn filename of this editor (string) - @param noName name to be used for an unnamed editor (string) + @type EditorAssembly + @param fn filename of this editor + @type str + @param noName name to be used for an unnamed editor + @type str @param addNext flag indicating to add the view next to the current - view (bool) + view + @type bool + @param indexes of the editor, first the split view index, second the + index within the view + @type tuple of two int """ editor = win.getEditor() if not fn: @@ -888,6 +933,12 @@ if addNext: index = self.currentTabWidget.currentIndex() + 1 self.currentTabWidget.insertWidget(index, win, noName) + elif indexes: + if indexes[0] < len(self.tabWidgets): + tw = self.tabWidgets[indexes[0]] + else: + tw = self.tabWidgets[-1] + tw.insertWidget(indexes[1], win, noName) else: self.currentTabWidget.addTab(win, noName) editor.setNoName(noName) @@ -903,6 +954,12 @@ if addNext: index = self.currentTabWidget.currentIndex() + 1 self.currentTabWidget.insertWidget(index, win, txt) + elif indexes: + if indexes[0] < len(self.tabWidgets): + tw = self.tabWidgets[indexes[0]] + else: + tw = self.tabWidgets[-1] + tw.insertWidget(indexes[1], win, txt) else: self.currentTabWidget.addTab(win, txt) index = self.currentTabWidget.indexOf(win) @@ -923,11 +980,15 @@ 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 - (TabWidget) - @param index index position to insert at (integer) - @param fn filename of this editor (string) - @param noName name to be used for an unnamed editor (string) + @type TabWidget + @param index index position to insert at + @type int + @param fn filename of this editor + @type str + @param noName name to be used for an unnamed editor + @type str """ editor = win.getEditor() if fn is None: @@ -966,7 +1027,9 @@ Protected method to show a view (i.e. window). @param win editor assembly to be shown - @param fn filename of this editor (string) + @type EditorAssembly + @param fn filename of this editor + @type str """ win.show() editor = win.getEditor() @@ -984,6 +1047,7 @@ Public method to return the active (i.e. current) window. @return reference to the active editor + @rtype Editor """ cw = self.currentTabWidget.currentWidget() if cw: @@ -996,6 +1060,7 @@ Public method to set up the viewmanager part of the Window menu. @param windowMenu reference to the window menu + @type QMenu """ pass @@ -1011,7 +1076,9 @@ Public method to change the displayed name of the editor. @param editor editor window to be changed - @param newName new name to be shown (string) + @type Editor + @param newName new name to be shown + @type str """ if newName: if self.filenameOnly: @@ -1029,8 +1096,10 @@ """ Protected slot to handle the modificationStatusChanged signal. - @param m flag indicating the modification status (boolean) + @param m flag indicating the modification status + @type bool @param editor editor window changed + @type Editor """ for tw in self.tabWidgets: if tw.hasEditor(editor): @@ -1053,6 +1122,7 @@ Protected slot to handle the syntaxerrorToggled signal. @param editor editor that sent the signal + @type Editor """ for tw in self.tabWidgets: if tw.hasEditor(editor): @@ -1095,14 +1165,26 @@ self.nextSplitAct.setEnabled(True) self.prevSplitAct.setEnabled(True) - def removeSplit(self): + @pyqtSlot() + def removeSplit(self, index=-1): """ - Public method used to remove the current split view. + Public method used to remove the current split view or a split view + by index. - @return flag indicating successfull removal + @param index index of the split to be removed (-1 means to + delete the current split) + @type int + @return flag indicating successful deletion + @rtype bool """ if len(self.tabWidgets) > 1: - tw = self.currentTabWidget + if index == -1: + tw = self.currentTabWidget + else: + if index < len(self.tabWidgets): + tw = self.tabWidgets[index] + else: + tw = self.tabWidgets[-1] res = True savedEditors = tw.editors[:] for editor in savedEditors: @@ -1133,11 +1215,36 @@ 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 + """ + if count > self.splitCount(): + while self.splitCount() < count: + self.addSplit() + elif count < self.splitCount(): + 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 (Qt.Horizontal or Qt.Vertical) + @return orientation of the split + @rtype Qt.Horizontal or Qt.Vertical """ return self.__splitter.orientation() @@ -1146,7 +1253,7 @@ Public method used to set the orientation of the split view. @param orientation orientation of the split - (Qt.Horizontal or Qt.Vertical) + @type Qt.Horizontal or Qt.Vertical """ self.__splitter.setOrientation(orientation) @@ -1190,7 +1297,8 @@ """ Private slot to handle the currentChanged signal. - @param index index of the current tab (integer) + @param index index of the current tab + @type int """ if index == -1 or not self.editors: return @@ -1216,9 +1324,12 @@ """ Public method called to filter the event queue. - @param watched the QObject being watched (QObject) - @param event the event that occurred (QEvent) + @param watched the QObject being watched + @type QObject + @param event the event that occurred + @type QEvent @return always False + @rtype bool """ if event.type() == QEvent.MouseButtonPress and \ not event.button() == Qt.RightButton: @@ -1290,10 +1401,33 @@ """ Public method to get a reference to a tab widget knowing its ID. - @param id_ id of the tab widget (long) - @return reference to the tab widget (TabWidget) + @param id_ id of the tab widget + @type int + @return reference to the tab widget + @rtype TabWidget """ for tw in self.tabWidgets: 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 + """ + editorLists = [] + for tabWidget in self.tabWidgets: + editors = [] + for index in range(tabWidget.count()): + widget = tabWidget.widget(index) + if isinstance(widget, EditorAssembly): + editor = widget.getEditor() + editors.append(editor) + editorLists.append(editors) + return editorLists