eric7/Plugins/ViewManagerPlugins/Tabview/Tabview.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8341
e470de1e6628
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
17 from PyQt6.QtWidgets import ( 17 from PyQt6.QtWidgets import (
18 QWidget, QHBoxLayout, QSplitter, QTabBar, QApplication, QToolButton, 18 QWidget, QHBoxLayout, QSplitter, QTabBar, QApplication, QToolButton,
19 QMenu, QLabel 19 QMenu, QLabel
20 ) 20 )
21 21
22 from E5Gui.E5Application import e5App 22 from E5Gui.EricApplication import ericApp
23 23
24 from ViewManager.ViewManager import ViewManager 24 from ViewManager.ViewManager import ViewManager
25 25
26 import QScintilla.Editor 26 import QScintilla.Editor
27 from QScintilla.Editor import Editor 27 from QScintilla.Editor import Editor
28 from QScintilla.EditorAssembly import EditorAssembly 28 from QScintilla.EditorAssembly import EditorAssembly
29 29
30 import UI.PixmapCache 30 import UI.PixmapCache
31 31
32 from E5Gui.E5TabWidget import E5TabWidget, E5WheelTabBar 32 from E5Gui.EricTabWidget import EricTabWidget, EricWheelTabBar
33 from E5Gui.E5Led import E5Led 33 from E5Gui.EricLed import EricLed
34 34
35 import Preferences 35 import Preferences
36 from Globals import isMacPlatform 36 from Globals import isMacPlatform
37 37
38 from eric7config import getConfig 38 from eric7config import getConfig
39 39
40 40
41 class TabBar(E5WheelTabBar): 41 class TabBar(EricWheelTabBar):
42 """ 42 """
43 Class implementing a customized tab bar supporting drag & drop. 43 Class implementing a customized tab bar supporting drag & drop.
44 44
45 @signal tabMoveRequested(int, int) emitted to signal a tab move request 45 @signal tabMoveRequested(int, int) emitted to signal a tab move request
46 giving the old and new index position 46 giving the old and new index position
160 self.tabCopyRequested[int, int].emit(fromIndex, toIndex) 160 self.tabCopyRequested[int, int].emit(fromIndex, toIndex)
161 event.acceptProposedAction() 161 event.acceptProposedAction()
162 super().dropEvent(event) 162 super().dropEvent(event)
163 163
164 164
165 class TabWidget(E5TabWidget): 165 class TabWidget(EricTabWidget):
166 """ 166 """
167 Class implementing a custimized tab widget. 167 Class implementing a custimized tab widget.
168 """ 168 """
169 def __init__(self, vm): 169 def __init__(self, vm):
170 """ 170 """
193 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab) 193 self.__tabBar.tabCopyRequested[int, int].connect(self.__copyTab)
194 194
195 self.vm = vm 195 self.vm = vm
196 self.editors = [] 196 self.editors = []
197 197
198 self.indicator = E5Led(self) 198 self.indicator = EricLed(self)
199 self.setCornerWidget(self.indicator, Qt.Corner.TopLeftCorner) 199 self.setCornerWidget(self.indicator, Qt.Corner.TopLeftCorner)
200 200
201 self.rightCornerWidget = QWidget(self) 201 self.rightCornerWidget = QWidget(self)
202 self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget) 202 self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget)
203 self.rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0) 203 self.rightCornerWidgetLayout.setContentsMargins(0, 0, 0, 0)
427 fn = editor.getFileName() 427 fn = editor.getFileName()
428 if fn: 428 if fn:
429 if Preferences.getUI("TabViewManagerFilenameOnly"): 429 if Preferences.getUI("TabViewManagerFilenameOnly"):
430 txt = os.path.basename(fn) 430 txt = os.path.basename(fn)
431 else: 431 else:
432 txt = e5App().getObject("Project").getRelativePath(fn) 432 txt = ericApp().getObject("Project").getRelativePath(fn)
433 433
434 maxFileNameChars = Preferences.getUI( 434 maxFileNameChars = Preferences.getUI(
435 "TabViewManagerFilenameLength") 435 "TabViewManagerFilenameLength")
436 if len(txt) > maxFileNameChars: 436 if len(txt) > maxFileNameChars:
437 txt = "...{0}".format(txt[-maxFileNameChars:]) 437 txt = "...{0}".format(txt[-maxFileNameChars:])
951 editor.setNoName(noName) 951 editor.setNoName(noName)
952 else: 952 else:
953 if self.filenameOnly: 953 if self.filenameOnly:
954 txt = os.path.basename(fn) 954 txt = os.path.basename(fn)
955 else: 955 else:
956 txt = e5App().getObject("Project").getRelativePath(fn) 956 txt = ericApp().getObject("Project").getRelativePath(fn)
957 if len(txt) > self.maxFileNameChars: 957 if len(txt) > self.maxFileNameChars:
958 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 958 txt = "...{0}".format(txt[-self.maxFileNameChars:])
959 if not QFileInfo(fn).isWritable(): 959 if not QFileInfo(fn).isWritable():
960 txt = self.tr("{0} (ro)").format(txt) 960 txt = self.tr("{0} (ro)").format(txt)
961 if addNext: 961 if addNext:
1006 editor.setNoName(noName) 1006 editor.setNoName(noName)
1007 else: 1007 else:
1008 if self.filenameOnly: 1008 if self.filenameOnly:
1009 txt = os.path.basename(fn) 1009 txt = os.path.basename(fn)
1010 else: 1010 else:
1011 txt = e5App().getObject("Project").getRelativePath(fn) 1011 txt = ericApp().getObject("Project").getRelativePath(fn)
1012 if len(txt) > self.maxFileNameChars: 1012 if len(txt) > self.maxFileNameChars:
1013 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 1013 txt = "...{0}".format(txt[-self.maxFileNameChars:])
1014 if not QFileInfo(fn).isWritable(): 1014 if not QFileInfo(fn).isWritable():
1015 txt = self.tr("{0} (ro)").format(txt) 1015 txt = self.tr("{0} (ro)").format(txt)
1016 nindex = tabWidget.insertWidget(index, win, txt) 1016 nindex = tabWidget.insertWidget(index, win, txt)
1089 """ 1089 """
1090 if newName: 1090 if newName:
1091 if self.filenameOnly: 1091 if self.filenameOnly:
1092 tabName = os.path.basename(newName) 1092 tabName = os.path.basename(newName)
1093 else: 1093 else:
1094 tabName = e5App().getObject("Project").getRelativePath(newName) 1094 tabName = ericApp().getObject("Project").getRelativePath(newName)
1095 if len(tabName) > self.maxFileNameChars: 1095 if len(tabName) > self.maxFileNameChars:
1096 tabName = "...{0}".format(tabName[-self.maxFileNameChars:]) 1096 tabName = "...{0}".format(tabName[-self.maxFileNameChars:])
1097 index = self.currentTabWidget.indexOf(editor) 1097 index = self.currentTabWidget.indexOf(editor)
1098 self.currentTabWidget.setTabText(index, tabName) 1098 self.currentTabWidget.setTabText(index, tabName)
1099 self.currentTabWidget.setTabToolTip(index, newName) 1099 self.currentTabWidget.setTabToolTip(index, newName)
1344 isinstance(event, QMouseEvent) and 1344 isinstance(event, QMouseEvent) and
1345 event.button() != Qt.MouseButton.RightButton 1345 event.button() != Qt.MouseButton.RightButton
1346 ): 1346 ):
1347 switched = True 1347 switched = True
1348 self.currentTabWidget.showIndicator(False) 1348 self.currentTabWidget.showIndicator(False)
1349 if isinstance(watched, E5TabWidget): 1349 if isinstance(watched, EricTabWidget):
1350 switched = watched is not self.currentTabWidget 1350 switched = watched is not self.currentTabWidget
1351 self.currentTabWidget = watched 1351 self.currentTabWidget = watched
1352 elif isinstance(watched, QTabBar): 1352 elif isinstance(watched, QTabBar):
1353 switched = watched.parent() is not self.currentTabWidget 1353 switched = watched.parent() is not self.currentTabWidget
1354 self.currentTabWidget = watched.parent() 1354 self.currentTabWidget = watched.parent()
1400 fn = editor.getFileName() 1400 fn = editor.getFileName()
1401 if fn: 1401 if fn:
1402 if self.filenameOnly: 1402 if self.filenameOnly:
1403 txt = os.path.basename(fn) 1403 txt = os.path.basename(fn)
1404 else: 1404 else:
1405 txt = e5App().getObject( 1405 txt = ericApp().getObject(
1406 "Project").getRelativePath(fn) 1406 "Project").getRelativePath(fn)
1407 if len(txt) > self.maxFileNameChars: 1407 if len(txt) > self.maxFileNameChars:
1408 txt = "...{0}".format(txt[-self.maxFileNameChars:]) 1408 txt = "...{0}".format(txt[-self.maxFileNameChars:])
1409 if not QFileInfo(fn).isWritable(): 1409 if not QFileInfo(fn).isWritable():
1410 txt = self.tr("{0} (ro)").format(txt) 1410 txt = self.tr("{0} (ro)").format(txt)

eric ide

mercurial