eric6/Plugins/ViewManagerPlugins/Tabview/Tabview.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7035
d2036d7f5ef6
parent 7258
aff39db4dacc
child 7362
028bf21bb5a2
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
5 5
6 """ 6 """
7 Module implementing a tabbed viewmanager class. 7 Module implementing a tabbed viewmanager class.
8 """ 8 """
9 9
10 from __future__ import unicode_literals
11 10
12 import os 11 import os
13 12
14 from PyQt5.QtCore import pyqtSlot, QPoint, QFileInfo, pyqtSignal, QEvent, \ 13 from PyQt5.QtCore import (
15 QByteArray, QMimeData, Qt, QSize 14 pyqtSlot, QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, QMimeData,
15 Qt, QSize
16 )
16 from PyQt5.QtGui import QColor, QDrag, QPixmap 17 from PyQt5.QtGui import QColor, QDrag, QPixmap
17 from PyQt5.QtWidgets import QWidget, QHBoxLayout, QSplitter, QTabBar, \ 18 from PyQt5.QtWidgets import (
18 QApplication, QToolButton, QMenu, QLabel 19 QWidget, QHBoxLayout, QSplitter, QTabBar, QApplication, QToolButton,
20 QMenu, QLabel
21 )
19 22
20 from E5Gui.E5Application import e5App 23 from E5Gui.E5Application import e5App
21 24
22 from ViewManager.ViewManager import ViewManager 25 from ViewManager.ViewManager import ViewManager
23 26
83 Protected method to handle mouse move events. 86 Protected method to handle mouse move events.
84 87
85 @param event reference to the mouse move event 88 @param event reference to the mouse move event
86 @type QMouseEvent 89 @type QMouseEvent
87 """ 90 """
88 if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \ 91 if (
89 (event.pos() - self.__dragStartPos).manhattanLength() > \ 92 event.buttons() == Qt.MouseButtons(Qt.LeftButton) and
90 QApplication.startDragDistance(): 93 (event.pos() - self.__dragStartPos).manhattanLength() >
94 QApplication.startDragDistance()
95 ):
91 drag = QDrag(self) 96 drag = QDrag(self)
92 mimeData = QMimeData() 97 mimeData = QMimeData()
93 index = self.tabAt(event.pos()) 98 index = self.tabAt(event.pos())
94 mimeData.setText(self.tabText(index)) 99 mimeData.setText(self.tabText(index))
95 mimeData.setData("action", b"tab-reordering") 100 mimeData.setData("action", b"tab-reordering")
114 @param event reference to the drag enter event 119 @param event reference to the drag enter event
115 @type QDragEnterEvent 120 @type QDragEnterEvent
116 """ 121 """
117 mimeData = event.mimeData() 122 mimeData = event.mimeData()
118 formats = mimeData.formats() 123 formats = mimeData.formats()
119 if "action" in formats and \ 124 if (
120 mimeData.data("action") == b"tab-reordering" and \ 125 "action" in formats and
121 "tabbar-id" in formats and \ 126 mimeData.data("action") == b"tab-reordering" and
122 "source-index" in formats and \ 127 "tabbar-id" in formats and
123 "tabwidget-id" in formats: 128 "source-index" in formats and
129 "tabwidget-id" in formats
130 ):
124 event.acceptProposedAction() 131 event.acceptProposedAction()
125 super(TabBar, self).dragEnterEvent(event) 132 super(TabBar, self).dragEnterEvent(event)
126 133
127 def dropEvent(self, event): 134 def dropEvent(self, event):
128 """ 135 """
605 def __contextMenuCloseOthers(self): 612 def __contextMenuCloseOthers(self):
606 """ 613 """
607 Private method to close the other tabs. 614 Private method to close the other tabs.
608 """ 615 """
609 index = self.contextMenuIndex 616 index = self.contextMenuIndex
610 for i in list(range(self.count() - 1, index, -1)) + \ 617 for i in (
611 list(range(index - 1, -1, -1)): 618 list(range(self.count() - 1, index, -1)) +
619 list(range(index - 1, -1, -1))
620 ):
612 editor = self.widget(i).getEditor() 621 editor = self.widget(i).getEditor()
613 self.vm.closeEditorWindow(editor) 622 self.vm.closeEditorWindow(editor)
614 623
615 def __contextMenuCloseAll(self): 624 def __contextMenuCloseAll(self):
616 """ 625 """
877 win.closeIt() 886 win.closeIt()
878 self.__inRemoveView = False 887 self.__inRemoveView = False
879 888
880 # if this was the last editor in this view, switch to the next, that 889 # if this was the last editor in this view, switch to the next, that
881 # still has open editors 890 # still has open editors
882 for i in list(range(self.tabWidgets.index(tw), -1, -1)) + \ 891 for i in (
892 list(range(self.tabWidgets.index(tw), -1, -1)) +
883 list(range(self.tabWidgets.index(tw) + 1, 893 list(range(self.tabWidgets.index(tw) + 1,
884 len(self.tabWidgets))): 894 len(self.tabWidgets)))
895 ):
885 if self.tabWidgets[i].hasEditors(): 896 if self.tabWidgets[i].hasEditors():
886 self.currentTabWidget.showIndicator(False) 897 self.currentTabWidget.showIndicator(False)
887 self.currentTabWidget = self.tabWidgets[i] 898 self.currentTabWidget = self.tabWidgets[i]
888 self.currentTabWidget.showIndicator(True) 899 self.currentTabWidget.showIndicator(True)
889 self.activeWindow().setFocus() 900 self.activeWindow().setFocus()
1320 @param event the event that occurred 1331 @param event the event that occurred
1321 @type QEvent 1332 @type QEvent
1322 @return always False 1333 @return always False
1323 @rtype bool 1334 @rtype bool
1324 """ 1335 """
1325 if event.type() == QEvent.MouseButtonPress and \ 1336 if (
1326 not event.button() == Qt.RightButton: 1337 event.type() == QEvent.MouseButtonPress and
1338 not event.button() == Qt.RightButton
1339 ):
1327 switched = True 1340 switched = True
1328 self.currentTabWidget.showIndicator(False) 1341 self.currentTabWidget.showIndicator(False)
1329 if isinstance(watched, E5TabWidget): 1342 if isinstance(watched, E5TabWidget):
1330 switched = watched is not self.currentTabWidget 1343 switched = watched is not self.currentTabWidget
1331 self.currentTabWidget = watched 1344 self.currentTabWidget = watched
1332 elif isinstance(watched, QTabBar): 1345 elif isinstance(watched, QTabBar):
1333 switched = watched.parent() is not self.currentTabWidget 1346 switched = watched.parent() is not self.currentTabWidget
1334 self.currentTabWidget = watched.parent() 1347 self.currentTabWidget = watched.parent()
1335 if switched: 1348 if switched:
1336 index = self.currentTabWidget.selectTab(event.pos()) 1349 index = self.currentTabWidget.selectTab(event.pos())
1337 switched = self.currentTabWidget.widget(index) is \ 1350 switched = (
1351 self.currentTabWidget.widget(index) is
1338 self.activeWindow() 1352 self.activeWindow()
1353 )
1339 elif isinstance(watched, QScintilla.Editor.Editor): 1354 elif isinstance(watched, QScintilla.Editor.Editor):
1340 for tw in self.tabWidgets: 1355 for tw in self.tabWidgets:
1341 if tw.hasEditor(watched): 1356 if tw.hasEditor(watched):
1342 switched = tw is not self.currentTabWidget 1357 switched = tw is not self.currentTabWidget
1343 self.currentTabWidget = tw 1358 self.currentTabWidget = tw
1378 fn = editor.getFileName() 1393 fn = editor.getFileName()
1379 if fn: 1394 if fn:
1380 if self.filenameOnly: 1395 if self.filenameOnly:
1381 txt = os.path.basename(fn) 1396 txt = os.path.basename(fn)
1382 else: 1397 else:
1383 txt = e5App().getObject("Project")\ 1398 txt = e5App().getObject(
1384 .getRelativePath(fn) 1399 "Project").getRelativePath(fn)
1385 if len(txt) > self.maxFileNameChars: 1400 if len(txt) > self.maxFileNameChars:
1386 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 1401 txt = "...{0}".format(txt[-self.maxFileNameChars:])
1387 if not QFileInfo(fn).isWritable(): 1402 if not QFileInfo(fn).isWritable():
1388 txt = self.tr("{0} (ro)").format(txt) 1403 txt = self.tr("{0} (ro)").format(txt)
1389 tabWidget.setTabText(index, txt) 1404 tabWidget.setTabText(index, txt)

eric ide

mercurial