Plugins/ViewManagerPlugins/Tabview/Tabview.py

branch
Py2 comp.
changeset 2525
8b507a9a2d40
parent 2424
8fe1fdc174ab
child 2791
a9577f248f04
equal deleted inserted replaced
2523:139f182b72f6 2525:8b507a9a2d40
4 # 4 #
5 5
6 """ 6 """
7 Module implementing a tabbed viewmanager class. 7 Module implementing a tabbed viewmanager class.
8 """ 8 """
9
10 from __future__ import unicode_literals # __IGNORE_WARNING__
9 11
10 import os 12 import os
11 13
12 from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, QMimeData, Qt 14 from PyQt4.QtCore import QPoint, QFileInfo, pyqtSignal, QEvent, QByteArray, QMimeData, Qt
13 from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, QSplitter, \ 15 from PyQt4.QtGui import QWidget, QColor, QHBoxLayout, QDrag, QPixmap, QSplitter, \
54 """ 56 """
55 Constructor 57 Constructor
56 58
57 @param parent reference to the parent widget (QWidget) 59 @param parent reference to the parent widget (QWidget)
58 """ 60 """
59 super().__init__(parent) 61 super(TabBar, self).__init__(parent)
60 self.setAcceptDrops(True) 62 self.setAcceptDrops(True)
61 63
62 self.__dragStartPos = QPoint() 64 self.__dragStartPos = QPoint()
63 65
64 def mousePressEvent(self, event): 66 def mousePressEvent(self, event):
67 69
68 @param event reference to the mouse press event (QMouseEvent) 70 @param event reference to the mouse press event (QMouseEvent)
69 """ 71 """
70 if event.button() == Qt.LeftButton: 72 if event.button() == Qt.LeftButton:
71 self.__dragStartPos = QPoint(event.pos()) 73 self.__dragStartPos = QPoint(event.pos())
72 super().mousePressEvent(event) 74 super(TabBar, self).mousePressEvent(event)
73 75
74 def mouseMoveEvent(self, event): 76 def mouseMoveEvent(self, event):
75 """ 77 """
76 Protected method to handle mouse move events. 78 Protected method to handle mouse move events.
77 79
92 drag.setMimeData(mimeData) 94 drag.setMimeData(mimeData)
93 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): 95 if event.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier):
94 drag.exec_(Qt.DropActions(Qt.CopyAction)) 96 drag.exec_(Qt.DropActions(Qt.CopyAction))
95 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier): 97 elif event.modifiers() == Qt.KeyboardModifiers(Qt.NoModifier):
96 drag.exec_(Qt.DropActions(Qt.MoveAction)) 98 drag.exec_(Qt.DropActions(Qt.MoveAction))
97 super().mouseMoveEvent(event) 99 super(TabBar, self).mouseMoveEvent(event)
98 100
99 def dragEnterEvent(self, event): 101 def dragEnterEvent(self, event):
100 """ 102 """
101 Protected method to handle drag enter events. 103 Protected method to handle drag enter events.
102 104
108 mimeData.data("action") == "tab-reordering" and \ 110 mimeData.data("action") == "tab-reordering" and \
109 "tabbar-id" in formats and \ 111 "tabbar-id" in formats and \
110 "source-index" in formats and \ 112 "source-index" in formats and \
111 "tabwidget-id" in formats: 113 "tabwidget-id" in formats:
112 event.acceptProposedAction() 114 event.acceptProposedAction()
113 super().dragEnterEvent(event) 115 super(TabBar, self).dragEnterEvent(event)
114 116
115 def dropEvent(self, event): 117 def dropEvent(self, event):
116 """ 118 """
117 Protected method to handle drop events. 119 Protected method to handle drop events.
118 120
137 self.tabMoveRequested.emit(fromIndex, toIndex) 139 self.tabMoveRequested.emit(fromIndex, toIndex)
138 event.acceptProposedAction() 140 event.acceptProposedAction()
139 elif event.proposedAction() == Qt.CopyAction: 141 elif event.proposedAction() == Qt.CopyAction:
140 self.tabCopyRequested[int, int].emit(fromIndex, toIndex) 142 self.tabCopyRequested[int, int].emit(fromIndex, toIndex)
141 event.acceptProposedAction() 143 event.acceptProposedAction()
142 super().dropEvent(event) 144 super(TabBar, self).dropEvent(event)
143 145
144 146
145 class TabWidget(E5TabWidget): 147 class TabWidget(E5TabWidget):
146 """ 148 """
147 Class implementing a custimized tab widget. 149 Class implementing a custimized tab widget.
150 """ 152 """
151 Constructor 153 Constructor
152 154
153 @param vm view manager widget (Tabview) 155 @param vm view manager widget (Tabview)
154 """ 156 """
155 super().__init__() 157 super(TabWidget, self).__init__()
156 self.setAttribute(Qt.WA_DeleteOnClose, True) 158 self.setAttribute(Qt.WA_DeleteOnClose, True)
157 159
158 self.__tabBar = TabBar(self) 160 self.__tabBar = TabBar(self)
159 self.setTabBar(self.__tabBar) 161 self.setTabBar(self.__tabBar)
160 162
214 216
215 ericPic = QPixmap(os.path.join(getConfig('ericPixDir'), 'eric_small.png')) 217 ericPic = QPixmap(os.path.join(getConfig('ericPixDir'), 'eric_small.png'))
216 self.emptyLabel = QLabel() 218 self.emptyLabel = QLabel()
217 self.emptyLabel.setPixmap(ericPic) 219 self.emptyLabel.setPixmap(ericPic)
218 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter) 220 self.emptyLabel.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter)
219 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") 221 super(TabWidget, self).addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "")
220 222
221 def __initMenu(self): 223 def __initMenu(self):
222 """ 224 """
223 Private method to initialize the tab context menu. 225 Private method to initialize the tab context menu.
224 """ 226 """
329 @param assembly editor assembly object to be added 331 @param assembly editor assembly object to be added
330 (QScintilla.EditorAssembly.EditorAssembly) 332 (QScintilla.EditorAssembly.EditorAssembly)
331 @param title title for the new tab (string) 333 @param title title for the new tab (string)
332 """ 334 """
333 editor = assembly.getEditor() 335 editor = assembly.getEditor()
334 super().addTab(assembly, UI.PixmapCache.getIcon("empty.png"), title) 336 super(TabWidget, self).addTab(assembly, UI.PixmapCache.getIcon("empty.png"), title)
335 if self.closeButton: 337 if self.closeButton:
336 self.closeButton.setEnabled(True) 338 self.closeButton.setEnabled(True)
337 else: 339 else:
338 self.setTabsClosable(True) 340 self.setTabsClosable(True)
339 self.navigationButton.setEnabled(True) 341 self.navigationButton.setEnabled(True)
355 (QScintilla.EditorAssembly.EditorAssembly) 357 (QScintilla.EditorAssembly.EditorAssembly)
356 @param title title for the new tab (string) 358 @param title title for the new tab (string)
357 @return index of the inserted tab (integer) 359 @return index of the inserted tab (integer)
358 """ 360 """
359 editor = assembly.getEditor() 361 editor = assembly.getEditor()
360 newIndex = super().insertTab(index, assembly, 362 newIndex = super(TabWidget, self).insertTab(index, assembly,
361 UI.PixmapCache.getIcon("empty.png"), 363 UI.PixmapCache.getIcon("empty.png"),
362 title) 364 title)
363 if self.closeButton: 365 if self.closeButton:
364 self.closeButton.setEnabled(True) 366 self.closeButton.setEnabled(True)
365 else: 367 else:
418 index = self.indexOf(object) 420 index = self.indexOf(object)
419 if index > -1: 421 if index > -1:
420 self.removeTab(index) 422 self.removeTab(index)
421 423
422 if not self.editors: 424 if not self.editors:
423 super().addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "") 425 super(TabWidget, self).addTab(self.emptyLabel, UI.PixmapCache.getIcon("empty.png"), "")
424 self.emptyLabel.show() 426 self.emptyLabel.show()
425 if self.closeButton: 427 if self.closeButton:
426 self.closeButton.setEnabled(False) 428 self.closeButton.setEnabled(False)
427 else: 429 else:
428 self.setTabsClosable(False) 430 self.setTabsClosable(False)
493 @return reference to the current page (Editor) 495 @return reference to the current page (Editor)
494 """ 496 """
495 if not self.editors: 497 if not self.editors:
496 return None 498 return None
497 else: 499 else:
498 return super().currentWidget() 500 return super(TabWidget, self).currentWidget()
499 501
500 def setCurrentWidget(self, assembly): 502 def setCurrentWidget(self, assembly):
501 """ 503 """
502 Public method to set the current tab by the given editor assembly. 504 Public method to set the current tab by the given editor assembly.
503 505
504 @param assembly editor assembly to determine current tab from 506 @param assembly editor assembly to determine current tab from
505 (EditorAssembly.EditorAssembly) 507 (EditorAssembly.EditorAssembly)
506 """ 508 """
507 super().setCurrentWidget(assembly) 509 super(TabWidget, self).setCurrentWidget(assembly)
508 510
509 def indexOf(self, object): 511 def indexOf(self, object):
510 """ 512 """
511 Public method to get the tab index of the given editor. 513 Public method to get the tab index of the given editor.
512 514
513 @param object object to get the index for (QLabel or Editor) 515 @param object object to get the index for (QLabel or Editor)
514 @return tab index of the editor (integer) 516 @return tab index of the editor (integer)
515 """ 517 """
516 if isinstance(object, QScintilla.Editor.Editor): 518 if isinstance(object, QScintilla.Editor.Editor):
517 object = object.parent() 519 object = object.parent()
518 return super().indexOf(object) 520 return super(TabWidget, self).indexOf(object)
519 521
520 def hasEditor(self, editor): 522 def hasEditor(self, editor):
521 """ 523 """
522 Public method to check for an editor. 524 Public method to check for an editor.
523 525

eric ide

mercurial