eric6/Plugins/ViewManagerPlugins/Tabview/Tabview.py

changeset 8218
7c09585bd960
parent 8205
4a0f1f896341
child 8256
26a8b92aeabd
equal deleted inserted replaced
8217:385f60c94548 8218:7c09585bd960
62 Constructor 62 Constructor
63 63
64 @param parent reference to the parent widget 64 @param parent reference to the parent widget
65 @type QWidget 65 @type QWidget
66 """ 66 """
67 super(TabBar, self).__init__(parent) 67 super().__init__(parent)
68 self.setAcceptDrops(True) 68 self.setAcceptDrops(True)
69 69
70 self.__dragStartPos = QPoint() 70 self.__dragStartPos = QPoint()
71 71
72 def mousePressEvent(self, event): 72 def mousePressEvent(self, event):
76 @param event reference to the mouse press event 76 @param event reference to the mouse press event
77 @type QMouseEvent 77 @type QMouseEvent
78 """ 78 """
79 if event.button() == Qt.MouseButton.LeftButton: 79 if event.button() == Qt.MouseButton.LeftButton:
80 self.__dragStartPos = QPoint(event.pos()) 80 self.__dragStartPos = QPoint(event.pos())
81 super(TabBar, self).mousePressEvent(event) 81 super().mousePressEvent(event)
82 82
83 def mouseMoveEvent(self, event): 83 def mouseMoveEvent(self, event):
84 """ 84 """
85 Protected method to handle mouse move events. 85 Protected method to handle mouse move events.
86 86
111 drag.exec(Qt.DropActions(Qt.DropAction.CopyAction)) 111 drag.exec(Qt.DropActions(Qt.DropAction.CopyAction))
112 elif event.modifiers() == Qt.KeyboardModifiers( 112 elif event.modifiers() == Qt.KeyboardModifiers(
113 Qt.KeyboardModifier.NoModifier 113 Qt.KeyboardModifier.NoModifier
114 ): 114 ):
115 drag.exec(Qt.DropActions(Qt.DropAction.MoveAction)) 115 drag.exec(Qt.DropActions(Qt.DropAction.MoveAction))
116 super(TabBar, self).mouseMoveEvent(event) 116 super().mouseMoveEvent(event)
117 117
118 def dragEnterEvent(self, event): 118 def dragEnterEvent(self, event):
119 """ 119 """
120 Protected method to handle drag enter events. 120 Protected method to handle drag enter events.
121 121
130 "tabbar-id" in formats and 130 "tabbar-id" in formats and
131 "source-index" in formats and 131 "source-index" in formats and
132 "tabwidget-id" in formats 132 "tabwidget-id" in formats
133 ): 133 ):
134 event.acceptProposedAction() 134 event.acceptProposedAction()
135 super(TabBar, self).dragEnterEvent(event) 135 super().dragEnterEvent(event)
136 136
137 def dropEvent(self, event): 137 def dropEvent(self, event):
138 """ 138 """
139 Protected method to handle drop events. 139 Protected method to handle drop events.
140 140
161 self.tabMoveRequested.emit(fromIndex, toIndex) 161 self.tabMoveRequested.emit(fromIndex, toIndex)
162 event.acceptProposedAction() 162 event.acceptProposedAction()
163 elif event.proposedAction() == Qt.DropAction.CopyAction: 163 elif event.proposedAction() == Qt.DropAction.CopyAction:
164 self.tabCopyRequested[int, int].emit(fromIndex, toIndex) 164 self.tabCopyRequested[int, int].emit(fromIndex, toIndex)
165 event.acceptProposedAction() 165 event.acceptProposedAction()
166 super(TabBar, self).dropEvent(event) 166 super().dropEvent(event)
167 167
168 168
169 class TabWidget(E5TabWidget): 169 class TabWidget(E5TabWidget):
170 """ 170 """
171 Class implementing a custimized tab widget. 171 Class implementing a custimized tab widget.
175 Constructor 175 Constructor
176 176
177 @param vm view manager widget 177 @param vm view manager widget
178 @type Tabview 178 @type Tabview
179 """ 179 """
180 super(TabWidget, self).__init__() 180 super().__init__()
181 181
182 self.__tabBar = TabBar(self) 182 self.__tabBar = TabBar(self)
183 self.setTabBar(self.__tabBar) 183 self.setTabBar(self.__tabBar)
184 iconSize = self.__tabBar.iconSize() 184 iconSize = self.__tabBar.iconSize()
185 self.__tabBar.setIconSize( 185 self.__tabBar.setIconSize(
235 os.path.join(getConfig('ericPixDir'), 'eric_small.png')) 235 os.path.join(getConfig('ericPixDir'), 'eric_small.png'))
236 self.emptyLabel = QLabel() 236 self.emptyLabel = QLabel()
237 self.emptyLabel.setPixmap(ericPic) 237 self.emptyLabel.setPixmap(ericPic)
238 self.emptyLabel.setAlignment( 238 self.emptyLabel.setAlignment(
239 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter) 239 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter)
240 super(TabWidget, self).addTab( 240 super().addTab(
241 self.emptyLabel, 241 self.emptyLabel,
242 UI.PixmapCache.getIcon("empty"), "") 242 UI.PixmapCache.getIcon("empty"), "")
243 243
244 def __initMenu(self): 244 def __initMenu(self):
245 """ 245 """
367 @type QScintilla.EditorAssembly.EditorAssembly 367 @type QScintilla.EditorAssembly.EditorAssembly
368 @param title title for the new tab 368 @param title title for the new tab
369 @type str 369 @type str
370 """ 370 """
371 editor = assembly.getEditor() 371 editor = assembly.getEditor()
372 super(TabWidget, self).addTab( 372 super().addTab(
373 assembly, UI.PixmapCache.getIcon("empty"), title) 373 assembly, UI.PixmapCache.getIcon("empty"), title)
374 self.setTabsClosable(True) 374 self.setTabsClosable(True)
375 self.navigationButton.setEnabled(True) 375 self.navigationButton.setEnabled(True)
376 376
377 if editor not in self.editors: 377 if editor not in self.editors:
396 @type str 396 @type str
397 @return index of the inserted tab 397 @return index of the inserted tab
398 @rtype int 398 @rtype int
399 """ 399 """
400 editor = assembly.getEditor() 400 editor = assembly.getEditor()
401 newIndex = super(TabWidget, self).insertTab( 401 newIndex = super().insertTab(
402 index, assembly, 402 index, assembly,
403 UI.PixmapCache.getIcon("empty"), 403 UI.PixmapCache.getIcon("empty"),
404 title) 404 title)
405 self.setTabsClosable(True) 405 self.setTabsClosable(True)
406 self.navigationButton.setEnabled(True) 406 self.navigationButton.setEnabled(True)
479 index = self.indexOf(widget) 479 index = self.indexOf(widget)
480 if index > -1: 480 if index > -1:
481 self.removeTab(index) 481 self.removeTab(index)
482 482
483 if not self.editors: 483 if not self.editors:
484 super(TabWidget, self).addTab( 484 super().addTab(
485 self.emptyLabel, UI.PixmapCache.getIcon("empty"), "") 485 self.emptyLabel, UI.PixmapCache.getIcon("empty"), "")
486 self.emptyLabel.show() 486 self.emptyLabel.show()
487 self.setTabsClosable(False) 487 self.setTabsClosable(False)
488 self.navigationButton.setEnabled(False) 488 self.navigationButton.setEnabled(False)
489 489
561 @rtype Editor 561 @rtype Editor
562 """ 562 """
563 if not self.editors: 563 if not self.editors:
564 return None 564 return None
565 else: 565 else:
566 return super(TabWidget, self).currentWidget() 566 return super().currentWidget()
567 567
568 def setCurrentWidget(self, assembly): 568 def setCurrentWidget(self, assembly):
569 """ 569 """
570 Public method to set the current tab by the given editor assembly. 570 Public method to set the current tab by the given editor assembly.
571 571
572 @param assembly editor assembly to determine current tab from 572 @param assembly editor assembly to determine current tab from
573 @type EditorAssembly.EditorAssembly 573 @type EditorAssembly.EditorAssembly
574 """ 574 """
575 super(TabWidget, self).setCurrentWidget(assembly) 575 super().setCurrentWidget(assembly)
576 576
577 def indexOf(self, widget): 577 def indexOf(self, widget):
578 """ 578 """
579 Public method to get the tab index of the given editor. 579 Public method to get the tab index of the given editor.
580 580
583 @return tab index of the editor 583 @return tab index of the editor
584 @rtype int 584 @rtype int
585 """ 585 """
586 if isinstance(widget, QScintilla.Editor.Editor): 586 if isinstance(widget, QScintilla.Editor.Editor):
587 widget = widget.parent() 587 widget = widget.parent()
588 return super(TabWidget, self).indexOf(widget) 588 return super().indexOf(widget)
589 589
590 def hasEditor(self, editor): 590 def hasEditor(self, editor):
591 """ 591 """
592 Public method to check for an editor. 592 Public method to check for an editor.
593 593

eric ide

mercurial