Plugins/ViewManagerPlugins/Tabview/Tabview.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2847
1843ef6e2656
parent 3007
bad2e89047e7
child 3058
0a02c433f52d
--- a/Plugins/ViewManagerPlugins/Tabview/Tabview.py	Tue Oct 15 22:03:54 2013 +0200
+++ b/Plugins/ViewManagerPlugins/Tabview/Tabview.py	Fri Oct 18 23:00:41 2013 +0200
@@ -11,9 +11,10 @@
 
 import os
 
-from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, QMimeData, Qt
-from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, QSplitter, \
-    QTabBar, QApplication, QToolButton, QMenu, QLabel
+from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, \
+    QMimeData, Qt
+from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, \
+    QSplitter, QTabBar, QApplication, QToolButton, QMenu, QLabel
 
 from E5Gui.E5Application import e5App
 
@@ -37,11 +38,11 @@
     """
     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 relocation
-        request giving the string encoded id of the old tab widget, the index in
-        the old tab widget and the new index position
+    @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
+        relocation request giving the string encoded id of the old tab widget,
+        the index in the old tab widget and the new index position
     @signal tabCopyRequested(str, int, int) emitted to signal a clone request
         giving the string encoded id of the source tab widget, the index in the
         source tab widget and the new index position
@@ -88,8 +89,9 @@
             mimeData.setText(self.tabText(index))
             mimeData.setData("action", "tab-reordering")
             mimeData.setData("tabbar-id", str(id(self)))
-            mimeData.setData("source-index",
-                             QByteArray.number(self.tabAt(self.__dragStartPos)))
+            mimeData.setData(
+                "source-index",
+                QByteArray.number(self.tabAt(self.__dragStartPos)))
             mimeData.setData("tabwidget-id", str(id(self.parentWidget())))
             drag.setMimeData(mimeData)
             if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier):
@@ -127,7 +129,8 @@
         if oldID != id(self):
             parentID = int(mimeData.data("tabwidget-id"))
             if event.proposedAction() == Qt.MoveAction:
-                self.tabRelocateRequested.emit(str(parentID), fromIndex, toIndex)
+                self.tabRelocateRequested.emit(
+                    str(parentID), fromIndex, toIndex)
                 event.acceptProposedAction()
             elif event.proposedAction() == Qt.CopyAction:
                 self.tabCopyRequested[str, int, int].emit(
@@ -167,7 +170,8 @@
         
         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
@@ -197,7 +201,8 @@
            not hasattr(self, 'setTabsClosable'):
             self.closeButton = QToolButton(self)
             self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png"))
-            self.closeButton.setToolTip(self.trUtf8("Close the current editor"))
+            self.closeButton.setToolTip(
+                self.trUtf8("Close the current editor"))
             self.closeButton.setEnabled(False)
             self.closeButton.clicked[bool].connect(self.__closeButtonClicked)
             self.rightCornerWidgetLayout.addWidget(self.closeButton)
@@ -214,11 +219,13 @@
         self.setTabContextMenuPolicy(Qt.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.AlignVCenter | Qt.AlignHCenter)
-        super(TabWidget, self).addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "")
+        super(TabWidget, self).addTab(self.emptyLabel,
+                       UI.PixmapCache.getIcon("empty.png"), "")
         
     def __initMenu(self):
         """
@@ -241,9 +248,10 @@
         self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"),
             self.trUtf8('Close'), self.__contextMenuClose)
         self.closeOthersMenuAct = self.__menu.addAction(
-            UI.PixmapCache.getIcon("tabCloseOther.png"), self.trUtf8("Close Others"),
-            self.__contextMenuCloseOthers)
-        self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll)
+            UI.PixmapCache.getIcon("tabCloseOther.png"),
+            self.trUtf8("Close Others"), self.__contextMenuCloseOthers)
+        self.__menu.addAction(
+            self.trUtf8('Close All'), self.__contextMenuCloseAll)
         self.__menu.addSeparator()
         self.saveMenuAct = \
             self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"),
@@ -260,7 +268,8 @@
         self.__menu.addAction(UI.PixmapCache.getIcon("print.png"),
             self.trUtf8('Print'), self.__contextMenuPrintFile)
         self.__menu.addSeparator()
-        self.copyPathAct = self.__menu.addAction(self.trUtf8("Copy Path to Clipboard"),
+        self.copyPathAct = self.__menu.addAction(
+            self.trUtf8("Copy Path to Clipboard"),
             self.__contextMenuCopyPathToClipboard)
         
     def __showContextMenu(self, coord, index):
@@ -273,7 +282,8 @@
         if self.editors:
             self.contextMenuEditor = self.widget(index).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:
@@ -383,7 +393,8 @@
         """
         Private slot to handle Caption change signals from the editor.
         
-        Updates the tab text and tooltip text to reflect the new caption information.
+        Updates the tab text and tooltip text to reflect the new caption
+        information.
         
         @param cap Caption for the editor
         @param editor Editor to update the caption for
@@ -395,7 +406,8 @@
             else:
                 txt = e5App().getObject("Project").getRelativePath(fn)
             
-            maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength")
+            maxFileNameChars = Preferences.getUI(
+                "TabViewManagerFilenameLength")
             if len(txt) > maxFileNameChars:
                 txt = "...{0}".format(txt[-maxFileNameChars:])
             if editor.isReadOnly():
@@ -414,7 +426,7 @@
         @param lineno line number of the current editor's cursor (zero based)
         """
         editor = self.sender()
-        if editor:
+        if editor and isinstance(editor, QScintilla.Editor.Editor):
             fn = editor.getFileName()
             if fn:
                 self.vm.editorLineChanged.emit(fn, lineno + 1)
@@ -436,7 +448,8 @@
             self.removeTab(index)
         
         if not self.editors:
-            super(TabWidget, self).addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "")
+            super(TabWidget, self).addTab(
+                self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "")
             self.emptyLabel.show()
             if self.closeButton:
                 self.closeButton.setEnabled(False)
@@ -484,8 +497,8 @@
         tw = self.vm.getTabWidgetById(int(sourceId))
         if tw is not None:
             editor = tw.widget(sourceIndex).getEditor()
-            newEditor, assembly = self.vm.cloneEditor(editor, editor.getFileType(),
-                                            editor.getFileName())
+            newEditor, assembly = self.vm.cloneEditor(
+                editor, editor.getFileType(), editor.getFileName())
             self.vm.insertView(assembly, self, targetIndex,
                                editor.getFileName(), editor.getNoName())
         
@@ -598,7 +611,8 @@
         
     def __contextMenuOpenRejections(self):
         """
-        Private slot to open a rejections file associated with the selected tab.
+        Private slot to open a rejections file associated with the selected
+        tab.
         """
         if self.contextMenuEditor:
             fileName = self.contextMenuEditor.getFileName()
@@ -616,7 +630,8 @@
     
     def __contextMenuCopyPathToClipboard(self):
         """
-        Private method to copy the file name of the selected tab to the clipboard.
+        Private method to copy the file name of the selected tab to the
+        clipboard.
         """
         if self.contextMenuEditor:
             fn = self.contextMenuEditor.getFileName()
@@ -683,21 +698,24 @@
     @signal editorOpened(str) emitted after an editor window was opened
     @signal editorOpenedEd(Editor) emitted after an editor window was opened
     @signal editorClosed(str) emitted just before an editor window gets closed
-    @signal editorClosedEd(Editor) emitted just before an editor window gets closed
+    @signal editorClosedEd(Editor) emitted just before an editor window gets
+        closed
     @signal editorSaved(str) emitted after an editor window was saved
     @signal checkActions(Editor) emitted when some actions should be checked
-            for their status
-    @signal cursorChanged(Editor) emitted after the cursor position of the active
-            window has changed
+        for their status
+    @signal cursorChanged(Editor) emitted after the cursor position of the
+        active window has changed
     @signal breakpointToggled(Editor) emitted when a breakpoint is toggled.
     @signal bookmarkToggled(Editor) emitted when a bookmark is toggled.
     @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled.
-    @signal previewStateChanged(bool) emitted to signal a change in the preview state
+    @signal previewStateChanged(bool) emitted to signal a change in the
+        preview state
     @signal editorLanguageChanged(Editor) emitted to signal a change of an
-            editors language
-    @signal editorTextChanged(Editor) emitted to signal a change of an editor's text
-    @signal editorLineChanged(str,int) emitted to signal a change of an editor's
-            current line (line is given one based)
+        editors language
+    @signal editorTextChanged(Editor) emitted to signal a change of an
+        editor's text
+    @signal editorLineChanged(str,int) emitted to signal a change of an
+        editor's current line (line is given one based)
     """
     changeCaption = pyqtSignal(str)
     editorChanged = pyqtSignal(str)
@@ -723,8 +741,6 @@
         Constructor
         
         @param parent parent widget (QWidget)
-        @param ui reference to the main user interface
-        @param dbs reference to the debug server object
         """
         self.tabWidgets = []
         
@@ -741,7 +757,8 @@
         self.setOrientation(Qt.Vertical)
         self.__inRemoveView = False
         
-        self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength")
+        self.maxFileNameChars = Preferences.getUI(
+            "TabViewManagerFilenameLength")
         self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly")
         
     def canCascade(self):
@@ -782,14 +799,14 @@
         
     def _removeAllViews(self):
         """
-        Protected method to remove all views (i.e. windows)
+        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)
+        Protected method to remove a view (i.e. window).
         
         @param win editor window to be removed
         """
@@ -804,7 +821,8 @@
         # 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))):
+                 list(range(self.tabWidgets.index(tw) + 1,
+                            len(self.tabWidgets))):
             if self.tabWidgets[i].hasEditors():
                 self.currentTabWidget.showIndicator(False)
                 self.currentTabWidget = self.tabWidgets[i]
@@ -824,7 +842,7 @@
         
     def _addView(self, win, fn=None, noName=""):
         """
-        Protected method to add a view (i.e. window)
+        Protected method to add a view (i.e. window).
         
         @param win editor assembly to be added
         @param fn filename of this editor (string)
@@ -862,10 +880,11 @@
         
     def insertView(self, win, tabWidget, index, fn=None, noName=""):
         """
-        Protected method to add a view (i.e. window)
+        Protected method to add a view (i.e. window).
         
         @param win editor assembly to be inserted
-        @param tabWidget reference to the tab widget to insert the editor into (TabWidget)
+        @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)
@@ -904,7 +923,7 @@
         
     def _showView(self, win, fn=None):
         """
-        Protected method to show a view (i.e. window)
+        Protected method to show a view (i.e. window).
         
         @param win editor assembly to be shown
         @param fn filename of this editor (string)
@@ -942,7 +961,8 @@
         
     def _initWindowActions(self):
         """
-        Protected method to define the user interface actions for window handling.
+        Protected method to define the user interface actions for window
+        handling.
         """
         pass
         
@@ -1025,7 +1045,8 @@
             size = self.width()
         else:
             size = self.height()
-        self.setSizes([int(size / len(self.tabWidgets))] * len(self.tabWidgets))
+        self.setSizes(
+            [int(size / len(self.tabWidgets))] * len(self.tabWidgets))
         self.splitRemoveAct.setEnabled(True)
         self.nextSplitAct.setEnabled(True)
         self.prevSplitAct.setEnabled(True)
@@ -1126,7 +1147,8 @@
             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)
@@ -1150,7 +1172,8 @@
                 self.currentTabWidget = watched.parent()
                 if switched:
                     index = self.currentTabWidget.selectTab(event.pos())
-                    switched = self.currentTabWidget.widget(index) is self.activeWindow()
+                    switched = self.currentTabWidget.widget(index) is \
+                        self.activeWindow()
             elif isinstance(watched, QScintilla.Editor.Editor):
                 for tw in self.tabWidgets:
                     if tw.hasEditor(watched):
@@ -1168,7 +1191,8 @@
                     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)
@@ -1181,7 +1205,8 @@
         """
         ViewManager.preferencesChanged(self)
         
-        self.maxFileNameChars = Preferences.getUI("TabViewManagerFilenameLength")
+        self.maxFileNameChars = Preferences.getUI(
+            "TabViewManagerFilenameLength")
         self.filenameOnly = Preferences.getUI("TabViewManagerFilenameOnly")
         
         for tabWidget in self.tabWidgets:
@@ -1193,7 +1218,8 @@
                         if self.filenameOnly:
                             txt = os.path.basename(fn)
                         else:
-                            txt = e5App().getObject("Project").getRelativePath(fn)
+                            txt = e5App().getObject("Project")\
+                                .getRelativePath(fn)
                         if len(txt) > self.maxFileNameChars:
                             txt = "...{0}".format(txt[-self.maxFileNameChars:])
                         if not QFileInfo(fn).isWritable():

eric ide

mercurial